use of com.mockobjects.dynamic.Mock in project struts by apache.
the class ActionComponentTest method testCreateParametersForContext.
public void testCreateParametersForContext() {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
Mock mockValueStack = new Mock(ValueStack.class);
HashMap<String, Object> ctx = new HashMap<>();
mockValueStack.expectAndReturn("getContext", ctx);
mockValueStack.expectAndReturn("getContext", ctx);
mockValueStack.expectAndReturn("getActionContext", ActionContext.getContext());
ActionComponent comp = new ActionComponent((ValueStack) mockValueStack.proxy(), req, res);
comp.addParameter("foo", "bar");
comp.addParameter("baz", new String[] { "jim", "sarah" });
HttpParameters params = comp.createParametersForContext();
assertNotNull(params);
assertEquals(2, params.keySet().size());
assertEquals("bar", params.get("foo").getValue());
assertEquals(2, params.get("baz").getMultipleValues().length);
mockValueStack.verify();
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class StaticParametersInterceptorTest method testParameterizable.
public void testParameterizable() throws Exception {
Mock mock = new Mock(Parameterizable.class);
MockActionInvocation mai = new MockActionInvocation();
MockActionProxy map = new MockActionProxy();
ActionConfig ac = new ActionConfig.Builder("", "", "").build();
Map params = ac.getParams();
map.setConfig(ac);
mai.setProxy(map);
mai.setAction(mock.proxy());
mock.expect("setParams", params);
interceptor.intercept(mai);
mock.verify();
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testAllowingByDefaultWithModel.
/**
* "name" should be removed from the map, as it is blocked.
* All other parameters should remain
*/
public void testAllowingByDefaultWithModel() throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
parameterMap.put("m1", "s1");
parameterMap.put("m2", "s2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
stack.push(new AllowingByDefaultModel());
Mock mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.matchAndReturn("getAction", new AllowingByDefaultAction());
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 two entries", 2, parameters.keySet().size());
assertTrue(parameters.get("job").isDefined());
assertFalse(parameters.get("name").isDefined());
assertFalse(parameters.get("m1").isDefined());
assertTrue(parameters.get("m2").isDefined());
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testBlockingByDefaultWithModel.
/**
* Only "name" should remain in the parameter map. All others
* should be removed
*/
public void testBlockingByDefaultWithModel() throws Exception {
Map<String, Object> parameterMap = new HashMap<>();
parameterMap.put("job", "Baker");
parameterMap.put("name", "Martin");
parameterMap.put("m1", "s1");
parameterMap.put("m2", "s2");
ActionContext actionContext = ActionContext.of(new HashMap<>()).bind();
actionContext.setParameters(HttpParameters.create(parameterMap).build());
stack.push(new BlockingByDefaultModel());
Mock mockInvocation = new Mock(ActionInvocation.class);
mockInvocation.expectAndReturn("getInvocationContext", actionContext);
mockInvocation.matchAndReturn("getAction", new BlockingByDefaultAction());
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 two entries", 2, parameters.keySet().size());
assertFalse(parameters.get("job").isDefined());
assertTrue(parameters.get("name").isDefined());
assertTrue(parameters.get("m1").isDefined());
assertFalse(parameters.get("m2").isDefined());
}
use of com.mockobjects.dynamic.Mock in project struts by apache.
the class AnnotationParameterFilterInterceptorTest method testAllowingByDefault.
/**
* "name" should be removed from the map, as it is blocked.
* All other parameters should remain
*/
public void testAllowingByDefault() 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 AllowingByDefaultAction();
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("Paramwter map should contain one entry", 1, parameters.keySet().size());
assertTrue(parameters.get("job").isDefined());
assertFalse(parameters.get("name").isDefined());
}
Aggregations