forked from Aloisius/ia-web-commons
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WAT: Duplicated payload metadata values for "Actual-Content-Length" a…
…nd "Trailing-Slop-Length" fixes #43 - avoid to add a duplicated "Actual-Content-Length" value - do not add a second value of "Trailing-Slop-Length" if 0
- Loading branch information
1 parent
bf9a9e0
commit 8f4c43f
Showing
6 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/org/archive/resource/arc/ARCResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.archive.resource.arc; | ||
|
||
|
||
import static org.archive.resource.ResourceConstants.PAYLOAD_LENGTH; | ||
import static org.archive.resource.ResourceConstants.PAYLOAD_SLOP_BYTES; | ||
|
||
import java.io.IOException; | ||
|
||
import org.archive.extract.ExtractingResourceFactoryMapper; | ||
import org.archive.extract.ExtractingResourceProducer; | ||
import org.archive.extract.ProducerUtils; | ||
import org.archive.extract.ResourceFactoryMapper; | ||
import org.archive.resource.Resource; | ||
import org.archive.resource.ResourceParseException; | ||
import org.archive.resource.ResourceProducer; | ||
import org.archive.util.StreamCopy; | ||
|
||
import com.github.openjson.JSONObject; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class ARCResourceTest extends TestCase { | ||
|
||
public void testARCResource() throws ResourceParseException, IOException { | ||
String testFileName = "../../format/arc/IAH-20080430204825-00000-blackbook-truncated.arc"; | ||
ResourceProducer producer = ProducerUtils.getProducer(getClass().getResource(testFileName).getPath()); | ||
ResourceFactoryMapper mapper = new ExtractingResourceFactoryMapper(); | ||
ExtractingResourceProducer extractor = new ExtractingResourceProducer(producer, mapper); | ||
|
||
Resource resource = extractor.getNext(); | ||
|
||
while (resource != null) { | ||
JSONObject payloadMD = resource.getMetaData().getTopMetaData().getJSONObject("Envelope") | ||
.getJSONObject("Payload-Metadata"); | ||
System.err.println(payloadMD); | ||
|
||
if (payloadMD.has(PAYLOAD_LENGTH)) { | ||
assertTrue(payloadMD.getLong(PAYLOAD_LENGTH) != -1); | ||
} | ||
if (payloadMD.has(PAYLOAD_SLOP_BYTES)) { | ||
// does not occur with the tested ARC file | ||
} | ||
|
||
StreamCopy.readToEOF(resource.getInputStream()); | ||
resource = extractor.getNext(); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/org/archive/resource/warc/WARCResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.archive.resource.warc; | ||
|
||
import static org.archive.resource.ResourceConstants.PAYLOAD_LENGTH; | ||
import static org.archive.resource.ResourceConstants.PAYLOAD_SLOP_BYTES; | ||
|
||
import java.io.IOException; | ||
|
||
import org.archive.extract.ExtractingResourceFactoryMapper; | ||
import org.archive.extract.ExtractingResourceProducer; | ||
import org.archive.extract.ProducerUtils; | ||
import org.archive.extract.ResourceFactoryMapper; | ||
import org.archive.resource.Resource; | ||
import org.archive.resource.ResourceParseException; | ||
import org.archive.resource.ResourceProducer; | ||
import org.archive.util.StreamCopy; | ||
|
||
import com.github.openjson.JSONObject; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class WARCResourceTest extends TestCase { | ||
|
||
public void testWARCResource() throws ResourceParseException, IOException { | ||
String testFileName = "../../format/warc/IAH-urls-wget.warc"; | ||
ResourceProducer producer = ProducerUtils.getProducer(getClass().getResource(testFileName).getPath()); | ||
ResourceFactoryMapper mapper = new ExtractingResourceFactoryMapper(); | ||
ExtractingResourceProducer extractor = new ExtractingResourceProducer(producer, mapper); | ||
|
||
Resource resource = extractor.getNext(); | ||
|
||
while (resource != null) { | ||
JSONObject payloadMD = resource.getMetaData().getTopMetaData().getJSONObject("Envelope") | ||
.getJSONObject("Payload-Metadata"); | ||
|
||
if (payloadMD.has(PAYLOAD_LENGTH)) { | ||
assertTrue(payloadMD.getLong(PAYLOAD_LENGTH) != -1); | ||
} | ||
if (payloadMD.has(PAYLOAD_SLOP_BYTES)) { | ||
assertEquals(4, payloadMD.getLong(PAYLOAD_SLOP_BYTES)); | ||
} | ||
|
||
StreamCopy.readToEOF(resource.getInputStream()); | ||
resource = extractor.getNext(); | ||
} | ||
} | ||
} |