use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class ChartResultTest method setUp.
protected void setUp() throws Exception {
super.setUp();
DefaultPieDataset data = new DefaultPieDataset();
data.setValue("Java", new Double(43.2));
data.setValue("Visual Basic", new Double(0.0));
data.setValue("C/C++", new Double(17.5));
mockChart = ChartFactory.createPieChart("Pie Chart", data, true, true, false);
stack = ActionContext.getContext().getValueStack();
mockActionProxy = EasyMock.createNiceMock(ActionProxy.class);
EasyMock.expect(mockActionProxy.getNamespace()).andReturn("/html");
actionInvocation = EasyMock.createMock(ActionInvocation.class);
EasyMock.expect(actionInvocation.getStack()).andReturn(stack).anyTimes();
os = new MockServletOutputStream();
responseMock = EasyMock.createNiceMock(HttpServletResponse.class);
ServletActionContext.setResponse((HttpServletResponse) responseMock);
}
use of com.opensymphony.xwork2.mock.MockActionProxy in project struts by apache.
the class ChartResultTest method testChartWithOGNLProperties.
public void testChartWithOGNLProperties() throws Exception {
EasyMock.expect(responseMock.getOutputStream()).andReturn(os);
EasyMock.replay(responseMock, mockActionProxy, actionInvocation);
ChartResult result = new ChartResult();
result.setChart(mockChart);
result.setHeight("${myHeight}");
result.setWidth("${myWidth}");
ValueStack stack = ActionContext.getContext().getValueStack();
stack.set("myHeight", 250);
stack.set("myWidth", 150);
result.execute(actionInvocation);
EasyMock.verify(responseMock);
assertEquals(result.getHeight(), stack.findValue("myHeight").toString());
assertEquals(result.getWidth(), stack.findValue("myWidth").toString());
assertEquals("250", result.getHeight().toString());
assertEquals("150", result.getWidth().toString());
assertTrue(os.isWritten());
}
use of com.opensymphony.xwork2.mock.MockActionProxy 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.mock.MockActionProxy in project struts by apache.
the class DefaultActionInvocationTester method testInvokingExistingMethodThatThrowsException.
public void testInvokingExistingMethodThatThrowsException() throws Exception {
// given
DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
container.inject(dai);
SimpleAction action = new SimpleAction() {
@Override
public String execute() throws Exception {
throw new IllegalArgumentException();
}
};
MockActionProxy proxy = new MockActionProxy();
proxy.setMethod("execute");
dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
dai.proxy = proxy;
dai.ognlUtil = new OgnlUtil();
// when
Throwable actual = null;
try {
dai.invokeAction(action, null);
} catch (Exception e) {
actual = e;
}
// then
assertNotNull(actual);
assertTrue(actual instanceof IllegalArgumentException);
}
use of com.opensymphony.xwork2.mock.MockActionProxy 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);
}
Aggregations