use of org.apache.sling.testing.tools.http.RequestBuilder in project sling by apache.
the class ITMDCFilter method startContainer.
@Before
public void startContainer() throws Exception {
if (testContainer == null) {
ServerConfiguration sc = new ServerConfiguration();
ExamSystem system = DefaultExamSystem.create(sc.config());
testContainer = PaxExamRuntime.createContainer(system);
testContainer.start();
new RetryLoop(new RetryLoop.Condition() {
public String getDescription() {
return "Check if MDCTestServlet is up";
}
public boolean isTrue() throws Exception {
RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
executor.execute(rb.buildGetRequest("/mdc")).assertStatus(200);
rb = new RequestBuilder(ServerConfiguration.getServerUrl());
//Create test config via servlet
executor.execute(rb.buildGetRequest("/mdc", "createTestConfig", "true"));
TimeUnit.SECONDS.sleep(1);
return true;
}
}, 5, 100);
}
}
use of org.apache.sling.testing.tools.http.RequestBuilder in project sling by apache.
the class ValidationServiceIT method testPostProcessorWithInvalidModel.
@Test
public void testPostProcessorWithInvalidModel() throws IOException, JsonException {
MultipartEntity entity = new MultipartEntity();
entity.addPart("sling:resourceType", new StringBody("validation/test/resourceType1"));
entity.addPart("field1", new StringBody("Hello World"));
final String url = String.format("http://localhost:%s", httpPort());
RequestBuilder requestBuilder = new RequestBuilder(url);
// test JSON response, because the HTML response overwrites the original exception (https://issues.apache.org/jira/browse/SLING-6703)
RequestExecutor re = requestExecutor.execute(requestBuilder.buildPostRequest("/content/validated/invalidresource").withEntity(entity).withHeader("Accept", "application/json").withCredentials("admin", "admin")).assertStatus(500);
String content = re.getContent();
JsonObject jsonResponse = Json.createReader(new StringReader(content)).readObject();
JsonObject error = jsonResponse.getJsonObject("error");
assertEquals("org.apache.sling.validation.impl.postprocessor.InvalidResourcePostProcessorException", error.getString("class"));
assertEquals("Validation errors: field1 : Property does not match the pattern \"^\\p{Upper}+$\"., Missing required property with name \"field2\".", error.getString("message"));
}
use of org.apache.sling.testing.tools.http.RequestBuilder in project sling by apache.
the class ITMDCFilter method testDefault.
@Test
public void testDefault() throws Exception {
RequestBuilder rb = new RequestBuilder(ServerConfiguration.getServerUrl());
// Add Sling POST options
RequestExecutor result = executor.execute(rb.buildGetRequest("/mdc", "foo", "bar"));
JsonObject jb = Json.createReader(new StringReader(result.getContent())).readObject();
assertEquals("/mdc", jb.getString("req.requestURI"));
assertEquals("foo=bar", jb.getString("req.queryString"));
assertEquals(ServerConfiguration.getServerUrl() + "/mdc", jb.getString("req.requestURL"));
log.info("Response {}", result.getContent());
}
use of org.apache.sling.testing.tools.http.RequestBuilder in project sling by apache.
the class RemoteLogDumper method failed.
@Override
protected void failed(Throwable e, Description description) {
final String baseUrl = getServerBaseUrl();
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
if (baseUrl != null) {
try {
warnIfNopMDCAdapterBeingUsed();
DefaultHttpClient httpClient = new DefaultHttpClient();
RequestExecutor executor = new RequestExecutor(httpClient);
RequestBuilder rb = new RequestBuilder(baseUrl);
Request r = rb.buildGetRequest(SERVLET_PATH, TEST_CLASS, description.getClassName(), TEST_NAME, description.getMethodName());
executor.execute(r);
int statusCode = executor.getResponse().getStatusLine().getStatusCode();
String msg = e.getMessage();
if (msg != null) {
pw.println(msg);
}
if (statusCode == 200) {
pw.printf("=============== Logs from server [%s] for [%s]===================%n", baseUrl, description.getMethodName());
pw.print(executor.getContent());
pw.println("========================================================");
} else {
pw.printf("Not able to fetch logs from [%s%s]. " + "TestLogServer probably not configured %n", baseUrl, SERVLET_PATH);
}
} catch (Throwable t) {
System.err.printf("Error occurred while fetching test logs from server [%s] %n", baseUrl);
t.printStackTrace(System.err);
}
System.err.print(sw.toString());
}
}
use of org.apache.sling.testing.tools.http.RequestBuilder in project sling by apache.
the class ConsoleTestClient method testResourceResolver.
@Test
public void testResourceResolver() throws Exception {
RequestBuilder rb = new RequestBuilder("http://localhost:9000");
final MultipartEntity entity = new MultipartEntity();
// Add Sling POST options
entity.addPart("lang", new StringBody("esp"));
entity.addPart("code", new InputStreamBody(getClass().getResourceAsStream("/test.js"), "test.js"));
executor.execute(rb.buildPostRequest("/system/console/scriptconsole.json").withEntity(entity).withCredentials("admin", "admin")).assertStatus(200);
}
Aggregations