use of org.apache.wicket.request.Request in project wicket by apache.
the class PageInstanceMapperTest method decode10.
@Test
public void decode10() {
final Url url = Url.parse("page?4");
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return Charset.forName("UTF-8");
}
@Override
public Url getClientUrl() {
return Url.parse("page");
}
@Override
public Object getContainerRequest() {
return null;
}
};
IRequestHandler handler = encoder.mapRequest(request);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
checkPage(page, 4);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class PageInstanceMapperTest method decode9.
@Test
public void decode9() {
final Url url = Url.parse("page?4");
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return Charset.forName("UTF-8");
}
@Override
public Url getClientUrl() {
return Url.parse("wicket/page");
}
@Override
public Object getContainerRequest() {
return null;
}
};
IRequestHandler handler = encoder.mapRequest(request);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
checkPage(page, 4);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class Session method setAttribute.
/**
* Adds or replaces the attribute with the given name and value.
*
* @param name
* The name of the attribute
* @param value
* The value of the attribute
*/
public final Session setAttribute(String name, Serializable value) {
if (!isTemporary()) {
RequestCycle cycle = RequestCycle.get();
if (cycle == null) {
throw new IllegalStateException("Cannot set the attribute: no RequestCycle available. If you get this error when using WicketTester.startPage(Page), make sure to call WicketTester.createRequestCycle() beforehand.");
}
ISessionStore store = getSessionStore();
Request request = cycle.getRequest();
// extra check on session binding event
if (value == this) {
Object current = store.getAttribute(request, name);
if (current == null) {
String id = store.getSessionId(request, false);
if (id != null) {
// this is a new instance. wherever it came from, bind
// the session now
store.bind(request, (Session) value);
}
}
}
// Set the actual attribute
store.setAttribute(request, name, value);
} else {
// session instance gets shared across threads
if (temporarySessionAttributes == null) {
temporarySessionAttributes = new HashMap<>(3);
}
temporarySessionAttributes.put(name, value);
}
return this;
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class HeaderResponseTest method before.
/**
* Prepare
*/
@Before
public void before() {
final Response realResponse = new StringResponse();
headerResponse = new HeaderResponse() {
@Override
protected Response getRealResponse() {
return realResponse;
}
};
reference = new ResourceReference("testReference") {
private static final long serialVersionUID = 1L;
@Override
public IResource getResource() {
return null;
}
};
RequestCycle requestCycle = mock(RequestCycle.class);
when(requestCycle.urlFor(any(IRequestHandler.class))).thenReturn(RESOURCE_NAME);
when(requestCycle.find(any())).thenReturn(Optional.empty());
Request request = mock(Request.class);
when(request.getCharset()).thenReturn(Charset.defaultCharset());
when(requestCycle.getRequest()).thenReturn(request);
UrlRenderer urlRenderer = mock(UrlRenderer.class);
when(urlRenderer.renderContextRelativeUrl((any(String.class)))).thenReturn(RESOURCE_NAME);
when(requestCycle.getUrlRenderer()).thenReturn(urlRenderer);
ThreadContext.setRequestCycle(requestCycle);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class RequestCycleUrlForTest method before.
@Before
public void before() {
Request request = mock(Request.class);
Url baseUrl = Url.parse("");
when(request.getClientUrl()).thenReturn(baseUrl);
Response response = new StringResponse() {
@Override
public String encodeURL(CharSequence url) {
return url + JSESSIONID;
}
};
IRequestMapper mapper = mock(IRequestMapper.class);
Url bookmarkablePageUrl = Url.parse(BOOKMARKABLE_PAGE_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<BookmarkablePageRequestHandler>(BookmarkablePageRequestHandler.class)))).thenReturn(bookmarkablePageUrl);
Url resourceUrl = Url.parse(RESOURCE_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceRequestHandler>(ResourceRequestHandler.class)))).thenReturn(resourceUrl);
Url resourceReferenceUrl = Url.parse(RES_REF_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceReferenceRequestHandler>(ResourceReferenceRequestHandler.class)))).thenReturn(resourceReferenceUrl);
IExceptionMapper exceptionMapper = mock(IExceptionMapper.class);
RequestCycleContext context = new RequestCycleContext(request, response, mapper, exceptionMapper);
requestCycle = new RequestCycle(context);
requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
}
Aggregations