MARMOTTA-508: warming-up marmotta via the webservices before running the ldp-testsuite
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2039c6ca Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2039c6ca Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2039c6ca Branch: refs/heads/develop Commit: 2039c6ca015964f139136cfe2bd7b3f85501b48f Parents: 99ab471 Author: Jakob Frank <[email protected]> Authored: Wed Sep 17 11:35:16 2014 +0200 Committer: Jakob Frank <[email protected]> Committed: Wed Sep 17 11:35:16 2014 +0200 ---------------------------------------------------------------------- .../marmotta/platform/ldp/api/LdpService.java | 4 + .../platform/ldp/webservices/LdpWebService.java | 24 ++-- .../marmotta/platform/ldp/LdpSuiteTest.java | 118 +++++++++++-------- .../ldp/webservices/LdpWebServiceTest.java | 4 +- 4 files changed, 88 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/2039c6ca/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/api/LdpService.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/api/LdpService.java b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/api/LdpService.java index 20ee27d..306cfa3 100644 --- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/api/LdpService.java +++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/api/LdpService.java @@ -64,6 +64,10 @@ public interface LdpService { return uri; } + public String stringValue() { + return uri.stringValue(); + } + public static InteractionModel fromURI(String uri) { if (LDP.Resource.stringValue().equals(uri)) { return LDPR; http://git-wip-us.apache.org/repos/asf/marmotta/blob/2039c6ca/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java index 87adf19..a70109c 100644 --- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java +++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java @@ -73,18 +73,18 @@ public class LdpWebService { public static final String PATH = "/ldp"; //TODO: at some point this will be root ('/') in marmotta public static final String LDP_SERVER_CONSTRAINTS = "http://wiki.apache.org/marmotta/LDPImplementationReport/2014-09-16"; - static final String LINK_REL_DESCRIBEDBY = "describedby"; - static final String LINK_REL_CONSTRAINEDBY = "http://www.w3.org/ns/ldp#constrainedBy"; - static final String LINK_REL_CONTENT = "content"; - static final String LINK_REL_META = "meta"; - static final String LINK_REL_TYPE = "type"; - static final String LINK_PARAM_ANCHOR = "anchor"; - static final String HTTP_HEADER_SLUG = "Slug"; - static final String HTTP_HEADER_ACCEPT_POST = "Accept-Post"; - static final String HTTP_HEADER_ACCEPT_PATCH = "Accept-Patch"; - static final String HTTP_HEADER_PREFER = "Prefer"; - static final String HTTP_HEADER_PREFERENCE_APPLIED = "Preference-Applied"; - static final String HTTP_METHOD_PATCH = "PATCH"; + public static final String LINK_REL_DESCRIBEDBY = "describedby"; + public static final String LINK_REL_CONSTRAINEDBY = "http://www.w3.org/ns/ldp#constrainedBy"; + public static final String LINK_REL_CONTENT = "content"; + public static final String LINK_REL_META = "meta"; + public static final String LINK_REL_TYPE = "type"; + public static final String LINK_PARAM_ANCHOR = "anchor"; + public static final String HTTP_HEADER_SLUG = "Slug"; + public static final String HTTP_HEADER_ACCEPT_POST = "Accept-Post"; + public static final String HTTP_HEADER_ACCEPT_PATCH = "Accept-Patch"; + public static final String HTTP_HEADER_PREFER = "Prefer"; + public static final String HTTP_HEADER_PREFERENCE_APPLIED = "Preference-Applied"; + public static final String HTTP_METHOD_PATCH = "PATCH"; private Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass()); http://git-wip-us.apache.org/repos/asf/marmotta/blob/2039c6ca/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/LdpSuiteTest.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/LdpSuiteTest.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/LdpSuiteTest.java index 7e13591..e9f2579 100644 --- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/LdpSuiteTest.java +++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/LdpSuiteTest.java @@ -18,16 +18,20 @@ package org.apache.marmotta.platform.ldp; import com.hp.hpl.jena.xmloutput.impl.Basic; +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.response.Response; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.marmotta.commons.vocabulary.LDP; import org.apache.marmotta.platform.core.api.triplestore.SesameService; import org.apache.marmotta.platform.core.test.base.JettyMarmotta; import org.apache.marmotta.platform.ldp.api.LdpService; import org.apache.marmotta.platform.ldp.webservices.LdpWebService; +import org.hamcrest.CoreMatchers; import org.junit.*; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; @@ -36,7 +40,10 @@ import org.openrdf.rio.RDFParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3.ldp.testsuite.LdpTestSuite; +import org.w3.ldp.testsuite.matcher.HttpStatusSuccessMatcher; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Link; import javax.ws.rs.core.UriBuilder; import java.io.IOException; import java.net.URISyntaxException; @@ -54,6 +61,8 @@ public class LdpSuiteTest { /** @see org.testng.TestNG#HAS_FAILURE */ private static final int TESTNG_STATUS_HAS_FAILURE = 1; + /** @see org.testng.TestNG#HAS_SKIPPED */ + private static final int TESTNG_STATUS_HAS_SKIPPED = 2; /** @see org.testng.TestNG#HAS_NO_TEST */ private static final int TESTNG_STATUS_HAS_NO_TEST = 8; @@ -79,57 +88,65 @@ public class LdpSuiteTest { @Before public void before() throws RepositoryException, IOException, RDFParseException { - log.debug("Performing required LDP re-initialization..."); - final SesameService sesameService = marmotta.getService(SesameService.class); - final LdpService ldpService = marmotta.getService(LdpService.class); - final RepositoryConnection conn = sesameService.getConnection(); - try { - conn.begin(); - - //warm up and initialization - HttpClient httpClient = HttpClientBuilder.create().build(); - final HttpResponse response = httpClient.execute(new HttpGet(baseUrl)); - Assume.assumeTrue(response.getStatusLine().getStatusCode() == 200); - final String container = ldpService.addResource(conn, baseUrl, - UriBuilder.fromUri(baseUrl).path(UUID.randomUUID().toString()).build().toString(), - LdpService.InteractionModel.LDPC, RDFFormat.TURTLE.getDefaultMIMEType(), - IOUtils.toInputStream("<> a <http://example.com/ldp/ContainerInteraction> . ")); - final String resource = ldpService.addResource(conn, baseUrl, - UriBuilder.fromUri(baseUrl).path(UUID.randomUUID().toString()).build().toString(), - LdpService.InteractionModel.LDPR, RDFFormat.TURTLE.getDefaultMIMEType(), - IOUtils.toInputStream("<> a <http://example.com/ldp/ResourceInteraction> . ")); - conn.commit(); - - //then actual test suite - - log.info("Running W3C official LDP Test Suite against '{}' server", baseUrl); - log.debug("(using {} as root container)", container); - Map<String, String> options = new HashMap<>(); - options.put("server", container); - options.put("basic", null); - options.put("non-rdf", null); - options.put("cont-res", resource); - if (!LdpService.SERVER_MANAGED_PROPERTIES.isEmpty()) { - options.put("read-only-prop", LdpService.SERVER_MANAGED_PROPERTIES.iterator().next().stringValue()); - } - options.put("httpLogging", null); - options.put("skipLogging", null); - options.put("excludedGroups", "MANUAL"); - - //reporting stuff - //options.put("earl", null); - //options.put("software", "Apache Marmotta"); - //options.put("language", "Java"); - //options.put("homepage", "http://marmotta.apache.org"); - //options.put("assertor", "http://marmotta.apache.org"); - //options.put("shortname", "Marmotta"); - //options.put("developer", "Jakob Frank, Sergio Fernández"); - - testSuite = new LdpTestSuite(options); - } finally { - conn.close(); + RestAssured + .expect() + .statusCode(HttpStatusSuccessMatcher.isSuccessful()) + .statusLine(CoreMatchers.startsWith("HTTP/1.1")) + .get(baseUrl); + + final String container = RestAssured + .given() + .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType()) + .header(HttpHeaders.LINK, Link.fromUri(LdpService.InteractionModel.LDPC.stringValue()).rel(LdpWebService.LINK_REL_TYPE).build().toString()) + .body("<> a <http://example.com/ContainerInteraction> . ".getBytes()) + .expect() + .statusCode(HttpStatusSuccessMatcher.isSuccessful()) + .header(HttpHeaders.LOCATION, CoreMatchers.notNullValue()) + .post(baseUrl) + .getHeader(HttpHeaders.LOCATION); + + final String resource = RestAssured + .given() + .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType()) + .header(HttpHeaders.LINK, Link.fromUri(LdpService.InteractionModel.LDPR.stringValue()).rel(LdpWebService.LINK_REL_TYPE).build().toString()) + .body("<> a <http://example.com/ResourceInteraction> .".getBytes()) + .expect() + .statusCode(HttpStatusSuccessMatcher.isSuccessful()) + .header(HttpHeaders.LOCATION, CoreMatchers.notNullValue()) + .post(baseUrl) + .getHeader(HttpHeaders.LOCATION); + + RestAssured.reset(); + + log.info("Container: {}", container); + log.info("Resource: {}", resource); + + //configure test suite + log.info("Running W3C official LDP Test Suite against '{}' server", baseUrl); + log.debug("(using {} as root container)", container); + Map<String, String> options = new HashMap<>(); + options.put("server", container); + options.put("basic", null); + options.put("non-rdf", null); + options.put("cont-res", resource); + if (!LdpService.SERVER_MANAGED_PROPERTIES.isEmpty()) { + options.put("read-only-prop", LdpService.SERVER_MANAGED_PROPERTIES.iterator().next().stringValue()); } + options.put("httpLogging", null); + options.put("skipLogging", null); + options.put("excludedGroups", "MANUAL"); + + //reporting stuff + //options.put("earl", null); + //options.put("software", "Apache Marmotta"); + //options.put("language", "Java"); + //options.put("homepage", "http://marmotta.apache.org"); + //options.put("assertor", "http://marmotta.apache.org"); + //options.put("shortname", "Marmotta"); + //options.put("developer", "Jakob Frank, Sergio Fernández"); + + testSuite = new LdpTestSuite(options); } @After @@ -142,6 +159,9 @@ public class LdpSuiteTest { testSuite.run(); Assert.assertTrue("ldp-testsuite finished with errors", (testSuite.getStatus() & TESTNG_STATUS_HAS_FAILURE) == 0); Assert.assertTrue("ldp-testsuite is empty - no test run", (testSuite.getStatus() & TESTNG_STATUS_HAS_NO_TEST) == 0); + if ((testSuite.getStatus() & TESTNG_STATUS_HAS_SKIPPED) != 0) { + log.warn("ldp-testsuite has skipped some tests"); + } } } http://git-wip-us.apache.org/repos/asf/marmotta/blob/2039c6ca/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java index 81412e8..bf51637 100644 --- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java +++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java @@ -27,6 +27,7 @@ import org.apache.marmotta.commons.util.HashUtils; import org.apache.marmotta.commons.vocabulary.LDP; import org.apache.marmotta.platform.core.exception.io.MarmottaImportException; import org.apache.marmotta.platform.core.test.base.JettyMarmotta; +import org.apache.marmotta.platform.ldp.api.LdpService; import org.apache.marmotta.platform.ldp.util.LdpUtils; import org.apache.marmotta.platform.ldp.webservices.util.HeaderMatchers; import org.hamcrest.CoreMatchers; @@ -297,7 +298,7 @@ public class LdpWebServiceTest { // Try LDPR final String ldpr = RestAssured .given() - .header(HttpHeaders.LINK, Link.fromUri(LDP.Resource.stringValue()).rel(LdpWebService.LINK_REL_TYPE).build().toString()) + .header(HttpHeaders.LINK, Link.fromUri(LdpService.InteractionModel.LDPR.stringValue()).rel(LdpWebService.LINK_REL_TYPE).build().toString()) .body(testResourceTTL.getBytes()) .contentType(RDFFormat.TURTLE.getDefaultMIMEType()) .expect() @@ -437,6 +438,7 @@ public class LdpWebServiceTest { return RestAssured .given() .header(LdpWebService.HTTP_HEADER_SLUG, String.valueOf(slug)) + .header(HttpHeaders.LINK, Link.fromUri(LdpService.InteractionModel.LDPC.stringValue()).rel(LdpWebService.LINK_REL_TYPE).build().toString()) .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType()) .body("<> a <http://example.com/unit-test> .".getBytes()) .expect()
