use of com.mockobjects.dynamic.Mock in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testBlockingByDefault.
/**
* Only "name" should remain in the parameter map. All others
* should be removed
*/
public void testBlockingByDefault() throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
Action action = new BlockingByDefaultAction();
stack.push(action);
Mock mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.matchAndReturn("getAction", action);
mockInvocation.matchAndReturn("getStack", stack);
mockInvocation.expectAndReturn("invoke", Action.SUCCESS);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
ActionInvocation invocation = (ActionInvocation) mockInvocation.proxy();
AnnotationParameterFilterInterceptor interceptor = new AnnotationParameterFilterInterceptor();
interceptor.intercept(invocation);
HttpParameters parameters = invocation.getInvocationContext().getParameters();
assertEquals("Parameter map should contain one entry", 1, parameters.keySet().size());
assertFalse(parameters.get("job").isDefined());
assertTrue(parameters.get("name").isDefined());
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategoryLevelInfo.
public void testThrownExceptionNoMatchLoggingCategoryLevelInfo() {
this.setupWithoutExceptionMappings();
Mock action = new Mock(Action.class);
Exception exception = new Exception("test");
mockInvocation.expectAndThrow("invoke", exception);
mockInvocation.matchAndReturn("getAction", action.proxy());
try {
interceptor.setLogEnabled(true);
interceptor.setLogCategory("showcase.unhandled");
interceptor.setLogLevel("info");
interceptor.intercept(invocation);
fail("Should not have reached this point.");
} catch (Exception e) {
assertEquals(e, exception);
}
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ExceptionMappingInterceptorTest method setUpWithExceptionMappings.
private void setUpWithExceptionMappings() {
ActionConfig actionConfig = new ActionConfig.Builder("", "", "").addExceptionMapping(new ExceptionMappingConfig.Builder("xwork", "org.apache.struts2.StrutsException", "spooky").build()).addExceptionMapping(new ExceptionMappingConfig.Builder("throwable", "java.lang.Throwable", "throwable").build()).build();
Mock actionProxy = new Mock(ActionProxy.class);
actionProxy.expectAndReturn("getConfig", actionConfig);
mockInvocation.expectAndReturn("getProxy", actionProxy.proxy());
invocation = (ActionInvocation) mockInvocation.proxy();
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategory.
public void testThrownExceptionNoMatchLoggingCategory() {
this.setupWithoutExceptionMappings();
Mock action = new Mock(Action.class);
Exception exception = new Exception("test");
mockInvocation.expectAndThrow("invoke", exception);
mockInvocation.matchAndReturn("getAction", action.proxy());
try {
interceptor.setLogEnabled(true);
interceptor.setLogCategory("showcase.unhandled");
interceptor.intercept(invocation);
fail("Should not have reached this point.");
} catch (Exception e) {
assertEquals(e, exception);
}
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ExceptionMappingInterceptorTest method testThrownExceptionMatching.
public void testThrownExceptionMatching() throws Exception {
this.setUpWithExceptionMappings();
Mock action = new Mock(Action.class);
Exception exception = new StrutsException("test");
mockInvocation.expectAndThrow("invoke", exception);
mockInvocation.matchAndReturn("getAction", action.proxy());
String result = interceptor.intercept(invocation);
assertNotNull(stack.findValue("exception"));
assertEquals(stack.findValue("exception"), exception);
assertEquals(result, "spooky");
// is on top of the root
ExceptionHolder holder = (ExceptionHolder) stack.getRoot().get(0);
// to invoke the method for unit test
assertNotNull(holder.getExceptionStack());
}
Aggregations