use of eu.europeana.metis.schema.jibx.AltLabel 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.AltLabel 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.AltLabel in project metis-framework by europeana.
the class LanguageTagStatisticsTest method testConstruction.
@Test
void testConstruction() {
// Define some about values
final String about1 = "about1";
final String about2 = "about2";
final String about3 = "about3";
final String about4 = "about4";
// Create contextual classes for later use. They are all valid to begin with.
final PlaceType place1 = new PlaceType();
place1.setPrefLabelList(Collections.singletonList(createPrefLabel("lang1", "value1")));
place1.setAbout(about1);
final PlaceType place2 = new PlaceType();
place2.setPrefLabelList(Collections.singletonList(createPrefLabel("lang2", "value2")));
place2.setAbout(about2);
final TimeSpanType timeSpan = new TimeSpanType();
timeSpan.setPrefLabelList(Collections.singletonList(createPrefLabel("lang3", "value3")));
timeSpan.setAbout(about3);
final Concept concept = new Concept();
final Concept.Choice choiceA = new Concept.Choice();
choiceA.setPrefLabel(createPrefLabel("lang4a", "value4a"));
final Concept.Choice choiceB = new Concept.Choice();
choiceB.setPrefLabel(createPrefLabel("lang4b", "value4b"));
concept.setChoiceList(Arrays.asList(choiceA, choiceB));
concept.setAbout(about4);
// Test that they are all represented.
final LanguageTagStatistics statistics1 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
assertEquals(new HashSet<>(Arrays.asList(about1, about2, about3, about4)), statistics1.getContextualClassesWithLanguage());
assertTrue(statistics1.containsContextualClass(about1));
assertTrue(statistics1.containsContextualClass(about2));
assertTrue(statistics1.containsContextualClass(about3));
assertTrue(statistics1.containsContextualClass(about4));
// Now make some preflabels invalid.
place1.getPrefLabelList().get(0).setLang(new Lang());
place2.getPrefLabelList().get(0).setLang(null);
timeSpan.getPrefLabelList().get(0).setString(" ");
concept.getChoiceList().get(0).getPrefLabel().getLang().setLang(" ");
final LanguageTagStatistics statistics2 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
assertEquals(Collections.singleton(about4), statistics2.getContextualClassesWithLanguage());
concept.getChoiceList().get(1).getPrefLabel().setString(null);
final LanguageTagStatistics statistics3 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
assertEquals(Collections.emptySet(), statistics3.getContextualClassesWithLanguage());
// Now make some preflabel collections invalid
place1.setPrefLabelList(Collections.emptyList());
place2.setPrefLabelList(null);
concept.getChoiceList().forEach(Concept.Choice::clearChoiceListSelect);
concept.getChoiceList().get(0).setAltLabel(new AltLabel());
concept.getChoiceList().get(0).getAltLabel().setString("altLabelValue");
concept.getChoiceList().get(0).getAltLabel().setLang(createLang("altLabelLanguage"));
concept.getChoiceList().get(1).setAltLabel(null);
final LanguageTagStatistics statistics4 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
assertEquals(Collections.emptySet(), statistics4.getContextualClassesWithLanguage());
concept.setChoiceList(null);
final LanguageTagStatistics statistics5 = new LanguageTagStatistics(Arrays.asList(place1, place2), Collections.singletonList(timeSpan), Collections.singletonList(concept));
assertEquals(Collections.emptySet(), statistics5.getContextualClassesWithLanguage());
}
use of eu.europeana.metis.schema.jibx.AltLabel in project metis-framework by europeana.
the class ItemExtractorUtilsTest method testToChoices.
@Test
void testToChoices() {
List<Choice> choices = new ArrayList<>();
List<AltLabel> altLabels = new ArrayList<>();
AltLabel label1 = new AltLabel();
AltLabel label2 = new AltLabel();
AltLabel label3 = new AltLabel();
Lang lang1 = new Lang();
lang1.setLang("lang1");
Lang lang2 = new Lang();
lang2.setLang("lang2");
Lang lang3 = new Lang();
lang3.setLang("lang3");
label1.setString("value1");
label1.setLang(lang1);
label2.setString("value2");
label1.setLang(lang2);
label3.setString("value3");
label1.setLang(lang3);
altLabels.add(label1);
altLabels.add(label3);
altLabels.add(label3);
ItemExtractorUtils.toChoices(altLabels, Choice::setAltLabel, choices);
assertTrue(choices.size() > 0);
for (AltLabel label : altLabels) {
List<Choice> result = choices.stream().filter(x -> x.getAltLabel().equals(label)).collect(Collectors.toList());
assertTrue(result.size() > 0);
}
}
use of eu.europeana.metis.schema.jibx.AltLabel 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