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.
*/
dateStr = "2010-06-23T13:33:21Z";
dateObj = WarcDateParser.getDate(dateStr);
cases = generate_header_datatype_cases(dateObj, dateStr, WarcConstants.FN_WARC_DATE, "warcDateStr", "warcDate");
test_headeradd_object_cases(cases, WarcConstants.FDT_DATE);
String refersToDateStr = "2010-06-23T13:33:21Z";
Date refersToDateObj = WarcDateParser.getDate(refersToDateStr);
cases = generate_header_datatype_cases(refersToDateObj, refersToDateStr, WarcConstants.FN_WARC_REFERS_TO_DATE, "warcRefersToDateStr", "warcRefersToDate");
test_headeradd_object_cases(cases, WarcConstants.FDT_DATE);
/*
* InetAddress.
*/
inetAddressStr = "174.36.20.141";
inetAddressObj = null;
try {
inetAddressObj = InetAddress.getByName(inetAddressStr);
} catch (UnknownHostException e) {
e.printStackTrace();
Assert.fail("Unexpected exception!");
}
cases = generate_header_datatype_cases(inetAddressObj, inetAddressStr, WarcConstants.FN_WARC_IP_ADDRESS, "warcIpAddress", "warcInetAddress");
test_headeradd_object_cases(cases, WarcConstants.FDT_INETADDRESS);
/*
* URI.
*/
String recordIdStr = "urn:uuid:12eab1ec-8615-4f09-b6d2-976d96552073";
Uri recordIdObj = Uri.create(recordIdStr);
cases = generate_header_datatype_cases(recordIdObj, "<" + recordIdStr + ">", WarcConstants.FN_WARC_RECORD_ID, "warcRecordIdStr", "warcRecordIdUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
String refersToStr = "urn:uuid:bfa9d26b-ff19-402a-8508-e7ff852d4ded";
Uri refersToObj = Uri.create(refersToStr);
cases = generate_header_datatype_cases(refersToObj, "<" + refersToStr + ">", WarcConstants.FN_WARC_REFERS_TO, "warcRefersToStr", "warcRefersToUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
String targetUriStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
Uri targetUriObj = Uri.create(targetUriStr);
cases = generate_header_datatype_cases(targetUriObj, targetUriStr, WarcConstants.FN_WARC_TARGET_URI, "warcTargetUriStr", "warcTargetUriUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
String warcinfoIdStr = "urn:uuid:1cb0e3be-d9e2-4058-bf00-9775c75a71a6";
Uri warcinfoIdObj = Uri.create(warcinfoIdStr);
cases = generate_header_datatype_cases(warcinfoIdObj, "<" + warcinfoIdStr + ">", WarcConstants.FN_WARC_WARCINFO_ID, "warcWarcinfoIdStr", "warcWarcinfoIdUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
String segmentOriginIdStr = "urn:uuid:c4fc410a-4c7b-4bcc-a251-382b1d669f9a";
Uri segmentOriginIdObj = Uri.create(segmentOriginIdStr);
cases = generate_header_datatype_cases(segmentOriginIdObj, "<" + segmentOriginIdStr + ">", WarcConstants.FN_WARC_SEGMENT_ORIGIN_ID, "warcSegmentOriginIdStr", "warcSegmentOriginIdUrl");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
Object[][] concurrentHeaders = new Object[][] {
{Uri.create("urn:uuid:173a3db1-9ba4-496e-9eaf-6e550a62fd88"), "<urn:uuid:173a3db1-9ba4-496e-9eaf-6e550a62fd88>"},
{Uri.create("urn:uuid:660b74e7-076e-4698-abba-4eeeb8e09bf1"), "<urn:uuid:660b74e7-076e-4698-abba-4eeeb8e09bf1>"},
{Uri.create("urn:uuid:e6c0d888-b384-4ef4-a698-6166bc0875b8"), "<urn:uuid:e6c0d888-b384-4ef4-a698-6166bc0875b8>"}
};
cases = generate_multivalue_cases(concurrentHeaders, WarcConstants.FN_WARC_CONCURRENT_TO, "warcConcurrentToList");
test_headeradd_multivalue_object_cases(cases, WarcConstants.FDT_URI);
String warcProfileStr = WarcConstants.PROFILE_IDENTICAL_PAYLOAD_DIGEST;
Uri warcProfileObj = Uri.create(warcProfileStr);
cases = generate_header_datatype_cases(warcProfileObj, warcProfileStr, WarcConstants.FN_WARC_PROFILE, "warcProfileStr", "warcProfileUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
warcProfileStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
warcProfileObj = Uri.create(warcProfileStr);
cases = generate_header_datatype_cases(warcProfileObj, warcProfileStr, WarcConstants.FN_WARC_PROFILE, "warcProfileStr", "warcProfileUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
String warcRefersToTargetUriStr = "urn:uuid:de715d47-9f36-4cdf-84db-eb3b47dcd0e3";
Uri warcRefersToTargetUriObj = Uri.create(warcRefersToTargetUriStr);
cases = generate_header_datatype_cases(warcRefersToTargetUriObj, warcRefersToTargetUriStr, WarcConstants.FN_WARC_REFERS_TO_TARGET_URI, "warcRefersToTargetUriStr", "warcRefersToTargetUriUri");
test_headeradd_object_cases(cases, WarcConstants.FDT_URI);
/*
public List<WarcConcurrentTo> warcConcurrentToList = new LinkedList<WarcConcurrentTo>();