Search in sources :

Example 1 with ProxyType

use of eu.europeana.metis.schema.jibx.ProxyType in project metis-framework by europeana.

the class LanguageClassifierTest method testCreateLanguageTagStatistics.

@Test
void testCreateLanguageTagStatistics() {
    // Create the RDF
    final RdfWrapper rdf = mock(RdfWrapper.class);
    // Create the contextual classes
    final PlaceType place1 = new PlaceType();
    place1.setAbout("place about 1");
    final PlaceType place2 = new PlaceType();
    place2.setAbout("place about 2");
    final TimeSpanType timeSpan = new TimeSpanType();
    timeSpan.setAbout("time span about");
    final Concept concept = new Concept();
    concept.setAbout("concept about");
    doReturn(Arrays.asList(place1, place2)).when(rdf).getPlaces();
    doReturn(Collections.singletonList(timeSpan)).when(rdf).getTimeSpans();
    doReturn(Collections.singletonList(concept)).when(rdf).getConcepts();
    // Create proxies
    final ProxyType providerProxy1 = new ProxyType();
    providerProxy1.setEuropeanaProxy(new EuropeanaProxy());
    providerProxy1.getEuropeanaProxy().setEuropeanaProxy(false);
    final ProxyType providerProxy2 = new ProxyType();
    providerProxy2.setEuropeanaProxy(new EuropeanaProxy());
    providerProxy2.getEuropeanaProxy().setEuropeanaProxy(false);
    doReturn(Arrays.asList(providerProxy1, providerProxy2, null)).when(rdf).getProviderProxies();
    // Test the method.
    final LanguageClassifier classifier = spy(new LanguageClassifier());
    final LanguageTagStatistics result = classifier.createLanguageTagStatistics(rdf);
    verify(classifier, times(1)).addProxyToStatistics(providerProxy1, result);
    verify(classifier, times(1)).addProxyToStatistics(providerProxy2, result);
    verify(classifier, times(2)).addProxyToStatistics(any(), any());
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) PlaceType(eu.europeana.metis.schema.jibx.PlaceType) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) EuropeanaProxy(eu.europeana.metis.schema.jibx.EuropeanaProxy) Test(org.junit.jupiter.api.Test)

Example 2 with ProxyType

use of eu.europeana.metis.schema.jibx.ProxyType in project metis-framework by europeana.

the class EnablingElementTest method testElementWithFixedGroup.

private <T extends ResourceOrLiteralType> void testElementWithFixedGroup(EnablingElement element, ContextualClassGroup group, Supplier<T> constructor, BiConsumer<ProxyType, T> setter) {
    final Set<ContextualClassGroup> groups = Collections.singleton(group);
    // Test with empty list
    assertTrue(element.analyze(Collections.emptyList(), Collections.emptyMap()).isEmpty());
    // Test with empty proxies
    final ProxyType proxy1 = new ProxyType();
    final ProxyType proxy2 = new ProxyType();
    assertTrue(element.analyze(Arrays.asList(proxy1, proxy2), Collections.emptyMap()).isEmpty());
    // Set just a value in one of them.
    // Note: we don't have to check a variety of values, ResourceLinkFromProxyTest already does.
    final T value = constructor.get();
    setter.accept(proxy1, value);
    value.setString("test value");
    assertEquals(groups, element.analyze(Arrays.asList(proxy1, proxy2), Collections.emptyMap()));
    assertEquals(groups, element.analyze(Arrays.asList(proxy2, proxy1), Collections.emptyMap()));
    // Set just a link in one of them.
    // Note: we don't have to check a variety of links, ResourceLinkFromProxyTest already does.
    value.setString(null);
    value.setResource(new Resource());
    value.getResource().setResource("test link");
    assertEquals(groups, element.analyze(Arrays.asList(proxy1, proxy2), Collections.emptyMap()));
    assertEquals(groups, element.analyze(Arrays.asList(proxy2, proxy1), Collections.emptyMap()));
}
Also used : Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) ProxyType(eu.europeana.metis.schema.jibx.ProxyType)

Example 3 with ProxyType

use of eu.europeana.metis.schema.jibx.ProxyType in project metis-framework by europeana.

the class ContextualClassesBreakdownClassifierTest method countQualifyingContextualClassTypes.

