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.wizard.selection.WizardAction;
11  import com.sri.emo.test.DatabaseTestFixture;
12  import com.sri.emo.test.EmoTestSuite;
13  import com.sri.emo.wizard.expressoimpl.WizardController;
14  import junit.framework.TestCase;
15  
16  /***
17   * @author Michael Rimov
18   */
19  public class TestRunWizard extends TestCase {
20  
21      /***
22       * DBUnit wrapping test fixture.
23       */
24      private DatabaseTestFixture databaseTestFixture;
25  
26      /***
27       * Controller test fixture.  Used for invoking controllers.
28       */
29      private ControllerTestFixture testFixture;
30  
31      /***
32       * Method called by JUnit automatically before tests.
33       * @throws Exception
34       */
35      protected void setUp() throws Exception {
36          databaseTestFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
37              EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
38  
39          databaseTestFixture.setUp();
40  
41          testFixture = new ControllerTestFixture();
42          testFixture.setUp();
43      }
44  
45      /***
46       * Method called by JUnit automatically after tests.
47       * @throws Exception
48       */
49      protected void tearDown() throws Exception {
50          databaseTestFixture.tearDown();
51          databaseTestFixture = null;
52  
53          testFixture.tearDown();
54          testFixture = null;
55          super.tearDown();
56      }
57  
58  
59      public void testNoWizardIdParameterThrowsException() throws Exception {
60          try {
61              testFixture.invokeFacade(WizardGatewayController.class, new HashMap(), RunWizard.STATE_NAME);
62              fail("Should have thrown controller exception.");
63          } catch (ControllerException ex) {
64              //a-ok
65          	assertNotNull(ex.getMessage());
66          }
67      }
68  
69      public void testRunWizardTransitionsToWizardAction() throws DBException, ControllerException {
70          Map params = new HashMap();
71          params.put(WizardController.WIZ_PARAMETER_ID, Integer.toString(DatabaseTestFixture.DEFAULT_WIZ_ID));
72  
73          ExpressoResponse response = testFixture.invokeFacade(WizardGatewayController.class, params, RunWizard.STATE_NAME);
74  
75          assertTrue(response != null);
76          assertTrue(response.getErrors() == null || response.getErrors().size() == 0);
77          assertTrue(WizardAction.class.getName().equals(response.getControllerClass()));
78      }
79  
80  }