String digestStr = "sha1:Y4N5SWNQBIBIGQ66IFXDMLGJW6FZFV6U";
WarcDigest digestObj = WarcDigest.parseWarcDigest(digestStr);
String contentTypeStr = "application/http; msgtype=response";
ContentType contentTypeObj = ContentType.parseContentType(contentTypeStr);
String dateStr = "2012-05-17T00:14:47Z";
Date dateObj = WarcDateParser.getDate(dateStr);
String inetAddressStr = "172.20.10.12";
InetAddress inetAddressObj = null;
try {
inetAddressObj = InetAddress.getByName(inetAddressStr);
} catch (UnknownHostException e) {
e.printStackTrace();
Assert.fail("Unexpected exception!");
}
String uriStr = "urn:uuid:a1bc4f20-d057-44bd-a299-bdf31f4dfa53";
Uri uriObj = Uri.create(uriStr);
/*
* Non warc headers.
*/
header = getTestHeader();
headerLine = header.addHeader("X-Header1", dateObj, dateStr);
Assert.assertNotNull(headerLine);
Assert.assertEquals("X-Header1", headerLine.name);
Assert.assertEquals(dateStr, headerLine.value);
headerLine = header.addHeader("X-Header2", dateObj, dateStr);
Assert.assertNotNull(headerLine);
Assert.assertEquals("X-Header2", headerLine.name);
Assert.assertEquals(dateStr, headerLine.value);
/*
* Duplicate date headers.
*/
header = getTestHeader();
headerLine = header.addHeader("WARC-Date", dateObj, dateStr);
Assert.assertNotNull(headerLine);
Assert.assertEquals("WARC-Date", headerLine.name);
Assert.assertEquals(dateStr, headerLine.value);
errors = header.diagnostics.getErrors();
warnings = header.diagnostics.getWarnings();
Assert.assertEquals(0, errors.size());
Assert.assertEquals(0, warnings.size());
headerLine = header.addHeader("WARC-Date", dateObj, dateStr);
Assert.assertNotNull(headerLine);
Assert.assertEquals("WARC-Date", headerLine.name);
Assert.assertEquals(dateStr, headerLine.value);
errors = header.diagnostics.getErrors();
warnings = header.diagnostics.getWarnings();
Assert.assertEquals(1, errors.size());
Assert.assertEquals(0, warnings.size());
diagnosis = errors.get(0);
Assert.assertEquals(DiagnosisType.DUPLICATE, diagnosis.type);
Assert.assertEquals("'WARC-Date' header", diagnosis.entity);
Assert.assertEquals(1, diagnosis.information.length);
/*
* Integer add header.
*/
cases = generate_invalid_datatype_cases(integerObj, integerStr, WarcConstants.FN_WARC_SEGMENT_NUMBER, WarcConstants.FN_WARC_RECORD_ID);
test_headeradd_object_cases(cases, WarcConstants.FDT_INTEGER);
/*
* Long add header.
*/
cases = generate_invalid_datatype_cases(longObj, longStr, WarcConstants.FN_CONTENT_LENGTH, WarcConstants.FN_CONTENT_TYPE);
test_headeradd_object_cases(cases, WarcConstants.FDT_LONG);
/*
* Digest add header.
*/
cases = generate_invalid_datatype_cases(digestObj, digestStr, WarcConstants.FN_WARC_BLOCK_DIGEST, WarcConstants.FN_WARC_SEGMENT_NUMBER);
test_headeradd_object_cases(cases, WarcConstants.FDT_DIGEST);
/*
* ContentType add header.
*/
cases = generate_invalid_datatype_cases(contentTypeObj, contentTypeStr, WarcConstants.FN_CONTENT_TYPE, WarcConstants.FN_WARC_BLOCK_DIGEST);
test_headeradd_object_cases(cases, WarcConstants.FDT_CONTENTTYPE);
/*
* Date add header.
*/
cases = generate_invalid_datatype_cases(dateObj, dateStr, WarcConstants.FN_WARC_DATE, WarcConstants.FN_CONTENT_TYPE);
test_headeradd_object_cases(cases, WarcConstants.FDT_DATE);
/*
* InetAddress add header.
*/
cases = generate_invalid_datatype_cases(inetAddressObj, inetAddressStr, WarcConstants.FN_WARC_IP_ADDRESS, WarcConstants.FN_WARC_DATE);
test_headeradd_object_cases(cases, WarcConstants.FDT_INETADDRESS);
/*
* URI add header.
*/
cases = generate_invalid_datatype_cases(uriObj, "<" + uriStr + ">", WarcConstants.FN_WARC_RECORD_ID, WarcConstants.FN_WARC_IP_ADDRESS);
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
/*
* Test datatype for headers.
*/
/*
WarcConstants.FN_WARC_TYPE
WarcConstants.FN_WARC_TRUNCATED
WarcConstants.FN_WARC_FILENAME
WarcConstants.FN_WARC_PROFILE
*/
/*
* Integer.
*/
String segmentNrStr = "42";
Integer segmentNrObj = Integer.parseInt(segmentNrStr);
cases = generate_header_datatype_cases(segmentNrObj, segmentNrStr, WarcConstants.FN_WARC_SEGMENT_NUMBER, "warcSegmentNumberStr", "warcSegmentNumber");
test_headeradd_object_cases(cases, WarcConstants.FDT_INTEGER);
/*
* Long.
*/
String contentLengthStr = "1234567890123456";
Long contentLengthObj = Long.parseLong(contentLengthStr);
cases = generate_header_datatype_cases(contentLengthObj, contentLengthStr, WarcConstants.FN_CONTENT_LENGTH, "contentLengthStr", "contentLength");
test_headeradd_object_cases(cases, WarcConstants.FDT_LONG);
String segmentTotalLengthStr = "9876543210987654";
Long segmentTotalLengthObj = Long.parseLong(segmentTotalLengthStr);
cases = generate_header_datatype_cases(segmentTotalLengthObj, segmentTotalLengthStr, WarcConstants.FN_WARC_SEGMENT_TOTAL_LENGTH, "warcSegmentTotalLengthStr", "warcSegmentTotalLength");
test_headeradd_object_cases(cases, WarcConstants.FDT_LONG);
/*
* Digest.
*/
String blockDigestStr = "sha1:Y4N5SWNQBIBIGQ66IFXDMLGJW6FZFV6U";
WarcDigest blockDigestObj = WarcDigest.parseWarcDigest(blockDigestStr);
cases = generate_header_datatype_cases(blockDigestObj, blockDigestStr, WarcConstants.FN_WARC_BLOCK_DIGEST, "warcBlockDigestStr", "warcBlockDigest");
test_headeradd_object_cases(cases, WarcConstants.FDT_DIGEST);
String payloadDigestStr = "sha1:BCCYP7NW6QIIOSM523Y5XHQKE5KWLMBD";
WarcDigest payloadDigestObj = WarcDigest.parseWarcDigest(payloadDigestStr);
cases = generate_header_datatype_cases(payloadDigestObj, payloadDigestStr, WarcConstants.FN_WARC_PAYLOAD_DIGEST, "warcPayloadDigestStr", "warcPayloadDigest");
test_headeradd_object_cases(cases, WarcConstants.FDT_DIGEST);
/*
* ContentType.
*/
contentTypeStr = "application/http; msgtype=request";
contentTypeObj = ContentType.parseContentType(contentTypeStr);
cases = generate_header_datatype_cases(contentTypeObj, contentTypeStr, WarcConstants.FN_CONTENT_TYPE, "contentTypeStr", "contentType");
test_headeradd_object_cases(cases, WarcConstants.FDT_CONTENTTYPE);
String identifiedPayloadTypeStr = "application/http; msgtype=response";
ContentType identifiedPayloadTypeObj = ContentType.parseContentType(identifiedPayloadTypeStr);
cases = generate_header_datatype_cases(identifiedPayloadTypeObj, identifiedPayloadTypeStr, WarcConstants.FN_WARC_IDENTIFIED_PAYLOAD_TYPE, "warcIdentifiedPayloadTypeStr", "warcIdentifiedPayloadType");
test_headeradd_object_cases(cases, WarcConstants.FDT_CONTENTTYPE);
/*
* Date.