org.openrdf.model.impl.URIImpl Java Examples

The following examples show how to use org.openrdf.model.impl.URIImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Test_REST_HASSTMT.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public void test_HASSTMT_sp() throws Exception {

      doInsertbyURL("POST", packagePath + "test_estcard.ttl");

      assertTrue(m_repo.hasStatement(new URIImpl(
            "http://www.bigdata.com/Mike"),// s
            RDFS.LABEL,// p
            null,// o
            false// includeInferred
            ));

      assertFalse(m_repo.hasStatement(new URIImpl(
            "http://www.bigdata.com/Mike"),// s
            RDF.BAG,// p
            null,// o
            false// includeInferred
            ));

   }
 
Example #2
Source File: GraphContextQueryTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testContextedBodySetResourceAsString() throws Exception {
    URI uri = new URIImpl("http://www.example.com/context#test");

    String resource = "http://www.example.com/resource#someResource";
    String resource2 = "http://www.example.com/resource#someOtherResource";

    Annotation annotation = anno4j.createObject(Annotation.class,uri);
    TextualBody body = anno4j.createObject(TextualBody.class,uri);
    annotation.addBody(body);
    body.setResourceAsString(resource);

    Annotation annotationDef = anno4j.createObject(Annotation.class,uri);
    TextualBody bodyDef = anno4j.createObject(TextualBody.class);
    annotationDef.addBody(bodyDef);
    bodyDef.setResourceAsString(resource2);

    List<TextualBody> result = anno4j.findAll(TextualBody.class, uri);
    assertEquals(1, result.size());
    assertEquals(resource, result.get(0).getResourceAsString());

    TextualBody result2 = anno4j.findByID(TextualBody.class, resource2);
    assertEquals(resource2, result2.getResourceAsString());
}
 
Example #3
Source File: SparqlParameters.java    From anno4j with Apache License 2.0 6 votes vote down vote up
private Object getDefaultValue(String value, Type type, ObjectConnection con) {
	Class<?> ctype = asClass(type);
	if (Set.class.equals(ctype)) {
		Object v = getDefaultValue(value, getComponentType(ctype, type), con);
		if (v == null)
			return null;
		return Collections.singleton(v);
	}
	ValueFactory vf = con.getValueFactory();
	ObjectFactory of = con.getObjectFactory();
	if (of.isDatatype(ctype)) {
		URIImpl datatype = new URIImpl("java:" + ctype.getName());
		return of.createValue(of.createObject(new LiteralImpl(value, datatype)));
	}
	return vf.createURI(value);
}
 
Example #4
Source File: ResourceObjectTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrefix() throws RepositoryException, IllegalAccessException, InstantiationException, ParseException, MalformedQueryException, QueryEvaluationException {
    Annotation anno = this.anno4j.createObject(Annotation.class, (Resource) new URIImpl("http://example.org/anno1"));
    Annotation anno2 = this.anno4j.createObject(Annotation.class, (Resource) new URIImpl("http://xmlns.com/foaf/0.1/anno2"));
    Annotation anno3 = this.anno4j.createObject(Annotation.class, (Resource) new URIImpl("http://purl.org/dc/terms/anno3"));

    QueryService qs = this.anno4j.createQueryService();
    qs.addPrefix("ex", "http://example.org/");

    List<Annotation> result = qs.addCriteria(".", "ex:anno1").execute(Annotation.class);

    assertEquals(1, result.size());

    QueryService qs2 = this.anno4j.createQueryService();
    List<Annotation> result2 = qs2.addCriteria(".", "foaf:anno2").execute(Annotation.class);

    assertEquals(1, result2.size());

    QueryService qs3 = this.anno4j.createQueryService();
    List<Annotation> result3 = qs3.addCriteria(".", "dcterms:anno3").execute(Annotation.class);

    assertEquals(1, result3.size());
}
 
