use of org.apache.wicket.request.resource.IResource in project wicket by apache.
the class ImageButton method onComponentTag.
/**
* Processes the component tag.
*
* @param tag
* Tag to modify
* @see org.apache.wicket.Component#onComponentTag(ComponentTag)
*/
@Override
protected final void onComponentTag(final ComponentTag tag) {
checkComponentTag(tag, "input");
checkComponentTagAttribute(tag, "type", "image");
final IResource resource = getImageResource();
if (resource != null) {
localizedImageResource.setResource(resource);
}
final ResourceReference resourceReference = getImageResourceReference();
if (resourceReference != null) {
localizedImageResource.setResourceReference(resourceReference);
}
localizedImageResource.setSrcAttribute(tag);
super.onComponentTag(tag);
}
use of org.apache.wicket.request.resource.IResource in project wicket by apache.
the class ResourceTest method bindToApplicationAsResourceAndRequestIt.
private void bindToApplicationAsResourceAndRequestIt(IResourceStream iResourceStream) {
IResource resource = new ResourceStreamResource(iResourceStream);
tester.getApplication().getSharedResources().add("resource", resource);
tester.getRequest().setUrl(tester.getRequestCycle().mapUrlFor(tester.getApplication().getSharedResources().get(Application.class, "resource", null, null, null, true), null));
tester.processRequest();
}
use of org.apache.wicket.request.resource.IResource in project wicket by apache.
the class WicketFilterTest method options.
@Test
public void options() throws IOException, ServletException, ParseException {
try {
application = new MockApplication();
WicketFilter filter = new WicketFilter();
filter.init(new FilterTestingConfig());
ThreadContext.setApplication(application);
final String failure = "Should never get here when an OPTIONS request is issued";
IResource resource = new AbstractResource() {
@Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
fail(failure);
return null;
}
};
application.getSharedResources().add("foo.txt", resource);
// check OPTIONS request is processed correctly
MockHttpServletRequest request = new MockHttpServletRequest(application, null, null);
request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.txt");
// test that we do not care about case
request.setMethod("OPtioNS");
MockHttpServletResponse response = new MockHttpServletResponse(request);
filter.doFilter(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertEquals("0", response.getHeader("Content-Length"));
assertFalse(Strings.isEmpty(response.getHeader("Allow")));
assertTrue(response.getHeader("Allow").toUpperCase().contains("GET"));
assertTrue(response.getHeader("Allow").toUpperCase().contains("POST"));
// try with a GET request to make sure we fail correctly
request = new MockHttpServletRequest(application, null, null);
request.setURL(request.getContextPath() + request.getServletPath() + "/wicket/resource/" + Application.class.getName() + "/foo.txt");
response = new MockHttpServletResponse(request);
try {
filter.doFilter(request, response, new FilterChain() {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {
}
});
} catch (AssertionError e) {
assertTrue(failure.equals(e.getMessage()));
}
} finally {
ThreadContext.detach();
}
}
use of org.apache.wicket.request.resource.IResource in project wicket by apache.
the class AnnotationsRoleAuthorizationStrategyTest method deniesResourceWithoutRequiredRole.
@Test
public void deniesResourceWithoutRequiredRole() throws Exception {
AnnotationsRoleAuthorizationStrategy strategy = new AnnotationsRoleAuthorizationStrategy(roles("role2"));
IResource resource = Mockito.mock(RestrictedResource.class);
assertFalse(strategy.isResourceAuthorized(resource, null));
}
use of org.apache.wicket.request.resource.IResource 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);
}
Aggregations