/
WarcRecordClientTest.java
91 lines (75 loc) · 3.48 KB
/
WarcRecordClientTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package dk.netarkivet.common.utils.warc;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.io.IOUtils;
import org.archive.io.ArchiveReader;
import org.archive.io.ArchiveRecord;
import org.archive.io.warc.WARCReaderFactory;
import org.archive.io.warc.WARCRecord;
import org.junit.Test;
import dk.netarkivet.common.distribute.arcrepository.BitarchiveRecord;
import dk.netarkivet.common.utils.service.WarcRecordClient;
public class WarcRecordClientTest {
final String WRS_URL = "https://localhost:10443/cgi-bin/warcrecordservice.cgi";
@Test
public void testBuildingBitarchiveRecord() throws IOException {
String fileName = "thisisa.warc";
File inputFile = new File("src/test/java/data.txt");
System.out.println(inputFile.getAbsolutePath());
// String fileName = inputFile.getName();
System.out.println("Name: " + fileName);
FileInputStream fileInputStream = new FileInputStream(inputFile);
ArchiveReader archiveReader = WARCReaderFactory.get(fileName, fileInputStream, true);
ArchiveRecord archiveRecord = archiveReader.get();
BitarchiveRecord bitarchiveRecord = new BitarchiveRecord(archiveRecord, fileName);
bitarchiveRecord.getData(System.out);
}
@Test
public void testBuildingBitarchiveRecord2() throws IOException {
String filename = "thisisa.warc";
File inputFile = new File("src/test/java/data.txt");
System.out.println(inputFile.getAbsolutePath());
FileInputStream fileInputStream = new FileInputStream(inputFile);
WARCRecord warcRecord = new WARCRecord(fileInputStream, filename, 0);
BitarchiveRecord bitarchiveRecord = new BitarchiveRecord(warcRecord, filename);
bitarchiveRecord.getData(System.out);
}
@Test
public void getHttpClient() {
}
@Test
public void getInstance() {
}
@Test
public void getWarc() {
}
@Test
public void get() throws IOException, URISyntaxException {
URI baseUri = new URI(WRS_URL);
//setting to NetarchiveSuite.
WarcRecordClient warcRecordClient = new WarcRecordClient(baseUri);
BitarchiveRecord bitarchiveRecord = warcRecordClient.getBitarchiveRecord("10-4-20161218234343407-00000-kb-test-har-003.kb.dk.warc.gz", 3442L);
assertNotNull("Should have non null BitarchiveRecord", bitarchiveRecord);
assertTrue("Expect a non-zero length bitarchiveRecord", IOUtils.toByteArray(bitarchiveRecord.getData()).length > 100);
System.out.println("\n\n" + IOUtils.toString(bitarchiveRecord.getData()));
}
@Test
public void getWithArc() throws IOException, URISyntaxException {
URI baseUri = new URI(WRS_URL);
//setting to NetarchiveSuite.
WarcRecordClient warcRecordClient = new WarcRecordClient(baseUri);
String filename = "42-23-20060726143926-00000-udvikling.kb.dk.arc.gz";
BitarchiveRecord bitarchiveRecord = warcRecordClient.getBitarchiveRecord(filename, 682L);
assertNotNull("Should have non null BitarchiveRecord", bitarchiveRecord);
assertTrue("Expect a non-zero length bitarchiveRecord", IOUtils.toByteArray(bitarchiveRecord.getData()).length > 10);
System.out.println("\n\n" + IOUtils.toString(bitarchiveRecord.getData()));
}
@Test
public void getFile() {
}
}