You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/02/21 16:30:45 UTC

[4/55] MARMOTTA-106: merged sesame-commons into marmotta-commons

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/http/ETagGeneratorTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/http/ETagGeneratorTest.java b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/http/ETagGeneratorTest.java
new file mode 100644
index 0000000..5c29ad9
--- /dev/null
+++ b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/http/ETagGeneratorTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2013 Salzburg Research.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package at.newmedialab.sesame.commons.http;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assume.assumeThat;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.sail.memory.MemoryStore;
+
+/**
+ * Test the ETag Generator
+ * 
+ * @author Sergio Fernández
+ */
+public class ETagGeneratorTest {
+
+    private static final String TEST_DATA = "/foaf/demo-data.foaf";
+    
+    private static final String URI_1 = "http://localhost:8080/LMF/resource/hans_meier";
+    
+    private static final String URI_2 = "http://localhost:8080/LMF/resource/sepp_huber";
+    
+    private static final String URI_3 = "http://localhost:8080/LMF/resource/anna_schmidt";
+
+    private Repository repository;
+
+    /**
+     * Setup memory repository and load initial data (demo-data.foaf)
+     * @throws RepositoryException
+     */
+    @Before
+    public void setup() throws RepositoryException, IOException, RDFParseException {
+        repository = new SailRepository(new MemoryStore());
+        repository.initialize();
+
+        InputStream rdfXML = this.getClass().getResourceAsStream(TEST_DATA);
+        assumeThat("Could not load testData from '" + TEST_DATA + "'", rdfXML, notNullValue(InputStream.class));
+
+        RepositoryConnection connection = repository.getConnection();
+        try {
+            connection.add(rdfXML, "http://localhost/foaf/", RDFFormat.RDFXML);
+            connection.commit();
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Shutdown the repository properly before the next test.
+     *
+     * @throws RepositoryException
+     */
+    @After
+    public void teardown() throws RepositoryException {
+        repository.shutDown();
+    }
+
+    /**
+     * Basic tests
+     */
+    @Test
+    public void runningTest() throws RepositoryException {
+        RepositoryConnection conn = repository.getConnection();
+        String etag = ETagGenerator.getETag(conn, URI_1);
+        Assert.assertNotNull(etag);
+        String wetag = ETagGenerator.getWeakETag(conn, URI_1);
+        Assert.assertNotNull(wetag);
+        conn.close();
+    }
+    
+    /**
+     * Invariant test
+     */
+    @Test
+    public void invariantTest() throws RepositoryException {
+        RepositoryConnection conn1 = repository.getConnection();
+        String etag1 = ETagGenerator.getETag(conn1, URI_1);
+        Assert.assertNotNull(etag1);
+        String wetag1 = ETagGenerator.getWeakETag(conn1, URI_1);
+        Assert.assertNotNull(wetag1);
+        conn1.close();
+        
+        RepositoryConnection conn2 = repository.getConnection();
+        String etag2 = ETagGenerator.getETag(conn2, URI_1);
+        Assert.assertNotNull(etag2);
+        String wetag2 = ETagGenerator.getWeakETag(conn2, URI_1);
+        Assert.assertNotNull(wetag2);
+        conn2.close();
+        
+        Assert.assertEquals(etag1, etag2);
+        Assert.assertEquals(wetag1, wetag2);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/LiteralCommonsTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/LiteralCommonsTest.java b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/LiteralCommonsTest.java
new file mode 100644
index 0000000..0c4918a
--- /dev/null
+++ b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/LiteralCommonsTest.java
@@ -0,0 +1,133 @@
+package at.newmedialab.sesame.commons.model;
+/*
+ * Copyright (c) 2012 Salzburg Research.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import at.newmedialab.sesame.commons.util.DateUtils;
+import org.apache.commons.lang.RandomStringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.openrdf.model.Literal;
+import org.openrdf.model.URI;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.sail.memory.MemoryStore;
+
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * Test the functions of the literal commons
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LiteralCommonsTest {
+
+    /**
+     * Test the creation of the cache keys for literals. All methods should return the same cache key for the
+     * same input data.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testCreateCacheKey() throws Exception {
+        Assert.assertNotEquals(LiteralCommons.createCacheKey("abc",null,(String)null), LiteralCommons.createCacheKey("ABC",null,(String)null));
+        Assert.assertNotEquals(LiteralCommons.createCacheKey("abc",null,(URI)null), LiteralCommons.createCacheKey("ABC",null,(URI)null));
+
+        Repository repository = new SailRepository(new MemoryStore());
+        repository.initialize();
+
+        ValueFactory vf = repository.getValueFactory();
+
+        // create a string literal without language and datatype and test if the hash key is correct between
+        // the different methods
+        String value1 = RandomStringUtils.random(128);
+        Literal literal1 = vf.createLiteral(value1);
+
+        Assert.assertEquals(LiteralCommons.createCacheKey(value1,null,(String)null),LiteralCommons.createCacheKey(literal1));
+        Assert.assertEquals(LiteralCommons.createCacheKey(value1,null,(URI)null),LiteralCommons.createCacheKey(literal1));
+
+        // create a string literal with language and without datatype and test if the hash key is correct between
+        // the different methods
+        String value2 = RandomStringUtils.random(128);
+        Locale locale2 = Locale.getDefault();
+        Literal literal2 = vf.createLiteral(value2,locale2.getLanguage().toLowerCase());
+
+        Assert.assertEquals(LiteralCommons.createCacheKey(value2,locale2,(String)null),LiteralCommons.createCacheKey(literal2));
+        Assert.assertEquals(LiteralCommons.createCacheKey(value2,locale2,(URI)null),LiteralCommons.createCacheKey(literal2));
+
+        // create a string literal with datatype and without language and test if the hash key is correct between
+        // the different methods
+        String value3 = RandomStringUtils.randomNumeric(3);
+        String datatype3 = Namespaces.NS_XSD + "integer";
+        Literal literal3 = vf.createLiteral(value3, vf.createURI(datatype3));
+
+        Assert.assertEquals(LiteralCommons.createCacheKey(value3,null,datatype3),LiteralCommons.createCacheKey(literal3));
+
+
+        // create a Date literal and test whether the hash key is correct between the different methods
+        Date value4 = new Date();
+        String datatype4 = LiteralCommons.getXSDType(value4.getClass());
+        Literal literal4 = vf.createLiteral(DateUtils.getXMLCalendar(value4));
+
+        Assert.assertEquals(datatype4,literal4.getDatatype().stringValue());
+        Assert.assertEquals(LiteralCommons.createCacheKey(value4,datatype4), LiteralCommons.createCacheKey(literal4));
+
+        repository.shutDown();
+    }
+
+
+    /**
+     * Test if the getXSDType() method returns the correct datatype for various Java types
+     */
+    @Test
+    public void testGetXSDType() {
+
+        // String
+        Assert.assertEquals(Namespaces.NS_XSD + "string" , LiteralCommons.getXSDType(String.class));
+
+        // int and Integer
+        Assert.assertEquals(Namespaces.NS_XSD + "integer", LiteralCommons.getXSDType(int.class));
+        Assert.assertEquals(Namespaces.NS_XSD + "integer", LiteralCommons.getXSDType(Integer.class));
+
+
+        // long and Long
+        Assert.assertEquals(Namespaces.NS_XSD + "long", LiteralCommons.getXSDType(long.class));
+        Assert.assertEquals(Namespaces.NS_XSD + "long", LiteralCommons.getXSDType(Long.class));
+
+        // double and Double
+        Assert.assertEquals(Namespaces.NS_XSD + "double", LiteralCommons.getXSDType(double.class));
+        Assert.assertEquals(Namespaces.NS_XSD + "double", LiteralCommons.getXSDType(Double.class));
+
+        // float and Float
+        Assert.assertEquals(Namespaces.NS_XSD + "float", LiteralCommons.getXSDType(float.class));
+        Assert.assertEquals(Namespaces.NS_XSD + "float", LiteralCommons.getXSDType(Float.class));
+
+
+        // boolean and Boolean
+        Assert.assertEquals(Namespaces.NS_XSD + "boolean", LiteralCommons.getXSDType(boolean.class));
+        Assert.assertEquals(Namespaces.NS_XSD + "boolean", LiteralCommons.getXSDType(Boolean.class));
+
+
+        // Date
+        Assert.assertEquals(Namespaces.NS_XSD + "dateTime", LiteralCommons.getXSDType(Date.class));
+
+    }
+    
+    public void testGetRDFLangStringType() throws Exception {
+    	Assert.assertEquals(Namespaces.NS_RDF+ "langString", LiteralCommons.getRDFLangStringType());
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/ResourceUtilsTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/ResourceUtilsTest.java b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/ResourceUtilsTest.java
new file mode 100644
index 0000000..8e00d03
--- /dev/null
+++ b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/ResourceUtilsTest.java
@@ -0,0 +1,693 @@
+package at.newmedialab.sesame.commons.model;
+/*
+ * Copyright (c) 2012 Salzburg Research.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.junit.Assume.assumeThat;
+
+import at.newmedialab.sesame.commons.repository.ResourceUtils;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import org.hamcrest.CoreMatchers;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.Literal;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParseException;
+import org.openrdf.sail.memory.MemoryStore;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Test the ResourceUtils (issue 108).
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class ResourceUtilsTest {
+
+    private static final String TEST_DATA = "/foaf/demo-data.foaf";
+
+    private Repository repository;
+
+    /**
+     * Setup memory repository and load initial data (demo-data.foaf)
+     * @throws RepositoryException
+     */
+    @Before
+    public void setup() throws RepositoryException, IOException, RDFParseException {
+        repository = new SailRepository(new MemoryStore());
+        repository.initialize();
+
+        // load demo data
+        InputStream rdfXML = this.getClass().getResourceAsStream(TEST_DATA);
+        // assumeThat("Could not load testfiles", Arrays.<Object> asList(vcard, sparql),
+        // everyItem(notNullValue()));
+        assumeThat("Could not load testData from '" + TEST_DATA + "'", rdfXML, notNullValue(InputStream.class));
+
+        RepositoryConnection connection = repository.getConnection();
+        try {
+            connection.add(rdfXML, "http://localhost/foaf/", RDFFormat.RDFXML);
+            connection.commit();
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Shutdown the repository properly before the next test.
+     *
+     * @throws RepositoryException
+     */
+    @After
+    public void teardown() throws RepositoryException {
+        repository.shutDown();
+    }
+
+
+    /**
+     * Test if listing resources yields the correct results
+     */
+    @Test
+    public void testListResources() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        List<String> resources = ImmutableList.copyOf(
+                Iterables.transform(
+                        ResourceUtils.listResources(connection),
+                        new Function<Resource, String>() {
+                            @Override
+                            public String apply(Resource input) {
+                                return input.stringValue();
+                            }
+                        }
+                        )
+                );
+
+        // test if the result has the expected size
+        Assert.assertEquals(4,resources.size());
+
+        // test if the result contains all resources that have been used as subject
+        Assert.assertThat(resources, hasItems(
+                "http://localhost:8080/LMF/resource/hans_meier",
+                "http://localhost:8080/LMF/resource/sepp_huber",
+                "http://localhost:8080/LMF/resource/anna_schmidt"
+                ));
+        connection.close();
+    }
+
+    /**
+     * Test if listing resources yields the correct results
+     */
+    @Test
+    public void testListResourcesByType() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        URI persons = connection.getValueFactory().createURI(Namespaces.NS_FOAF + "Person");
+
+        List<String> resources = ImmutableList.copyOf(
+                Iterables.transform(
+                        ResourceUtils.listResources(connection,persons),
+                        new Function<Resource, String>() {
+                            @Override
+                            public String apply(Resource input) {
+                                return input.stringValue();
+                            }
+                        }
+                        )
+                );
+
+        // test if the result has the expected size
+        Assert.assertEquals(3,resources.size());
+
+        // test if the result contains all resources that have been used as subject
+        Assert.assertThat(resources, hasItems(
+                "http://localhost:8080/LMF/resource/hans_meier",
+                "http://localhost:8080/LMF/resource/sepp_huber",
+                "http://localhost:8080/LMF/resource/anna_schmidt"
+                ));
+        connection.close();
+    }
+
+
+    /**
+     * Test listing resources with a given prefix.
+     *
+     * @throws RepositoryException
+     */
+    @Test
+    public void testListResourcesByPrefix() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            // Part 1: unlimited listing; we test that the resources with correct prefix are contained and the
+            // resources with incorrect prefix not
+
+            List<String> resources1 = ImmutableList.copyOf(
+                    Iterables.transform(
+                            ResourceUtils.listResourcesByPrefix(connection, "http://localhost:8080/LMF/resource/h"),
+                            new Function<Resource, String>() {
+                                @Override
+                                public String apply(Resource input) {
+                                    return input.stringValue();
+                                }
+                            }
+                            )
+                    );
+
+            // test if the result has the expected size
+            Assert.assertEquals(1,resources1.size());
+
+            // test if the result contains all resources that have been used as subject
+            Assert.assertThat(resources1, hasItems(
+                    "http://localhost:8080/LMF/resource/hans_meier"
+                    ));
+            Assert.assertThat(resources1, not(hasItems(
+                    "http://localhost:8080/LMF/resource/sepp_huber",
+                    "http://localhost:8080/LMF/resource/anna_schmidt"
+                    )));
+
+
+            // Part 2: limited listing; check whether limit and offset work as expected
+            List<String> resources2 = ImmutableList.copyOf(
+                    Iterables.transform(
+                            ResourceUtils.listResourcesByPrefix(connection, "http://localhost:8080/LMF/resource/",0,2),
+                            new Function<Resource, String>() {
+                                @Override
+                                public String apply(Resource input) {
+                                    return input.stringValue();
+                                }
+                            }
+                            )
+                    );
+
+            // test if the result has the expected size
+            Assert.assertEquals(2,resources2.size());
+
+            // test if the result contains some of resources that have been used as subject
+            Assert.assertThat(resources2, anyOf(
+                    hasItem("http://localhost:8080/LMF/resource/hans_meier"),
+                    hasItem("http://localhost:8080/LMF/resource/sepp_huber"),
+                    hasItem("http://localhost:8080/LMF/resource/anna_schmidt")
+                    ));
+
+            // increase offset by 2 (i.e. next batch of resources)
+            List<String> resources3 = ImmutableList.copyOf(
+                    Iterables.transform(
+                            ResourceUtils.listResourcesByPrefix(connection, "http://localhost:8080/LMF/resource/",2,2),
+                            new Function<Resource, String>() {
+                                @Override
+                                public String apply(Resource input) {
+                                    return input.stringValue();
+                                }
+                            }
+                            )
+                    );
+
+            // test if the result has the expected size
+            Assert.assertEquals(1,resources3.size());
+
+            // test if the result contains some of resources that have been used as subject
+            Assert.assertThat(resources3, anyOf(
+                    hasItem("http://localhost:8080/LMF/resource/hans_meier"),
+                    hasItem("http://localhost:8080/LMF/resource/sepp_huber"),
+                    hasItem("http://localhost:8080/LMF/resource/anna_schmidt")
+                    ));
+        } finally {
+            connection.close();
+        }
+
+    }
+
+
+    /**
+     * Test retrieving properties
+     */
+    @Test
+    public void testGetProperty() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI sepp = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/sepp_huber");
+            URI anna = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/anna_schmidt");
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+
+            // test if getProperty returns the correct names
+            Assert.assertEquals("Hans Meier", ResourceUtils.getProperty(connection,hans,"foaf:name"));
+            Assert.assertEquals("Sepp Huber", ResourceUtils.getProperty(connection,sepp,"foaf:name"));
+            Assert.assertEquals("Anna Schmidt", ResourceUtils.getProperty(connection,anna,"foaf:name"));
+
+            // firstName not set
+            Assert.assertNull(ResourceUtils.getProperty(connection,hans,"foaf:firstName"));
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test retrieving properties
+     */
+    @Test
+    public void testGetProperties() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI sepp = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/sepp_huber");
+            URI anna = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/anna_schmidt");
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+
+            List<String> sepp_names = ImmutableList.copyOf(ResourceUtils.getProperties(connection,sepp,"foaf:name"));
+            List<String> anna_names = ImmutableList.copyOf(ResourceUtils.getProperties(connection,anna,"foaf:name"));
+            List<String> hans_names = ImmutableList.copyOf(ResourceUtils.getProperties(connection,hans,"foaf:name"));
+            List<String> hans_xyz = ImmutableList.copyOf(ResourceUtils.getProperties(connection,hans,"foaf:xyz"));
+
+            Assert.assertEquals(1,sepp_names.size());
+            Assert.assertEquals(1,anna_names.size());
+            Assert.assertEquals(1,hans_names.size());
+            Assert.assertEquals(0,hans_xyz.size());
+
+            Assert.assertThat(sepp_names, hasItem("Sepp Huber"));
+            Assert.assertThat(anna_names, hasItem("Anna Schmidt"));
+            Assert.assertThat(hans_names, hasItem("Hans Meier"));
+
+        } finally {
+            connection.close();
+        }
+    }
+
+
+    /**
+     * Test setting properties
+     */
+    @Test
+    public void testSetProperty() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI toni = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/toni_schneider");
+            URI name = connection.getValueFactory().createURI(Namespaces.NS_FOAF + "name");
+
+            ResourceUtils.setProperty(connection,toni,"foaf:name","Anton Schneider");
+
+            // test if getProperty returns the correct names
+            Assert.assertEquals("Anton Schneider", ResourceUtils.getProperty(connection,toni,"foaf:name"));
+
+            // test if getStatements returns the correct statement
+            RepositoryResult<Statement> triples = connection.getStatements(toni,name,null,true);
+            Assert.assertTrue(triples.hasNext());
+            Assert.assertEquals("Anton Schneider", triples.next().getObject().stringValue());
+            triples.close();
+        } finally {
+            connection.close();
+        }
+    }
+
+
+    /**
+     * Test removing properties
+     */
+    @Test
+    public void testRemoveProperty() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+
+            // test if getProperty returns the correct names
+            Assert.assertEquals("Hans Meier", ResourceUtils.getProperty(connection,hans,"foaf:name"));
+
+            ResourceUtils.removeProperty(connection,hans, "foaf:name");
+
+            Assert.assertNull(ResourceUtils.getProperty(connection,hans,"foaf:name"));
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test listing outgoing statements
+     */
+    @Test
+    public void testListOutgoingStatements() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+
+            List<Statement> result = ImmutableList.copyOf(
+                    ResourceUtils.listOutgoing(connection,hans)
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(12,result.size());
+
+            Assert.assertThat(result, allOf(
+                    CoreMatchers.<Statement>hasItem(hasProperty("object", is(connection.getValueFactory().createLiteral("Hans Meier")))),
+                    CoreMatchers.<Statement>hasItem(hasProperty("object", is(connection.getValueFactory().createURI(Namespaces.NS_FOAF + "Person"))))
+                    ));
+
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test listing outgoing nodes
+     */
+    @Test
+    public void testListOutgoingNodes() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+
+            List<Value> result = ImmutableList.copyOf(
+                    ResourceUtils.listOutgoingNodes(connection, hans, "foaf:name")
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(1,result.size());
+
+            Assert.assertThat(result, hasItems(
+                    (Value) connection.getValueFactory().createLiteral("Hans Meier")
+                    ));
+
+        } finally {
+            connection.close();
+        }
+    }
+
+
+    /**
+     * Test adding outgoing statements (by string label of the property)
+     */
+    @Test
+    public void testaddOutgoingNodeLabel() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI toni = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/toni_schneider");
+            URI name = connection.getValueFactory().createURI(Namespaces.NS_FOAF + "name");
+            String property = "foaf:name";
+            Literal value    = connection.getValueFactory().createLiteral("Anton Schneider");
+
+            ResourceUtils.addOutgoingNode(connection,toni,property,value,null);
+
+            // test if getProperty returns the correct names
+            Assert.assertEquals("Anton Schneider", ResourceUtils.getProperty(connection,toni,"foaf:name"));
+
+            // test if getStatements returns the correct statement
+            RepositoryResult<Statement> triples = connection.getStatements(toni,name,null,true);
+            Assert.assertTrue(triples.hasNext());
+            Assert.assertEquals("Anton Schneider", triples.next().getObject().stringValue());
+            triples.close();
+
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test adding outgoing statements (by string label of the property)
+     */
+    @Test
+    @SuppressWarnings("deprecation")
+    public void testaddOutgoingNodeProperty() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI toni = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/toni_schneider");
+            URI name = connection.getValueFactory().createURI(Namespaces.NS_FOAF + "name");
+            Literal value    = connection.getValueFactory().createLiteral("Anton Schneider");
+
+            ResourceUtils.addOutgoingNode(connection,toni,name,value,null);
+
+            // test if getProperty returns the correct names
+            Assert.assertEquals("Anton Schneider", ResourceUtils.getProperty(connection,toni,"foaf:name"));
+
+            // test if getStatements returns the correct statement
+            RepositoryResult<Statement> triples = connection.getStatements(toni,name,null,true);
+            Assert.assertTrue(triples.hasNext());
+            Assert.assertEquals("Anton Schneider", triples.next().getObject().stringValue());
+            triples.close();
+
+        } finally {
+            connection.close();
+        }
+    }
+
+
+    /**
+     * Test listing outgoing nodes
+     */
+    @Test
+    public void testRemoveOutgoingNodes() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+
+            List<Value> result1 = ImmutableList.copyOf(
+                    ResourceUtils.listOutgoingNodes(connection, hans, "foaf:name")
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(1,result1.size());
+
+            Assert.assertThat(result1, hasItems(
+                    (Value) connection.getValueFactory().createLiteral("Hans Meier")
+                    ));
+
+            ResourceUtils.removeOutgoingNode(connection,hans,"foaf:name", null, null);
+
+            List<Value> result2 = ImmutableList.copyOf(
+                    ResourceUtils.listOutgoingNodes(connection, hans, "foaf:name")
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(0,result2.size());
+
+
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test listing incoming statements
+     */
+    @Test
+    public void testListIncomingStatements() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/sepp_huber");
+
+            List<Statement> result = ImmutableList.copyOf(
+                    ResourceUtils.listIncoming(connection, hans)
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(2,result.size());
+
+            Assert.assertThat(result, allOf(
+                    CoreMatchers.<Statement>hasItem(hasProperty("subject", is(connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier")))),
+                    CoreMatchers.<Statement>hasItem(hasProperty("subject", is(connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/anna_schmidt"))))
+                    ));
+
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test listing incoming nodes
+     */
+    @Test
+    public void testListIncomingNodes() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/sepp_huber");
+
+            List<Resource> result = ImmutableList.copyOf(
+                    ResourceUtils.listIncomingNodes(connection, hans, "foaf:knows")
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(2,result.size());
+
+            Assert.assertThat(result, hasItems(
+                    (Resource) connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier"),
+                    (Resource) connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/anna_schmidt")
+                    ));
+
+        } finally {
+            connection.close();
+        }
+    }
+
+
+    /**
+     * Test getting various forms of labels
+     */
+    @Test
+    public void testGetLabel() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI r1 = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/r1");
+            URI r2 = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/r2");
+            URI r3 = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/r3");
+            URI c1 = connection.getValueFactory().createURI("http://localhost:8080/LMF/context/c1");
+
+            URI rdfs_label = connection.getValueFactory().createURI(Namespaces.NS_RDFS + "label");
+            URI dct_title  = connection.getValueFactory().createURI(Namespaces.NS_DC_TERMS + "title");
+            URI skos_label = connection.getValueFactory().createURI(Namespaces.NS_SKOS + "prefLabel");
+
+            connection.add(r1,rdfs_label,connection.getValueFactory().createLiteral("R1"));
+            connection.add(r2,dct_title,connection.getValueFactory().createLiteral("R2","en"));
+            connection.add(r3,skos_label,connection.getValueFactory().createLiteral("R3"),c1);
+
+            Assert.assertEquals("R1", ResourceUtils.getLabel(connection,r1));
+            Assert.assertEquals("R2", ResourceUtils.getLabel(connection,r2));
+            Assert.assertEquals("R3", ResourceUtils.getLabel(connection,r3));
+
+            Assert.assertEquals("r1", ResourceUtils.getLabel(connection,r1, Locale.ENGLISH));
+            Assert.assertEquals("R2", ResourceUtils.getLabel(connection,r2, Locale.ENGLISH));
+            Assert.assertEquals("r3", ResourceUtils.getLabel(connection,r3, Locale.ENGLISH));
+
+            Assert.assertEquals("r1", ResourceUtils.getLabel(connection,r1, c1));
+            Assert.assertEquals("r2", ResourceUtils.getLabel(connection,r2, c1));
+            Assert.assertEquals("R3", ResourceUtils.getLabel(connection,r3, c1));
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test setting labels.
+     *
+     * @throws RepositoryException
+     */
+    @Test
+    public void testSetLabel() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI r1 = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/r1");
+            URI r2 = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/r2");
+            URI r3 = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/r3");
+            URI c1 = connection.getValueFactory().createURI("http://localhost:8080/LMF/context/c1");
+
+
+            ResourceUtils.setLabel(connection,r1,"R1");
+            ResourceUtils.setLabel(connection,r2,Locale.ENGLISH,"R2");
+            ResourceUtils.setLabel(connection,r3,"R3",c1);
+
+
+            Assert.assertEquals("R1", ResourceUtils.getLabel(connection,r1));
+            Assert.assertEquals("R2", ResourceUtils.getLabel(connection,r2));
+            Assert.assertEquals("R3", ResourceUtils.getLabel(connection,r3));
+
+            Assert.assertEquals("r1", ResourceUtils.getLabel(connection,r1, Locale.ENGLISH));
+            Assert.assertEquals("R2", ResourceUtils.getLabel(connection,r2, Locale.ENGLISH));
+            Assert.assertEquals("r3", ResourceUtils.getLabel(connection,r3, Locale.ENGLISH));
+
+            Assert.assertEquals("r1", ResourceUtils.getLabel(connection,r1, c1));
+            Assert.assertEquals("r2", ResourceUtils.getLabel(connection,r2, c1));
+            Assert.assertEquals("R3", ResourceUtils.getLabel(connection,r3, c1));
+        } finally {
+            connection.close();
+        }
+
+    }
+
+    /**
+     * Test returning types
+     */
+    @Test
+    public void testGetTypes() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/sepp_huber");
+
+            List<Resource> result = ImmutableList.copyOf(
+                    ResourceUtils.getTypes(connection, hans)
+                    );
+
+            // check that the number of results is correct
+            Assert.assertEquals(1,result.size());
+
+            Assert.assertThat(result, hasItem(connection.getValueFactory().createURI(Namespaces.NS_FOAF + "Person")));
+
+        } finally {
+            connection.close();
+        }
+    }
+
+    /**
+     * Test hasType()
+     */
+    @Test
+    public void testHasTypes() throws RepositoryException {
+        RepositoryConnection connection = repository.getConnection();
+
+        try {
+            URI hans = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/sepp_huber");
+
+            Assert.assertTrue(ResourceUtils.hasType(connection,hans,connection.getValueFactory().createURI(Namespaces.NS_FOAF + "Person")));
+            Assert.assertFalse(ResourceUtils.hasType(connection,hans,connection.getValueFactory().createURI(Namespaces.NS_FOAF + "XYZ")));
+        } finally {
+            connection.close();
+        }
+    }
+
+
+
+    /**
+     * Test if claimed memory resources are properly disposed of when the connection is closed but an iterator is still open
+     *
+     * TODO: How can we check this?
+     *
+     */
+    public void testResultDispose() {
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/URICommonsTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/URICommonsTest.java b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/URICommonsTest.java
new file mode 100644
index 0000000..e07f17e
--- /dev/null
+++ b/commons/marmotta-commons/src/test/java/at/newmedialab/sesame/commons/model/URICommonsTest.java
@@ -0,0 +1,71 @@
+package at.newmedialab.sesame.commons.model;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openrdf.model.URI;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.sail.memory.MemoryStore;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(Parameterized.class)
+public class URICommonsTest {
+
+
+    private final String prefix;
+    private final String local;
+    private URI uri;
+    private String uri_string;
+
+    @Parameters(name = "{0}{1}")
+    public static List<String[]> data() {
+        final ArrayList<String[]> d = new ArrayList<String[]>();
+
+        d.add(new String[] { "http://www.example.com/foo/", "bar" });
+        d.add(new String[] { "http://www.example.com/foo#", "bar" });
+
+        return d;
+    }
+
+    public URICommonsTest(String prefix, String local) {
+        this.prefix = prefix;
+        this.local = local;
+    }
+
+    @Before
+    public void setup() throws RepositoryException {
+        Repository repository = new SailRepository(new MemoryStore());
+        repository.initialize();
+
+        uri_string = prefix + local;
+        uri = repository.getValueFactory().createURI(prefix, local);
+
+        repository.shutDown();
+    }
+
+    @Test
+    public void testSplitNamespace() {
+        String[] split = URICommons.splitNamespace(uri_string);
+
+        assertEquals(2, split.length);
+        Assert.assertThat(split, equalTo(new String[] { prefix, local }));
+    }
+
+    @Test
+    public void testCreateCacheKey() {
+        assertEquals(uri_string, URICommons.createCacheKey(uri));
+        assertEquals(uri.stringValue(), URICommons.createCacheKey(uri_string));
+        assertEquals(URICommons.createCacheKey(uri_string), URICommons.createCacheKey(uri));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/marmotta-commons/src/test/resources/foaf/demo-data.foaf
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/test/resources/foaf/demo-data.foaf b/commons/marmotta-commons/src/test/resources/foaf/demo-data.foaf
new file mode 100644
index 0000000..37694c3
--- /dev/null
+++ b/commons/marmotta-commons/src/test/resources/foaf/demo-data.foaf
@@ -0,0 +1,69 @@
+<!--
+  ~ Copyright (c) 2012 Salzburg Research.
+  ~
+  ~  Licensed under the Apache License, Version 2.0 (the "License");
+  ~  you may not use this file except in compliance with the License.
+  ~  You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~  See the License for the specific language governing permissions and
+  ~  limitations under the License.
+  -->
+
+<rdf:RDF
+        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+        xmlns:foaf="http://xmlns.com/foaf/0.1/"
+        xmlns:dc="http://purl.org/dc/elements/1.1/">
+
+    <foaf:Person rdf:about="http://localhost:8080/LMF/resource/hans_meier" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+        <foaf:name>Hans Meier</foaf:name>
+        <dc:description>Hans Meier is a software engineer living in Salzburg</dc:description>
+        <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.software_engineering"/>
+        <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.linux"/>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Java" />
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/>
+        <foaf:based_near rdf:resource="http://sws.geonames.org/2766824/"/>
+        <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/hans_meier.jpg"/>
+
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" />
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt"/>
+
+        <foaf:account>
+            <foaf:OnlineAccount>
+                <foaf:accountName>Example</foaf:accountName>
+                <foaf:accountServiceHomepage>http://www.example.com</foaf:accountServiceHomepage>
+            </foaf:OnlineAccount>
+        </foaf:account>
+    </foaf:Person>
+
+    <foaf:Person rdf:about="http://localhost:8080/LMF/resource/sepp_huber" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+        <foaf:name>Sepp Huber</foaf:name>
+        <dc:description>Sepp Huber is an alpinist living in Traunstein. He is a good climber, but not as famous as his cousin Alexander Huber.</dc:description>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/>
+        <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" />
+        <foaf:based_near rdf:resource="http://dbpedia.org/resource/Traunstein"/>
+
+        <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" />
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/hans_meier" />
+    </foaf:Person>
+
+    <foaf:Person rdf:about="http://localhost:8080/LMF/resource/anna_schmidt" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+        <foaf:name>Anna Schmidt</foaf:name>
+        <dc:description>Anna Schmidt is working as PR manager for mountaineers coming from Garmisch-Partenkirchen. She likes mountaineering and is also a Linux enthusiast.</dc:description>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/>
+        <foaf:interest rdf:resource="http://dbpedia.org/resource/Linux"/>
+        <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" />
+        <foaf:based_near rdf:resource="http://dbpedia.org/resource/Garmisch-Partenkirchen"/>
+        <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt.jpg"/>
+
+        <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" />
+        <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" />
+    </foaf:Person>
+
+
+</rdf:RDF>

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/c77916e8/commons/pom.xml
----------------------------------------------------------------------
diff --git a/commons/pom.xml b/commons/pom.xml
index 85d15f1..71756c0 100644
--- a/commons/pom.xml
+++ b/commons/pom.xml
@@ -31,12 +31,13 @@
 
     <modules>
         <module>marmotta-commons</module>
-        <module>sesame-commons</module>
         <module>sesame-filter</module>
         <module>sesame-tools-rio-api</module>
         <module>sesame-tools-rio-ical</module>
+<!-- 
         <module>sesame-tools-rio-jsonld</module>
         <module>sesame-tools-rio-rdfa</module>
+-->
         <module>sesame-tools-rio-rdfjson</module>
         <module>sesame-tools-rio-rss</module>
         <module>sesame-tools-rio-vcard</module>