use of eu.europeana.metis.schema.jibx.Begin 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.Begin in project metis-framework by europeana.
the class ContextualClassesBreakdownClassifierTest method testEntityQualifiesForAgent.
@Test
void testEntityQualifiesForAgent() {
// Create objects
final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
final AgentType agent = new AgentType();
final List<PrefLabel> prefLabelList = new ArrayList<>();
final Begin begin = new Begin();
final DateOfBirth dateOfBirth = new DateOfBirth();
final List<PlaceOfBirth> placeOfBirthList = new ArrayList<>();
final End end = new End();
final DateOfDeath dateOfDeath = new DateOfDeath();
final List<PlaceOfDeath> placeOfDeathList = new ArrayList<>();
final List<ProfessionOrOccupation> professionOrOccupationList = new ArrayList<>();
// Test empty agent
assertFalse(classifier.entityQualifies(agent));
// Set values
agent.setPrefLabelList(prefLabelList);
agent.setBegin(begin);
agent.setDateOfBirth(dateOfBirth);
agent.setPlaceOfBirthList(placeOfBirthList);
agent.setEnd(end);
agent.setDateOfDeath(dateOfDeath);
agent.setPlaceOfDeathList(placeOfDeathList);
agent.setProfessionOrOccupationList(professionOrOccupationList);
// Test prefLabel absent (and rest present)
doReturn(false).when(classifier).hasLiteralProperty(prefLabelList);
doReturn(true).when(classifier).hasProperty(begin);
doReturn(true).when(classifier).hasProperty(dateOfBirth);
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
doReturn(true).when(classifier).hasProperty(end);
doReturn(true).when(classifier).hasProperty(dateOfDeath);
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
doReturn(true).when(classifier).hasResourceOrLiteralProperty(professionOrOccupationList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel present (and rest absent)
doReturn(true).when(classifier).hasLiteralProperty(prefLabelList);
doReturn(false).when(classifier).hasProperty(begin);
doReturn(false).when(classifier).hasProperty(dateOfBirth);
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
doReturn(false).when(classifier).hasProperty(end);
doReturn(false).when(classifier).hasProperty(dateOfDeath);
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
doReturn(false).when(classifier).hasResourceOrLiteralProperty(professionOrOccupationList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and begin present
doReturn(true).when(classifier).hasProperty(begin);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(begin);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and dateOfBirth present
doReturn(true).when(classifier).hasProperty(dateOfBirth);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(dateOfBirth);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and placeOfBirth present
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfBirthList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and end present
doReturn(true).when(classifier).hasProperty(end);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(end);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and dateOfDeath present
doReturn(true).when(classifier).hasProperty(dateOfDeath);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasProperty(dateOfDeath);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and placeOfDeath present
doReturn(true).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
assertTrue(classifier.entityQualifies(agent));
doReturn(false).when(classifier).hasResourceOrLiteralProperty(placeOfDeathList);
assertFalse(classifier.entityQualifies(agent));
// Test prefLabel and professionOrOccupation present
doReturn(true).when(classifier).hasResourceOrLiteralProperty(professionOrOccupationList);
assertTrue(classifier.entityQualifies(agent));
}
use of eu.europeana.metis.schema.jibx.Begin in project metis-framework by europeana.
the class ContextualClassesBreakdownClassifierTest method testEntityQualifiesForTimeSpan.
@Test
void testEntityQualifiesForTimeSpan() {
// Create objects
final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
final TimeSpanType timeSpan = new TimeSpanType();
final Begin begin = new Begin();
final End end = new End();
// Test empty time span
assertFalse(classifier.entityQualifies(timeSpan));
// Set values
timeSpan.setBegin(begin);
timeSpan.setEnd(end);
// Test all present
doReturn(true).when(classifier).hasProperty(begin);
doReturn(true).when(classifier).hasProperty(end);
assertTrue(classifier.entityQualifies(timeSpan));
// Test without begin
doReturn(false).when(classifier).hasProperty(begin);
assertFalse(classifier.entityQualifies(timeSpan));
doReturn(true).when(classifier).hasProperty(begin);
assertTrue(classifier.entityQualifies(timeSpan));
// Test withouty end
doReturn(false).when(classifier).hasProperty(end);
assertFalse(classifier.entityQualifies(timeSpan));
}
use of eu.europeana.metis.schema.jibx.Begin in project metis-framework by europeana.
the class AgentFieldInputTest method testAgent.
@Test
void testAgent() {
AgentType agentType = new AgentType();
agentType.setAbout("test about");
AgentImpl agentImpl = new AgentImpl();
agentImpl.setAbout(agentType.getAbout());
RecordDao mongoServerMock = mock(RecordDao.class);
Datastore datastoreMock = mock(Datastore.class);
@SuppressWarnings("unchecked") Query<AgentImpl> queryMock = mock(Query.class);
when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
when(mongoServerMock.getDatastore()).thenReturn(datastoreMock);
when(datastoreMock.find(AgentImpl.class)).thenReturn(queryMock);
when(datastoreMock.save(agentImpl)).thenReturn(agentImpl);
when(queryMock.filter(Filters.eq("about", agentType.getAbout()))).thenReturn(queryMock);
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);
agentType.setAltLabelList(altLabelList);
Begin begin = new Begin();
begin.setString("test begin");
agentType.setBegin(begin);
End end = new End();
end.setString("test end");
agentType.setEnd(end);
List<Note> noteList = new ArrayList<>();
Note note = new Note();
note.setString("test note");
assertNotNull(note);
noteList.add(note);
agentType.setNoteList(noteList);
List<PrefLabel> prefLabelList = new ArrayList<>();
PrefLabel prefLabel = new PrefLabel();
prefLabel.setLang(lang);
prefLabel.setString("test pred label");
assertNotNull(prefLabel);
prefLabelList.add(prefLabel);
agentType.setPrefLabelList(prefLabelList);
// store in mongo
AgentImpl agent = new AgentFieldInput().apply(agentType);
mongoServerMock.getDatastore().save(agent);
assertEquals(agentType.getAbout(), agent.getAbout());
assertEquals(agentType.getBegin().getString(), agent.getBegin().values().iterator().next().get(0));
assertEquals(agentType.getEnd().getString(), agent.getEnd().values().iterator().next().get(0));
assertEquals(agentType.getNoteList().get(0).getString(), agent.getNote().values().iterator().next().get(0));
assertTrue(agent.getAltLabel().containsKey(agentType.getAltLabelList().get(0).getLang().getLang()));
assertTrue(agent.getPrefLabel().containsKey(agentType.getPrefLabelList().get(0).getLang().getLang()));
assertEquals(agentType.getAltLabelList().get(0).getString(), agent.getAltLabel().values().iterator().next().get(0));
assertEquals(agentType.getPrefLabelList().get(0).getString(), agent.getPrefLabel().values().iterator().next().get(0));
}
Aggregations