Example #5
Source File: TestBlobsWriteTask.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Note: Blank nodes are NOT included in this test since the test helper is
     * not smart enough to verify the blank nodes will not be unified when using
     * standard bnode semantics. However, {@link TestBlobsIndex} does verify
     * both standard and told bnode semantics.
     */
    public void test_add_various_standardBNodes() {

        /* The values that we will be testing with.
         */
        final Value[] valuesIn = new Value[] {//
          
                new LiteralImpl("abc"), //
                RDF.TYPE,//
                RDF.PROPERTY,//
                new LiteralImpl("test"),//
                new LiteralImpl("test", "en"),//
                new LiteralImpl("10", new URIImpl("http://www.w3.org/2001/XMLSchema#int")),
                new LiteralImpl("12", new URIImpl("http://www.w3.org/2001/XMLSchema#float")),
                new LiteralImpl("12.", new URIImpl("http://www.w3.org/2001/XMLSchema#float")),
                new LiteralImpl("12.0", new URIImpl("http://www.w3.org/2001/XMLSchema#float")),
                new LiteralImpl("12.00", new URIImpl("http://www.w3.org/2001/XMLSchema#float")),
//                new BNodeImpl("a"),//
//                new BNodeImpl("12"),//
        };

        doAddTermsTest(valuesIn, false/* toldBNodes */);
        
    }
 
Example #6
Source File: AbstractRMLProcessor.java    From GeoTriples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
	List<Value> 
	
		objects = processObjectMap(objectMap, node,
				map, subject, predicate, dataset);
	
	for (Value object : objects) {
		if (object.stringValue() != null) {
			Set<GraphMap> graphs = pom.getGraphMaps();
			if (graphs.isEmpty())
				dataset.add(subject, predicate, object);
			else
				for (GraphMap graph : graphs) {
					Resource graphResource = new URIImpl(graph
							.getConstantValue().toString());
					dataset.add(subject, predicate, object,
							graphResource);
				}

		}
	}
}
 
Example #7
Source File: TestBigdataSailRemoteRepository.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Get using an access path with the context position bound. 
     */
    public void test_GET_accessPath_delete_c_nothingMatched() throws Exception {

        if(TestMode.quads != getTestMode())
            return;

        doInsertbyURL("POST", packagePath
                + "test_delete_by_access_path.trig");

        final long result = countResults(doGetWithAccessPath(//
//                requestPath,//
                null,// s
                null,// p
                null,// o
                new URIImpl("http://xmlns.com/foaf/0.1/XXX") // c
        ));

        assertEquals(0, result);
        
    }
 
Example #8
Source File: AnonymousConceptTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
public void testIntersectionOf() throws Exception {
	tearDown();
	config.addConcept(MyThing.class);
	config.addConcept(AConcept.class);
	config.addConcept(MyConcept.class);
	config.addBehaviour(MyClass.class);
	config.addConcept(AnonyoumsIntersectionConcept.class);
	setUp();
	URIImpl id = new URIImpl("urn:test:my-concept");
	Object main = con.getObject(id);
	main = con.addDesignation(main, MyThing.class);
	main = con.addDesignation(main, AConcept.class);
	assertTrue(main instanceof AnonyoumsIntersectionConcept);
	assertTrue(main instanceof MyConcept);
	assertEquals(((MyConcept) main).hello(), "world");
}
 
Example #9
Source File: AbstractTestNanoSparqlClient.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
* Sets up a simple data set on the server.
* 
* @throws Exception
*/
protected void setupDataOnServer() throws Exception {
    
    final URI mike = new URIImpl(BD.NAMESPACE + "Mike");
    final URI bryan = new URIImpl(BD.NAMESPACE + "Bryan");
    final URI person = new URIImpl(BD.NAMESPACE + "Person");
    final URI likes = new URIImpl(BD.NAMESPACE + "likes");
    final URI rdf = new URIImpl(BD.NAMESPACE + "RDF");
    final URI rdfs = new URIImpl(BD.NAMESPACE + "RDFS");
    final Literal label1 = new LiteralImpl("Mike");
    final Literal label2 = new LiteralImpl("Bryan");

  {
     final Graph g = new LinkedHashModel();
     g.add(mike, RDF.TYPE, person);
     g.add(mike, likes, rdf);
     g.add(mike, RDFS.LABEL, label1);
     g.add(bryan, RDF.TYPE, person);
     g.add(bryan, likes, rdfs);
     g.add(bryan, RDFS.LABEL, label2);

     m_repo.add(new AddOp(g));
  }

}
 
