Search in sources :

Example 1 with DefaultUnknownHandlerManager

use of com.opensymphony.xwork2.DefaultUnknownHandlerManager in project struts by apache.

the class DefaultActionInvocationTester method testUnknownHandlerManagerThatThrowsException.

public void testUnknownHandlerManagerThatThrowsException() throws Exception {
    // given
    DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
    container.inject(dai);
    UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return true;
        }

        @Override
        public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
            throw new NoSuchMethodException();
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("notExists");
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    dai.unknownHandlerManager = uhm;
    // when
    // when
    Throwable actual = null;
    try {
        dai.invokeAction(new SimpleAction(), null);
    } catch (Exception e) {
        actual = e;
    }
    // then
    assertNotNull(actual);
    assertTrue(actual instanceof NoSuchMethodException);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 2 with DefaultUnknownHandlerManager

use of com.opensymphony.xwork2.DefaultUnknownHandlerManager in project struts by apache.

the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsSuccess.

public void testUnknownHandlerManagerThatReturnsSuccess() throws Exception {
    // given
    DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
    container.inject(dai);
    UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return true;
        }

        @Override
        public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
            return "success";
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("notExists");
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    dai.unknownHandlerManager = uhm;
    // when
    String result = dai.invokeAction(new SimpleAction(), null);
    // then
    assertNotNull(result);
    assertEquals("success", result);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 3 with DefaultUnknownHandlerManager

use of com.opensymphony.xwork2.DefaultUnknownHandlerManager in project struts by apache.

the class DefaultActionInvocationTester method testActionEventListener.

public void testActionEventListener() throws Exception {
    ActionProxy actionProxy = actionProxyFactory.createActionProxy("", "ExceptionFoo", "exceptionMethod", new HashMap<String, Object>());
    DefaultActionInvocation defaultActionInvocation = (DefaultActionInvocation) actionProxy.getInvocation();
    SimpleActionEventListener actionEventListener = new SimpleActionEventListener("prepared", "exceptionHandled");
    defaultActionInvocation.setActionEventListener(actionEventListener);
    defaultActionInvocation.init(actionProxy);
    SimpleAction action = (SimpleAction) defaultActionInvocation.getAction();
    action.setThrowException(true);
    defaultActionInvocation.unknownHandlerManager = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return false;
        }
    };
    String result = defaultActionInvocation.invoke();
    // then
    assertEquals("prepared", action.getName());
    assertEquals("exceptionHandled", result);
}
Also used : MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 4 with DefaultUnknownHandlerManager

use of com.opensymphony.xwork2.DefaultUnknownHandlerManager in project struts by apache.

the class DefaultActionInvocationTester method testInvokingMissingMethod.

public void testInvokingMissingMethod() throws Exception {
    // given
    DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
    container.inject(dai);
    SimpleAction action = new SimpleAction() {

        @Override
        public String execute() throws Exception {
            return ERROR;
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("notExists");
    UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return false;
        }
    };
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    dai.unknownHandlerManager = uhm;
    // when
    Throwable actual = null;
    try {
        dai.invokeAction(action, null);
    } catch (Exception e) {
        actual = e;
    }
    // then
    assertNotNull(actual);
    assertTrue(actual instanceof NoSuchMethodException);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 5 with DefaultUnknownHandlerManager

use of com.opensymphony.xwork2.DefaultUnknownHandlerManager in project struts by apache.

the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsNull.

public void testUnknownHandlerManagerThatReturnsNull() throws Exception {
    // given
    DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
    container.inject(dai);
    UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {

        @Override
        public boolean hasUnknownHandlers() {
            return true;
        }

        @Override
        public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
            return null;
        }
    };
    MockActionProxy proxy = new MockActionProxy();
    proxy.setMethod("notExists");
    dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
    dai.proxy = proxy;
    dai.ognlUtil = new OgnlUtil();
    dai.unknownHandlerManager = uhm;
    // when
    Throwable actual = null;
    try {
        dai.invokeAction(new SimpleAction(), null);
    } catch (Exception e) {
        actual = e;
    }
    // then
    assertNotNull(actual);
    assertTrue(actual instanceof NoSuchMethodException);
}
Also used : OgnlUtil(com.opensymphony.xwork2.ognl.OgnlUtil) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Aggregations

MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)5 OgnlUtil (com.opensymphony.xwork2.ognl.OgnlUtil)4 DefaultUnknownHandlerManager (com.opensymphony.xwork2.DefaultUnknownHandlerManager)3 UnknownHandlerManager (com.opensymphony.xwork2.UnknownHandlerManager)3 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)3 UnknownHandler (com.opensymphony.xwork2.UnknownHandler)2 SomeUnknownHandler (com.opensymphony.xwork2.config.providers.SomeUnknownHandler)2 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 UnknownHandlerConfig (com.opensymphony.xwork2.config.entities.UnknownHandlerConfig)1