use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testEmptyFieldAdd.
/*--------------------------------------------------------------------------
* Set of Tests that check if all Methods correctly throw a IllegalArgumentExceptions
* when parsing an empty string as field
* - important to prevent "" fields within the Entityhub
*--------------------------------------------------------------------------
*/
@Test(expected = IllegalArgumentException.class)
public void testEmptyFieldAdd() {
Representation rep = createRepresentation(null);
rep.add("", "test");
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testNullFieldAddReference.
@Test(expected = IllegalArgumentException.class)
public void testNullFieldAddReference() {
Representation rep = createRepresentation(null);
rep.addReference(null, "urn:test");
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testEmptyFieldGetFirstReference.
@Test(expected = IllegalArgumentException.class)
public void testEmptyFieldGetFirstReference() {
Representation rep = createRepresentation(null);
rep.getFirstReference("");
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testMultipleAddAndRemove.
@Test
public void testMultipleAddAndRemove() throws MalformedURLException, URISyntaxException {
String field = "urn:the.field:used.for.this.Test";
ValueFactory vf = getValueFactory();
Representation rep = createRepresentation(null);
Reference ref = vf.createReference("http://www.test.org/test");
Text text = vf.createText("test", "en");
Integer i = 42;
Double d = Math.PI;
URI uri = new URI("http://www.test.org/uriTest");
URL url = new URL("http://www.test.org/urlTest");
String[] textAsArray = new String[] { "Test text as Array", "en" };
Collection<Object> values = Arrays.asList(ref, text, i, d);
Collection<Object> convertedValues = Arrays.asList((Object) url, uri, textAsArray);
Collection<Object> allValues = Arrays.asList(ref, text, i, d, uri, url, textAsArray);
// test adding of collections
rep.add(field, values);
assertTrue(asCollection(rep.get(field)).size() == 4);
rep.remove(field, values);
assertFalse(rep.get(field).hasNext());
// test adding of Iterators
rep.add(field, values.iterator());
assertTrue(asCollection(rep.get(field)).size() == 4);
rep.remove(field, values.iterator());
assertFalse(rep.get(field).hasNext());
// test adding of Enumerations
Vector<Object> v = new Vector<Object>(values);
rep.add(field, v.elements());
assertTrue(asCollection(rep.get(field)).size() == 4);
rep.remove(field, v.elements());
assertFalse(rep.get(field).hasNext());
// test adding and removing elements that need to be converted
// only for collections this time -> want to test only converting is
// applied for both add and remove
rep.add(field, convertedValues);
assertTrue(asCollection(rep.get(field)).size() == 3);
rep.remove(field, convertedValues);
assertFalse(rep.get(field).hasNext());
// a final test to ensure, that remove does not only delete all values
rep.add(field, allValues);
assertTrue(asCollection(rep.get(field)).size() == 7);
rep.remove(field, convertedValues);
assertTrue(asCollection(rep.get(field)).size() == 4);
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testRemoveNaturalTextWithWrongNullLanguage.
@Test
public void testRemoveNaturalTextWithWrongNullLanguage() {
String field = "urn:the.field:used.for.this.Test";
Representation rep = initNaturalLanguageTest(field);
// remove a specific text, but with wrong null language -> also no effect
rep.removeNaturalText(field, NL_TEST_de, (String) null);
assertTrue(asCollection(rep.get(field)).size() == NL_TEST_all.size());
}
Aggregations