Search in sources :

Example 1 with SomeUnknownHandler

use of com.opensymphony.xwork2.config.providers.SomeUnknownHandler in project struts by apache.

the class UnknownHandlerManagerTest method testInvocationOrder.

public void testInvocationOrder() throws ConfigurationException, NoSuchMethodException {
    SomeUnknownHandler uh1 = new SomeUnknownHandler();
    uh1.setActionMethodResult("uh1");
    SomeUnknownHandler uh2 = new SomeUnknownHandler();
    uh2.setActionMethodResult("uh2");
    UnknownHandlerManagerMock uhm = new UnknownHandlerManagerMock();
    uhm.addUnknownHandler(uh1);
    uhm.addUnknownHandler(uh2);
    // should pick the first one
    assertEquals("uh1", uhm.handleUnknownMethod(null, null));
    // should pick the second one
    uh1.setActionMethodResult(null);
    assertEquals("uh2", uhm.handleUnknownMethod(null, null));
    // should not pick any
    uh1.setActionMethodResult(null);
    uh2.setActionMethodResult(null);
    try {
        uhm.handleUnknownMethod(null, null);
        fail("Should throw exception!");
    } catch (NoSuchMethodException e) {
        assertTrue(true);
    }
}
Also used : SomeUnknownHandler(com.opensymphony.xwork2.config.providers.SomeUnknownHandler) UnknownHandlerManagerMock(com.opensymphony.xwork2.UnknownHandlerManagerMock)

Example 2 with SomeUnknownHandler

use of com.opensymphony.xwork2.config.providers.SomeUnknownHandler in project struts by apache.

the class DefaultUnknownHandlerManagerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    // Make sure we are using the actionConfig we initialized.
    ActionConfig.Builder actionConfigBuilder = new ActionConfig.Builder("com", "someAction", "someClass");
    actionConfig = actionConfigBuilder.build();
    someUnknownHandler = new SomeUnknownHandler();
    someUnknownHandler.setActionConfig(actionConfig);
    someUnknownHandler.setActionMethodResult("specialActionMethod");
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) SomeUnknownHandler(com.opensymphony.xwork2.config.providers.SomeUnknownHandler)

Example 3 with SomeUnknownHandler

use of com.opensymphony.xwork2.config.providers.SomeUnknownHandler in project struts by apache.

the class DefaultUnknownHandlerManagerTest method testHandleUnknownAction.

/**
 * Relationshsip when UnknownAction method is called.
 */
public void testHandleUnknownAction() {
    DefaultUnknownHandlerManager defaultUnknownHandlerManager = new DefaultUnknownHandlerManager();
    defaultUnknownHandlerManager.unknownHandlers = new ArrayList<>();
    defaultUnknownHandlerManager.unknownHandlers.add(someUnknownHandler);
    ActionConfig newActionConfig = defaultUnknownHandlerManager.handleUnknownAction("arbitraryNameSpace", "arbitraryActionName");
    assertEquals(newActionConfig, actionConfig);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Example 4 with SomeUnknownHandler

use of com.opensymphony.xwork2.config.providers.SomeUnknownHandler 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)

Example 5 with SomeUnknownHandler

use of com.opensymphony.xwork2.config.providers.SomeUnknownHandler in project struts by apache.

the class UnknownHandlerManagerTest method testEmptyStack.

public void testEmptyStack() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-unknownhandler-stack-empty.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

SomeUnknownHandler (com.opensymphony.xwork2.config.providers.SomeUnknownHandler)4 DefaultUnknownHandlerManager (com.opensymphony.xwork2.DefaultUnknownHandlerManager)2 UnknownHandler (com.opensymphony.xwork2.UnknownHandler)2 UnknownHandlerManager (com.opensymphony.xwork2.UnknownHandlerManager)2 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)2 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)2 UnknownHandlerManagerMock (com.opensymphony.xwork2.UnknownHandlerManagerMock)1