use of org.apache.wicket.request.Request in project wicket by apache.
the class CryptoMapperTest method resourceReferenceWithLessSegments.
/**
* Relative ResourceReferences, WICKET-3514
*/
@Test
public void resourceReferenceWithLessSegments() {
PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt");
Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
url.getSegments().remove(url.getSegments().size() - 1);
url.getSegments().remove(url.getSegments().size() - 1);
url.getSegments().add("less-crypt.txt");
Request request = getRequest(url);
IRequestHandler requestHandler = mapper.mapRequest(request);
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
assertThat(requestHandler, instanceOf(ResourceReferenceRequestHandler.class));
ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;
assertEquals(getClass(), handler.getResourceReference().getScope());
assertEquals("less-crypt.txt", handler.getResourceReference().getName());
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class CryptoMapperTest method resourceReferenceWithMoreSegments.
/**
* Relative ResourceReferences, WICKET-3514
*/
@Test
public void resourceReferenceWithMoreSegments() {
PackageResourceReference resource = new PackageResourceReference(getClass(), "crypt/crypt.txt");
Url url = mapper.mapHandler(new ResourceReferenceRequestHandler(resource));
url.getSegments().remove(url.getSegments().size() - 1);
url.getSegments().add("more");
url.getSegments().add("more-crypt.txt");
Request request = getRequest(url);
IRequestHandler requestHandler = mapper.mapRequest(request);
assertNotNull(requestHandler);
requestHandler = unwrapRequestHandlerDelegate(requestHandler);
ResourceReferenceRequestHandler handler = (ResourceReferenceRequestHandler) requestHandler;
assertEquals(getClass(), handler.getResourceReference().getScope());
assertEquals("crypt/more/more-crypt.txt", handler.getResourceReference().getName());
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class LocaleAwarePageParametersTest method newApplication.
@Override
protected WebApplication newApplication() {
return new MockApplication() {
@Override
protected void init() {
super.init();
mountPage("unaware", LocaleUnawarePageParametersPage.class);
mount(new MountedMapper("aware", LocaleAwarePageParametersPage.class) {
@Override
protected Locale resolveLocale() {
return resolveUserLocale();
}
});
}
@Override
public Session newSession(Request request, Response response) {
final Session session = super.newSession(request, response);
session.setLocale(Locale.GERMANY);
return session;
}
};
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class MountedMapperTest method exactMountGetsBetterScore_ThanParameterOne_ThenOptionalOne.
@Test
public void exactMountGetsBetterScore_ThanParameterOne_ThenOptionalOne() throws Exception {
final Url url = Url.parse("all/sindex");
final MountedMapper exactMount = new MountedMapper("/all/sindex", MockPage.class);
final MountedMapper requiredParam = new MountedMapper("/all/${exp}", MockPage.class);
final MountedMapper optionalParameter = new MountedMapper("/all/#{exp}", MockPage.class);
final MountedMapper requiredOptionalParam = new MountedMapper("/all/${exp}/#{opt}", MockPage.class);
Request request = getRequest(url);
final int exactCompatScore = exactMount.getCompatibilityScore(request);
final int requiredParamScore = requiredParam.getCompatibilityScore(request);
final int optCompatScore = optionalParameter.getCompatibilityScore(request);
final int requiredOptCompatScore = requiredOptionalParam.getCompatibilityScore(request);
// all the mappers above must be eligible for the give URL (i.e. their score must be > 0)
assertTrue("exactMount mapper must be eligible to handle the request", exactCompatScore > 0);
assertTrue("requiredParam mapper must be eligible to handle the request", requiredParamScore > 0);
assertTrue("optionalParameter mapper must be eligible to handle the request", optCompatScore > 0);
assertTrue("requiredOptionalParam mapper must be eligible to handle the request", requiredOptCompatScore > 0);
assertTrue("exactCompatScore should have greater compatibility score than required one" + " got exact = " + exactCompatScore + " and required= " + requiredParamScore, exactCompatScore > requiredParamScore);
assertTrue("exactCompatScore should have greater compatibility score than required+optional one" + " got exact = " + exactCompatScore + " and requiredOptional= " + requiredOptCompatScore, exactCompatScore > requiredOptCompatScore);
assertTrue("exactCompatScore should have greater compatibility score than optional one" + " got exact = " + exactCompatScore + " and optional = " + optCompatScore, requiredParamScore > optCompatScore);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class ResourceMapperTest method validPathWithParams.
/**
* testValidPathWithParams()
*/
@Test
public void validPathWithParams() {
Request request = createRequest("test/resource/1/fred");
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(0, 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());
}
Aggregations