1 package com.sri.emo.wizard.selection.management;
2
3 import com.jcorporate.expresso.core.controller.Block;
4 import com.jcorporate.expresso.core.controller.ControllerException;
5 import com.jcorporate.expresso.core.controller.ExpressoRequest;
6 import com.jcorporate.expresso.core.controller.ExpressoResponse;
7 import com.jcorporate.expresso.core.controller.Input;
8 import com.jcorporate.expresso.core.controller.NonHandleableException;
9 import com.jcorporate.expresso.core.db.DBException;
10 import com.sri.emo.dbobj.WizStep;
11 import com.sri.emo.test.DatabaseTestFixture;
12 import com.sri.emo.test.StateHandlerTestFixture;
13 import junit.framework.TestCase;
14
15 /***
16 * @author Michael Rimov
17 *
18 */
19 public class TestPromptInstructions extends TestCase {
20 private PromptInstructions promptInstructions = null;
21 StateHandlerTestFixture stateHandlerTestFixture;
22
23 protected void setUp() throws Exception {
24 super.setUp();
25 promptInstructions = null;
26 stateHandlerTestFixture = new StateHandlerTestFixture();
27 stateHandlerTestFixture.setUp();
28 }
29
30 protected void tearDown() throws Exception {
31 stateHandlerTestFixture.tearDown();
32
33 promptInstructions = null;
34 stateHandlerTestFixture = null;
35 super.tearDown();
36 }
37
38 public void testHandleRequestNewWizStep() throws DBException, ControllerException, NonHandleableException {
39 promptInstructions = new PromptInstructions(Integer.toString(DatabaseTestFixture.DEFAULT_WIZ_ID)
40 , Integer.toString(DatabaseTestFixture.DEFAULT_WELCOME_STEP));
41
42 ExpressoRequest request = stateHandlerTestFixture.getControllerRequest(DatabaseTestFixture.DEFAULT_WIZ_ID,DatabaseTestFixture.DEFAULT_WELCOME_STEP
43 , PromptInstructions.STATE_NAME);
44 ExpressoResponse response = stateHandlerTestFixture.getControllerResponse(request);
45
46 promptInstructions.handleRequest(request, response);
47
48 assertTrue(response.getErrors() == null || response.getErrors().getErrorCount() == 0);
49 assertTrue(response.getBlock("wizstep") != null);
50 Block stepDef = response.getBlock("wizstep");
51 Input title = stepDef.getInput(WizStep.FLD_TITLE);
52 assertTrue(title != null);
53
54 Input helptext = stepDef.getInput(WizStep.FLD_HELPTEXT);
55 assertTrue(helptext != null);
56
57 Input directive = stepDef.getInput(WizStep.FLD_DIRECTIVE);
58 assertTrue(directive != null);
59 }
60
61 public void testHandleRequestWithExistingWizStep() throws DBException, ControllerException, NonHandleableException {
62 promptInstructions = new PromptInstructions(Integer.toString(DatabaseTestFixture.DEFAULT_WIZ_ID)
63 , Integer.toString(DatabaseTestFixture.DEFAULT_WELCOME_STEP));
64 ExpressoRequest request = stateHandlerTestFixture.getControllerRequest(12, PromptInstructions.STATE_NAME);
65 request.setParameter(WizStep.FLD_ID, Integer.toString(DatabaseTestFixture.DEFAULT_WELCOME_STEP));
66 request.setParameter(PromptInstructions.PARAM_INPUT_ID, "5");
67 ExpressoResponse response = stateHandlerTestFixture.getControllerResponse(request);
68
69 promptInstructions.handleRequest(request, response);
70
71 assertTrue(response.getErrors() == null || response.getErrors().getErrorCount() == 0);
72 assertTrue(response.getBlock("wizstep") != null);
73 Block stepDef = response.getBlock("wizstep");
74 Input title = stepDef.getInput(WizStep.FLD_TITLE);
75 assertTrue(title != null);
76 assertTrue("Welcome".equals(title.getDefaultValue()));
77
78 Input helptext = stepDef.getInput(WizStep.FLD_HELPTEXT);
79 assertTrue(helptext != null);
80 assertTrue("This wizard will help you decide which movie you want to see.".equals(helptext.getDefaultValue()));
81
82 Input directive = stepDef.getInput(WizStep.FLD_DIRECTIVE);
83 assertTrue(directive != null);
84 assertTrue("Click Next To Continue".equals(directive.getDefaultValue()));
85
86 }
87
88 }