tests
This commit is contained in:
parent
e6f1773d63
commit
9f1c7b8e17
|
@ -28,7 +28,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.oaf.*;
|
import eu.dnetlib.dhp.schema.oaf.Datasource;
|
||||||
|
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;
|
||||||
|
import eu.dnetlib.dhp.schema.oaf.Result;
|
||||||
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
|
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
@ -46,11 +51,8 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
lenient()
|
lenient()
|
||||||
.when(vocs.getTermAsQualifier(anyString(), anyString()))
|
.when(vocs.getTermAsQualifier(anyString(), anyString()))
|
||||||
.thenAnswer(
|
.thenAnswer(invocation -> OafMapperUtils
|
||||||
invocation -> OafMapperUtils
|
.qualifier(invocation.getArgument(1), invocation.getArgument(1), invocation.getArgument(0), invocation.getArgument(0)));
|
||||||
.qualifier(
|
|
||||||
invocation.getArgument(1), invocation.getArgument(1), invocation.getArgument(0),
|
|
||||||
invocation.getArgument(0)));
|
|
||||||
|
|
||||||
lenient().when(vocs.termExists(anyString(), anyString())).thenReturn(true);
|
lenient().when(vocs.termExists(anyString(), anyString())).thenReturn(true);
|
||||||
|
|
||||||
|
@ -78,6 +80,23 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
assertEquals(getValueAsString("issnPrinted", fields), ds.getJournal().getIssnPrinted());
|
assertEquals(getValueAsString("issnPrinted", fields), ds.getJournal().getIssnPrinted());
|
||||||
assertEquals(getValueAsString("issnOnline", fields), ds.getJournal().getIssnOnline());
|
assertEquals(getValueAsString("issnOnline", fields), ds.getJournal().getIssnOnline());
|
||||||
assertEquals(getValueAsString("issnLinking", fields), ds.getJournal().getIssnLinking());
|
assertEquals(getValueAsString("issnLinking", fields), ds.getJournal().getIssnLinking());
|
||||||
|
|
||||||
|
assertEquals("pubsrepository::journal", ds.getDatasourcetype().getClassid());
|
||||||
|
assertEquals("dnet:datasource_typologies", ds.getDatasourcetype().getSchemeid());
|
||||||
|
|
||||||
|
assertEquals("pubsrepository::journal", ds.getDatasourcetypeui().getClassid());
|
||||||
|
assertEquals("dnet:datasource_typologies_ui", ds.getDatasourcetypeui().getSchemeid());
|
||||||
|
|
||||||
|
assertEquals("National", ds.getJurisdiction().getClassid());
|
||||||
|
assertEquals("eosc:jurisdictions", ds.getJurisdiction().getSchemeid());
|
||||||
|
|
||||||
|
assertTrue(ds.getThematic());
|
||||||
|
assertTrue(ds.getKnowledgegraph());
|
||||||
|
|
||||||
|
assertEquals(1, ds.getContentpolicies().size());
|
||||||
|
assertEquals("Journal article", ds.getContentpolicies().get(0).getClassid());
|
||||||
|
assertEquals("eosc:contentpolicies", ds.getContentpolicies().get(0).getSchemeid());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -119,7 +138,7 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
assertEquals(getValueAsString("country", fields).split("@@@")[1], o.getCountry().getSchemeid());
|
assertEquals(getValueAsString("country", fields).split("@@@")[1], o.getCountry().getSchemeid());
|
||||||
assertEquals(getValueAsString("country", fields).split("@@@")[1], o.getCountry().getSchemename());
|
assertEquals(getValueAsString("country", fields).split("@@@")[1], o.getCountry().getSchemename());
|
||||||
assertEquals(getValueAsString("collectedfromname", fields), o.getCollectedfrom().get(0).getValue());
|
assertEquals(getValueAsString("collectedfromname", fields), o.getCollectedfrom().get(0).getValue());
|
||||||
List<String> alternativenames = getValueAsList("alternativenames", fields);
|
final List<String> alternativenames = getValueAsList("alternativenames", fields);
|
||||||
assertEquals(2, alternativenames.size());
|
assertEquals(2, alternativenames.size());
|
||||||
assertTrue(alternativenames.contains("Pippo"));
|
assertTrue(alternativenames.contains("Pippo"));
|
||||||
assertTrue(alternativenames.contains("Foo"));
|
assertTrue(alternativenames.contains("Foo"));
|
||||||
|
@ -216,73 +235,72 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
private List<TypedField> prepareMocks(final String jsonFile) throws IOException, SQLException {
|
private List<TypedField> prepareMocks(final String jsonFile) throws IOException, SQLException {
|
||||||
final String json = IOUtils.toString(getClass().getResourceAsStream(jsonFile));
|
final String json = IOUtils.toString(getClass().getResourceAsStream(jsonFile));
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
final List<TypedField> list = mapper.readValue(json, new TypeReference<List<TypedField>>() {
|
final List<TypedField> list = mapper.readValue(json, new TypeReference<List<TypedField>>() {});
|
||||||
});
|
|
||||||
|
|
||||||
for (final TypedField tf : list) {
|
for (final TypedField tf : list) {
|
||||||
if (tf.getValue() == null) {
|
if (tf.getValue() == null) {
|
||||||
switch (tf.getType()) {
|
switch (tf.getType()) {
|
||||||
case "not_used":
|
case "not_used":
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
Mockito.when(rs.getBoolean(tf.getField())).thenReturn(false);
|
Mockito.when(rs.getBoolean(tf.getField())).thenReturn(false);
|
||||||
break;
|
break;
|
||||||
case "date":
|
case "date":
|
||||||
Mockito.when(rs.getDate(tf.getField())).thenReturn(null);
|
Mockito.when(rs.getDate(tf.getField())).thenReturn(null);
|
||||||
break;
|
break;
|
||||||
case "int":
|
case "int":
|
||||||
Mockito.when(rs.getInt(tf.getField())).thenReturn(0);
|
Mockito.when(rs.getInt(tf.getField())).thenReturn(0);
|
||||||
break;
|
break;
|
||||||
case "double":
|
case "double":
|
||||||
Mockito.when(rs.getDouble(tf.getField())).thenReturn(0.0);
|
Mockito.when(rs.getDouble(tf.getField())).thenReturn(0.0);
|
||||||
break;
|
break;
|
||||||
case "array":
|
case "array":
|
||||||
Mockito.when(rs.getArray(tf.getField())).thenReturn(null);
|
Mockito.when(rs.getArray(tf.getField())).thenReturn(null);
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
default:
|
default:
|
||||||
Mockito.when(rs.getString(tf.getField())).thenReturn(null);
|
Mockito.when(rs.getString(tf.getField())).thenReturn(null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (tf.getType()) {
|
switch (tf.getType()) {
|
||||||
case "not_used":
|
case "not_used":
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
Mockito
|
Mockito
|
||||||
.when(rs.getBoolean(tf.getField()))
|
.when(rs.getBoolean(tf.getField()))
|
||||||
.thenReturn(Boolean.parseBoolean(tf.getValue().toString()));
|
.thenReturn(Boolean.parseBoolean(tf.getValue().toString()));
|
||||||
break;
|
break;
|
||||||
case "date":
|
case "date":
|
||||||
Mockito
|
Mockito
|
||||||
.when(rs.getDate(tf.getField()))
|
.when(rs.getDate(tf.getField()))
|
||||||
.thenReturn(Date.valueOf(tf.getValue().toString()));
|
.thenReturn(Date.valueOf(tf.getValue().toString()));
|
||||||
break;
|
break;
|
||||||
case "int":
|
case "int":
|
||||||
Mockito
|
Mockito
|
||||||
.when(rs.getInt(tf.getField()))
|
.when(rs.getInt(tf.getField()))
|
||||||
.thenReturn(new Integer(tf.getValue().toString()));
|
.thenReturn(new Integer(tf.getValue().toString()));
|
||||||
break;
|
break;
|
||||||
case "double":
|
case "double":
|
||||||
Mockito
|
Mockito
|
||||||
.when(rs.getDouble(tf.getField()))
|
.when(rs.getDouble(tf.getField()))
|
||||||
.thenReturn(new Double(tf.getValue().toString()));
|
.thenReturn(new Double(tf.getValue().toString()));
|
||||||
break;
|
break;
|
||||||
case "array":
|
case "array":
|
||||||
final Array arr = Mockito.mock(Array.class);
|
final Array arr = Mockito.mock(Array.class);
|
||||||
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(o -> o.toString())
|
||||||
.toArray(String[]::new);
|
.toArray(String[]::new);
|
||||||
|
|
||||||
Mockito.when(arr.getArray()).thenReturn(values);
|
Mockito.when(arr.getArray()).thenReturn(values);
|
||||||
Mockito.when(rs.getArray(tf.getField())).thenReturn(arr);
|
Mockito.when(rs.getArray(tf.getField())).thenReturn(arr);
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
default:
|
default:
|
||||||
Mockito.when(rs.getString(tf.getField())).thenReturn(tf.getValue().toString());
|
Mockito.when(rs.getString(tf.getField())).thenReturn(tf.getValue().toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,27 +312,27 @@ public class MigrateDbEntitiesApplicationTest {
|
||||||
for (final TypedField tf : list) {
|
for (final TypedField tf : list) {
|
||||||
|
|
||||||
switch (tf.getType()) {
|
switch (tf.getType()) {
|
||||||
case "not_used":
|
case "not_used":
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
Mockito.verify(rs, Mockito.atLeastOnce()).getBoolean(tf.getField());
|
Mockito.verify(rs, Mockito.atLeastOnce()).getBoolean(tf.getField());
|
||||||
break;
|
break;
|
||||||
case "date":
|
case "date":
|
||||||
Mockito.verify(rs, Mockito.atLeastOnce()).getDate(tf.getField());
|
Mockito.verify(rs, Mockito.atLeastOnce()).getDate(tf.getField());
|
||||||
break;
|
break;
|
||||||
case "int":
|
case "int":
|
||||||
Mockito.verify(rs, Mockito.atLeastOnce()).getInt(tf.getField());
|
Mockito.verify(rs, Mockito.atLeastOnce()).getInt(tf.getField());
|
||||||
break;
|
break;
|
||||||
case "double":
|
case "double":
|
||||||
Mockito.verify(rs, Mockito.atLeastOnce()).getDouble(tf.getField());
|
Mockito.verify(rs, Mockito.atLeastOnce()).getDouble(tf.getField());
|
||||||
break;
|
break;
|
||||||
case "array":
|
case "array":
|
||||||
Mockito.verify(rs, Mockito.atLeastOnce()).getArray(tf.getField());
|
Mockito.verify(rs, Mockito.atLeastOnce()).getArray(tf.getField());
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
default:
|
default:
|
||||||
Mockito.verify(rs, Mockito.atLeastOnce()).getString(tf.getField());
|
Mockito.verify(rs, Mockito.atLeastOnce()).getString(tf.getField());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,11 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "pubsrepository::journal@@@dnet:datasource_typologies"
|
"value": "pubsrepository::journal@@@dnet:datasource_typologies"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"field": "datasourcetypeui",
|
||||||
|
"type": "string",
|
||||||
|
"value": "pubsrepository::journal@@@dnet:datasource_typologies_ui"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"field": "provenanceaction",
|
"field": "provenanceaction",
|
||||||
"type": "not_used",
|
"type": "not_used",
|
||||||
|
@ -241,5 +246,27 @@
|
||||||
"field": "issnLinking",
|
"field": "issnLinking",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"value": "2579-5447"
|
"value": "2579-5447"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "jurisdiction",
|
||||||
|
"type": "string",
|
||||||
|
"value": "National@@@eosc:jurisdictions"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "thematic",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "knowledgegraph",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "contentpolicies",
|
||||||
|
"type": "array",
|
||||||
|
"value": [
|
||||||
|
"Journal article@@@eosc:contentpolicies"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue