use of com.mockobjects.servlet.MockHttpServletRequest in project commons-configuration by apache.
the class TestServletRequestConfiguration method createConfiguration.
/**
* Returns a new servlet request configuration that is backed by the passed in configuration.
*
* @param base the configuration with the underlying values
* @return the servlet request configuration
*/
private ServletRequestConfiguration createConfiguration(final Configuration base) {
final ServletRequest request = new MockHttpServletRequest() {
@Override
public Map<?, ?> getParameterMap() {
return new ConfigurationMap(base);
}
@Override
public String[] getParameterValues(final String key) {
return base.getStringArray(key);
}
};
final ServletRequestConfiguration config = new ServletRequestConfiguration(request);
config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
return config;
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class BackgroundProcessTest method testSerializeDeserialize.
public void testSerializeDeserialize() throws Exception {
final NotSerializableException expectedException = new NotSerializableException(new MockHttpServletRequest());
final Semaphore lock = new Semaphore(1);
lock.acquire();
MockActionInvocationWithActionInvoker invocation = new MockActionInvocationWithActionInvoker(new Callable<String>() {
@Override
public String call() throws Exception {
lock.release();
throw expectedException;
}
});
invocation.setInvocationContext(ActionContext.getContext());
BackgroundProcess bp = new BackgroundProcess("BackgroundProcessTest.testSerializeDeserialize", invocation, Thread.MIN_PRIORITY);
if (!lock.tryAcquire(1500L, TimeUnit.MILLISECONDS)) {
lock.release();
fail("background thread did not release lock on timeout");
}
lock.release();
bp.result = "BackgroundProcessTest.testSerializeDeserialize";
bp.done = true;
// give a chance to background thread to set exception
Thread.sleep(1000);
assertEquals(expectedException, bp.exception);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(bp);
oos.close();
byte[] b = baos.toByteArray();
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(b);
ObjectInputStream ois = new ObjectInputStream(bais);
BackgroundProcess deserializedBp = (BackgroundProcess) ois.readObject();
ois.close();
bais.close();
assertNull("invocation should not be serialized", deserializedBp.invocation);
assertNull("exception should not be serialized", deserializedBp.exception);
assertEquals(bp.result, deserializedBp.result);
assertEquals(bp.done, deserializedBp.done);
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class RolesInterceptorTest method testIsAllowed_emptyAllowedAndDisallowed.
public void testIsAllowed_emptyAllowedAndDisallowed() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest() {
public boolean isUserInRole(String role) {
return "admin".equals(role);
}
};
// allow all
interceptor.setAllowedRoles("");
interceptor.setDisallowedRoles("admin");
assertFalse(interceptor.isAllowed(request, null));
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class RolesInterceptorTest method testIsAllowed_adminAllowedExceptManager.
public void testIsAllowed_adminAllowedExceptManager() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest() {
public boolean isUserInRole(String role) {
return "admin".equals(role);
}
};
// allow all
interceptor.setAllowedRoles("admin");
interceptor.setDisallowedRoles("manager");
assertTrue(interceptor.isAllowed(request, null));
}
use of com.mockobjects.servlet.MockHttpServletRequest in project struts by apache.
the class DefaultActionMapperTest method setUp.
protected void setUp() throws Exception {
super.setUp();
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