Example #10
Source File: TestBigdataSailRemoteRepository.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Get everything with a specific subject.
     */
    public void test_GET_accessPath_delete_s() throws Exception {

        doInsertbyURL("POST", packagePath
                + "test_delete_by_access_path.ttl");

        final long result = countResults(doGetWithAccessPath(//
//                requestPath,//
                new URIImpl("http://www.bigdata.com/Mike"),// s
                null,// p
                null
        ));

        assertEquals(3, result);
        
    }
 
Example #11
Source File: TestBigdataSailRemoteRepository.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Delete everything with a specific object (a Literal).
     */
    public void test_DELETE_accessPath_delete_o_Literal() throws Exception {

        doInsertbyURL("POST", packagePath
                + "test_delete_by_access_path.ttl");

        final long mutationResult = doDeleteWithAccessPath(//
//                requestPath,//
                null,// s
                null,// p
                new URIImpl("http://www.bigdata.com/Bryan")// o
        );

        assertEquals(1, mutationResult);
        
    }
 
Example #12
Source File: Test_REST_DELETE_BY_ACCESS_PATH.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Delete using an access path with the context position bound.
 */
public void test_DELETE_accessPath_delete_c_nothingMatched()
      throws Exception {

   if (TestMode.quads != getTestMode())
      return;

   doInsertbyURL("POST", packagePath + "test_delete_by_access_path.trig");

   final long mutationResult = doDeleteWithAccessPath(//
         // requestPath,//
         null,// s
         null,// p
         null,// o
         new URIImpl("http://xmlns.com/foaf/0.1/XXX") // c
   );

   assertEquals(0, mutationResult);

}
 
Example #13
Source File: CRUDTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
/**
 * Tests basic object creation and persistence of triples.
 */
@Test
public void testCreate() throws Exception {
    // Create an Anno4j instance and get its repository connection for direct triple access:
    Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false);
    RepositoryConnection repoConnection = anno4j.getRepository().getConnection();

    // Test simple object creation:
    Person p = anno4j.createObject(Person.class, (Resource) new URIImpl("urn:anno4j_test:p1"));
    p.setMbox("[email protected]");

    // Two statments (rdf:type, foaf:mbox) should be created:
    Collection<Statement> statements = getStatements(repoConnection);
    assertEquals(2, statements.size());
    assertTrue(statements.contains(new StatementImpl(new URIImpl("urn:anno4j_test:p1"),
                                                     new URIImpl(RDF.TYPE),
                                                     new URIImpl(FOAF.PERSON))));
    assertTrue(statements.contains(new StatementImpl(new URIImpl("urn:anno4j_test:p1"),
            new URIImpl(FOAF.MBOX),
            new LiteralImpl("[email protected]"))));
}
 
Example #14
Source File: TestBigdataSailRemoteRepository.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Get using an access path which does not match anything.
     */
    public void test_GET_accessPath_delete_NothingMatched() throws Exception {

        doInsertbyURL("POST", packagePath
                + "test_delete_by_access_path.ttl");

        final long result = countResults(doGetWithAccessPath(//
//                requestPath,//
                null,// s
                null,// p
                new URIImpl("http://xmlns.com/foaf/0.1/XXX")// o
        ));

        assertEquals(0, result);
        
    }
 
Example #15
Source File: TestBigdataSailRemoteRepository.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Delete everything with a specific subject.
     */
    public void test_DELETE_accessPath_delete_s() throws Exception {

        doInsertbyURL("POST", packagePath
                + "test_delete_by_access_path.ttl");

        final long mutationResult = doDeleteWithAccessPath(//
//                requestPath,//
                new URIImpl("http://www.bigdata.com/Mike"),// s
                null,// p
                null
        );

        assertEquals(3, mutationResult);
        
    }
 
