Search in sources :

Example 1 with HiddenLabel

use of eu.europeana.metis.schema.jibx.HiddenLabel 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)

Aggregations

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