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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations