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.core.security.SuperUser;
9   import com.jcorporate.expresso.services.test.ControllerTestFixture;
10  import com.jcorporate.expresso.services.test.TestSystemInitializer;
11  import com.sri.emo.dbobj.WizDefinition;
12  import com.sri.emo.test.DatabaseTestFixture;
13  import com.sri.emo.test.EmoTestSuite;
14  import com.sri.emo.wizard.expressoimpl.WizardController;
15  import org.jmock.MockObjectTestCase;
16  
17  /***
18   * @author Michael Rimov
19   */
20  public class TestPromptDeleteWizard extends MockObjectTestCase {
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      protected void setUp() throws Exception {
33          databaseTestFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
34              EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
35  
36          databaseTestFixture.setUp();
37  
38          testFixture = new ControllerTestFixture();
39          testFixture.setUp();
40      }
41  
42      protected void tearDown() throws Exception {
43          databaseTestFixture.tearDown();
44          databaseTestFixture = null;
45  
46          testFixture.tearDown();
47          testFixture = null;
48          super.tearDown();
49      }
50  
51  
52      public void testNoWizardIdParameterThrowsException() throws Exception {
53          try {
54              testFixture.invokeFacade(WizardGatewayController.class, new HashMap(), PromptDeleteWizard.STATE_NAME);
55              fail("Should have thrown controller exception.");
56          } catch (ControllerException ex) {
57              //a-ok
58          	assertNotNull(ex.getMessage());
59          }
60      }
61  
62  
63      public void testPromptDeleteSelectionWizard() throws DBException, ControllerException {
64          Map params = new HashMap();
65          params.put(WizardController.WIZ_PARAMETER_ID,Integer.toString(DatabaseTestFixture.DEFAULT_WIZ_ID));
66  
67          ExpressoResponse response = testFixture.invokeFacade(WizardGatewayController.class, params, PromptDeleteWizard.STATE_NAME);
68          assertTrue(response != null);
69          assertTrue(response.getErrors() == null || response.getErrors().size() == 0);
70  
71          WizDefinition wizdef = new WizDefinition();
72          wizdef.setRequestingUser(SuperUser.INSTANCE);
73          wizdef.setId(DatabaseTestFixture.DEFAULT_WIZ_ID);
74          wizdef.retrieve();
75  
76          assertEquals(wizdef.getWizName(), response.getOutput("prompt").getContent());
77  
78          assertTrue(response.getTransition("yes") != null);
79  
80  
81          assertTrue(response.getTransition("no") != null);
82  
83  
84      }
85  
86  }