use of eu.europeana.metis.schema.jibx.CollectionName in project metis-framework by europeana.
the class RdfWrapperTest method testGetDatasetName.
@Test
void testGetDatasetName() {
// Set up to return a europeana aggregation
final EuropeanaAggregationType entity = mock(EuropeanaAggregationType.class);
final RdfWrapper rdf = spy(new RdfWrapper(new RDF()));
when(rdf.getEuropeanaAggregation()).thenReturn(Optional.of(entity));
// Test if dataset name exists and collection name does not
final DatasetName datasetName = new DatasetName();
datasetName.setString("test1");
when(entity.getDatasetName()).thenReturn(datasetName);
assertEquals(datasetName.getString(), rdf.getDatasetName());
// Test if dataset name and collection name exist
final CollectionName collectionName = new CollectionName();
collectionName.setString("test2");
when(entity.getCollectionName()).thenReturn(collectionName);
assertEquals(datasetName.getString(), rdf.getDatasetName());
// Test if dataset name does not exist, but collection name does.
datasetName.setString("");
assertEquals(collectionName.getString(), rdf.getDatasetName());
datasetName.setString(null);
assertEquals(collectionName.getString(), rdf.getDatasetName());
when(entity.getDatasetName()).thenReturn(null);
assertEquals(collectionName.getString(), rdf.getDatasetName());
// Test if neither dataset name nor collection name exists
collectionName.setString("");
assertTrue(rdf.getDatasetName().isEmpty());
collectionName.setString(null);
assertTrue(rdf.getDatasetName().isEmpty());
when(entity.getCollectionName()).thenReturn(null);
assertTrue(rdf.getDatasetName().isEmpty());
// If there is no europeana aggregation
when(rdf.getEuropeanaAggregation()).thenReturn(Optional.of(entity));
assertTrue(rdf.getDatasetName().isEmpty());
}
Aggregations