use of eu.europeana.metis.schema.jibx.Note in project metis-framework by europeana.
the class PlaceFieldInputTest method testPlace.
@Test
void testPlace() {
PlaceImpl placeImpl = new PlaceImpl();
placeImpl.setAbout("test about");
RecordDao mongoServerMock = mock(RecordDao.class);
Datastore datastoreMock = mock(Datastore.class);
@SuppressWarnings("unchecked") Query<PlaceImpl> queryMock = mock(Query.class);
when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
when(datastoreMock.find(PlaceImpl.class)).thenReturn(queryMock);
when(datastoreMock.save(placeImpl)).thenReturn(placeImpl);
when(queryMock.filter(Filters.eq("about", placeImpl.getAbout()))).thenReturn(queryMock);
PlaceType place = new PlaceType();
place.setAbout("test about");
List<AltLabel> altLabelList = new ArrayList<>();
AltLabel altLabel = new AltLabel();
Lang lang = new Lang();
lang.setLang("en");
altLabel.setLang(lang);
altLabel.setString("test alt label");
assertNotNull(altLabel);
altLabelList.add(altLabel);
place.setAltLabelList(altLabelList);
List<Note> noteList = new ArrayList<>();
Note note = new Note();
note.setString("test note");
assertNotNull(note);
noteList.add(note);
place.setNoteList(noteList);
List<PrefLabel> prefLabelList = new ArrayList<>();
PrefLabel prefLabel = new PrefLabel();
prefLabel.setLang(lang);
prefLabel.setString("test pred label");
assertNotNull(prefLabel);
prefLabelList.add(prefLabel);
place.setPrefLabelList(prefLabelList);
List<IsPartOf> isPartOfList = new ArrayList<>();
IsPartOf isPartOf = new IsPartOf();
isPartOf.setString("test resource");
isPartOfList.add(isPartOf);
place.setIsPartOfList(isPartOfList);
Lat posLat = new Lat();
posLat.setLat(Float.valueOf("1.0"));
place.setLat(posLat);
_Long posLong = new _Long();
posLong.setLong(Float.valueOf("1.0"));
place.setLong(posLong);
// create mongo place
PlaceImpl placeMongo = new PlaceFieldInput().apply(place);
mongoServerMock.getDatastore().save(placeMongo);
assertEquals(place.getAbout(), placeMongo.getAbout());
assertEquals(place.getNoteList().get(0).getString(), placeMongo.getNote().values().iterator().next().get(0));
assertTrue(placeMongo.getAltLabel().containsKey(place.getAltLabelList().get(0).getLang().getLang()));
assertEquals(place.getAltLabelList().get(0).getString(), placeMongo.getAltLabel().values().iterator().next().get(0));
assertEquals(place.getPrefLabelList().get(0).getString(), placeMongo.getPrefLabel().values().iterator().next().get(0));
assertEquals(place.getIsPartOfList().get(0).getString(), placeMongo.getIsPartOf().values().iterator().next().get(0));
assertEquals(Float.toString(place.getLat().getLat()), Float.toString(placeMongo.getLatitude()));
assertEquals(Float.toString(place.getLong().getLong()), Float.toString(placeMongo.getLongitude()));
}
use of eu.europeana.metis.schema.jibx.Note in project metis-framework by europeana.
the class TimespanFieldInputTest method testTimespan.
@Test
void testTimespan() {
TimeSpanType timespan = new TimeSpanType();
timespan.setAbout("test about");
List<AltLabel> altLabelList = new ArrayList<>();
AltLabel altLabel = new AltLabel();
Lang lang = new Lang();
lang.setLang("en");
altLabel.setLang(lang);
altLabel.setString("test alt label");
assertNotNull(altLabel);
altLabelList.add(altLabel);
timespan.setAltLabelList(altLabelList);
Begin begin = new Begin();
begin.setString("test begin");
timespan.setBegin(begin);
End end = new End();
end.setString("test end");
timespan.setEnd(end);
List<Note> noteList = new ArrayList<>();
Note note = new Note();
note.setString("test note");
assertNotNull(note);
noteList.add(note);
timespan.setNoteList(noteList);
List<PrefLabel> prefLabelList = new ArrayList<>();
PrefLabel prefLabel = new PrefLabel();
prefLabel.setLang(lang);
prefLabel.setString("test pred label");
assertNotNull(prefLabel);
prefLabelList.add(prefLabel);
timespan.setPrefLabelList(prefLabelList);
List<HiddenLabel> hiddelLabelList = new ArrayList<>();
HiddenLabel hiddenLabel = new HiddenLabel();
hiddenLabel.setLang(lang);
hiddenLabel.setString("test hidden label");
assertNotNull(hiddenLabel);
hiddelLabelList.add(hiddenLabel);
timespan.setHiddenLabelList(hiddelLabelList);
List<IsPartOf> isPartOfList = new ArrayList<>();
IsPartOf isPartOf = new IsPartOf();
eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource isPartOfResource = new eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource();
isPartOfResource.setResource("test resource");
isPartOf.setResource(isPartOfResource);
isPartOfList.add(isPartOf);
timespan.setIsPartOfList(isPartOfList);
TimespanImpl timespanImpl = new TimespanImpl();
timespanImpl.setAbout(timespan.getAbout());
// create mongo
RecordDao mongoServerMock = mock(RecordDao.class);
Datastore datastoreMock = mock(Datastore.class);
@SuppressWarnings("unchecked") Query<TimespanImpl> queryMock = mock(Query.class);
when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
when(datastoreMock.find(TimespanImpl.class)).thenReturn(queryMock);
when(datastoreMock.save(timespanImpl)).thenReturn(timespanImpl);
when(queryMock.filter(Filters.eq("about", timespan.getAbout()))).thenReturn(queryMock);
TimespanImpl timespanMongo = new TimespanFieldInput().apply(timespan);
mongoServerMock.getDatastore().save(timespanMongo);
assertEquals(timespan.getAbout(), timespanMongo.getAbout());
assertEquals(timespan.getBegin().getString(), timespanMongo.getBegin().values().iterator().next().get(0));
assertEquals(timespan.getEnd().getString(), timespanMongo.getEnd().values().iterator().next().get(0));
assertEquals(timespan.getNoteList().get(0).getString(), timespanMongo.getNote().values().iterator().next().get(0));
assertTrue(timespanMongo.getAltLabel().containsKey(timespan.getAltLabelList().get(0).getLang().getLang()));
assertTrue(timespanMongo.getPrefLabel().containsKey(timespan.getPrefLabelList().get(0).getLang().getLang()));
assertTrue(timespanMongo.getHiddenLabel().containsKey(timespan.getHiddenLabelList().get(0).getLang().getLang()));
assertEquals(timespan.getAltLabelList().get(0).getString(), timespanMongo.getAltLabel().values().iterator().next().get(0));
assertEquals(timespan.getPrefLabelList().get(0).getString(), timespanMongo.getPrefLabel().values().iterator().next().get(0));
assertEquals(timespan.getIsPartOfList().get(0).getResource().getResource(), timespanMongo.getIsPartOf().values().iterator().next().get(0));
}
use of eu.europeana.metis.schema.jibx.Note in project metis-framework by europeana.
the class DereferenceUtilsTest method testConceptListExtractedValues.
@Test
void testConceptListExtractedValues() {
RDF rdf = new RDF();
ProxyType proxy = new ProxyType();
ArrayList<ProxyType> proxyList = new ArrayList<>();
proxyList.add(proxy);
rdf.setProxyList(proxyList);
Concept concept = new Concept();
concept.setAbout("http://dummy1.dum");
Choice choice1 = new Choice();
BroadMatch broadMatch = new BroadMatch();
broadMatch.setResource("http://dummy2.dum");
choice1.setBroadMatch(broadMatch);
Choice choice2 = new Choice();
CloseMatch closeMatch = new CloseMatch();
closeMatch.setResource("http://dummy3.dum");
choice2.setCloseMatch(closeMatch);
Choice choice3 = new Choice();
ExactMatch exactMatch = new ExactMatch();
exactMatch.setResource("http://dummy4.dum");
choice3.setExactMatch(exactMatch);
Choice choice4 = new Choice();
NarrowMatch narrowMatch = new NarrowMatch();
narrowMatch.setResource("http://dummy5.dum");
choice4.setNarrowMatch(narrowMatch);
Choice choice5 = new Choice();
RelatedMatch relatedMatch = new RelatedMatch();
relatedMatch.setResource("http://dummy6.dum");
choice5.setRelatedMatch(relatedMatch);
Choice choice6 = new Choice();
Related related = new Related();
related.setResource("http://dummy7.dum");
choice6.setRelated(related);
Choice choice7 = new Choice();
Broader broader = new Broader();
broader.setResource("http://dummy8.dum");
choice7.setBroader(broader);
Choice choice8 = new Choice();
Note note = new Note();
note.setString("Note");
choice8.setNote(note);
ArrayList<Choice> choiceList = new ArrayList<>();
choiceList.add(choice1);
choiceList.add(choice2);
choiceList.add(choice3);
choiceList.add(choice4);
choiceList.add(choice5);
choiceList.add(choice6);
choiceList.add(choice7);
concept.setChoiceList(choiceList);
ArrayList<Concept> conceptList = new ArrayList<>();
conceptList.add(concept);
rdf.setConceptList(conceptList);
Set<String> result = DereferenceUtils.extractReferencesForDereferencing(rdf);
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(result.contains("http://dummy8.dum"));
}
use of eu.europeana.metis.schema.jibx.Note in project metis-framework by europeana.
the class DereferenceUtilsTest method testPlaceListExtractedValues.
@Test
void testPlaceListExtractedValues() {
RDF rdf = new RDF();
ProxyType proxy = new ProxyType();
ArrayList<ProxyType> proxyList = new ArrayList<>();
proxyList.add(proxy);
rdf.setProxyList(proxyList);
PlaceType place = new PlaceType();
place.setAbout("http://dummy1.dum");
IsPartOf isPartOf = new IsPartOf();
ResourceOrLiteralType.Resource resource3 = new ResourceOrLiteralType.Resource();
resource3.setResource("http://dummy2.dum");
isPartOf.setResource(resource3);
ArrayList<IsPartOf> isPartOfList = new ArrayList<>();
isPartOfList.add(isPartOf);
place.setIsPartOfList(isPartOfList);
SameAs sameAs = new SameAs();
sameAs.setResource("http://dummy3.dum");
ArrayList<SameAs> sameAsList = new ArrayList<>();
sameAsList.add(sameAs);
place.setSameAList(sameAsList);
HasPart hasPart = new HasPart();
Resource resource4 = new Resource();
resource4.setResource("http://dummy4.dum");
hasPart.setResource(resource4);
ArrayList<HasPart> hasPartList = new ArrayList<>();
hasPartList.add(hasPart);
place.setHasPartList(hasPartList);
// Should be rejected
Note note = new Note();
note.setString("Note");
ArrayList<Note> noteList = new ArrayList<>();
noteList.add(note);
place.setNoteList(noteList);
ArrayList<PlaceType> placeList = new ArrayList<>();
placeList.add(place);
rdf.setPlaceList(placeList);
Set<String> result = DereferenceUtils.extractReferencesForDereferencing(rdf);
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(result.contains("http://dummy2.dum"));
}
use of eu.europeana.metis.schema.jibx.Note in project metis-framework by europeana.
the class DereferenceUtilsTest method testTimeSpanListExtractedValues.
@Test
void testTimeSpanListExtractedValues() {
RDF rdf = new RDF();
ProxyType proxy = new ProxyType();
ArrayList<ProxyType> proxyList = new ArrayList<>();
proxyList.add(proxy);
rdf.setProxyList(proxyList);
TimeSpanType timeSpan = new TimeSpanType();
timeSpan.setAbout("http://dummy1.dum");
HasPart hasPart = new HasPart();
Resource resource3 = new Resource();
resource3.setResource("http://dummy2.dum");
hasPart.setResource(resource3);
ArrayList<HasPart> hasPartList = new ArrayList<>();
hasPartList.add(hasPart);
timeSpan.setHasPartList(hasPartList);
IsPartOf isPartOf = new IsPartOf();
ResourceOrLiteralType.Resource resource4 = new ResourceOrLiteralType.Resource();
resource4.setResource("http://dummy4.dum");
isPartOf.setResource(resource4);
ArrayList<IsPartOf> isPartOfList = new ArrayList<>();
isPartOfList.add(isPartOf);
timeSpan.setIsPartOfList(isPartOfList);
SameAs sameAs = new SameAs();
sameAs.setResource("http://dummy5.dum");
ArrayList<SameAs> sameAsList = new ArrayList<>();
sameAsList.add(sameAs);
timeSpan.setSameAList(sameAsList);
// Should be rejected
Note note = new Note();
note.setString("Note");
ArrayList<Note> noteList = new ArrayList<>();
noteList.add(note);
timeSpan.setNoteList(noteList);
ArrayList<TimeSpanType> timeSpanList = new ArrayList<>();
timeSpanList.add(timeSpan);
rdf.setTimeSpanList(timeSpanList);
Set<String> result = DereferenceUtils.extractReferencesForDereferencing(rdf);
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(result.contains("http://dummy4.dum"));
}
Aggregations