Search in sources :

Example 1 with HtmlResponse

use of org.apache.sling.servlets.post.HtmlResponse in project sling by apache.

the class SlingPostServletTest method testRedirection.

private void testRedirection(String requestPath, String resourcePath, String redirect, String expected) throws Exception {
    RedirectServletResponse resp = new RedirectServletResponse();
    SlingHttpServletRequest request = new RedirectServletRequest(redirect, requestPath);
    PostResponse htmlResponse = new HtmlResponse();
    htmlResponse.setPath(resourcePath);
    assertEquals(expected != null, servlet.redirectIfNeeded(request, htmlResponse, resp));
    assertEquals(expected, resp.redirectLocation);
}
Also used : HtmlResponse(org.apache.sling.servlets.post.HtmlResponse) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) PostResponse(org.apache.sling.servlets.post.PostResponse)

Example 2 with HtmlResponse

use of org.apache.sling.servlets.post.HtmlResponse in project sling by apache.

the class RequestPropertyTest method collectContent.

@SuppressWarnings("unchecked")
private Map<String, RequestProperty> collectContent(Param... kvs) throws Throwable {
    final List<Map.Entry<String, RequestParameter>> params = new ArrayList<Map.Entry<String, RequestParameter>>();
    for (int i = 0; i < kvs.length; i++) {
        final Param kv = kvs[i];
        final RequestParameter[] param = new RequestParameter[kv.value.length];
        for (int j = 0; j < kv.value.length; j++) {
            final String strValue = kv.value[j];
            final RequestParameter aparam = context.mock(RequestParameter.class, "requestParameter" + i + "#" + j);
            context.checking(new Expectations() {

                {
                    allowing(aparam).getString();
                    will(returnValue(strValue));
                }
            });
            param[j] = aparam;
        }
        final Map.Entry<String, RequestParameter> entry = context.mock(Map.Entry.class, "entry" + i);
        context.checking(new Expectations() {

            {
                allowing(entry).getKey();
                will(returnValue(kv.key));
                allowing(entry).getValue();
                will(returnValue(param));
            }
        });
        params.add(entry);
    }
    final Set set = context.mock(Set.class);
    context.checking(new Expectations() {

        {
            one(set).iterator();
            will(returnValue(params.iterator()));
        }
    });
    final RequestParameterMap map = context.mock(RequestParameterMap.class);
    context.checking(new Expectations() {

        {
            one(map).entrySet();
            will(returnValue(set));
        }
    });
    final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
    context.checking(new Expectations() {

        {
            Vector names = new Vector();
            names.add("./param");
            one(request).getParameterNames();
            will(returnValue(names.elements()));
            one(request).getRequestParameterMap();
            will(returnValue(map));
        }
    });
    final HtmlResponse response = new HtmlResponse();
    response.setPath("/test/path");
    Map<String, RequestProperty> props = (Map<String, RequestProperty>) PrivateAccessor.invoke(new ModifyOperation(), "collectContent", COLLECT_CLASSES, new Object[] { request, response });
    return props;
}
Also used : Expectations(org.jmock.Expectations) HtmlResponse(org.apache.sling.servlets.post.HtmlResponse) Set(java.util.Set) RequestParameter(org.apache.sling.api.request.RequestParameter) ArrayList(java.util.ArrayList) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) RequestParameterMap(org.apache.sling.api.request.RequestParameterMap) RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) ModifyOperation(org.apache.sling.servlets.post.impl.operations.ModifyOperation) RequestParameterMap(org.apache.sling.api.request.RequestParameterMap) Map(java.util.Map) Vector(java.util.Vector)

Aggregations

SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 HtmlResponse (org.apache.sling.servlets.post.HtmlResponse)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 Vector (java.util.Vector)1 RequestParameter (org.apache.sling.api.request.RequestParameter)1 RequestParameterMap (org.apache.sling.api.request.RequestParameterMap)1 MockSlingHttpServletRequest (org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest)1 PostResponse (org.apache.sling.servlets.post.PostResponse)1 RequestProperty (org.apache.sling.servlets.post.impl.helper.RequestProperty)1 ModifyOperation (org.apache.sling.servlets.post.impl.operations.ModifyOperation)1 Expectations (org.jmock.Expectations)1