1 package com.sri.emo.wizard.wizardgateway;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import com.jcorporate.expresso.core.controller.ControllerException;
6 import com.jcorporate.expresso.core.controller.ExpressoResponse;
7 import com.jcorporate.expresso.core.db.DBException;
8 import com.jcorporate.expresso.services.test.ControllerTestFixture;
9 import com.jcorporate.expresso.services.test.TestSystemInitializer;
10 import com.sri.emo.controller.SelectionWizardManager;
11 import com.sri.emo.wizard.completion.management.CompletionEditor;
12 import com.sri.emo.test.DatabaseTestFixture;
13 import com.sri.emo.test.EmoTestSuite;
14 import junit.framework.TestCase;
15
16 /***
17 *
18 * @author Michael Rimov
19 */
20 public class TestDoAddWizard extends TestCase {
21
22 /***
23 * DBUnit wrapping test fixture.
24 */
25 private DatabaseTestFixture databaseTestFixture;
26
27 /***
28 * Controller test fixture. Used for invoking controllers.
29 */
30 private ControllerTestFixture testFixture;
31
32 /***
33 * Method called by JUnit automatically before tests.
34 * @throws Exception
35 */
36 protected void setUp() throws Exception {
37 databaseTestFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
38 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
39
40 databaseTestFixture.setUp();
41
42 testFixture = new ControllerTestFixture();
43 testFixture.setUp();
44 }
45
46 /***
47 * Method called by JUnit automatically after tests.
48 * @throws Exception
49 */
50 protected void tearDown() throws Exception {
51 databaseTestFixture.tearDown();
52 databaseTestFixture = null;
53
54 testFixture.tearDown();
55 testFixture = null;
56 super.tearDown();
57 }
58
59 public void testNoWizardTypeIdParameterThrowsException() throws Exception {
60 try {
61 testFixture.invokeFacade(WizardGatewayController.class, new HashMap(), DoAddWizard.STATE_NAME);
62 fail("Should have thrown controller exception.");
63 } catch (ControllerException ex) {
64
65 assertNotNull(ex.getMessage());
66 }
67 }
68
69 public void testAddSelectionWizardTransitionsToSelectionManager() throws DBException, ControllerException {
70 Map params = new HashMap();
71 params.put(AddWizardHandler.PARAM_WIZARD_TYPE,AddWizardHandler.SELECTION_WIZARD);
72
73 ExpressoResponse response = testFixture.invokeFacade(WizardGatewayController.class, params, DoAddWizard.STATE_NAME);
74
75 assertTrue(response != null);
76 assertTrue(response.getErrors() == null || response.getErrors().size() == 0);
77 assertTrue(SelectionWizardManager.class.getName().equals(response.getControllerClass()));
78 }
79
80 public void testAddCompletionWizardTransitionsToCompletionManager() throws DBException, ControllerException {
81 Map params = new HashMap();
82 params.put(AddWizardHandler.PARAM_WIZARD_TYPE,AddWizardHandler.COMPLETION_WIZARD);
83
84 ExpressoResponse response = testFixture.invokeFacade(WizardGatewayController.class, params, DoAddWizard.STATE_NAME);
85
86 assertTrue(response != null);
87 assertTrue(response.getErrors() == null || response.getErrors().size() == 0);
88 assertTrue(CompletionEditor.class.getName().equals(response.getControllerClass()));
89
90 }
91 }