use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class MediaRangeListTest method testHttpEquivParam.
public void testHttpEquivParam() {
MockSlingHttpServletRequest req = new MockSlingHttpServlet3Request(null, null, null, null, null) {
@Override
public String getHeader(String name) {
return name.equals(MediaRangeList.HEADER_ACCEPT) ? "text/plain" : super.getHeader(name);
}
@Override
public String getParameter(String name) {
return name.equals(MediaRangeList.PARAM_ACCEPT) ? "text/html" : super.getParameter(name);
}
@Override
public Enumeration<String> getHeaderNames() {
return null;
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
return null;
}
};
MediaRangeList rangeList = new MediaRangeList(req);
assertTrue("Did not contain media type from query param", rangeList.contains("text/html"));
assertFalse("Contained media type from overridden Accept header", rangeList.contains("text/plain"));
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.
the class NamedTransformImageServletTest method testAccepts_invalidLastSuffix.
@Test
public void testAccepts_invalidLastSuffix() throws Exception {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + new Random().nextInt() + "/foo", "");
final boolean result = servlet.accepts(request);
assertFalse(result);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.
the class NamedTransformImageServletTest method testAccepts_invalidNamedTransform.
@Test
public void testAccepts_invalidNamedTransform() throws Exception {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/path", "", "transform", "unknown/image.png", "");
final boolean result = servlet.accepts(request);
assertFalse(result);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.
the class NamedTransformImageServletTest method setUp.
@Before
public void setUp() throws Exception {
servlet = new NamedTransformImageServlet();
imageTransformers.put(IMAGE_TRANSFORM_RESIZE, resizeImageTransformer);
imageTransformers.put(IMAGE_TRANSFORM_GREYSCALE, greyscaleImageTransformer);
namedImageTransformers.put(NAMED_TRANSFORM_FEATURE, featureImageTransformer);
namedImageTransformers.put(NAMED_TRANSFORM_SMALL, smallImageTransformer);
mockRequest = new MockSlingHttpServletRequest("/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + new Random().nextInt() + "/image.png", "");
MockitoAnnotations.initMocks(this);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest 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);
}
Aggregations