forked from D-Net/dnet-hadoop
tests
This commit is contained in:
parent
0fda2c3a30
commit
2559299da4
|
@ -21,7 +21,11 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Datasource;
|
||||||
import eu.dnetlib.dhp.schema.oaf.Oaf;
|
import eu.dnetlib.dhp.schema.oaf.Oaf;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Organization;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Project;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Relation;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class MigrateDbEntitiesApplicationTest {
|
public class MigrateDbEntitiesApplicationTest {
|
||||||
|
@ -42,8 +46,17 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
|
|
||||||
final List<Oaf> list = app.processDatasource(rs);
|
final List<Oaf> list = app.processDatasource(rs);
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
verifyMocks(fields);
|
verifyMocks(fields);
|
||||||
|
|
||||||
|
final Datasource ds = (Datasource) list.get(0);
|
||||||
|
assertValidId(ds.getId());
|
||||||
|
assertEquals(ds.getOfficialname().getValue(), getValueAsString("officialname", fields));
|
||||||
|
assertEquals(ds.getEnglishname().getValue(), getValueAsString("englishname", fields));
|
||||||
|
assertEquals(ds.getContactemail().getValue(), getValueAsString("contactemail", fields));
|
||||||
|
assertEquals(ds.getWebsiteurl().getValue(), getValueAsString("websiteurl", fields));
|
||||||
|
assertEquals(ds.getNamespaceprefix().getValue(), getValueAsString("namespaceprefix", fields));
|
||||||
|
assertEquals(ds.getCollectedfrom().get(0).getKey(), getValueAsString("collectedfromid", fields));
|
||||||
|
assertEquals(ds.getCollectedfrom().get(0).getValue(), getValueAsString("collectedfromname", fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -52,8 +65,14 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
|
|
||||||
final List<Oaf> list = app.processProject(rs);
|
final List<Oaf> list = app.processProject(rs);
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
verifyMocks(fields);
|
verifyMocks(fields);
|
||||||
|
|
||||||
|
final Project p = (Project) list.get(0);
|
||||||
|
assertValidId(p.getId());
|
||||||
|
assertEquals(p.getAcronym().getValue(), getValueAsString("acronym", fields));
|
||||||
|
assertEquals(p.getTitle().getValue(), getValueAsString("title", fields));
|
||||||
|
assertEquals(p.getCollectedfrom().get(0).getKey(), getValueAsString("collectedfromid", fields));
|
||||||
|
assertEquals(p.getCollectedfrom().get(0).getValue(), getValueAsString("collectedfromname", fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -65,6 +84,18 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
verifyMocks(fields);
|
verifyMocks(fields);
|
||||||
|
|
||||||
|
final Organization o = (Organization) list.get(0);
|
||||||
|
assertValidId(o.getId());
|
||||||
|
assertEquals(o.getLegalshortname().getValue(), getValueAsString("legalshortname", fields));
|
||||||
|
assertEquals(o.getLegalname().getValue(), getValueAsString("legalname", fields));
|
||||||
|
assertEquals(o.getWebsiteurl().getValue(), getValueAsString("websiteurl", fields));
|
||||||
|
assertEquals(o.getCountry().getClassid(), getValueAsString("country", fields).split("@@@")[0]);
|
||||||
|
assertEquals(o.getCountry().getClassname(), getValueAsString("country", fields).split("@@@")[1]);
|
||||||
|
assertEquals(o.getCountry().getSchemeid(), getValueAsString("country", fields).split("@@@")[2]);
|
||||||
|
assertEquals(o.getCountry().getSchemename(), getValueAsString("country", fields).split("@@@")[3]);
|
||||||
|
assertEquals(o.getCollectedfrom().get(0).getKey(), getValueAsString("collectedfromid", fields));
|
||||||
|
assertEquals(o.getCollectedfrom().get(0).getValue(), getValueAsString("collectedfromname", fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -75,6 +106,13 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
|
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
verifyMocks(fields);
|
verifyMocks(fields);
|
||||||
|
|
||||||
|
final Relation r1 = (Relation) list.get(0);
|
||||||
|
final Relation r2 = (Relation) list.get(1);
|
||||||
|
assertValidId(r1.getSource());
|
||||||
|
assertValidId(r2.getSource());
|
||||||
|
assertEquals(r1.getSource(), r2.getTarget());
|
||||||
|
assertEquals(r2.getSource(), r1.getTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -85,6 +123,13 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
|
|
||||||
assertEquals(2, list.size());
|
assertEquals(2, list.size());
|
||||||
verifyMocks(fields);
|
verifyMocks(fields);
|
||||||
|
|
||||||
|
final Relation r1 = (Relation) list.get(0);
|
||||||
|
final Relation r2 = (Relation) list.get(1);
|
||||||
|
assertValidId(r1.getSource());
|
||||||
|
assertValidId(r2.getSource());
|
||||||
|
assertEquals(r1.getSource(), r2.getTarget());
|
||||||
|
assertEquals(r2.getSource(), r1.getTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -201,7 +246,23 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertValidId(final String id) {
|
||||||
|
assertEquals(49, id.length());
|
||||||
|
assertEquals('|', id.charAt(2));
|
||||||
|
assertEquals(':', id.charAt(15));
|
||||||
|
assertEquals(':', id.charAt(16));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getValueAsString(final String name, final List<TypedField> fields) {
|
||||||
|
return fields.stream()
|
||||||
|
.filter(f -> f.getField().equals(name))
|
||||||
|
.map(TypedField::getValue)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(o -> o.toString())
|
||||||
|
.findFirst()
|
||||||
|
.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
{
|
{
|
||||||
"field": "contactemail",
|
"field": "contactemail",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": null
|
"value": "test@test.it"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "openairecompatibility",
|
"field": "openairecompatibility",
|
||||||
|
@ -230,10 +230,5 @@
|
||||||
"field": "journal",
|
"field": "journal",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "2579-5449@@@2597-6540@@@"
|
"value": "2579-5449@@@2597-6540@@@"
|
||||||
},
|
|
||||||
{
|
|
||||||
"field": "collectedfromid",
|
|
||||||
"type": "string",
|
|
||||||
"value": "openaire____::SnVybmFsIEZha3VsdGFzIFNhc3RyYSBVbml2ZXJzaXRhcyBFa2FzYWt0aQ=="
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
{
|
{
|
||||||
"field": "legalshortname",
|
"field": "legalshortname",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": null
|
"value": "MSFTResearch"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "legalname",
|
"field": "legalname",
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
{
|
{
|
||||||
"field": "websiteurl",
|
"field": "websiteurl",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": null
|
"value": "https://www.microsoft.com/en-us/research/"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "logourl",
|
"field": "logourl",
|
||||||
|
@ -107,12 +107,12 @@
|
||||||
{
|
{
|
||||||
"field": "collectedfromid",
|
"field": "collectedfromid",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": null
|
"value": "openaire____::TEST"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "collectedfromname",
|
"field": "collectedfromname",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": null
|
"value": "TEST"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"field": "country",
|
"field": "country",
|
||||||
|
|
Loading…
Reference in New Issue