Example #16
Source File: RDFSPropertySpecTest.java    From anno4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnspecifiedDomain() throws Exception {
    Anno4j anno4j = new Anno4j();
    BuildableRDFSProperty property = anno4j.createObject(BuildableRDFSProperty.class);

    BuildableRDFSClazz rdfsClazz = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(RDFS.CLAZZ));
    BuildableRDFSClazz owlThing = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(OWL.THING));
    property.setRanges(Sets.<RDFSClazz>newHashSet(rdfsClazz));

    ClassName range = property.getRangeJavaPoetClassName(generationConfig);
    assertEquals(ClassName.get(ResourceObject.class), range);

    property.setRanges(Sets.<RDFSClazz>newHashSet(owlThing));
    range = property.getRangeJavaPoetClassName(generationConfig);
    assertEquals(ClassName.get(ResourceObject.class), range);
}
 
Example #17
Source File: TestBigdataSailRemoteRepository.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Delete everything in a named graph (context).
     */
    public void test_DELETE_accessPath_delete_c() throws Exception {

        if(TestMode.quads != getTestMode())
            return;
        
        doInsertbyURL("POST", packagePath
                + "test_delete_by_access_path.trig");

        final long mutationResult = doDeleteWithAccessPath(//
//                requestPath,//
                null,// s
                null,// p
                null,// o
                new URIImpl("http://www.bigdata.com/") // c
        );

        assertEquals(3, mutationResult);
        
    }
 
Example #18
Source File: ValidatedTransactionTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testContextPersistence() throws Exception {
    Anno4j anno4j = new Anno4j();

    // The contexts:
    URI context1 = new URIImpl("urn:test:context1");

    SpecialTestResource resource1 = anno4j.createObject(SpecialTestResource.class, context1, new URIImpl("urn:test:res1"));
    // Make resources valid:
    setValidCardinalities(resource1);

    // Modify the resources using a validated transaction:
    Transaction transaction = anno4j.createValidatedTransaction(context1);
    transaction.begin();
    List<SpecialTestResource> resources = transaction.findAll(SpecialTestResource.class);
    for(SpecialTestResource current : resources) {
        current.setSuperproperty1(Sets.newHashSet(1, 2, 3));
    }
    transaction.commit();

    // Refind the resources in their respective context:
    resources = anno4j.createQueryService(context1)
                      .addCriteria(".", "urn:test:res1")
                      .execute(SpecialTestResource.class);
    assertFalse(resources.isEmpty());
    resource1 = resources.get(0);

    // Check that the changes are present:
    assertEquals(Sets.newHashSet(1, 2, 3), resource1.getSuperproperty1());
}
 
Example #19
Source File: ResourceObjectTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPostSetResourceAsStringModification() throws Exception {
    Annotation annotation = anno4j.createObject(Annotation.class);
    annotation.setResourceAsString("http://www.somepage.org/resource1/");

    TextualBody body = this.anno4j.createObject(TextualBody.class, (Resource) new URIImpl("http://example.org/body"));
    annotation.addBody(body);

    Annotation annotation1 = anno4j.findByID(Annotation.class, annotation.getResourceAsString());
    assertEquals("http://www.somepage.org/resource1/", annotation1.getResourceAsString());
    assertEquals(1, annotation1.getBodies().size());
    assertEquals(body.getResourceAsString(), annotation1.getBodies().iterator().next().getResourceAsString());
}
 
Example #20
Source File: XSDValueSpaceValidatorTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testNegative() throws Exception {
    BuildableRDFSClazz xsdNegativeInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.NEGATIVE_INTEGER));

    MethodSpec.Builder methodBuilder = method.toBuilder();
    validator.addValueSpaceCheck(methodBuilder, param, xsdNegativeInt);
    String code = methodBuilder.build().code.toString();

    Matcher matcher = Pattern.compile("if\\s*\\((x\\s*>=\\s*0|0\\s*<=\\s*x)\\)").matcher(code);
    assertTrue(matcher.find());
}
 
