marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wik...@apache.org
Subject [1/8] git commit: added some prefix testing for checking the reimplementation
Date Tue, 26 Mar 2013 10:11:48 GMT
Updated Branches:
  refs/heads/master 9c7cae8c9 -> 720247ff4


added some prefix testing for checking the reimplementation


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/d19f38fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/d19f38fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/d19f38fa

Branch: refs/heads/master
Commit: d19f38fad0c1aa44a5115445227670dc7c7c1641
Parents: 92cc01a
Author: Sergio Fernández <wikier@apache.org>
Authored: Tue Mar 26 09:11:43 2013 +0100
Committer: Sergio Fernández <wikier@apache.org>
Committed: Tue Mar 26 09:11:43 2013 +0100

----------------------------------------------------------------------
 .../platform/core/test/base/JettyMarmotta.java     |    1 -
 .../core/test/config/ConfigurationServiceTest.java |   13 +-
 .../core/test/prefix/PrefixServiceTest.java        |  103 +++++++++++++++
 .../core/test/prefix/PrefixWebServiceTest.java     |   99 ++++++++++++++
 4 files changed, 208 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d19f38fa/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
index 8e5ded1..c75fefd 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
@@ -93,7 +93,6 @@ public class JettyMarmotta extends AbstractMarmotta {
         ServletHolder restEasyFilter  = new ServletHolder(org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.class);
         restEasyFilter.setInitParameter("resteasy.injector.factory", TestInjectorFactory.class.getCanonicalName());
 
-
         if(webservice != null) {
             TestApplication.setTestedWebServices(webservice);
             //restEasyFilter.setInitParameter("resteasy.resources", webservice.getName());

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d19f38fa/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/config/ConfigurationServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/config/ConfigurationServiceTest.java
b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/config/ConfigurationServiceTest.java
index d548307..fcdb96f 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/config/ConfigurationServiceTest.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/config/ConfigurationServiceTest.java
@@ -17,17 +17,17 @@
  */
 package org.apache.marmotta.platform.core.test.config;
 
-import junit.framework.Assert;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.test.base.EmbeddedMarmotta;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
 /**
  * Test the functionality of the configuration service
  * <p/>
@@ -137,8 +137,7 @@ public class ConfigurationServiceTest {
         // test without / with default value
         Assert.assertNull(configurationService.getStringConfiguration(key));
         Assert.assertEquals(value, configurationService.getIntConfiguration(key, value));
-        Assert.assertEquals((double)value,configurationService.getDoubleConfiguration(key,
value));
-
+        Assert.assertEquals((double) value,configurationService.getDoubleConfiguration(key,
value), 1e-15);
 
         // set value to a new value
         configurationService.setIntConfiguration(key, value);

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d19f38fa/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixServiceTest.java
b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixServiceTest.java
new file mode 100644
index 0000000..f07ed61
--- /dev/null
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixServiceTest.java
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.marmotta.platform.core.test.prefix;
+
+import java.net.URISyntaxException;
+
+import org.apache.marmotta.platform.core.api.prefix.PrefixService;
+import org.apache.marmotta.platform.core.test.base.EmbeddedMarmotta;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test the functionality of the prefix service
+ * 
+ * @author Sergio Fernández
+ */
+public class PrefixServiceTest {
+
+    private static EmbeddedMarmotta marmotta;
+    private static PrefixService prefixService;
+
+    @BeforeClass
+    public static void setUp() {
+        marmotta = new EmbeddedMarmotta();
+        prefixService = marmotta.getService(PrefixService.class);
+    }
+    
+    @AfterClass
+    public static void tearDown() {
+        marmotta.shutdown();
+        marmotta = null;
+        prefixService = null;
+    }
+
+    @Test
+    public void testSet() throws IllegalArgumentException, URISyntaxException {
+        String prefix = "foo";
+        String namespace = "http://foo#";
+
+        Assert.assertNull(prefixService.getNamespace(prefix));
+
+        prefixService.add(prefix, namespace);
+        Assert.assertNotNull(prefixService.getNamespace(prefix));
+        Assert.assertEquals(namespace, prefixService.getNamespace(prefix));
+        Assert.assertEquals(prefix, prefixService.getPrefix(namespace));
+
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testDoubleSet() throws IllegalArgumentException, URISyntaxException {
+        String prefix = "bar";
+        String namespace1 = "http://bar1#";
+        String namespace2 = "http://bar2#";
+
+        Assert.assertNull(prefixService.getNamespace(prefix));
+
+        prefixService.add(prefix, namespace1);
+        Assert.assertNotNull(prefixService.getNamespace(prefix));
+        Assert.assertEquals(namespace1, prefixService.getNamespace(prefix));
+        Assert.assertEquals(prefix, prefixService.getPrefix(namespace1));
+        
+        prefixService.add(prefix, namespace2);
+
+    }
+    
+    @Test
+    public void testForceDoubleSet() throws IllegalArgumentException, URISyntaxException
{
+        String prefix = "baz";
+        String namespace1 = "http://baz1#";
+        String namespace2 = "http://baz2#";
+
+        Assert.assertNull(prefixService.getNamespace(prefix));
+
+        prefixService.add(prefix, namespace1);
+        Assert.assertNotNull(prefixService.getNamespace(prefix));
+        Assert.assertEquals(namespace1, prefixService.getNamespace(prefix));
+        Assert.assertEquals(prefix, prefixService.getPrefix(namespace1));
+        
+        prefixService.forceAdd(prefix, namespace2);
+        Assert.assertNotNull(prefixService.getNamespace(prefix));
+        Assert.assertEquals(namespace2, prefixService.getNamespace(prefix));
+        Assert.assertEquals(prefix, prefixService.getPrefix(namespace2));        
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/d19f38fa/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixWebServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixWebServiceTest.java
b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixWebServiceTest.java
new file mode 100644
index 0000000..104f990
--- /dev/null
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/prefix/PrefixWebServiceTest.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.marmotta.platform.core.test.prefix;
+
+import static com.jayway.restassured.RestAssured.expect;
+import static com.jayway.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.io.IOException;
+
+import org.apache.marmotta.platform.core.api.prefix.PrefixService;
+import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
+import org.apache.marmotta.platform.core.webservices.prefix.PrefixWebService;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jayway.restassured.RestAssured;
+
+/**
+ * Test the functionality of the prefix web service
+ * 
+ * @author Sergio Fernández
+ */
+public class PrefixWebServiceTest {
+
+    private static JettyMarmotta marmotta;
+    private static PrefixService prefixService;
+
+    @BeforeClass
+    public static void setUp() {
+        marmotta = new JettyMarmotta("/marmotta", 8080, PrefixWebService.class);
+        prefixService = marmotta.getService(PrefixService.class);
+
+        RestAssured.baseURI = "http://localhost";
+        RestAssured.port = 8080;
+        RestAssured.basePath = "/marmotta";
+
+    }
+
+    @AfterClass
+    public static void tearDown() {
+        marmotta.shutdown();
+    }
+
+    @Test
+    public void testSet() throws IOException, InterruptedException {
+    	
+        String prefix = "foo";
+        String namespace = "http://foo#";
+        
+        Assert.assertNull(prefixService.getNamespace(prefix));
+        
+        expect().
+    		statusCode(404).
+    	when().
+    		get("/prefix/" + prefix);
+        
+        given().
+        expect().
+        	statusCode(201).
+        when().
+        	post("/prefix/" + prefix + "?uri=" + namespace);
+
+        Assert.assertNotNull(prefixService.getNamespace(prefix));
+        Assert.assertEquals(namespace, prefixService.getNamespace(prefix));
+        Assert.assertEquals(prefix, prefixService.getPrefix(namespace));
+
+        expect().
+        	statusCode(200).
+        	body(prefix, equalTo(namespace)).
+        when().
+        	get("/prefix/" + prefix);
+        
+        expect().
+    		statusCode(200).
+    		//body(namespace, equalTo(prefix)).
+    	when().
+    		get("/prefix/reverse?uri=" + namespace);
+
+    }
+
+}


Mime
View raw message