use of eu.europeana.metis.schema.jibx.ResourceOrLiteralType in project metis-framework by europeana.
the class ContextualClassesBreakdownClassifierTest method testHasResourceOrLiteralProperty.
@Test
void testHasResourceOrLiteralProperty() {
final ContextualClassesClassifier classifier = spy(new ContextualClassesClassifier());
// Test with null or empty list
assertFalse(classifier.hasResourceOrLiteralProperty(null));
assertFalse(classifier.hasResourceOrLiteralProperty(Collections.emptyList()));
// Test with objects
final ResourceOrLiteralType object1 = new ResourceOrLiteralType();
final ResourceOrLiteralType object2 = new ResourceOrLiteralType();
doReturn(false).when(classifier).hasProperty(object1);
doReturn(true).when(classifier).hasProperty(object2);
assertFalse(classifier.hasResourceOrLiteralProperty(Arrays.asList(object1, object1)));
assertTrue(classifier.hasResourceOrLiteralProperty(Arrays.asList(object1, object2)));
assertTrue(classifier.hasResourceOrLiteralProperty(Arrays.asList(object2, object1)));
assertTrue(classifier.hasResourceOrLiteralProperty(Arrays.asList(object2, object2)));
}
use of eu.europeana.metis.schema.jibx.ResourceOrLiteralType 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 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 in project metis-framework by europeana.
the class LanguageTagStatisticsTest method testAddToStatisticsForResourceOrLiteralType.
@Test
void testAddToStatisticsForResourceOrLiteralType() {
// Create the mock.
final LanguageTagStatistics statistics = spy(new LanguageTagStatistics(null, null, null));
// Create valid resource or literal types
final String resource1 = "resource1";
final String resource2 = "resource2";
final String resource3 = "resource3";
final String resource4 = "resource4";
doReturn(true).when(statistics).containsContextualClass(resource1);
doReturn(true).when(statistics).containsContextualClass(resource2);
doReturn(true).when(statistics).containsContextualClass(resource3);
doReturn(false).when(statistics).containsContextualClass(resource4);
final ResourceOrLiteralType valid1 = createResourceOrLiteralType("lang", null, "value1");
final ResourceOrLiteralType valid2 = createResourceOrLiteralType("lang", resource2, null);
final ResourceOrLiteralType valid3 = createResourceOrLiteralType("lang", resource3, "value3");
final ResourceOrLiteralType valid4 = createResourceOrLiteralType("lang", resource4, "value4");
// Create invalid resource or literal types
final ResourceOrLiteralType invalid1 = createResourceOrLiteralType(" ", "resourceA", "valueA");
final ResourceOrLiteralType invalid2 = createResourceOrLiteralType(null, "resourceB", "valueB");
final ResourceOrLiteralType invalid3 = createResourceOrLiteralType("lang3", null, null);
final ResourceOrLiteralType invalid4 = createResourceOrLiteralType("lang4", "", " ");
final ResourceOrLiteralType invalid5 = createResourceOrLiteralType("lang4", resource4, " ");
invalid2.setLang(null);
invalid3.setResource(null);
// Create property types
final PropertyType propertyType1 = PropertyType.DC_FORMAT;
final PropertyType propertyType2 = PropertyType.EDM_CURRENT_LOCATION;
final PropertyType propertyType3 = PropertyType.DC_TYPE;
final PropertyType propertyType4 = PropertyType.EDM_HAS_TYPE;
final PropertyType propertyType5 = PropertyType.DC_COVERAGE;
final PropertyType propertyType6 = PropertyType.DC_DESCRIPTION;
// Test sanity checks
assertThrows(IllegalArgumentException.class, () -> statistics.addToStatistics(valid1, null));
assertThrows(IllegalArgumentException.class, () -> statistics.addToStatistics((ResourceOrLiteralType) null, null));
statistics.addToStatistics((ResourceOrLiteralType) null, propertyType1);
assertTrue(statistics.getQualifiedProperties().isEmpty());
assertTrue(statistics.getQualifiedPropertiesWithLanguage().isEmpty());
// Test for invalid literal types: empty value means not registered at all.
statistics.addToStatistics(invalid1, propertyType1);
statistics.addToStatistics(invalid2, propertyType2);
statistics.addToStatistics(invalid3, propertyType3);
statistics.addToStatistics(invalid4, propertyType4);
statistics.addToStatistics(invalid5, propertyType5);
assertEquals(EnumSet.of(propertyType1, propertyType2, propertyType5), statistics.getQualifiedProperties());
assertTrue(statistics.getQualifiedPropertiesWithLanguage().isEmpty());
// Test for valid literal type: add new type.
statistics.addToStatistics(valid1, propertyType3);
statistics.addToStatistics(valid2, propertyType4);
statistics.addToStatistics(valid3, propertyType6);
assertEquals(EnumSet.of(propertyType1, propertyType2, propertyType3, propertyType4, propertyType5, propertyType6), statistics.getQualifiedProperties());
assertEquals(EnumSet.of(propertyType3, propertyType4, propertyType6), statistics.getQualifiedPropertiesWithLanguage());
// Test for valid literal type: add to already registered type with language.
statistics.addToStatistics(valid4, propertyType3);
assertEquals(EnumSet.of(propertyType1, propertyType2, propertyType3, propertyType4, propertyType5, propertyType6), statistics.getQualifiedProperties());
assertEquals(EnumSet.of(propertyType3, propertyType4, propertyType6), statistics.getQualifiedPropertiesWithLanguage());
// Test for valid literal type: add to already registered type without language.
statistics.addToStatistics(valid4, propertyType2);
assertEquals(EnumSet.of(propertyType1, propertyType2, propertyType3, propertyType4, propertyType5, propertyType6), statistics.getQualifiedProperties());
assertEquals(EnumSet.of(propertyType2, propertyType3, propertyType4, propertyType6), statistics.getQualifiedPropertiesWithLanguage());
}
use of eu.europeana.metis.schema.jibx.ResourceOrLiteralType in project metis-framework by europeana.
the class ItemExtractorUtilsTest method testExtractLabelResourceReturnNull.
@Test
void testExtractLabelResourceReturnNull() {
LabelResource label = new LabelResource(null);
ResourceOrLiteralType output = ItemExtractorUtils.extractLabelResource(label, ResourceOrLiteralType::new);
assertNotNull(output);
assertEquals("", output.getString());
assertNull(output.getLang());
assertNull(output.getResource());
}
Aggregations