use of org.apache.wicket.request.Request in project wicket by apache.
the class ResourceMapperTest method validPathWithParamsAndQueryPath.
/**
* testValidPathWithParamsAndQueryPath()
*/
@Test
public void validPathWithParamsAndQueryPath() {
Request request = createRequest("test/resource/1/fred?foo=bar&foo=baz&value=12");
IRequestHandler requestHandler = mapper.mapRequest(request);
assertNotNull(requestHandler);
assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
assertEquals(request.getUrl(), mapper.mapHandler(requestHandler));
tester.processRequest(requestHandler);
PageParameters params = resource.pageParameters;
assertNotNull(params);
assertEquals(3, params.getAllNamed().size());
assertEquals(2, params.getIndexedCount());
StringValue paramId = params.get(0);
assertNotNull(paramId);
assertEquals(1, paramId.toInt());
StringValue paramName = params.get(1);
assertNotNull(paramName);
assertEquals("fred", paramName.toString());
List<StringValue> foo = params.getValues("foo");
assertNotNull(foo.size() == 2);
assertEquals("bar", foo.get(0).toString(""));
assertEquals("baz", foo.get(1).toString(""));
StringValue paramValue = params.get("value");
assertEquals(12, paramValue.toInt());
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class ResourceMapperTest method placeholders.
/**
* testPlaceholders()
*/
@Test
public void placeholders() {
Request request = createRequest("test2/image/resource/foo/bar?a=abc&b=123");
IRequestHandler requestHandler = mapperWithPlaceholder.mapRequest(request);
assertNotNull(requestHandler);
assertEquals(ResourceReferenceRequestHandler.class, requestHandler.getClass());
assertEquals(request.getUrl(), mapperWithPlaceholder.mapHandler(requestHandler));
tester.processRequest(requestHandler);
PageParameters params = resource.pageParameters;
assertNotNull(params);
assertEquals(3, params.getAllNamed().size());
assertEquals(2, params.getIndexedCount());
assertEquals("foo", params.get(0).toString());
assertEquals("bar", params.get(1).toString());
assertEquals("image", params.get("name").toString());
assertEquals("abc", params.get("a").toString());
assertEquals("123", params.get("b").toString());
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class ResourceMapperTest method placeholdersWithQueryParamDuplicate.
/**
* testPlaceholdersWithQueryParamDuplicate()
*/
@Test
public void placeholdersWithQueryParamDuplicate() {
// we have one named parameter that exists twice
Request request = createRequest("test2/image/resource/foo/bar?name=name-2&val=123");
IRequestHandler handler = mapperWithPlaceholder.mapRequest(request);
assertNotNull(handler);
assertEquals(ResourceReferenceRequestHandler.class, handler.getClass());
// the query part of the duplicate should be gone now
Url newUrl = mapperWithPlaceholder.mapHandler(handler);
assertEquals(Url.parse("test2/name-2/resource/foo/bar?val=123"), newUrl);
// create new request
request = createRequest(newUrl.toString());
// get handler again
handler = mapperWithPlaceholder.mapRequest(request);
assertNotNull(handler);
tester.processRequest(handler);
PageParameters params = resource.pageParameters;
assertNotNull(params);
assertEquals(2, params.getAllNamed().size());
assertEquals(2, params.getIndexedCount());
assertEquals("foo", params.get(0).toString());
assertEquals("bar", params.get(1).toString());
assertEquals("name-2", params.get("name").toString());
assertEquals("123", params.get("val").toString());
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class ResourceMapperTest method requestWithEmptyFilename.
/**
*/
@Test
public void requestWithEmptyFilename() {
// request invalid path with empty filename
// this must not return a handler
Request request = createRequest("test2/image/");
IRequestHandler handler = mapperWithPlaceholder.mapRequest(request);
assertNull(handler);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class ComponentRenderer method renderPage.
/**
* Collects the html generated by rendering a page.
*
* @param page
* supplier of the page
* @return the html rendered by the panel
*/
public CharSequence renderPage(final Supplier<? extends Page> page) {
return inThreadContext(() -> {
Request request = newRequest();
BufferedWebResponse response = new BufferedWebResponse(null);
RequestCycle cycle = application.createRequestCycle(request, response);
ThreadContext.setRequestCycle(cycle);
page.get().renderPage();
return response.getText();
});
}
Aggregations