use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testFieldRemoval.
@Test
public void testFieldRemoval() throws URISyntaxException {
String field = "urn:the.field:used.for.this.Test";
ValueFactory vf = getValueFactory();
Representation rep = createRepresentation(null);
// Test removal for References
String strRef = "urn:testValue";
rep.addReference(field, strRef);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.removeReference(field, strRef);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
Reference ref = vf.createReference("urn:testValue2");
rep.add(field, ref);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.remove(field, ref);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
// test removal for texts (with and without language)
String strText = "test text";
String strTextLang = "en";
rep.addNaturalText(field, strText, strTextLang);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.removeNaturalText(field, strText, strTextLang);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
String strTextNoLang = "test text without lang";
rep.addNaturalText(field, strTextNoLang);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.removeNaturalText(field, strTextNoLang);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
// there is also the possibility to explicitly parse null as language
// could internally case differences however externally this is the same
rep.addNaturalText(field, strTextNoLang, (String) null);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.removeNaturalText(field, strTextNoLang, (String) null);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
Text text = vf.createText("Das ist ein Text zum testen des Text Objektes", "de");
rep.add(field, text);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.remove(field, text);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
// Test a dataTypes values
Integer intValue = 42;
rep.add(field, intValue);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.remove(field, intValue);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
// Some Values are converted by the add(String field,Object value) Method
// to other data types. This MUST also be assured for removal
// NOTE: testing the conversions is done in other test methods!
URI testURI = new URI("http://www.test.org/test");
rep.add(field, testURI);
assertTrue(asCollection(rep.getFieldNames()).contains(field));
rep.remove(field, testURI);
assertFalse(asCollection(rep.getFieldNames()).contains(field));
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class YardTest method testCreateWithNull.
@Test
public void testCreateWithNull() throws YardException {
Yard yard = getYard();
Representation test = yard.create(null);
assertNotNull("Parsing NULL to create(String) MUST create a valid Representation", test);
// add id to cleanup list
representationIds.add(test.getId());
Representation test2 = yard.create(null);
assertNotNull("Parsing NULL to create(String) MUST create a valid Representation", test2);
// add id to cleanup list
representationIds.add(test2.getId());
assertNotSame(test, test2);
assertFalse("Two Representation created with create(null) MUST NOT be equals", test.equals(test2));
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class YardTest method testRemoveAll.
/**
* Tests that multiple Representations are removed.
*
* @throws YardException
*/
@Test
public void testRemoveAll() throws YardException {
// NOTE: This test needs not to use the create(..) method, because we
// remove the created representation form the store anyway as part of the
// test
String id = "urn:yard.test.testRemoveAll:representation.id1";
String id2 = "urn:yard.test.testRemoveAll:representation.id2";
String field = "urn:the.field:used.for.this.Test";
String testValue = "This is a test";
Yard yard = getYard();
// use both ways to add the two Representations (should make no differences,
// but one never can know ...
// create and add
Representation test1 = yard.create(id);
// add value
test1.add(field, testValue);
// store
yard.store(test1);
// create
Representation test2 = yard.getValueFactory().createRepresentation(id2);
// add value
test2.add(field, testValue);
// store
yard.store(test2);
// test if stored
assertTrue(yard.isRepresentation(test1.getId()));
assertTrue(yard.isRepresentation(test2.getId()));
// remove
yard.removeAll();
// test if removed
assertFalse(yard.isRepresentation(test1.getId()));
assertFalse(yard.isRepresentation(test2.getId()));
//test that Yard is still useable after removeAll
// store
yard.store(test1);
// test if stored
assertTrue(yard.isRepresentation(test1.getId()));
// remove
yard.removeAll();
assertFalse(yard.isRepresentation(test1.getId()));
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testNullFieldGetReferences.
@Test(expected = IllegalArgumentException.class)
public void testNullFieldGetReferences() {
Representation rep = createRepresentation(null);
rep.getReferences(null);
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RepresentationTest method testRemoveStringValuesByRemovingNaturalLanguageTextsWithNoLanguage.
/**
* String values are treated the same as natural language values with the default (<code>null</code>)
* language. <br>
* Removing a natural language value with no defined language MUST therefore also remove a string value
* with the parse same text.
*/
@Test
public void testRemoveStringValuesByRemovingNaturalLanguageTextsWithNoLanguage() {
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 only the text
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));
}
Aggregations