forked from D-Net/dnet-hadoop
extended test for mapping project_organization relations
This commit is contained in:
parent
60e4fbd78b
commit
1dd1e4fe3a
|
@ -440,7 +440,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
|
||||||
|
|
||||||
final List<KeyValue> properties = Lists
|
final List<KeyValue> properties = Lists
|
||||||
.newArrayList(
|
.newArrayList(
|
||||||
keyValue("contribution", String.valueOf(rs.getDouble("totalcost"))),
|
keyValue("contribution", String.valueOf(rs.getDouble("contribution"))),
|
||||||
keyValue("currency", rs.getString("currency")));
|
keyValue("currency", rs.getString("currency")));
|
||||||
|
|
||||||
final Relation r1 = OafMapperUtils
|
final Relation r1 = OafMapperUtils
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
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.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
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.lenient;
|
import static org.mockito.Mockito.lenient;
|
||||||
|
|
||||||
|
@ -31,11 +29,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup;
|
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.*;
|
||||||
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
|
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class MigrateDbEntitiesApplicationTest {
|
class MigrateDbEntitiesApplicationTest {
|
||||||
|
|
||||||
private MigrateDbEntitiesApplication app;
|
private MigrateDbEntitiesApplication app;
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessService() throws Exception {
|
void testProcessService() throws Exception {
|
||||||
final List<TypedField> fields = prepareMocks("services_resultset_entry.json");
|
final List<TypedField> fields = prepareMocks("services_resultset_entry.json");
|
||||||
|
|
||||||
final List<Oaf> list = app.processService(rs);
|
final List<Oaf> list = app.processService(rs);
|
||||||
|
@ -74,7 +73,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
.getCollectedfrom()
|
.getCollectedfrom()
|
||||||
.stream()
|
.stream()
|
||||||
.map(KeyValue::getKey)
|
.map(KeyValue::getKey)
|
||||||
.forEach(dsId -> assertValidId(dsId));
|
.forEach(this::assertValidId);
|
||||||
|
|
||||||
assertEquals(1, ds.getPid().size());
|
assertEquals(1, ds.getPid().size());
|
||||||
assertEquals("r3d100010218", ds.getPid().get(0).getValue());
|
assertEquals("r3d100010218", ds.getPid().get(0).getValue());
|
||||||
|
@ -163,14 +162,14 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
.stream()
|
.stream()
|
||||||
.map(Qualifier::getSchemeid)
|
.map(Qualifier::getSchemeid)
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
assertTrue(cpSchemeId.size() == 1);
|
assertEquals(1,cpSchemeId.size());
|
||||||
assertTrue(cpSchemeId.contains("eosc:contentpolicies"));
|
assertTrue(cpSchemeId.contains("eosc:contentpolicies"));
|
||||||
HashSet<String> cpSchemeName = ds
|
HashSet<String> cpSchemeName = ds
|
||||||
.getContentpolicies()
|
.getContentpolicies()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Qualifier::getSchemename)
|
.map(Qualifier::getSchemename)
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
assertTrue(cpSchemeName.size() == 1);
|
assertEquals(1, cpSchemeName.size());
|
||||||
assertTrue(cpSchemeName.contains("eosc:contentpolicies"));
|
assertTrue(cpSchemeName.contains("eosc:contentpolicies"));
|
||||||
assertEquals(2, ds.getContentpolicies().size());
|
assertEquals(2, ds.getContentpolicies().size());
|
||||||
assertEquals("Taxonomic classification", ds.getContentpolicies().get(0).getClassid());
|
assertEquals("Taxonomic classification", ds.getContentpolicies().get(0).getClassid());
|
||||||
|
@ -193,7 +192,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessProject() throws Exception {
|
void testProcessProject() throws Exception {
|
||||||
final List<TypedField> fields = prepareMocks("projects_resultset_entry.json");
|
final List<TypedField> fields = prepareMocks("projects_resultset_entry.json");
|
||||||
|
|
||||||
final List<Oaf> list = app.processProject(rs);
|
final List<Oaf> list = app.processProject(rs);
|
||||||
|
@ -211,7 +210,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessOrganization() throws Exception {
|
void testProcessOrganization() throws Exception {
|
||||||
final List<TypedField> fields = prepareMocks("organizations_resultset_entry.json");
|
final List<TypedField> fields = prepareMocks("organizations_resultset_entry.json");
|
||||||
|
|
||||||
final List<Oaf> list = app.processOrganization(rs);
|
final List<Oaf> list = app.processOrganization(rs);
|
||||||
|
@ -238,7 +237,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessDatasourceOrganization() throws Exception {
|
void testProcessDatasourceOrganization() throws Exception {
|
||||||
final List<TypedField> fields = prepareMocks("datasourceorganization_resultset_entry.json");
|
final List<TypedField> fields = prepareMocks("datasourceorganization_resultset_entry.json");
|
||||||
|
|
||||||
final List<Oaf> list = app.processServiceOrganization(rs);
|
final List<Oaf> list = app.processServiceOrganization(rs);
|
||||||
|
@ -255,7 +254,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessProjectOrganization() throws Exception {
|
void testProcessProjectOrganization() throws Exception {
|
||||||
final List<TypedField> fields = prepareMocks("projectorganization_resultset_entry.json");
|
final List<TypedField> fields = prepareMocks("projectorganization_resultset_entry.json");
|
||||||
|
|
||||||
final List<Oaf> list = app.processProjectOrganization(rs);
|
final List<Oaf> list = app.processProjectOrganization(rs);
|
||||||
|
@ -271,6 +270,38 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
assertEquals(r2.getSource(), r1.getTarget());
|
assertEquals(r2.getSource(), r1.getTarget());
|
||||||
assertValidId(r1.getCollectedfrom().get(0).getKey());
|
assertValidId(r1.getCollectedfrom().get(0).getKey());
|
||||||
assertValidId(r2.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
|
@Test
|
||||||
|
@ -289,7 +320,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessClaims_rels() throws Exception {
|
void testProcessClaims_rels() throws Exception {
|
||||||
final List<TypedField> fields = prepareMocks("claimsrel_resultset_entry.json");
|
final List<TypedField> fields = prepareMocks("claimsrel_resultset_entry.json");
|
||||||
|
|
||||||
final List<Oaf> list = app.processClaims(rs);
|
final List<Oaf> list = app.processClaims(rs);
|
||||||
|
@ -320,9 +351,6 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
|
|
||||||
assertValidId(r1.getCollectedfrom().get(0).getKey());
|
assertValidId(r1.getCollectedfrom().get(0).getKey());
|
||||||
assertValidId(r2.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 {
|
private List<TypedField> prepareMocks(final String jsonFile) throws IOException, SQLException {
|
||||||
|
@ -385,7 +413,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
final String[] values = ((List<?>) tf.getValue())
|
final String[] values = ((List<?>) tf.getValue())
|
||||||
.stream()
|
.stream()
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.map(o -> o.toString())
|
.map(Object::toString)
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
|
|
||||||
Mockito.when(arr.getArray()).thenReturn(values);
|
Mockito.when(arr.getArray()).thenReturn(values);
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
{
|
{
|
||||||
"field": "project",
|
"field": "project",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "nsf_________::1700003"
|
"value": "corda__h2020::824273"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "resporganization",
|
"field": "resporganization",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "nsf_________::University_of_Notre_Dame"
|
"value": "corda__h2020::999945647"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "participantnumber",
|
"field": "participantnumber",
|
||||||
|
@ -16,8 +16,13 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "contribution",
|
"field": "contribution",
|
||||||
"type": "not_used",
|
"type": "double",
|
||||||
"value": null
|
"value": 436754
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "currency",
|
||||||
|
"type": "string",
|
||||||
|
"value": "EUR"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "startdate",
|
"field": "startdate",
|
||||||
|
@ -52,12 +57,12 @@
|
||||||
{
|
{
|
||||||
"field": "collectedfromid",
|
"field": "collectedfromid",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "openaire____::nsf"
|
"value": "openaire____::corda_h2020"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "collectedfromname",
|
"field": "collectedfromname",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "NSF - National Science Foundation"
|
"value": "CORDA - COmmon Research DAta Warehouse - Horizon 2020"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "semantics",
|
"field": "semantics",
|
||||||
|
|
Loading…
Reference in New Issue