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);
}
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;
}
Aggregations