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()));
}
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));
}
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));
}
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;
}
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);
}
Aggregations