You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/06/13 10:58:40 UTC

[080/100] [abbrv] git commit: MARMOTTA-438: improved resource management to have the base url from each test case

MARMOTTA-438: improved resource management to have the base url from each test case


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

Branch: refs/heads/ldp
Commit: def9d41f9a911032c6833c9747c6e7d6b8ca8d9e
Parents: 477ccd3
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Apr 14 18:32:09 2014 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Apr 14 18:32:09 2014 +0200

----------------------------------------------------------------------
 .../platform/ldp/testsuite/LdpTestCase.java     |  4 +-
 .../ldp/testsuite/LdpTestCaseRunner.java        | 44 ++++++++++++++++--
 .../platform/ldp/testsuite/LdpTestCases.java    | 49 ++++++++------------
 .../ldp/testsuite/LdpTestCasesRunner.java       | 38 +++++++++++----
 4 files changed, 88 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/def9d41f/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
index 176494b..e293d71 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
@@ -88,10 +88,8 @@ public class LdpTestCase /* extends TestCase */ {
      */
     private URI testAssertion;
 
-    public LdpTestCase(URI uri, String label) {
-        //super(label);
+    public LdpTestCase(URI uri) {
         this.uri = uri;
-        this.label = label;
     }
 
     public URI getUri() {

http://git-wip-us.apache.org/repos/asf/marmotta/blob/def9d41f/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
index 051952b..79a6079 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
@@ -17,11 +17,24 @@
 
 package org.apache.marmotta.platform.ldp.testsuite;
 
+import com.jayway.restassured.RestAssured;
+import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
+import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
+import org.apache.marmotta.platform.ldp.webservices.LdpWebService;
+import org.junit.*;
+import org.junit.rules.TestName;
 import org.junit.runner.Description;
 import org.junit.runner.Runner;
 import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.Suite;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import static org.junit.Assert.assertEquals;
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+import static org.junit.Assert.assertNotNull;
 
 /**
  * LDP Test Case JUnit Runner
@@ -30,7 +43,11 @@ import static org.junit.Assert.assertEquals;
  */
 public class LdpTestCaseRunner extends Runner {
 
-    private LdpTestCase testCase;
+    private static Logger log = LoggerFactory.getLogger(LdpTestCaseRunner.class);
+
+    private final LdpTestCase testCase;
+
+    private String baseUrl;
 
     public LdpTestCaseRunner(LdpTestCase testCase) {
         this.testCase = testCase;
@@ -38,7 +55,7 @@ public class LdpTestCaseRunner extends Runner {
 
     @Override
     public Description getDescription() {
-        return Description.createSuiteDescription(testCase.getLabel());
+        return Description.createSuiteDescription(testCase.getUri().getLocalName());
     }
 
     @Override
@@ -54,8 +71,25 @@ public class LdpTestCaseRunner extends Runner {
     }
 
     private void run() {
-        assertEquals(testCase.getLabel().substring(3), testCase.getUri().getLocalName().substring(2));
-        //TODO: actual execution
+        Assume.assumeNotNull(baseUrl);
+        assertNotNull(testCase);
+        assertNotNull(testCase.getUri());
+        String context = buildContext(testCase);
+        log.info("Executing LDP Test Case {} over context {}...", testCase.getUri().getLocalName(), context);
+
+        //TODO: actual test case execution
+    }
+
+    private String buildContext(LdpTestCase testCase) {
+        return baseUrl + "/" + testCase.getUri().getLocalName().toLowerCase();
+    }
+
+    public String getBaseUrl() {
+        return baseUrl;
+    }
+
+    public void setBaseUrl(String baseUrl) {
+        this.baseUrl = baseUrl;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/def9d41f/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
index ddffa8f..c60aba4 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
@@ -18,17 +18,13 @@
 package org.apache.marmotta.platform.ldp.testsuite;
 
 import com.jayway.restassured.RestAssured;
-import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
 import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
 import org.apache.marmotta.platform.ldp.webservices.LdpWebService;
-import org.junit.*;
+import org.junit.ClassRule;
+import org.junit.rules.ExternalResource;
 import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.core.UriBuilder;
-import java.io.IOException;
-import java.net.URISyntaxException;
 
 /**
  * LDP Test Cases
@@ -46,35 +42,30 @@ public class LdpTestCases {
 
     public final static String MANIFEST_CACHE = "LDP-Test-Cases-WD-live";
 
-    private static Logger log = LoggerFactory.getLogger(LdpTestCases.class);
+    @ClassRule
+    public static ExternalResource marmotta = new MarmottaResource();
 
-    private static JettyMarmotta marmotta;
+    public static class MarmottaResource extends ExternalResource {
 
-    private static String baseUrl;
+        JettyMarmotta marmotta;
 
-    @BeforeClass
-    public static void setup() throws MarmottaImportException, URISyntaxException, IOException {
-        marmotta = new JettyMarmotta("/marmotta", LdpWebService.class);
-        RestAssured.baseURI = "http://localhost";
-        RestAssured.port = marmotta.getPort();
-        RestAssured.basePath = marmotta.getContext();
-        baseUrl = UriBuilder.fromUri("http://localhost").port(marmotta.getPort()).path(marmotta.getContext()).build().toString();
-    }
+        String baseUrl;
 
-    @Before
-    public void before() {
-        log.warn("before");
-    }
+        @Override
+        protected void before() throws Throwable {
+            marmotta = new JettyMarmotta("/marmotta-ldp", LdpWebService.class);
+            RestAssured.baseURI = "http://localhost";
+            RestAssured.port = marmotta.getPort();
+            RestAssured.basePath = marmotta.getContext();
+            baseUrl = UriBuilder.fromUri("http://localhost").port(marmotta.getPort()).path(marmotta.getContext()).build().toString();
+        }
 
-    @After
-    public void after() {
-        log.warn("after");
-    }
+        @Override
+        protected void after() {
+            //marmotta.shutdown();
+            marmotta = null;
+        }
 
-    @AfterClass
-    public static void shutdown() {
-        //marmotta.shutdown();
-        marmotta = null;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/def9d41f/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
index 31fee36..f9fc57a 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
@@ -17,8 +17,12 @@
 
 package org.apache.marmotta.platform.ldp.testsuite;
 
+import org.apache.commons.lang3.StringUtils;
+import org.junit.rules.TestRule;
 import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.Suite;
+import org.junit.runners.model.FrameworkField;
 import org.openrdf.model.URI;
 import org.openrdf.query.*;
 import org.openrdf.repository.Repository;
@@ -30,6 +34,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -42,11 +48,29 @@ public class LdpTestCasesRunner extends Suite {
 
     private static Logger log = LoggerFactory.getLogger(LdpTestCasesRunner.class);
 
+    private LdpTestCases.MarmottaResource marmotta;
+
     public LdpTestCasesRunner(Class<?> klass) throws Throwable {
         super(klass, buildTestCasesFromManifest());
+
+        //TODO: it should be an easier way to do it...
+        for (TestRule rule : this.classRules()) {
+            if (LdpTestCases.MarmottaResource.class.equals(rule.getClass())) {
+                marmotta = (LdpTestCases.MarmottaResource)rule;
+                break;
+            }
+        }
+    }
+
+    @Override
+    protected void runChild(Runner runner, RunNotifier notifier) {
+        if (runner instanceof LdpTestCaseRunner) {
+            ((LdpTestCaseRunner)runner).setBaseUrl(marmotta.baseUrl);
+        }
+        super.runChild(runner, notifier);
     }
 
-    private static List<Runner> buildTestCasesFromManifest() {
+    private static List<Runner> buildTestCasesFromManifest() throws Throwable {
         List<Runner> runners = new ArrayList<>();
 
         String path = LdpTestCases.ROOT_PATH + LdpTestCases.MANIFEST_CACHE + ".ttl";
@@ -56,20 +80,14 @@ public class LdpTestCasesRunner extends Suite {
             try {
                 conn.begin();
 
-                //TODO: this query is not final, it needs to evolve in parallel with the test cases
-                String testCasesQuery = LdpTestCasesUtils.getNormativeNamespacesSparql() + "\n" +
-                        "SELECT ?tc ?label \n" +
-                        "WHERE { \n" +
-                        "  ?tc a td:TestCase ; \n" +
-                        "      rdfs:label ?label . \n" +
-                        "}";
+                String testCasesQuery = LdpTestCasesUtils.getNormativeNamespacesSparql()+ "\n"
+                        + "SELECT ?tc WHERE { ?tc a td:TestCase }";
                 TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, testCasesQuery);
                 TupleQueryResult results = tupleQuery.evaluate();
                 try {
                     while (results.hasNext()) {
                         BindingSet bindings = results.next();
-                        LdpTestCase testCase = new LdpTestCase((URI)bindings.getValue("tc"), bindings.getValue("label").stringValue());
-                        //TODO: set more data to the test case
+                        LdpTestCase testCase = new LdpTestCase((URI)bindings.getValue("tc"));
                         runners.add(new LdpTestCaseRunner(testCase));
                     }
                 } finally {