From 1dd1e4fe3a224935d3c021f09ae4284e2a22b29e Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Thu, 28 Jul 2022 11:27:08 +0200 Subject: [PATCH] extended test for mapping project_organization relations --- .../raw/MigrateDbEntitiesApplication.java | 2 +- .../raw/MigrateDbEntitiesApplicationTest.java | 62 ++++++++++++++----- .../projectorganization_resultset_entry.json | 17 +++-- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java index 8296e99cd..f40d3d19b 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java @@ -440,7 +440,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List properties = Lists .newArrayList( - keyValue("contribution", String.valueOf(rs.getDouble("totalcost"))), + keyValue("contribution", String.valueOf(rs.getDouble("contribution"))), keyValue("currency", rs.getString("currency"))); final Relation r1 = OafMapperUtils diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java index 9048a22ea..06947103a 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java @@ -1,9 +1,7 @@ package eu.dnetlib.dhp.oa.graph.raw; -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.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.lenient; @@ -31,11 +29,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; +import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.oaf.*; import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils; @ExtendWith(MockitoExtension.class) -public class MigrateDbEntitiesApplicationTest { +class MigrateDbEntitiesApplicationTest { private MigrateDbEntitiesApplication app; @@ -61,7 +60,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessService() throws Exception { + void testProcessService() throws Exception { final List fields = prepareMocks("services_resultset_entry.json"); final List list = app.processService(rs); @@ -74,7 +73,7 @@ public class MigrateDbEntitiesApplicationTest { .getCollectedfrom() .stream() .map(KeyValue::getKey) - .forEach(dsId -> assertValidId(dsId)); + .forEach(this::assertValidId); assertEquals(1, ds.getPid().size()); assertEquals("r3d100010218", ds.getPid().get(0).getValue()); @@ -163,14 +162,14 @@ public class MigrateDbEntitiesApplicationTest { .stream() .map(Qualifier::getSchemeid) .collect(Collectors.toCollection(HashSet::new)); - assertTrue(cpSchemeId.size() == 1); + assertEquals(1,cpSchemeId.size()); assertTrue(cpSchemeId.contains("eosc:contentpolicies")); HashSet cpSchemeName = ds .getContentpolicies() .stream() .map(Qualifier::getSchemename) .collect(Collectors.toCollection(HashSet::new)); - assertTrue(cpSchemeName.size() == 1); + assertEquals(1, cpSchemeName.size()); assertTrue(cpSchemeName.contains("eosc:contentpolicies")); assertEquals(2, ds.getContentpolicies().size()); assertEquals("Taxonomic classification", ds.getContentpolicies().get(0).getClassid()); @@ -193,7 +192,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessProject() throws Exception { + void testProcessProject() throws Exception { final List fields = prepareMocks("projects_resultset_entry.json"); final List list = app.processProject(rs); @@ -211,7 +210,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessOrganization() throws Exception { + void testProcessOrganization() throws Exception { final List fields = prepareMocks("organizations_resultset_entry.json"); final List list = app.processOrganization(rs); @@ -238,7 +237,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessDatasourceOrganization() throws Exception { + void testProcessDatasourceOrganization() throws Exception { final List fields = prepareMocks("datasourceorganization_resultset_entry.json"); final List list = app.processServiceOrganization(rs); @@ -255,7 +254,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessProjectOrganization() throws Exception { + void testProcessProjectOrganization() throws Exception { final List fields = prepareMocks("projectorganization_resultset_entry.json"); final List list = app.processProjectOrganization(rs); @@ -271,6 +270,38 @@ public class MigrateDbEntitiesApplicationTest { assertEquals(r2.getSource(), r1.getTarget()); assertValidId(r1.getCollectedfrom().get(0).getKey()); assertValidId(r2.getCollectedfrom().get(0).getKey()); + + assertEquals(ModelConstants.PROJECT_ORGANIZATION, r1.getRelType()); + assertEquals(ModelConstants.PROJECT_ORGANIZATION, r2.getRelType()); + + assertEquals(ModelConstants.PARTICIPATION, r1.getSubRelType()); + assertEquals(ModelConstants.PARTICIPATION, r2.getSubRelType()); + + if (r1.getSource().startsWith("40")) { + assertEquals(ModelConstants.HAS_PARTICIPANT, r1.getRelClass()); + assertEquals(ModelConstants.IS_PARTICIPANT, r2.getRelClass()); + } else if (r1.getSource().startsWith("20")) { + assertEquals(ModelConstants.IS_PARTICIPANT, r1.getRelClass()); + assertEquals(ModelConstants.HAS_PARTICIPANT, r2.getRelClass()); + } + + assertNotNull(r1.getProperties()); + checkProperty(r1, "contribution", "436754.0"); + checkProperty(r2, "contribution", "436754.0"); + + checkProperty(r1, "currency","EUR"); + checkProperty(r2, "currency", "EUR"); + } + + private void checkProperty(Relation r, String property, String value) { + final List p = r + .getProperties() + .stream() + .filter(kv -> kv.getKey().equals(property)) + .collect(Collectors.toList()); + assertFalse(p.isEmpty()); + assertEquals(1, p.size()); + assertEquals(value, p.get(0).getValue()); } @Test @@ -289,7 +320,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessClaims_rels() throws Exception { + void testProcessClaims_rels() throws Exception { final List fields = prepareMocks("claimsrel_resultset_entry.json"); final List list = app.processClaims(rs); @@ -320,9 +351,6 @@ public class MigrateDbEntitiesApplicationTest { assertValidId(r1.getCollectedfrom().get(0).getKey()); assertValidId(r2.getCollectedfrom().get(0).getKey()); - - // System.out.println(new ObjectMapper().writeValueAsString(r1)); - // System.out.println(new ObjectMapper().writeValueAsString(r2)); } private List prepareMocks(final String jsonFile) throws IOException, SQLException { @@ -385,7 +413,7 @@ public class MigrateDbEntitiesApplicationTest { final String[] values = ((List) tf.getValue()) .stream() .filter(Objects::nonNull) - .map(o -> o.toString()) + .map(Object::toString) .toArray(String[]::new); Mockito.when(arr.getArray()).thenReturn(values); diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json index a3305926d..02cebae38 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json @@ -2,12 +2,12 @@ { "field": "project", "type": "string", - "value": "nsf_________::1700003" + "value": "corda__h2020::824273" }, { "field": "resporganization", "type": "string", - "value": "nsf_________::University_of_Notre_Dame" + "value": "corda__h2020::999945647" }, { "field": "participantnumber", @@ -16,8 +16,13 @@ }, { "field": "contribution", - "type": "not_used", - "value": null + "type": "double", + "value": 436754 + }, + { + "field": "currency", + "type": "string", + "value": "EUR" }, { "field": "startdate", @@ -52,12 +57,12 @@ { "field": "collectedfromid", "type": "string", - "value": "openaire____::nsf" + "value": "openaire____::corda_h2020" }, { "field": "collectedfromname", "type": "string", - "value": "NSF - National Science Foundation" + "value": "CORDA - COmmon Research DAta Warehouse - Horizon 2020" }, { "field": "semantics",