Search in sources :

Example 16 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class ExceptionMappingInterceptorTest method testThrownExceptionNoMatchLoggingCategoryLevelError.

public void testThrownExceptionNoMatchLoggingCategoryLevelError() {
    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("error");
        interceptor.intercept(invocation);
        fail("Should not have reached this point.");
    } catch (Exception e) {
        assertEquals(e, exception);
    }
}
Also used : Mock(com.mockobjects.dynamic.Mock) StrutsException(org.apache.struts2.StrutsException) ValidationException(com.opensymphony.xwork2.validator.ValidationException)

Example 17 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class ExceptionMappingInterceptorTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    stack = ActionContext.getContext().getValueStack();
    mockInvocation = new Mock(ActionInvocation.class);
    mockInvocation.expectAndReturn("getStack", stack);
    mockInvocation.expectAndReturn("getInvocationContext", ActionContext.of(new HashMap<>()).bind());
    interceptor = new ExceptionMappingInterceptor();
    interceptor.init();
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 18 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultActionValidatorManagerTest method setUp.

@Override
protected void setUp() throws Exception {
    actionValidatorManager = new DefaultActionValidatorManager();
    super.setUp();
    mockValidatorFileParser = new Mock(ValidatorFileParser.class);
    actionValidatorManager.setValidatorFileParser((ValidatorFileParser) mockValidatorFileParser.proxy());
    mockValidatorFactory = new Mock(ValidatorFactory.class);
    actionValidatorManager.setValidatorFactory((ValidatorFactory) mockValidatorFactory.proxy());
    stubValueStack = new StubValueStack();
    ActionContext.of(new HashMap<>()).withValueStack(stubValueStack).bind();
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setContainer(container);
    factory.setFileManager(new DefaultFileManager());
    actionValidatorManager.setFileManagerFactory(factory);
}
Also used : DefaultFileManagerFactory(com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory) StubValueStack(com.opensymphony.xwork2.StubValueStack) DefaultFileManager(com.opensymphony.xwork2.util.fs.DefaultFileManager) Mock(com.mockobjects.dynamic.Mock)

Example 19 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class DefaultValidatorFactoryTest method testParseValidators.

public void testParseValidators() {
    Mock mockValidatorFileParser = new Mock(ValidatorFileParser.class);
    mockValidatorFileParser.expect("parseValidatorDefinitions", C.args(C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("com/opensymphony/xwork2/validator/validators/default.xml")));
    mockValidatorFileParser.expect("parseValidatorDefinitions", C.args(C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("validators.xml")));
    mockValidatorFileParser.expect("parseValidatorDefinitions", C.args(C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("myOther-validators.xml")));
    mockValidatorFileParser.expect("parseValidatorDefinitions", C.args(C.IS_NOT_NULL, C.IS_NOT_NULL, C.eq("my-validators.xml")));
    DefaultValidatorFactory factory = new DefaultValidatorFactory(null, (ValidatorFileParser) mockValidatorFileParser.proxy());
}
Also used : Mock(com.mockobjects.dynamic.Mock)

Example 20 with Mock

use of com.mockobjects.dynamic.Mock in project struts by apache.

the class StrutsLocalizedTextProviderTest method testFindTextInChildProperty.

public void testFindTextInChildProperty() throws Exception {
    ModelDriven action = new ModelDrivenAction2();
    TestBean2 bean = (TestBean2) action.getModel();
    Bar bar = new Bar();
    bean.setBarObj(bar);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("hashCode", 0);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    ActionContext.getContext().getValueStack().push(action);
    ActionContext.getContext().getValueStack().push(action.getModel());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "invalid.fieldvalue.barObj.title", Locale.getDefault());
    assertEquals("Title is invalid!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) ModelDriven(com.opensymphony.xwork2.ModelDriven) TestBean2(com.opensymphony.xwork2.test.TestBean2) Mock(com.mockobjects.dynamic.Mock)

Aggregations

Mock (com.mockobjects.dynamic.Mock)91 HashMap (java.util.HashMap)14 ValidationException (com.opensymphony.xwork2.validator.ValidationException)12 StrutsException (org.apache.struts2.StrutsException)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 ActionInvocation (com.opensymphony.xwork2.ActionInvocation)10 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 ActionContext (com.opensymphony.xwork2.ActionContext)8 TreeMap (java.util.TreeMap)8 ActionProxy (com.opensymphony.xwork2.ActionProxy)6 HttpParameters (org.apache.struts2.dispatcher.HttpParameters)6 MockHttpSession (org.springframework.mock.web.MockHttpSession)6 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)4 Container (com.opensymphony.xwork2.inject.Container)4 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)4 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)4 LinkedHashMap (java.util.LinkedHashMap)4 Action (com.opensymphony.xwork2.Action)3