forked from D-Net/dnet-hadoop
tests
This commit is contained in:
parent
ad7a131b18
commit
478a958f09
|
@ -1,14 +1,15 @@
|
||||||
package eu.dnetlib.dhp.oa.graph.raw;
|
package eu.dnetlib.dhp.oa.graph.raw;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.schema.oaf.*;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -17,86 +18,121 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Dataset;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Oaf;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Publication;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Relation;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Software;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class MappersTest {
|
public class MappersTest {
|
||||||
|
|
||||||
@Mock private Map<String, String> code2name;
|
@Mock
|
||||||
|
private Map<String, String> code2name;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
when(code2name.get(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
when(code2name.get(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPublication() throws IOException {
|
void testPublication() throws IOException {
|
||||||
final String xml = IOUtils.toString(getClass().getResourceAsStream("oaf_record.xml"));
|
final String xml = IOUtils.toString(getClass().getResourceAsStream("oaf_record.xml"));
|
||||||
|
|
||||||
final List<Oaf> list = new OafToOafMapper(code2name).processMdRecord(xml);
|
final List<Oaf> list = new OafToOafMapper(code2name).processMdRecord(xml);
|
||||||
|
|
||||||
assertEquals(3, list.size());
|
assertEquals(3, list.size());
|
||||||
assertTrue(list.get(0) instanceof Publication);
|
assertTrue(list.get(0) instanceof Publication);
|
||||||
assertTrue(list.get(1) instanceof Relation);
|
assertTrue(list.get(1) instanceof Relation);
|
||||||
assertTrue(list.get(2) instanceof Relation);
|
assertTrue(list.get(2) instanceof Relation);
|
||||||
|
|
||||||
final Publication p = (Publication) list.get(0);
|
final Publication p = (Publication) list.get(0);
|
||||||
final Relation r1 = (Relation) list.get(1);
|
final Relation r1 = (Relation) list.get(1);
|
||||||
final Relation r2 = (Relation) list.get(2);
|
final Relation r2 = (Relation) list.get(2);
|
||||||
|
|
||||||
assertValidId(p.getId());
|
assertValidId(p.getId());
|
||||||
assertTrue(StringUtils.isNotBlank(p.getTitle().get(0).getValue()));
|
assertTrue(StringUtils.isNotBlank(p.getTitle().get(0).getValue()));
|
||||||
assertTrue(p.getAuthor().size() > 0);
|
assertTrue(p.getAuthor().size() > 0);
|
||||||
assertTrue(p.getSubject().size() > 0);
|
assertTrue(p.getSubject().size() > 0);
|
||||||
assertTrue(StringUtils.isNotBlank(p.getJournal().getIssnOnline()));
|
assertTrue(StringUtils.isNotBlank(p.getJournal().getIssnOnline()));
|
||||||
assertTrue(StringUtils.isNotBlank(p.getJournal().getName()));
|
assertTrue(StringUtils.isNotBlank(p.getJournal().getName()));
|
||||||
|
|
||||||
assertValidId(r1.getSource());
|
assertValidId(r1.getSource());
|
||||||
assertValidId(r2.getSource());
|
assertValidId(r2.getTarget());
|
||||||
assertEquals(r1.getSource(), r2.getTarget());
|
assertValidId(r2.getSource());
|
||||||
assertEquals(r2.getSource(), r1.getTarget());
|
assertValidId(r2.getTarget());
|
||||||
assertTrue(StringUtils.isNotBlank(r1.getRelClass()));
|
assertNotNull(r1.getDataInfo());
|
||||||
assertTrue(StringUtils.isNotBlank(r2.getRelClass()));
|
assertNotNull(r2.getDataInfo());
|
||||||
assertTrue(StringUtils.isNotBlank(r1.getRelType()));
|
assertNotNull(r1.getDataInfo().getTrust());
|
||||||
assertTrue(StringUtils.isNotBlank(r2.getRelType()));
|
assertNotNull(r2.getDataInfo().getTrust());
|
||||||
}
|
assertEquals(r1.getSource(), r2.getTarget());
|
||||||
|
assertEquals(r2.getSource(), r1.getTarget());
|
||||||
|
assertTrue(StringUtils.isNotBlank(r1.getRelClass()));
|
||||||
|
assertTrue(StringUtils.isNotBlank(r2.getRelClass()));
|
||||||
|
assertTrue(StringUtils.isNotBlank(r1.getRelType()));
|
||||||
|
assertTrue(StringUtils.isNotBlank(r2.getRelType()));
|
||||||
|
|
||||||
@Test
|
// System.out.println(new ObjectMapper().writeValueAsString(r1));
|
||||||
void testDataset() throws IOException {
|
// System.out.println(new ObjectMapper().writeValueAsString(r2));
|
||||||
final String xml = IOUtils.toString(getClass().getResourceAsStream("odf_dataset.xml"));
|
}
|
||||||
|
|
||||||
final List<Oaf> list = new OdfToOafMapper(code2name).processMdRecord(xml);
|
@Test
|
||||||
|
void testDataset() throws IOException {
|
||||||
|
final String xml = IOUtils.toString(getClass().getResourceAsStream("odf_dataset.xml"));
|
||||||
|
|
||||||
assertEquals(1, list.size());
|
final List<Oaf> list = new OdfToOafMapper(code2name).processMdRecord(xml);
|
||||||
assertTrue(list.get(0) instanceof Dataset);
|
|
||||||
|
|
||||||
final Dataset d = (Dataset) list.get(0);
|
assertEquals(3, list.size());
|
||||||
|
assertTrue(list.get(0) instanceof Dataset);
|
||||||
|
assertTrue(list.get(1) instanceof Relation);
|
||||||
|
assertTrue(list.get(2) instanceof Relation);
|
||||||
|
|
||||||
assertValidId(d.getId());
|
final Dataset d = (Dataset) list.get(0);
|
||||||
assertTrue(StringUtils.isNotBlank(d.getTitle().get(0).getValue()));
|
final Relation r1 = (Relation) list.get(1);
|
||||||
assertTrue(d.getAuthor().size() > 0);
|
final Relation r2 = (Relation) list.get(2);
|
||||||
assertTrue(d.getSubject().size() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
assertValidId(d.getId());
|
||||||
void testSoftware() throws IOException {
|
assertTrue(StringUtils.isNotBlank(d.getTitle().get(0).getValue()));
|
||||||
final String xml = IOUtils.toString(getClass().getResourceAsStream("odf_software.xml"));
|
assertTrue(d.getAuthor().size() > 0);
|
||||||
|
assertTrue(d.getSubject().size() > 0);
|
||||||
|
|
||||||
final List<Oaf> list = new OdfToOafMapper(code2name).processMdRecord(xml);
|
assertValidId(r1.getSource());
|
||||||
|
assertValidId(r2.getTarget());
|
||||||
|
assertValidId(r2.getSource());
|
||||||
|
assertValidId(r2.getTarget());
|
||||||
|
assertNotNull(r1.getDataInfo());
|
||||||
|
assertNotNull(r2.getDataInfo());
|
||||||
|
assertNotNull(r1.getDataInfo().getTrust());
|
||||||
|
assertNotNull(r2.getDataInfo().getTrust());
|
||||||
|
assertEquals(r1.getSource(), r2.getTarget());
|
||||||
|
assertEquals(r2.getSource(), r1.getTarget());
|
||||||
|
assertTrue(StringUtils.isNotBlank(r1.getRelClass()));
|
||||||
|
assertTrue(StringUtils.isNotBlank(r2.getRelClass()));
|
||||||
|
assertTrue(StringUtils.isNotBlank(r1.getRelType()));
|
||||||
|
assertTrue(StringUtils.isNotBlank(r2.getRelType()));
|
||||||
|
}
|
||||||
|
|
||||||
assertEquals(1, list.size());
|
@Test
|
||||||
assertTrue(list.get(0) instanceof Software);
|
void testSoftware() throws IOException {
|
||||||
|
final String xml = IOUtils.toString(getClass().getResourceAsStream("odf_software.xml"));
|
||||||
|
|
||||||
final Software s = (Software) list.get(0);
|
final List<Oaf> list = new OdfToOafMapper(code2name).processMdRecord(xml);
|
||||||
|
|
||||||
assertValidId(s.getId());
|
assertEquals(1, list.size());
|
||||||
assertTrue(StringUtils.isNotBlank(s.getTitle().get(0).getValue()));
|
assertTrue(list.get(0) instanceof Software);
|
||||||
assertTrue(s.getAuthor().size() > 0);
|
|
||||||
assertTrue(s.getSubject().size() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertValidId(final String id) {
|
final Software s = (Software) list.get(0);
|
||||||
assertEquals(49, id.length());
|
|
||||||
assertEquals('|', id.charAt(2));
|
assertValidId(s.getId());
|
||||||
assertEquals(':', id.charAt(15));
|
assertTrue(StringUtils.isNotBlank(s.getTitle().get(0).getValue()));
|
||||||
assertEquals(':', id.charAt(16));
|
assertTrue(s.getAuthor().size() > 0);
|
||||||
}
|
assertTrue(s.getSubject().size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertValidId(final String id) {
|
||||||
|
assertEquals(49, id.length());
|
||||||
|
assertEquals('|', id.charAt(2));
|
||||||
|
assertEquals(':', id.charAt(15));
|
||||||
|
assertEquals(':', id.charAt(16));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,7 @@
|
||||||
<oaf:language>und</oaf:language>
|
<oaf:language>und</oaf:language>
|
||||||
<oaf:concept id="https://zenodo.org/communities/epfl"/>
|
<oaf:concept id="https://zenodo.org/communities/epfl"/>
|
||||||
<oaf:hostedBy id="re3data_____::r3d100010468" name="Zenodo"/>
|
<oaf:hostedBy id="re3data_____::r3d100010468" name="Zenodo"/>
|
||||||
|
<oaf:projectid>corda_______::226852</oaf:projectid>
|
||||||
<oaf:collectedFrom id="re3data_____::r3d100010468" name="Zenodo"/>
|
<oaf:collectedFrom id="re3data_____::r3d100010468" name="Zenodo"/>
|
||||||
</metadata>
|
</metadata>
|
||||||
<about xmlns:dc="http://purl.org/dc/elements/1.1/"
|
<about xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
|
Loading…
Reference in New Issue