use of org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse in project sling by apache.
the class JsonResponseTest method testSend.
public void testSend() throws Exception {
res.onChange("modified", "argument1");
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
res.send(response, true);
JsonObject result = Json.createReader(new StringReader(response.getOutput().toString())).readObject();
assertProperty(result, HtmlResponse.PN_STATUS_CODE, Integer.toString(HttpServletResponse.SC_OK));
assertEquals(JSONResponse.RESPONSE_CONTENT_TYPE, response.getContentType());
assertEquals(JSONResponse.RESPONSE_CHARSET, response.getCharacterEncoding());
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse in project sling by apache.
the class JsonResponseTest method testSetError.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public void testSetError() throws IOException {
String errMsg = "Dummy error";
res.setError(new Error(errMsg));
MockSlingHttpServletResponse resp = new MockSlingHttpServletResponse();
res.send(resp, true);
JsonObject json = res.getJson();
JsonValue error = assertProperty(json, "error");
assertProperty((JsonObject) error, "class", Error.class.getName());
assertProperty((JsonObject) error, "message", errMsg);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse in project acs-aem-commons by Adobe-Consulting-Services.
the class CustomComponentActivatorListServletTest method testCustom.
@Test
public void testCustom() throws Exception {
CustomComponentActivatorListServlet servlet = new CustomComponentActivatorListServlet();
servlet.activate(Collections.singletonMap("components", new String[] { "test=my/test/component" }));
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(null, null, null, null, null);
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
servlet.doGet(request, response);
String result = response.getOutput().toString();
JSONAssert.assertEquals("{\"components\":[{\"propertyName\":\"test\",\"componentPath\":\"my/test/component\"}]}", result, JSONCompareMode.NON_EXTENSIBLE);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse in project acs-aem-commons by Adobe-Consulting-Services.
the class CustomComponentActivatorListServletTest method testDefault.
@Test
public void testDefault() throws Exception {
CustomComponentActivatorListServlet servlet = new CustomComponentActivatorListServlet();
servlet.activate(Collections.emptyMap());
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(null, null, null, null, null);
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
servlet.doGet(request, response);
String result = response.getOutput().toString();
JSONAssert.assertEquals(DEFAULT_RESULT, result, JSONCompareMode.NON_EXTENSIBLE);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse in project acs-aem-commons by Adobe-Consulting-Services.
the class OptionsServletTest method testWithBadType.
@Test
public void testWithBadType() throws Exception {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/apps/acs-commons/components/utilities/designer/clientlibsmanager/options", "html", "json", null, null);
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
servlet.doGet(request, response);
assertEquals("application/json", response.getContentType());
assertEquals("[]", response.getOutput().toString());
}
Aggregations