Search in sources :

Example 1 with Begin

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));
}
Also used : HiddenLabel(eu.europeana.metis.schema.jibx.HiddenLabel) TimespanImpl(eu.europeana.corelib.solr.entity.TimespanImpl) ArrayList(java.util.ArrayList) RecordDao(eu.europeana.metis.mongo.dao.RecordDao) Begin(eu.europeana.metis.schema.jibx.Begin) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) IsPartOf(eu.europeana.metis.schema.jibx.IsPartOf) Lang(eu.europeana.metis.schema.jibx.LiteralType.Lang) Datastore(dev.morphia.Datastore) AltLabel(eu.europeana.metis.schema.jibx.AltLabel) Note(eu.europeana.metis.schema.jibx.Note) End(eu.europeana.metis.schema.jibx.End) Test(org.junit.jupiter.api.Test)

Example 2 with Begin

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));
}
Also used : DateOfBirth(eu.europeana.metis.schema.jibx.DateOfBirth) ArrayList(java.util.ArrayList) PlaceOfBirth(eu.europeana.metis.schema.jibx.PlaceOfBirth) AgentType(eu.europeana.metis.schema.jibx.AgentType) Begin(eu.europeana.metis.schema.jibx.Begin) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) ProfessionOrOccupation(eu.europeana.metis.schema.jibx.ProfessionOrOccupation) End(eu.europeana.metis.schema.jibx.End) DateOfDeath(eu.europeana.metis.schema.jibx.DateOfDeath) PlaceOfDeath(eu.europeana.metis.schema.jibx.PlaceOfDeath) Test(org.junit.jupiter.api.Test)

Example 3 with Begin

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));
}
Also used : TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) Begin(eu.europeana.metis.schema.jibx.Begin) End(eu.europeana.metis.schema.jibx.End) Test(org.junit.jupiter.api.Test)

Example 4 with Begin

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));
}
Also used : ArrayList(java.util.ArrayList) Lang(eu.europeana.metis.schema.jibx.LiteralType.Lang) RecordDao(eu.europeana.metis.mongo.dao.RecordDao) AgentImpl(eu.europeana.corelib.solr.entity.AgentImpl) AgentType(eu.europeana.metis.schema.jibx.AgentType) Datastore(dev.morphia.Datastore) AltLabel(eu.europeana.metis.schema.jibx.AltLabel) Note(eu.europeana.metis.schema.jibx.Note) Begin(eu.europeana.metis.schema.jibx.Begin) PrefLabel(eu.europeana.metis.schema.jibx.PrefLabel) End(eu.europeana.metis.schema.jibx.End) Test(org.junit.jupiter.api.Test)

Aggregations

Begin (eu.europeana.metis.schema.jibx.Begin)4 End (eu.europeana.metis.schema.jibx.End)4 Test (org.junit.jupiter.api.Test)4 PrefLabel (eu.europeana.metis.schema.jibx.PrefLabel)3 ArrayList (java.util.ArrayList)3 Datastore (dev.morphia.Datastore)2 RecordDao (eu.europeana.metis.mongo.dao.RecordDao)2 AgentType (eu.europeana.metis.schema.jibx.AgentType)2 AltLabel (eu.europeana.metis.schema.jibx.AltLabel)2 Lang (eu.europeana.metis.schema.jibx.LiteralType.Lang)2 Note (eu.europeana.metis.schema.jibx.Note)2 TimeSpanType (eu.europeana.metis.schema.jibx.TimeSpanType)2 AgentImpl (eu.europeana.corelib.solr.entity.AgentImpl)1 TimespanImpl (eu.europeana.corelib.solr.entity.TimespanImpl)1 DateOfBirth (eu.europeana.metis.schema.jibx.DateOfBirth)1 DateOfDeath (eu.europeana.metis.schema.jibx.DateOfDeath)1 HiddenLabel (eu.europeana.metis.schema.jibx.HiddenLabel)1 IsPartOf (eu.europeana.metis.schema.jibx.IsPartOf)1 PlaceOfBirth (eu.europeana.metis.schema.jibx.PlaceOfBirth)1 PlaceOfDeath (eu.europeana.metis.schema.jibx.PlaceOfDeath)1