Search in sources :

Example 1 with Resource

use of eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource 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 2 with Resource

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

the class ContextualClassesBreakdownClassifierTest method testHasProperty.

@Test
void testHasProperty() {
    final ContextualClassesClassifier classifier = new ContextualClassesClassifier();
    // Test for literals
    assertFalse(classifier.hasProperty((LiteralType) null));
    final LiteralType literal = new LiteralType();
    literal.setString(null);
    assertFalse(classifier.hasProperty(literal));
    literal.setString(" ");
    assertFalse(classifier.hasProperty(literal));
    literal.setString("test 1");
    assertTrue(classifier.hasProperty(literal));
    // Test for resources
    assertFalse(classifier.hasProperty((ResourceType) null));
    final ResourceType resource = new ResourceType();
    resource.setResource(null);
    assertFalse(classifier.hasProperty(resource));
    resource.setResource(" ");
    assertFalse(classifier.hasProperty(resource));
    resource.setResource("test 2");
    assertTrue(classifier.hasProperty(resource));
    // Test for resource/literal objects
    assertFalse(classifier.hasProperty((ResourceOrLiteralType) null));
    final ResourceOrLiteralType object = new ResourceOrLiteralType();
    object.setResource(null);
    object.setString(null);
    assertFalse(classifier.hasProperty(object));
    object.setString(" ");
    assertFalse(classifier.hasProperty(object));
    object.setString("test");
    assertTrue(classifier.hasProperty(object));
    object.setString(null);
    object.setResource(new Resource());
    object.getResource().setResource(null);
    assertFalse(classifier.hasProperty(object));
    object.getResource().setResource(" ");
    assertFalse(classifier.hasProperty(object));
    object.getResource().setResource("test 3");
    assertTrue(classifier.hasProperty(object));
}
Also used : Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) LiteralType(eu.europeana.metis.schema.jibx.LiteralType) ResourceType(eu.europeana.metis.schema.jibx.ResourceType) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) Test(org.junit.jupiter.api.Test)

Example 3 with Resource

use of eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource 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 4 with Resource

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

the class FieldInputUtilsTest method prepareRLT.

private ResourceOrLiteralType prepareRLT() {
    ResourceOrLiteralType rlt = new ResourceOrLiteralType();
    ResourceOrLiteralType.Lang lang = new ResourceOrLiteralType.Lang();
    lang.setLang("en");
    rlt.setLang(lang);
    Resource res = new Resource();
    res.setResource("test resource");
    rlt.setResource(res);
    rlt.setString("test string");
    return rlt;
}
Also used : Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) Lang(eu.europeana.metis.schema.jibx.LiteralType.Lang) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType)

Example 5 with Resource

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

the class ResourceLinkFromProxyTest method testGetLinksAndValuesInChoice.

private <T extends ResourceOrLiteralType> void testGetLinksAndValuesInChoice(ResourceLinkFromProxy resource, Supplier<T> constructor, BiConsumer<Choice, T> setter) {
    // Create objects
    final ProxyType proxy = new ProxyType();
    final T value1 = constructor.get();
    final T value2 = constructor.get();
    // Test with null list
    proxy.setChoiceList(null);
    assertNoLinks(proxy, resource);
    assertNoValues(proxy, resource);
    // Test with null or empty choices
    proxy.setChoiceList(Arrays.asList(null, new Choice()));
    setter.accept(proxy.getChoiceList().get(1), null);
    assertNoLinks(proxy, resource);
    assertNoValues(proxy, resource);
    // Test with null value and empty value
    proxy.setChoiceList(Arrays.asList(new Choice(), new Choice()));
    setter.accept(proxy.getChoiceList().get(0), value1);
    setter.accept(proxy.getChoiceList().get(1), value2);
    value1.setResource(null);
    value1.setString(null);
    value2.setResource(new Resource());
    value2.getResource().setResource(" ");
    value2.setString(" ");
    assertNoLinks(proxy, resource);
    assertNoValues(proxy, resource);
    // Test with actual value
    final String testResource1 = "test resource 1";
    final String testResource2 = "test resource 2";
    final String testLiteral1 = "test literal 1";
    final String testLiteral2 = "test literal 2";
    value1.setResource(new Resource());
    value1.getResource().setResource(testResource1);
    value2.getResource().setResource(testResource2);
    value1.setString(testLiteral1);
    value2.setString(testLiteral2);
    final List<String> linksDifferent = resource.getLinkAndValueGetter().getLinks(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testResource1, testResource2), linksDifferent);
    final List<String> valuesDifferent = resource.getLinkAndValueGetter().getValues(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testLiteral1, testLiteral2), valuesDifferent);
    // Test with the same values
    value2.getResource().setResource(testResource1);
    value2.setString(testLiteral1);
    final List<String> linksSame = resource.getLinkAndValueGetter().getLinks(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testResource1, testResource1), linksSame);
    final List<String> valuesSame = resource.getLinkAndValueGetter().getValues(proxy).collect(Collectors.toList());
    assertEquals(Arrays.asList(testLiteral1, testLiteral1), valuesSame);
}
Also used : Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) ProxyType(eu.europeana.metis.schema.jibx.ProxyType)

Aggregations

Resource (eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource)20 ProxyType (eu.europeana.metis.schema.jibx.ProxyType)10 ResourceOrLiteralType (eu.europeana.metis.schema.jibx.ResourceOrLiteralType)9 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 Choice (eu.europeana.metis.schema.jibx.EuropeanaType.Choice)5 RDF (eu.europeana.metis.schema.jibx.RDF)4 HashSet (java.util.HashSet)4 ProxyFieldType (eu.europeana.enrichment.api.internal.ProxyFieldType)3 Created (eu.europeana.metis.schema.jibx.Created)3 HasPart (eu.europeana.metis.schema.jibx.HasPart)3 List (java.util.List)3 Set (java.util.Set)3 AboutType (eu.europeana.metis.schema.jibx.AboutType)2 Coverage (eu.europeana.metis.schema.jibx.Coverage)2 Format (eu.europeana.metis.schema.jibx.Format)2 HasMet (eu.europeana.metis.schema.jibx.HasMet)2 IsPartOf (eu.europeana.metis.schema.jibx.IsPartOf)2 Issued (eu.europeana.metis.schema.jibx.Issued)2 Note (eu.europeana.metis.schema.jibx.Note)2