use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class ServletActionContextTest method setUp.
public void setUp() {
Map<String, Object> extraContext = new HashMap<>();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
servletContext = new MockServletContext();
extraContext.put(HTTP_REQUEST, request);
extraContext.put(HTTP_RESPONSE, response);
extraContext.put(SERVLET_CONTEXT, servletContext);
actionContext = ActionContext.of(extraContext).bind();
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class RolesInterceptorTest method testIsAllowed_userAllowedAndGuestDisallowed.
public void testIsAllowed_userAllowedAndGuestDisallowed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest() {
public boolean isUserInRole(String role) {
return "user".equals(role) || "guest".equals(role);
}
};
// has to be a user
interceptor.setAllowedRoles("user");
// and not a guest
interceptor.setDisallowedRoles("guest");
assertFalse(interceptor.isAllowed(request, null));
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class RolesInterceptorTest method testIsAllowed.
public void testIsAllowed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest() {
public boolean isUserInRole(String role) {
return "admin".equals(role);
}
};
interceptor.setAllowedRoles("admin");
assertTrue(interceptor.isAllowed(request, null));
interceptor.setAllowedRoles("bar, admin");
assertTrue(interceptor.isAllowed(request, null));
interceptor.setAllowedRoles(null);
assertTrue(interceptor.isAllowed(request, null));
interceptor.setDisallowedRoles("bar");
assertTrue(interceptor.isAllowed(request, null));
interceptor.setDisallowedRoles("bar, admin");
assertTrue(!interceptor.isAllowed(request, null));
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class RolesInterceptorTest method testIsAllowed_sameRoleAllowedAndDisallowed.
public void testIsAllowed_sameRoleAllowedAndDisallowed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest() {
public boolean isUserInRole(String role) {
return "admin".equals(role);
}
};
interceptor.setAllowedRoles("admin");
interceptor.setDisallowedRoles("admin");
assertFalse(interceptor.isAllowed(request, null));
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class Restful2ActionMapperTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
mapper = new Restful2ActionMapper();
mapper.setExtensions("");
req = new MockHttpServletRequest();
req.setupGetParameterMap(new HashMap());
req.setupGetContextPath("/my/namespace");
config = new DefaultConfiguration();
PackageConfig pkg = new PackageConfig.Builder("myns").namespace("/my/namespace").build();
PackageConfig pkg2 = new PackageConfig.Builder("my").namespace("/my").build();
config.addPackageConfig("mvns", pkg);
config.addPackageConfig("my", pkg2);
configManager = new ConfigurationManager(Container.DEFAULT_NAME) {
public Configuration getConfiguration() {
return config;
}
};
}
Aggregations