use of org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient 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());
}
}
use of org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient in project sling by apache.
the class ServerSideTestClient method runTests.
public TestResults runTests(String testPackageOrClassName) throws Exception {
final RemoteTestHttpClient testClient = new RemoteTestHttpClient(serverBaseUrl + "/system/sling/junit", serverUsername, serverPassword, true);
final TestResults r = new TestResults();
final Map<String, String> options = new HashMap<String, String>();
options.put("forceReload", "true");
final RequestExecutor executor = testClient.runTests(testPackageOrClassName, null, "json", options);
executor.assertContentType("application/json");
String content = executor.getContent();
if (!content.trim().isEmpty()) {
final JsonArray json = JsonUtil.parseArray(content);
for (int i = 0; i < json.size(); i++) {
final JsonObject obj = json.getJsonObject(i);
if ("test".equals(obj.getString("INFO_TYPE"))) {
r.testCount++;
if (obj.containsKey("failure")) {
r.failures.add(JsonUtil.toString(obj.get("failure")));
}
}
}
}
return r;
}
use of org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient in project sling by apache.
the class SlingRemoteExecutionRule method invokeRemote.
private void invokeRemote(String remoteUrl, String remoteUsername, String remotePassword, FrameworkMethod method) throws Throwable {
final String testClassesSelector = method.getMethod().getDeclaringClass().getName();
final String methodName = method.getMethod().getName();
final RemoteTestHttpClient testHttpClient = new RemoteTestHttpClient(remoteUrl, remoteUsername, remotePassword, false);
testHttpClient.setRequestCustomizer(this);
final RequestExecutor executor = testHttpClient.runTests(testClassesSelector, methodName, "serialized");
log.debug("Ran test {} method {} at URL {}", new Object[] { testClassesSelector, methodName, remoteUrl });
final HttpEntity entity = executor.getResponse().getEntity();
if (entity != null) {
try {
final Object o = new ObjectInputStream(entity.getContent()).readObject();
if (!(o instanceof ExecutionResult)) {
throw new IllegalStateException("Expected an ExecutionResult, got a " + o.getClass().getName());
}
final ExecutionResult result = (ExecutionResult) o;
if (result.isFailure()) {
throw result.getException();
}
} finally {
entity.consumeContent();
}
}
}
Aggregations