Author: alexdma
Date: Tue Feb 28 16:22:14 2012
New Revision: 1294717

URL: http://svn.apache.org/viewvc?rev=1294717&view=rev
Log:
More integration tests on scopes. introduced mirror tests for sessions where 
applicable (STANBOL-472)

Modified:
    
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/ScopeTest.java
    
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/SessionTest.java

Modified: 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/ScopeTest.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/ScopeTest.java?rev=1294717&r1=1294716&r2=1294717&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/ScopeTest.java
 (original)
+++ 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/ScopeTest.java
 Tue Feb 28 16:22:14 2012
@@ -29,28 +29,11 @@ public class ScopeTest extends StanbolTe
 
     private static final String _ROOT_URI = "/ontonet";
 
+    private static final String URI_SCOPE_CLASS = 
"http://kres.iks-project.eu/ontology/onm/meta.owl#Scope";;;
     private static final String BASE_SCOPES_URI = _ROOT_URI + "/ontology";
 
     private static final Logger log = LoggerFactory.getLogger(ScopeTest.class);
 
-    private static final String ONT_FOAF_URI = 
"http://xmlns.com/foaf/spec/index.rdf";;
-
-    private static final String ONT_PIZZA_URI = 
"http://www.co-ode.org/ontologies/pizza/2007/02/12/pizza.owl";;
-
-    private static final String ONT_WINE_URI = 
"http://www.schemaweb.info/webservices/rest/GetRDFByID.aspx?id=62";;
-
-    private static final String REG_TEST_URI = 
"http://www.ontologydesignpatterns.org/registry/krestest.owl";;
-
-    private static final String SCOPE_BIZ_URI = BASE_SCOPES_URI + "/" + "Biz";
-
-    private static final String SCOPE_DRUNK_URI = BASE_SCOPES_URI + "/" + 
"Drunk";
-
-    private static final String SCOPE_USER_URI = BASE_SCOPES_URI + "/" + 
"User";
-
-    private static final String SCOPE1_URI = BASE_SCOPES_URI + "/" + 
"Pippo%20Baudo";
-
-    private static final String SCOPE2_URI = BASE_SCOPES_URI + "/" + 
"TestScope2";
-
     private String encodeURI(String s) {
         StringBuilder o = new StringBuilder();
         for (char ch : s.toCharArray()) {
@@ -70,7 +53,55 @@ public class ScopeTest extends StanbolTe
 
     @Test
     public void testActive() throws Exception {
+        RequestExecutor request;
 
+        String tempActiveScopeUri = BASE_SCOPES_URI + "/" + 
getClass().getCanonicalName() + "-testActive-"
+                                    + System.currentTimeMillis() + "-active";
+        String tempInactiveScopeUri = BASE_SCOPES_URI + "/" + 
getClass().getCanonicalName() + "-testActive-"
+                                      + System.currentTimeMillis() + 
"-inactive";
+
+        // Scopes should not be there
+        request = 
executor.execute(builder.buildGetRequest(tempActiveScopeUri).withHeader("Accept",
+            KRFormat.TURTLE));
+        request.assertStatus(404);
+        log.info("Request: " + tempActiveScopeUri + " (should return 404) ... 
DONE");
+        request = 
executor.execute(builder.buildGetRequest(tempInactiveScopeUri).withHeader("Accept",
+            KRFormat.TURTLE));
+        request.assertStatus(404);
+        log.info("Request: " + tempInactiveScopeUri + " (should return 404) 
... DONE");
+
+        // Create scopes, only activate one
+        executor.execute(builder.buildOtherRequest(new 
HttpPut(builder.buildUrl(tempActiveScopeUri
+                                                                               
 + "?activate=true"))));
+        log.info("PUT Request: " + tempActiveScopeUri + " ... DONE");
+        executor.execute(builder.buildOtherRequest(new 
HttpPut(builder.buildUrl(tempInactiveScopeUri))));
+        log.info("PUT Request: " + tempInactiveScopeUri + " ... DONE");
+
+        // By default, we should only see the active scope
+        
executor.execute(builder.buildGetRequest(BASE_SCOPES_URI).withHeader("Accept", 
KRFormat.TURTLE))
+                .assertStatus(200)
+                .assertContentRegexp(false,
+                    tempInactiveScopeUri + ">\\s+rdf:type\\s+<" + 
URI_SCOPE_CLASS + ">")
+                .assertContentRegexp(true, tempActiveScopeUri + 
">\\s+rdf:type\\s+<" + URI_SCOPE_CLASS + ">");
+        log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
+
+        // Using with-inactive we should see both scopes
+        executor.execute(
+            builder.buildGetRequest(BASE_SCOPES_URI + 
"?with-inactive=true").withHeader("Accept",
+                KRFormat.TURTLE))
+                .assertStatus(200)
+                .assertContentRegexp(true,
+                    tempInactiveScopeUri + ">\\s+rdf:type\\s+<" + 
URI_SCOPE_CLASS + ">")
+                .assertContentRegexp(true, tempActiveScopeUri + 
">\\s+rdf:type\\s+<" + URI_SCOPE_CLASS + ">");
+        log.info("Request: " + BASE_SCOPES_URI + " ... DONE");
+
+        // Delete scopes
+        executor.execute(builder.buildOtherRequest(new 
HttpDelete(builder.buildUrl(tempActiveScopeUri))));
+        log.info("DELETE Request: " + tempActiveScopeUri + " ... DONE");
+        executor.execute(builder.buildOtherRequest(new 
HttpDelete(builder.buildUrl(tempInactiveScopeUri))));
+        log.info("DELETE Request: " + tempInactiveScopeUri + " ... DONE");
+
+        // We won't test here if deletion succeeded.
     }
 
     @Test
@@ -95,11 +126,13 @@ public class ScopeTest extends StanbolTe
         executor.execute(builder.buildOtherRequest(new 
HttpPut(builder.buildUrl(tempScopeUri))));
         log.info("PUT Request: " + tempScopeUri + " ... DONE");
 
-        // Scope should not be there
+        // Scope should be there now
         request = executor.execute(builder.buildGetRequest(tempScopeUri)
                 .withHeader("Accept", KRFormat.TURTLE));
-        request.assertStatus(200);
+        request.assertStatus(200).assertContentContains(tempScopeUri);
         log.info("Request: " + tempScopeUri + " ... DONE");
+        
+        // TODO the U of CRUD
 
         // Delete scope
         executor.execute(builder.buildOtherRequest(new 
HttpDelete(builder.buildUrl(tempScopeUri))));
@@ -114,7 +147,7 @@ public class ScopeTest extends StanbolTe
 
     @Test
     public void testLocking() throws Exception {
-
+        // TODO first we need some offline content to POST
     }
 
     @Test

Modified: 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/SessionTest.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/SessionTest.java?rev=1294717&r1=1294716&r2=1294717&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/SessionTest.java
 (original)
+++ 
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/ontologymanager/web/it/SessionTest.java
 Tue Feb 28 16:22:14 2012
@@ -16,12 +16,11 @@
  */
 package org.apache.stanbol.ontologymanager.web.it;
 
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-
-import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.stanbol.commons.testing.http.RequestExecutor;
 import org.apache.stanbol.commons.testing.stanbol.StanbolTestBase;
+import org.apache.stanbol.commons.web.base.format.KRFormat;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,17 +51,75 @@ public class SessionTest extends Stanbol
     }
 
     @Test
-    public void testSessionCreation() throws ClientProtocolException, 
IOException {
+    public void testCRUD() throws Exception {
+        RequestExecutor request;
 
-        /*
-         * log.info(executor.execute(
-         * 
builder.buildPostRequest(SESSION_URI+"?scope="+encodeURI("http://localhost:8080/ontonet/ontology/User";
-         * )) .withHeader("Content-type",MediaType.APPLICATION_FORM_URLENCODED)
-         * .withHeader("Accept",KRFormat.RDF_XML) ).getContent()); 
//.assertStatus(200);
-         */
+        // The needed Web resources to GET from.
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.TURTLE))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " ... DONE");
+
+        String tempScopeUri = SESSION_URI + "/" + 
getClass().getCanonicalName() + "-"
+                              + System.currentTimeMillis();
+
+        // Scope should not be there
+        request = executor.execute(builder.buildGetRequest(tempScopeUri)
+                .withHeader("Accept", KRFormat.TURTLE));
+        request.assertStatus(404);
+        log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
+
+        // Create scope
+        executor.execute(builder.buildOtherRequest(new 
HttpPut(builder.buildUrl(tempScopeUri))));
+        log.info("PUT Request: " + tempScopeUri + " ... DONE");
+
+        // Scope should be there now
+        request = executor.execute(builder.buildGetRequest(tempScopeUri)
+                .withHeader("Accept", KRFormat.TURTLE));
+        request.assertStatus(200).assertContentContains(tempScopeUri);
+        log.info("Request: " + tempScopeUri + " ... DONE");
+
+        // TODO the U of CRUD
+
+        // Delete scope
+        executor.execute(builder.buildOtherRequest(new 
HttpDelete(builder.buildUrl(tempScopeUri))));
+        log.info("DELETE Request: " + tempScopeUri + " ... DONE");
+
+        // Scope should not be there
+        request = executor.execute(builder.buildGetRequest(tempScopeUri)
+                .withHeader("Accept", KRFormat.TURTLE));
+        request.assertStatus(404);
+        log.info("Request: " + tempScopeUri + " (should return 404) ... DONE");
+    }
 
-        assertTrue(true);
+    @Test
+    public void testLocking() throws Exception {
+        // TODO first we need some offline content to POST
+    }
 
+    @Test
+    public void testSupportedOWLFormats() throws Exception {
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.OWL_XML))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " (Accept: " + KRFormat.OWL_XML + 
")" + " ... DONE");
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.MANCHESTER_OWL))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " (Accept: " + 
KRFormat.MANCHESTER_OWL + ")" + " ... DONE");
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.FUNCTIONAL_OWL))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " (Accept: " + 
KRFormat.FUNCTIONAL_OWL + ")" + " ... DONE");
+    }
+
+    @Test
+    public void testSupportedRDFFormats() throws Exception {
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.RDF_XML))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " (Accept: " + KRFormat.RDF_XML + 
")" + " ... DONE");
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.RDF_JSON))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " (Accept: " + KRFormat.RDF_JSON 
+ ")" + " ... DONE");
+        
executor.execute(builder.buildGetRequest(SESSION_URI).withHeader("Accept", 
KRFormat.TURTLE))
+                .assertStatus(200);
+        log.info("Request: " + SESSION_URI + " (Accept: " + KRFormat.TURTLE + 
")" + " ... DONE");
     }
 
     private char toHex(int ch) {


Reply via email to