Example #21
Source File: XSDValueSpaceValidatorTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonNegative() throws Exception {
    BuildableRDFSClazz xsdNonNegativeInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.NON_NEGATIVE_INTEGER));

    MethodSpec.Builder methodBuilder = method.toBuilder();
    validator.addValueSpaceCheck(methodBuilder, param, xsdNonNegativeInt);
    String code = methodBuilder.build().code.toString();

    Matcher matcher = Pattern.compile("if\\s*\\((x\\s*<\\s*0|0\\s*>\\s*x)\\)").matcher(code);
    assertTrue(matcher.find());
}
 
Example #22
Source File: Test_REST_DELETE_BY_ACCESS_PATH.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Delete everything with a specific predicate.
 */
public void test_DELETE_accessPath_delete_p() throws Exception {

   doInsertbyURL("POST", packagePath + "test_delete_by_access_path.ttl");

   final long mutationResult = doDeleteWithAccessPath(//
         // requestPath,//
         null,// s
         new URIImpl("http://www.w3.org/2000/01/rdf-schema#label"),// p
         null// o
   );

   assertEquals(2, mutationResult);

}
 
Example #23
Source File: XSDValueSpaceValidatorTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPositive() throws Exception {
    BuildableRDFSClazz xsdPositiveInt = anno4j.createObject(BuildableRDFSClazz.class, (Resource) new URIImpl(XSD.POSITIVE_INTEGER));

    MethodSpec.Builder methodBuilder = method.toBuilder();
    validator.addValueSpaceCheck(methodBuilder, param, xsdPositiveInt);
    String code = methodBuilder.build().code.toString();

    Matcher matcher = Pattern.compile("if\\s*\\((x\\s*<=\\s*0|0\\s*>=\\s*x)\\)").matcher(code);
    assertTrue(matcher.find());
}
 
Example #24
Source File: MethodNameBuilderTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testJavaPoetMethodSpec() throws Exception {
    MethodNameBuilder builder = MethodNameBuilder.forObjectRepository(anno4j.getObjectRepository());

    RDFSProperty age = anno4j.createObject(RDFSProperty.class, (Resource) new URIImpl("http://example.org/#age"));

    // Test singular:
    assertEquals("getAge", builder.getJavaPoetMethodSpec("get", age, config, false).name);

    // Test plural:
    assertEquals("getAges", builder.getJavaPoetMethodSpec("get", age, config, true).name);

    // Test building with RDFS label:
    age.setLabels(Sets.<CharSequence>newHashSet(new LangString("Alter", "de")));
    assertEquals("getAlter", builder.getJavaPoetMethodSpec("get", age, config, false).name);

    // Test resource for which no name can be extracted:
    boolean exceptionThrown = false;
    try {
        RDFSProperty noName = anno4j.createObject(RDFSProperty.class, (Resource) new URIImpl("http://example.org/#"));
        MethodNameBuilder.forObjectRepository(anno4j.getObjectRepository())
                .getJavaPoetMethodSpec("foo", noName, config, false);
    } catch (IllegalArgumentException e) {
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
}
 
Example #25
Source File: OWLJavaFileGeneratorTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testOWLEquivalence() throws Exception {
    ObjectConnection connection = modelBuilder.getConnection();

    OWLClazz drink = connection.findObject(OWLClazz.class, new URIImpl("http://example.de/ont#Drink"));
    OWLClazz beverage = connection.findObject(OWLClazz.class, new URIImpl("http://example.de/ont#Beverage"));

    assertTrue((drink != null && beverage == null) || (drink == null && beverage != null));
}
 
Example #26
Source File: TestFullyInlineTypedLiteralIV.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void test_encodeDecode_comparator() {
       
    final List<IV<?,?>> ivs = new LinkedList<IV<?,?>>();
       {

           final URI datatype = new URIImpl("http://www.bigdata.com");
           
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(""));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(" "));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("1"));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("12"));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("123"));
           
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("","en",null/*datatype*/));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(" ","en",null/*datatype*/));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("1","en",null/*datatype*/));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("12","fr",null/*datatype*/));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("123","de",null/*datatype*/));

           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("", null, datatype));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>(" ", null, datatype));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("1", null, datatype));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("12", null, datatype));
           ivs.add(new FullyInlineTypedLiteralIV<BigdataLiteral>("123", null, datatype));

       }
       
       final IV<?, ?>[] e = ivs.toArray(new IV[0]);

       AbstractEncodeDecodeKeysTestCase.doEncodeDecodeTest(e);

       AbstractEncodeDecodeKeysTestCase.doComparatorTest(e);
   
}
 
