1
|
package eu.dnetlib.data.oai.store.mongo;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.util.zip.ZipEntry;
|
5
|
import java.util.zip.ZipOutputStream;
|
6
|
|
7
|
import org.apache.commons.io.IOUtils;
|
8
|
import org.apache.commons.io.output.ByteArrayOutputStream;
|
9
|
import org.bson.types.Binary;
|
10
|
import org.junit.Before;
|
11
|
import org.junit.Test;
|
12
|
import org.springframework.core.io.ClassPathResource;
|
13
|
|
14
|
import eu.dnetlib.oai.conf.OAIConfigurationReader;
|
15
|
import eu.dnetlib.oai.mongo.RecordInfoGenerator;
|
16
|
|
17
|
/**
|
18
|
* RecordInfoGenerator Tester.
|
19
|
*
|
20
|
* @author <Authors name>
|
21
|
* @version 1.0
|
22
|
* @since
|
23
|
*
|
24
|
* <pre>
|
25
|
* Apr 6, 2016
|
26
|
* </pre>
|
27
|
*/
|
28
|
public class RecordInfoGeneratorTest {
|
29
|
|
30
|
private final RecordInfoGenerator gen = new RecordInfoGenerator();
|
31
|
private final String filePath = "/eu/dnetlib/data/oai/store/mongo/testRecord.xml";
|
32
|
private Binary binaryXML;
|
33
|
|
34
|
@Before
|
35
|
public void before() throws Exception {
|
36
|
final String testRecord = IOUtils.toString(new ClassPathResource(this.filePath).getInputStream());
|
37
|
this.binaryXML = createCompressRecord(testRecord);
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Method: decompressRecord(final byte[] input)
|
42
|
*/
|
43
|
@Test
|
44
|
public void testDecompressRecord() throws Exception {
|
45
|
final long timeStart = System.currentTimeMillis();
|
46
|
final String record = this.gen.decompressRecord(this.binaryXML.getData());
|
47
|
final long timeEnd = System.currentTimeMillis();
|
48
|
System.out.println("Decompressed record in ms " + (timeEnd - timeStart));
|
49
|
System.out.println(record);
|
50
|
}
|
51
|
|
52
|
private Binary createCompressRecord(final String record) throws IOException {
|
53
|
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
54
|
final ZipOutputStream zos = new ZipOutputStream(os);
|
55
|
final ZipEntry entry = new ZipEntry(OAIConfigurationReader.BODY_FIELD);
|
56
|
zos.putNextEntry(entry);
|
57
|
zos.write(record.getBytes());
|
58
|
zos.closeEntry();
|
59
|
// zos.flush();
|
60
|
zos.close();
|
61
|
return new Binary(os.toByteArray());
|
62
|
}
|
63
|
|
64
|
}
|