@Test
void countQualifyingContextualClassTypes() {
    // Create mocks of the classifier and test empty object.
    final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
    final RdfWrapper entity = mock(RdfWrapper.class);
    assertEquals(0, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    // Create the contextual objects.
    final List<AgentType> agents = Collections.singletonList(new AgentType());
    final List<Concept> concepts = Collections.singletonList(new Concept());
    final List<PlaceType> places = Arrays.asList(new PlaceType(), new PlaceType());
    final List<TimeSpanType> timeSpans = Collections.singletonList(new TimeSpanType());
    doReturn(agents).when(entity).getAgents();
    doReturn(concepts).when(entity).getConcepts();
    doReturn(places).when(entity).getPlaces();
    doReturn(timeSpans).when(entity).getTimeSpans();
    // Set the about values in the contextual objects
    final String agentAbout = "agentAbout";
    final String conceptAbout = "conceptAbout";
    final String linkedPlaceAbout = "linkedPlaceAbout";
    final String unlinkedPlaceAbout = "unlinkedPlaceAbout";
    final String existingTimespanAbout = "existingTimeSpanAbout";
    final String absentTimespanAbout = "absentTimeSpanAbout";
    agents.get(0).setAbout(agentAbout);
    concepts.get(0).setAbout(conceptAbout);
    places.get(0).setAbout(linkedPlaceAbout);
    places.get(1).setAbout(unlinkedPlaceAbout);
    timeSpans.get(0).setAbout(existingTimespanAbout);
    // Create links to most objects and check that they are indeed obtainable.
    final List<ProxyType> proxies = Arrays.asList(new ProxyType(), new ProxyType());
    doReturn(proxies).when(entity).getProviderProxies();
    proxies.get(0).setSameAList(Arrays.asList(new SameAs(), new SameAs(), new SameAs()));
    proxies.get(1).setSameAList(Arrays.asList(new SameAs(), new SameAs(), new SameAs()));
    proxies.get(0).getSameAList().get(0).setResource(agentAbout);
    proxies.get(0).getSameAList().get(1).setResource(conceptAbout);
    proxies.get(0).getSameAList().get(2).setResource(linkedPlaceAbout);
    proxies.get(1).getSameAList().get(0).setResource(agentAbout);
    proxies.get(1).getSameAList().get(1).setResource(existingTimespanAbout);
    proxies.get(1).getSameAList().get(2).setResource(absentTimespanAbout);
    assertEquals(new HashSet<>(Arrays.asList(agentAbout, conceptAbout, linkedPlaceAbout)), ResourceLinkFromProxy.SAME_AS.getLinkAndValueGetter().getLinks(proxies.get(0)).collect(Collectors.toSet()));
    assertEquals(new HashSet<>(Arrays.asList(agentAbout, existingTimespanAbout, absentTimespanAbout)), ResourceLinkFromProxy.SAME_AS.getLinkAndValueGetter().getLinks(proxies.get(1)).collect(Collectors.toSet()));
    // Do the tests for no qualifying entities (except the unlinked one).
    doReturn(false).when(classifier).entityQualifies(agents.get(0));
    doReturn(false).when(classifier).entityQualifies(concepts.get(0));
    doReturn(false).when(classifier).entityQualifies(places.get(0));
    doReturn(true).when(classifier).entityQualifies(places.get(1));
    doReturn(false).when(classifier).entityQualifies(timeSpans.get(0));
    assertEquals(0, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    // Make some of them qualifying and do the tests again.
    doReturn(true).when(classifier).entityQualifies(agents.get(0));
    assertEquals(1, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    doReturn(true).when(classifier).entityQualifies(concepts.get(0));
    assertEquals(2, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    doReturn(true).when(classifier).entityQualifies(places.get(0));
    assertEquals(3, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    doReturn(true).when(classifier).entityQualifies(timeSpans.get(0));
    assertEquals(4, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    // Make some of them non-qualifying and do the tests again.
    doReturn(false).when(classifier).entityQualifies(agents.get(0));
    assertEquals(3, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    doReturn(false).when(classifier).entityQualifies(concepts.get(0));
    assertEquals(2, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    doReturn(false).when(classifier).entityQualifies(places.get(0));
    assertEquals(1, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
    doReturn(false).when(classifier).entityQualifies(timeSpans.get(0));
    assertEquals(0, classifier.countQualifyingContextualClassTypes(entity).getCompleteContextualResources());
}
Also used : Concept(eu.europeana.metis.schema.jibx.Concept) PlaceType(eu.europeana.metis.schema.jibx.PlaceType) TimeSpanType(eu.europeana.metis.schema.jibx.TimeSpanType) AgentType(eu.europeana.metis.schema.jibx.AgentType) RdfWrapper(eu.europeana.indexing.utils.RdfWrapper) SameAs(eu.europeana.metis.schema.jibx.SameAs) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Test(org.junit.jupiter.api.Test)

Example 4 with ProxyType

use of eu.europeana.metis.schema.jibx.ProxyType in project metis-framework by europeana.

the class EnablingElementsBreakdownClassifierTest method testAnalyzeForElements.

@Test
void testAnalyzeForElements() {
    // Create some objects.
    final EnablingElementsClassifier classifier = new EnablingElementsClassifier();
    final String link = "link";
    final Map<String, Set<Class<? extends AboutType>>> contextualObjectMap = Collections.singletonMap(link, EnumSet.allOf(ContextualClassGroup.class).stream().map(ContextualClassGroup::getContextualClass).collect(Collectors.toSet()));
    // Create proxy with Created and a HasMet.
    final Created created = new Created();
    created.setString(link);
    created.setResource(new Resource());
    created.getResource().setResource(link);
    final HasMet hasMet = new HasMet();
    hasMet.setResource(link);
    final ProxyType proxy = new ProxyType();
    proxy.setChoiceList(Collections.singletonList(new Choice()));
    proxy.getChoiceList().get(0).setCreated(created);
    proxy.setHasMetList(Collections.singletonList(hasMet));
    final List<ProxyType> proxies = Collections.singletonList(proxy);
    // Test for some queries that the answer is the same as calling the enum directly. The enum
    // itself is tested in its own unit test class.
    assertEquals(EnablingElement.EDM_HAS_MET.analyze(proxies, contextualObjectMap), classifier.analyzeForElement(EnablingElement.EDM_HAS_MET, proxies, contextualObjectMap));
    assertEquals(EnablingElement.DCTERMS_CREATED.analyze(proxies, contextualObjectMap), classifier.analyzeForElement(EnablingElement.DCTERMS_CREATED, proxies, contextualObjectMap));
    assertEquals(EnablingElement.DCTERMS_ISSUED.analyze(proxies, contextualObjectMap), classifier.analyzeForElement(EnablingElement.DCTERMS_ISSUED, proxies, contextualObjectMap));
}
Also used : HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) HasMet(eu.europeana.metis.schema.jibx.HasMet) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Created(eu.europeana.metis.schema.jibx.Created) Test(org.junit.jupiter.api.Test)

Example 5 with ProxyType

use of eu.europeana.metis.schema.jibx.ProxyType in project metis-framework by europeana.

the class ProxyFieldInputTest method testProxy.

@Test
void testProxy() throws InstantiationException, IllegalAccessException {
    // The fields of the proxy come from the ProvidedCHO
    ProxyType proxy = createProxyFields();
    testMongo(proxy);
}
Also used : ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Test(org.junit.jupiter.api.Test)

Aggregations

ProxyType (eu.europeana.metis.schema.jibx.ProxyType)36 Test (org.junit.jupiter.api.Test)20 ArrayList (java.util.ArrayList)18 RDF (eu.europeana.metis.schema.jibx.RDF)11 Resource (eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource)11 Choice (eu.europeana.metis.schema.jibx.EuropeanaType.Choice)8 Set (java.util.Set)8 ResourceOrLiteralType (eu.europeana.metis.schema.jibx.ResourceOrLiteralType)7 EuropeanaProxy (eu.europeana.metis.schema.jibx.EuropeanaProxy)6 Created (eu.europeana.metis.schema.jibx.Created)5 EuropeanaAggregationType (eu.europeana.metis.schema.jibx.EuropeanaAggregationType)5 Issued (eu.europeana.metis.schema.jibx.Issued)5 Temporal (eu.europeana.metis.schema.jibx.Temporal)5 HashSet (java.util.HashSet)5 ProxyFieldType (eu.europeana.enrichment.api.internal.ProxyFieldType)4 Concept (eu.europeana.metis.schema.jibx.Concept)4 CurrentLocation (eu.europeana.metis.schema.jibx.CurrentLocation)4 HasPart (eu.europeana.metis.schema.jibx.HasPart)4 IsPartOf (eu.europeana.metis.schema.jibx.IsPartOf)4 SearchTermContext (eu.europeana.enrichment.api.internal.SearchTermContext)3