Example #27
Source File: JavaNameResolver.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public String getPluralParameterName(URI name) {
	String ns = name.getNamespace();
	String localPart = name.getLocalName();
	String plural = plural(localPart);
	if (model.contains(new URIImpl(ns + plural), null, null)) {
		plural = localPart;
	}
	return word(plural);
}
 
Example #28
Source File: RoleMapperTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public void testSubclasses3() throws Exception {
	mapper.addConcept(Display.class);
	mapper.addBehaviour(DisplaySupport.class, new URIImpl("urn:test:Display"));
	mapper.addConcept(SubDisplay.class);
	assertTrue(findRoles("urn:test:Display").contains(Display.class));
	assertTrue(findRoles("urn:test:Display").contains(DisplaySupport.class));
	assertTrue(findRoles("urn:test:SubDisplay").contains(Display.class));
	assertTrue(findRoles("urn:test:SubDisplay").contains(SubDisplay.class));
	assertTrue(findRoles("urn:test:SubDisplay").contains(DisplaySupport.class));
}
 
Example #29
Source File: RDFStoreTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testLongLangRoundTrip()
	throws Exception
{
	StringBuffer sb = new StringBuffer();
	for (int i = 0; i < 512; i++) {
		sb.append(Character.toChars('A' + (i % 26)));
	}
	URI subj = new URIImpl(EXAMPLE_NS + PICASSO);
	URI pred = new URIImpl(EXAMPLE_NS + PAINTS);
	Literal obj = new LiteralImpl("guernica" + sb.toString(), "es");

	testValueRoundTrip(subj, pred, obj);
}
 
Example #30
Source File: CRUDTest.java    From anno4j with Apache License 2.0 5 votes vote down vote up
/**
 * Tests behaviour of Anno4j when the type of resources in the repository are different from the ones in the Java domain model.
 */
@Test
public void testReadWrongType() throws Exception {
    // Create an Anno4j instance and get its repository connection for direct triple access:
    Anno4j anno4j = new Anno4j(new SailRepository(new MemoryStore()), null, false);
    RepositoryConnection repoConnection = anno4j.getRepository().getConnection();

    // Add some triples to the repository:
    repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:p1"),
            new URIImpl(RDF.TYPE),
            new URIImpl("urn:anno4j_test:some_other_class")));
    repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:a2"),
            new URIImpl(RDF.TYPE),
            new URIImpl(OADM.ANNOTATION)));
    repoConnection.add(new StatementImpl(new URIImpl("urn:anno4j_test:a2"),
            new URIImpl(OADM.HAS_BODY),
            new LiteralImpl("I'm not an IRI.")));

    // Test retrieving a resource with a different type:
    Person p1 = anno4j.findByID(Person.class, "urn:anno4j_test:p1");
    assertNull(p1);

    // Test retrieving a property value with wrong type:
    boolean exceptionThrown = false;
    try {
        Annotation a2 = anno4j.findByID(Annotation.class, "urn:anno4j_test:a2");
        Set<Body> bodies = a2.getBodies();
        Body body = bodies.iterator().next();
        body.getResourceAsString(); // Prevent code elimination
    } catch (ClassCastException e) {
        exceptionThrown = true;
    }
    assertTrue(exceptionThrown);
}