use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testRemoveStringValuesByRemovingNaturalLanguageTextsWithNullLanguage.
/**
* String values are treated the same as natural language values with the default (<code>null</code>)
* language. <br>
* Removing a natural language value with parsing null as language MUST therefore also remove a string
* value with the parse same text.
*/
@Test
public void testRemoveStringValuesByRemovingNaturalLanguageTextsWithNullLanguage() {
String field = "urn:the.field:used.for.this.Test";
Representation rep = initNaturalLanguageTest(field);
Set<String> textSet = new HashSet<String>(NL_TEST_all);
// remove a string value by parsing the text and null as language
rep.removeNaturalText(field, NL_TEST_string, (String) null);
for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next().getText())) ;
// only one element should be removed
assertTrue(textSet.size() == 1);
// and this should be the stringTest
assertTrue(textSet.remove(NL_TEST_string));
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testGetFirstValueWithUnsupportedType.
@Test(expected = UnsupportedTypeException.class)
public void testGetFirstValueWithUnsupportedType() {
String field = "urn:the.field:used.for.this.Test";
Representation rep = createRepresentation(null);
Object value = getUnsupportedValueInstance();
if (value == null) {
// this test is not needed therefore return an dummy Exception
throw new UnsupportedTypeException(Object.class, "dummy exception to successfully complete this unnecessary test");
} else {
Class<?> unsupported = value.getClass();
rep.getFirst(field, unsupported);
}
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testNullFieldAddNaturalText.
@Test(expected = IllegalArgumentException.class)
public void testNullFieldAddNaturalText() {
Representation rep = createRepresentation(null);
rep.addNaturalText(null, "test");
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testRemoveStringValuesByRemovingNaturalLanguageTextsWithEmptyLanguageArray.
/**
* String values are treated the same as natural language values with the default (<code>null</code>)
* language. <br>
* Removing a natural language value with an empty language array MUST be interpreted as default language
* and therefore remove the String value.
*/
@Test
public void testRemoveStringValuesByRemovingNaturalLanguageTextsWithEmptyLanguageArray() {
String field = "urn:the.field:used.for.this.Test";
Representation rep = initNaturalLanguageTest(field);
Set<String> textSet = new HashSet<String>(NL_TEST_all);
// remove a string value by parsing an empty list of languages
rep.removeNaturalText(field, NL_TEST_string);
textSet.addAll(Arrays.asList(NL_TEST_string, NL_TEST_noLang, NL_TEST_en, NL_TEST_en2, NL_TEST_de, NL_TEST_de_AT));
for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next().getText())) ;
// only one element should be removed
assertTrue(textSet.size() == 1);
// and this should be the stringTest
assertTrue(textSet.remove(NL_TEST_string));
// re add the value for further tests
rep.add(field, NL_TEST_string);
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testNullFieldRemove.
@Test(expected = IllegalArgumentException.class)
public void testNullFieldRemove() {
Representation rep = createRepresentation(null);
rep.remove(null, "test");
}
Aggregations