use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testEmptyFieldRemoveAllNaturalText.
@Test(expected = IllegalArgumentException.class)
public void testEmptyFieldRemoveAllNaturalText() {
Representation rep = createRepresentation(null);
rep.removeAllNaturalText("", "de");
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testURIToReferenceConversion.
/**
* Tests if {@link Reference} instances are correctly generated for {@link URI}. This test also depends on
* the correct implementation of the {@link Reference#equals(Object)} method
*
* @throws URISyntaxException
*/
@Test
public void testURIToReferenceConversion() throws URISyntaxException {
String field = "urn:the.field:used.for.this.Test";
URI uri = new URI("http://www.test.org/uriTest");
ValueFactory vf = getValueFactory();
Representation rep = createRepresentation(null);
// test conversion
rep.add(field, uri);
Iterator<Reference> refs = rep.getReferences(field);
assertTrue(refs.hasNext());
assertEquals(refs.next().getReference(), uri.toString());
assertFalse(refs.hasNext());
// test multiple adds do not generate duplicate References
rep.add(field, uri);
assertTrue(asCollection(rep.get(field)).size() == 1);
// test adding a equivalent reference
rep.add(field, vf.createReference(uri.toString()));
assertTrue(asCollection(rep.get(field)).size() == 1);
// test removing
rep.remove(field, uri);
assertFalse(rep.get(field).hasNext());
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testRemoveAllNaturalLanguageValuesByParsingNullAsLanguageArray.
@Test
public void testRemoveAllNaturalLanguageValuesByParsingNullAsLanguageArray() {
String field = "urn:the.field:used.for.this.Test";
Representation rep = initNaturalLanguageTest(field);
// add a reference to ensure that only texts (and strings) are removed
String testReference = "http://www.test.org/test";
rep.addReference(field, testReference);
// test removal of all natural language values by parsing only a single argument
rep.removeAllNaturalText(field);
Iterator<Text> texts = rep.get(field, (String[]) null);
assertFalse(texts.hasNext());
// text of the added reference is still present
assertTrue(rep.get(field).hasNext());
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testRemoveNaturalTextWithCorrectAndWrongLanguage.
@Test
public void testRemoveNaturalTextWithCorrectAndWrongLanguage() {
String field = "urn:the.field:used.for.this.Test";
Representation rep = initNaturalLanguageTest(field);
// remove a specific text, parse one correct and one wrong lang
rep.removeNaturalText(field, NL_TEST_en2, "de", "en");
Set<String> textSet = new HashSet<String>(NL_TEST_all);
// remove all remaining values
for (Iterator<Text> texts = rep.getText(field); texts.hasNext(); textSet.remove(texts.next().getText())) ;
// and check that the value we expect to be removed is still in the set
assertTrue(textSet.size() == 1);
assertTrue(textSet.contains(NL_TEST_en2));
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testNullFieldRemoveAll.
@Test(expected = IllegalArgumentException.class)
public void testNullFieldRemoveAll() {
Representation rep = createRepresentation(null);
rep.removeAll(null);
}
Aggregations