public class TestArcVersionHeader {
@Test
public void test_arcversionheader() {
ByteArrayInputStream in;
ByteCountingPushBackInputStream pbin;
ArcFieldParsers fieldParsers = new ArcFieldParsers();
Diagnostics<Diagnosis> diagnostics = new Diagnostics<Diagnosis>();
fieldParsers.diagnostics = diagnostics;
ArcVersionHeader header;
byte[] bytes;
String digestAlgorithm = null;
Long length = 0L;
Object[][] expectedDiagnoses;
String tmpStr;
try {
bytes = new byte[0];
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
/*
* Invalid parameters.
*/
try {
ArcVersionHeader.create(null, null);
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
try {
ArcVersionHeader.create(ArcVersion.VERSION_1, null);
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
try {
ArcVersionHeader.create(ArcVersion.VERSION_1, "");
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
try {
header = ArcVersionHeader.processPayload(null, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
try {
header = ArcVersionHeader.processPayload(pbin, -1, digestAlgorithm, fieldParsers, diagnostics);
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
try {
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, null, diagnostics);
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
try {
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, null);
Assert.fail("Exception expected!");
} catch (IllegalArgumentException e) {
}
/*
* Empty stream.
*/
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* Single newline.
*/
bytes = "\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* 2 newlines.
*/
bytes = "\n\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* Newline and v1 block desc.
*/
bytes = ("\n" + ArcConstants.VERSION_1_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(1, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* Newline and v2 block desc.
*/
bytes = ("\n" + ArcConstants.VERSION_2_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(2, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.
*/
bytes = "1 0 InternetArchive\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1, header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.1.
*/
bytes = "1 1 InternetArchive\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1_1, header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V2.
*/
bytes = "2 0 InternetArchive\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_2, header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* Vx.0.
*/
bytes = "x 0 InternetArchive\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID_EXPECTED, "'" + ArcConstants.FN_VERSION_NUMBER + "' value", 2},
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.x.
*/
bytes = "1 x InternetArchive\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertFalse(header.isVersionValid);
Assert.assertNull(header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID_EXPECTED, "'" + ArcConstants.FN_RESERVED + "' value", 2},
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.0 invalid block desc.
*/
bytes = "1 0 InternetArchive\nAtomic Twister!\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1, header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.0 incomplete.
*/
bytes = "1 0\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1, header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.0 too long.
*/
bytes = "1 0 Internet Archive\n".getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1, header.version);
Assert.assertFalse(header.isValidBlockdDesc);
Assert.assertEquals(0, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1},
{DiagnosisType.ERROR, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V2.0 and v1 block desc.
*/
bytes = ("2 0 InternetArchive\n" + ArcConstants.VERSION_1_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_2, header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(1, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.0 and v2 block desc.
*/
bytes = ("1 0 InternetArchive\n" + ArcConstants.VERSION_2_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1, header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(2, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* Newline and v2 block desc.
*/
bytes = ("1 1 InternetArchive\n" + ArcConstants.VERSION_2_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertFalse(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1_1, header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(2, header.blockDescVersion);
Assert.assertTrue(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 0);
expectedDiagnoses = new Object[][] {
{DiagnosisType.INVALID, ArcConstants.ARC_VERSION_BLOCK, 1}
};
TestBaseUtils.compareDiagnoses(expectedDiagnoses, header.diagnostics.getErrors());
diagnostics.reset();
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.0 and v1 block desc.
*/
bytes = ("1 0 InternetArchive\n" + ArcConstants.VERSION_1_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertTrue(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1, header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(1, header.blockDescVersion);
Assert.assertFalse(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 10);
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V1.1 and v1 block desc.
*/
String mdData;
mdData = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n";
mdData += "<arcmetadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\"" +
" xmlns:dcterms=\"http://purl.org/dc/terms/\"" +
" xmlns:arc=\"http://archive.org/arc/1.0/\"" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
" xmlns=\"http://archive.org/arc/1.0/\"" +
" xsi:schemaLocation=\"http://archive.org/arc/1.0/ http://www.archive.org/arc/1.0/arc.xsd\">\r\n";
mdData += "<arc:software>Heritrix @VERSION@ http://crawler.archive.org</arc:software>\r\n";
mdData += "<arc:hostname>blackbook</arc:hostname>\r\n";
mdData += "<arc:ip>192.168.1.13</arc:ip>\r\n";
mdData += "<dcterms:isPartOf>archive.org-shallow</dcterms:isPartOf>\r\n";
mdData += "<dc:description>archive.org shallow</dc:description>\r\n";
mdData += "<arc:operator>Admin</arc:operator>\r\n";
mdData += "<ns0:date xmlns:ns0=\"http://purl.org/dc/elements/1.1/\" xsi:type=\"dcterms:W3CDTF\">2008-04-30T20:48:24+00:00</ns0:date>\r\n";
mdData += "<arc:http-header-user-agent>Mozilla/5.0 (compatible; heritrix/1.14.0 +http://crawler.archive.org)</arc:http-header-user-agent>\r\n";
mdData += "<arc:http-header-from>archive-crawler-agent@lists.sourceforge.net</arc:http-header-from>\r\n";
mdData += "<arc:robots>classic</arc:robots>\r\n";
mdData += "<dc:format>ARC file version 1.1</dc:format>\r\n";
mdData += "<dcterms:conformsTo xsi:type=\"dcterms:URI\">http://www.archive.org/web/researcher/ArcFileFormat.php</dcterms:conformsTo>\r\n";
mdData += "</arcmetadata>\r\n";
bytes = ("1 1 InternetArchive\n" + ArcConstants.VERSION_1_BLOCK_DEF + "\n" + mdData).getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertTrue(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_1_1, header.version);
Assert.assertTrue(header.isValidBlockdDesc);
Assert.assertEquals(1, header.blockDescVersion);
Assert.assertFalse(header.diagnostics.hasErrors());
Assert.assertFalse(header.diagnostics.hasWarnings());
// Save testfile.
SaveArcTestFiles.saveTestArcVersionHeader(bytes,
!header.diagnostics.hasErrors() && !header.diagnostics.hasWarnings(), 11);
tmpStr = header.toString();
Assert.assertNotNull(tmpStr);
/*
* V2.0 and v2 block desc.
*/
bytes = ("2 0 InternetArchive\n" + ArcConstants.VERSION_2_BLOCK_DEF + "\n").getBytes();
length = (long)bytes.length;
in = new ByteArrayInputStream(bytes);
pbin = new ByteCountingPushBackInputStream(in, 8192);
header = ArcVersionHeader.processPayload(pbin, length, digestAlgorithm, fieldParsers, diagnostics);
Assert.assertTrue(header.isValid());
Assert.assertTrue(header.isVersionValid);
Assert.assertEquals(ArcVersion.VERSION_2, header.version);