01: package org.strecks.controller.chain.command;
02:
03: import static org.easymock.EasyMock.expect;
04: import static org.testng.Assert.*;
05:
06: import java.util.HashMap;
07: import java.util.Map;
08:
09: import org.apache.struts.action.Action;
10: import org.apache.struts.action.ActionServlet;
11: import org.apache.struts.chain.contexts.ServletActionContext;
12: import org.apache.struts.config.ActionConfig;
13: import org.apache.struts.config.ModuleConfig;
14: import org.strecks.controller.ActionCreator;
15: import org.testng.annotations.Test;
16:
17: /**
18: * @author Phil Zoio
19: */
20: public class TestCreateAction extends AbstractTestChain {
21:
22: @Test
23: public void testCreateAction() throws Exception {
24: ActionCreator actionCreator = newMock(ActionCreator.class);
25: CreateAction createAction = getCreateAction(actionCreator);
26: ServletActionContext actionContext = getActionContext();
27: ActionConfig actionConfig = newMock(ActionConfig.class);
28: ModuleConfig moduleConfig = newMock(ModuleConfig.class);
29: ActionServlet servlet = newMock(ActionServlet.class);
30: Map applicationScope = newMock(Map.class);
31: Map actions = new HashMap();
32: Action action = new Action();
33:
34: expect(actionConfig.getModuleConfig()).andReturn(moduleConfig);
35: expect(moduleConfig.getPrefix()).andReturn("prefix");
36: expect(actionContext.getApplicationScope()).andReturn(
37: applicationScope);
38: expect(applicationScope.get("actionsprefix"))
39: .andReturn(actions);
40: expect(actionCreator.createAction(String.class)).andReturn(
41: action);
42: expect(actionContext.getActionServlet()).andReturn(servlet);
43:
44: replayMocks();
45: createAction.getAction(actionContext, "java.lang.String",
46: actionConfig);
47: verifyMocks();
48:
49: assertEquals(1, actions.size());
50: }
51:
52: public CreateAction getCreateAction(
53: final ActionCreator actionCreator) {
54: return new CreateAction() {
55: protected ActionCreator newActionCreator() {
56: return actionCreator;
57: }
58: };
59: }
60:
61: }
|