Search in sources :

Example 1 with RequestCustomizer

use of org.apache.sling.testing.tools.http.RequestCustomizer in project sling by apache.

the class SlingRemoteTestRunner method maybeExecuteTests.

private void maybeExecuteTests() throws Exception {
    if (testHttpClient != null) {
        // Tests already ran
        return;
    }
    testHttpClient = new RemoteTestHttpClient(testParameters.getJunitServletUrl(), this.username, this.password, true);
    // Let the parameters class customize the request if desired 
    if (testParameters instanceof RequestCustomizer) {
        testHttpClient.setRequestCustomizer((RequestCustomizer) testParameters);
    }
    // Run tests remotely and get response
    final RequestExecutor executor = testHttpClient.runTests(testParameters.getTestClassesSelector(), testParameters.getTestMethodSelector(), "json");
    executor.assertContentType("application/json");
    final JsonArray json = Json.createReader(new StringReader(JsonTicksConverter.tickToDoubleQuote(executor.getContent()))).readArray();
    // based on this vlaue
    for (int i = 0; i < json.size(); i++) {
        final JsonObject obj = json.getJsonObject(i);
        if (obj.containsKey("INFO_TYPE") && "test".equals(obj.getString("INFO_TYPE"))) {
            children.add(new SlingRemoteTest(testClass, obj));
        }
    }
    log.info("Server-side tests executed as {} at {} with path {}", new Object[] { this.username, testParameters.getJunitServletUrl(), testHttpClient.getTestExecutionPath() });
    // Optionally check that number of tests is as expected
    if (testParameters instanceof SlingTestsCountChecker) {
        ((SlingTestsCountChecker) testParameters).checkNumberOfTests(children.size());
    }
}
Also used : JsonArray(javax.json.JsonArray) RequestExecutor(org.apache.sling.testing.tools.http.RequestExecutor) StringReader(java.io.StringReader) JsonObject(javax.json.JsonObject) RemoteTestHttpClient(org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient) RequestCustomizer(org.apache.sling.testing.tools.http.RequestCustomizer)

Aggregations

StringReader (java.io.StringReader)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 RemoteTestHttpClient (org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient)1 RequestCustomizer (org.apache.sling.testing.tools.http.RequestCustomizer)1 RequestExecutor (org.apache.sling.testing.tools.http.RequestExecutor)1