use of org.apache.sling.testing.tools.http.RequestExecutor 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.testing.tools.http.RequestExecutor 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