Search in sources :

Example 1 with UnknownHandlerManager

use of com.opensymphony.xwork2.UnknownHandlerManager 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 UnknownHandlerManager

use of com.opensymphony.xwork2.UnknownHandlerManager 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 UnknownHandlerManager

use of com.opensymphony.xwork2.UnknownHandlerManager 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 4 with UnknownHandlerManager

use of com.opensymphony.xwork2.UnknownHandlerManager 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)

Example 5 with UnknownHandlerManager

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

the class UnknownHandlerManagerTest method testStack.

public void testStack() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-unknownhandler-stack.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    loadConfigurationProviders(provider);
    configurationManager.reload();
    UnknownHandlerManager unknownHandlerManager = new DefaultUnknownHandlerManager();
    container.inject(unknownHandlerManager);
    List<UnknownHandler> unknownHandlers = unknownHandlerManager.getUnknownHandlers();
    assertNotNull(unknownHandlers);
    assertEquals(2, unknownHandlers.size());
    UnknownHandler uh1 = unknownHandlers.get(0);
    UnknownHandler uh2 = unknownHandlers.get(1);
    assertTrue(uh1 instanceof SomeUnknownHandler);
    assertTrue(uh2 instanceof SomeUnknownHandler);
}
Also used : DefaultUnknownHandlerManager(com.opensymphony.xwork2.DefaultUnknownHandlerManager) UnknownHandler(com.opensymphony.xwork2.UnknownHandler) SomeUnknownHandler(com.opensymphony.xwork2.config.providers.SomeUnknownHandler) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) SomeUnknownHandler(com.opensymphony.xwork2.config.providers.SomeUnknownHandler) DefaultUnknownHandlerManager(com.opensymphony.xwork2.DefaultUnknownHandlerManager) UnknownHandlerManager(com.opensymphony.xwork2.UnknownHandlerManager)

Aggregations

MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)4 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 UnknownHandlerConfig (com.opensymphony.xwork2.config.entities.UnknownHandlerConfig)1