extended test for mapping project_organization relations

This commit is contained in:
Claudio Atzori 2022-07-28 11:27:08 +02:00
parent 60e4fbd78b
commit 1dd1e4fe3a
3 changed files with 57 additions and 24 deletions

View File

@ -440,7 +440,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
final List<KeyValue> 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

View File

@ -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<TypedField> fields = prepareMocks("services_resultset_entry.json");
final List<Oaf> 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<String> 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<TypedField> fields = prepareMocks("projects_resultset_entry.json");
final List<Oaf> list = app.processProject(rs);
@ -211,7 +210,7 @@ public class MigrateDbEntitiesApplicationTest {
}
@Test
public void testProcessOrganization() throws Exception {
void testProcessOrganization() throws Exception {
final List<TypedField> fields = prepareMocks("organizations_resultset_entry.json");
final List<Oaf> list = app.processOrganization(rs);
@ -238,7 +237,7 @@ public class MigrateDbEntitiesApplicationTest {
}
@Test
public void testProcessDatasourceOrganization() throws Exception {
void testProcessDatasourceOrganization() throws Exception {
final List<TypedField> fields = prepareMocks("datasourceorganization_resultset_entry.json");
final List<Oaf> list = app.processServiceOrganization(rs);
@ -255,7 +254,7 @@ public class MigrateDbEntitiesApplicationTest {
}
@Test
public void testProcessProjectOrganization() throws Exception {
void testProcessProjectOrganization() throws Exception {
final List<TypedField> fields = prepareMocks("projectorganization_resultset_entry.json");
final List<Oaf> 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<KeyValue> 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<TypedField> fields = prepareMocks("claimsrel_resultset_entry.json");
final List<Oaf> 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<TypedField> 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);

View File

@ -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",