1 package com.sri.emo.wizard.completion.management;
2
3 import java.util.Map;
4 import com.sri.emo.wizard.completion.model.CompletionBean;
5 import com.jcorporate.expresso.services.test.ControllerTestFixture;
6 import com.sri.emo.test.DatabaseTestFixture;
7 import com.jcorporate.expresso.services.test.TestSystemInitializer;
8 import com.sri.emo.test.EmoTestSuite;
9 import java.util.HashMap;
10 import com.jcorporate.expresso.core.controller.ExpressoRequest;
11 import com.jcorporate.expresso.core.controller.ExpressoResponse;
12 import com.jcorporate.expresso.core.controller.Controller;
13
14 abstract public class BaseCompletionFixtureTemplate {
15
16
17 public BaseCompletionFixtureTemplate(String controllerStateName) {
18 controllerState = controllerStateName;
19 }
20
21 /***
22 * Override in your derived classes to change the parameters sent to the
23 * controller.
24 * @param parameterMap Map
25 */
26 protected void modifyParameters(Map parameterMap) {
27
28 }
29
30 /***
31 *
32 * @param completionBean CompletionBean
33 */
34 protected void modifyCompletionBean(CompletionBean completionBean) {
35
36 }
37
38 protected ControllerTestFixture testFixture;
39 protected DatabaseTestFixture databaseFixture = null;
40 private final String controllerState;
41 private CompletionBean beanToCompareTo;
42
43 private Map parameters;
44
45
46 protected void setCompletionBean(CompletionBean newBean) {
47 beanToCompareTo = newBean;
48 }
49
50 protected String getControllerState() {
51 return controllerState;
52 }
53
54 protected Map getParameters() {
55 return parameters;
56 }
57
58 protected void setUp() throws Exception {
59 testFixture = new ControllerTestFixture();
60 testFixture.setUp();
61
62 databaseFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
63 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
64 parameters = new HashMap();
65
66 }
67
68 protected void tearDown() throws Exception {
69 testFixture.tearDown();
70 testFixture = null;
71 databaseFixture.tearDown();
72 databaseFixture = null;
73 parameters = null;
74 }
75
76 public CompletionBean getCompletionBean() {
77 return beanToCompareTo;
78 }
79
80 public ExpressoResponse invokeController() throws Exception {
81 setUp();
82 modifyParameters(getParameters() );
83 modifyCompletionBean(this.getCompletionBean());
84
85 ExpressoRequest request = testFixture.buildControllerRequest(getParameters() , getControllerState());
86 request.getSession().setPersistentAttribute(CompletionBeanManager.BEAN_NAME,this.getCompletionBean());
87
88 Controller completionEditor = testFixture.buildController(CompletionEditor.class);
89
90 ExpressoResponse response = testFixture.invokeState(getControllerState(), completionEditor, request);
91
92 tearDown();
93 return response;
94 }
95
96 }