use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.
the class RepresentationTest method testNonExistingFields.
/**
* Tests if value iterators for non existing fields return an Iterator with no elements (Here it is
* important, that in such cases methods do not return <code>null</code>).
*/
@Test
public void testNonExistingFields() {
String field = "urn:this.field:does.not:exist";
// Iterators MUST NOT be NULL but MUST NOT contain any element
Representation rep = createRepresentation(null);
Iterator<String> fieldIt = rep.getFieldNames();
assertNotNull(fieldIt);
assertFalse(fieldIt.hasNext());
Iterator<Object> valueIt = rep.get(field);
assertNotNull(valueIt);
assertFalse(valueIt.hasNext());
Iterator<Reference> refIt = rep.getReferences(field);
assertNotNull(refIt);
assertFalse(refIt.hasNext());
Iterator<Text> textIt = rep.get(field, (String[]) null);
assertNotNull(textIt);
assertFalse(textIt.hasNext());
}
use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.
the class RepresentationTest method testReferences.
@Test
public void testReferences() {
String field = "urn:the.field:used.for.this.Test";
Set<String> refs = new HashSet<String>(Arrays.asList("http://www.test.org/test1", "urn:test.org:test.1"));
Representation rep = createRepresentation(null);
for (String ref : refs) {
rep.addReference(field, ref);
}
Iterator<Reference> refIterator = rep.getReferences(field);
assertNotNull(refIterator);
while (refIterator.hasNext()) {
Reference ref = refIterator.next();
assertTrue(refs.remove(ref.getReference()));
}
assertTrue(refs.isEmpty());
}
use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.
the class RepresentationTest method testURLToReferenceConversion.
/**
* Tests if {@link Reference} instances are correctly generated for {@link URL}. This test also depends on
* the correct implementation of the {@link Reference#equals(Object)} method
*
* @throws MalformedURLException
*/
@Test
public void testURLToReferenceConversion() throws MalformedURLException {
String field = "urn:the.field:used.for.this.Test";
URL url = new URL("http://www.test.org/urlTest");
ValueFactory vf = getValueFactory();
Representation rep = createRepresentation(null);
// test empty reference
Iterator<Reference> refs = rep.getReferences(field);
assertFalse(refs.hasNext());
// test conversion
rep.add(field, url);
refs = rep.getReferences(field);
assertTrue(refs.hasNext());
assertEquals(refs.next().getReference(), url.toString());
assertFalse(refs.hasNext());
// test multiple adds do not generate duplicate References
rep.add(field, url);
assertTrue(asCollection(rep.get(field)).size() == 1);
// test adding a equivalent reference
rep.add(field, vf.createReference(url.toString()));
assertTrue(asCollection(rep.get(field)).size() == 1);
// test removing
rep.remove(field, url);
assertFalse(rep.get(field).hasNext());
}
use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.
the class ClerezzaYardTest method testRemovalOfTypeRepresentationStatement.
/**
* The Clerezza Yard uses the Statement<br>
* <code>representationId -> rdf:type -> Representation</code><br>
* to identify that an IRI in the RDF graph (Graph) represents a
* Representation. This Triple is added when a Representation is stored and
* removed if retrieved from the Yard.<p>
* This tests if this functions as expected
* @throws YardException
*/
@Test
public void testRemovalOfTypeRepresentationStatement() throws YardException {
Yard yard = getYard();
ValueFactory vf = yard.getValueFactory();
Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
Representation test = create();
//the rdf:type Representation MUST NOT be within the Representation
Assert.assertFalse(test.get(RDF.type.getUnicodeString()).hasNext());
//now add the statement and see if an IllegalStateException is thrown
/*
* The triple within this Statement is internally used to "mark" the
* URI of the Representation as
*/
test.add(RDF.type.getUnicodeString(), representationType);
}
use of org.apache.stanbol.entityhub.servicesapi.model.Reference in project stanbol by apache.
the class SesameYardTest method testRemovalOfTypeRepresentationStatement.
/**
* The Clerezza Yard uses the Statement<br>
* <code>representationId -> rdf:type -> Representation</code><br>
* to identify that an UriRef in the RDF graph (MGraph) represents a
* Representation. This Triple is added when a Representation is stored and
* removed if retrieved from the Yard.<p>
* This tests if this functions as expected
* @throws YardException
*/
@Test
public void testRemovalOfTypeRepresentationStatement() throws YardException {
Yard yard = getYard();
ValueFactory vf = yard.getValueFactory();
Reference representationType = vf.createReference(RdfResourceEnum.Representation.getUri());
Representation test = create();
//the rdf:type Representation MUST NOT be within the Representation
Assert.assertFalse(test.get(NamespaceEnum.rdf + "type").hasNext());
//now add the statement and see if an IllegalStateException is thrown
/*
* The triple within this Statement is internally used to "mark" the
* URI of the Representation as
*/
test.add(NamespaceEnum.rdf + "type", representationType);
}
Aggregations