BrBETA_dnet-hadoop/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/collection/CollectionJobTest.java

80 lines
3.0 KiB
Java
Raw Normal View History

2019-03-18 10:47:28 +01:00
package eu.dnetlib.dhp.collection;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.model.mdstore.MetadataRecord;
import eu.dnetlib.dhp.model.mdstore.Provenance;
import org.apache.commons.io.FileUtils;
2019-03-18 10:47:28 +01:00
import org.apache.commons.io.IOUtils;
import org.junit.*;
2019-03-18 10:47:28 +01:00
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
2019-03-18 10:47:28 +01:00
public class CollectionJobTest {
private Path testDir;
2019-03-18 10:47:28 +01:00
@Before
public void setup() throws IOException {
testDir = Files.createTempDirectory("dhp-collection");
}
@After
public void teadDown() throws IOException {
FileUtils.deleteDirectory(testDir.toFile());
}
2019-03-18 10:47:28 +01:00
@Test
2019-10-29 18:10:20 +01:00
public void tesCollection() throws Exception {
2019-03-18 10:47:28 +01:00
Provenance provenance = new Provenance("pippo", "puppa", "ns_prefix");
GenerateNativeStoreSparkJob.main(new String[] {
"-mt", "local",
"-w", "wid",
"-e", "XML",
"-d", ""+System.currentTimeMillis(),
"-p", new ObjectMapper().writeValueAsString(provenance),
"-x", "./*[local-name()='record']/*[local-name()='header']/*[local-name()='identifier']",
"-i", this.getClass().getResource("/eu/dnetlib/dhp/collection/native.seq").toString(),
"-o", testDir.toString()+"/store",
"-t", "true",
"-ru", "",
"-rp", "",
"-rh", "",
"-ro", "",
"-rr", ""});
2019-04-03 16:05:16 +02:00
System.out.println(new ObjectMapper().writeValueAsString(provenance));
}
2019-03-18 10:47:28 +01:00
@Test
public void testGenerationMetadataRecord() throws Exception {
final String xml = IOUtils.toString(this.getClass().getResourceAsStream("./record.xml"));
MetadataRecord record = GenerateNativeStoreSparkJob.parseRecord(xml, "./*[local-name()='record']/*[local-name()='header']/*[local-name()='identifier']", "XML", new Provenance("foo", "bar", "ns_prefix"), System.currentTimeMillis(), null,null);
2019-04-03 16:05:16 +02:00
assert record != null;
2019-03-18 10:47:28 +01:00
System.out.println(record.getId());
System.out.println(record.getOriginalId());
}
@Test
public void TestEquals () throws IOException {
final String xml = IOUtils.toString(this.getClass().getResourceAsStream("./record.xml"));
MetadataRecord record = GenerateNativeStoreSparkJob.parseRecord(xml, "./*[local-name()='record']/*[local-name()='header']/*[local-name()='identifier']", "XML", new Provenance("foo", "bar", "ns_prefix"), System.currentTimeMillis(), null,null);
MetadataRecord record1 = GenerateNativeStoreSparkJob.parseRecord(xml, "./*[local-name()='record']/*[local-name()='header']/*[local-name()='identifier']", "XML", new Provenance("foo", "bar", "ns_prefix"), System.currentTimeMillis(), null,null);
2019-04-03 16:05:16 +02:00
assert record != null;
2019-03-18 10:47:28 +01:00
record.setBody("ciao");
2019-04-03 16:05:16 +02:00
assert record1 != null;
2019-03-18 10:47:28 +01:00
record1.setBody("mondo");
2019-04-03 16:05:16 +02:00
Assert.assertEquals(record, record1);
2019-03-18 10:47:28 +01:00
}
}