1   package com.sri.emo.wizard.selection;
2   
3   /* ===================================================================
4    * Copyright 2002-04 SRI International.
5    * Released under the MOZILLA PUBLIC LICENSE Version 1.1
6    * which can be obtained at http://www.mozilla.org/MPL/MPL-1.1.html
7    *
8    * This program is distributed in the hope that it will be useful, but
9    * WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11   * See the MOZILLA PUBLIC LICENSE for more details.
12   * =================================================================== */
13  
14  
15  import com.jcorporate.expresso.services.test.TestSystemInitializer;
16  import com.sri.emo.test.DatabaseTestFixture;
17  import com.sri.emo.test.EmoTestSuite;
18  import com.sri.emo.wizard.Wizard;
19  import com.sri.emo.wizard.WizardException;
20  import com.sri.emo.wizard.WizardPage;
21  import com.sri.emo.wizard.defaults.SequentialWizard;
22  import com.sri.emo.wizard.defaults.WizardTestModel;
23  import junit.framework.TestCase;
24  import com.jcorporate.expresso.core.security.SuperUser;
25  import com.jcorporate.expresso.core.registry.MutableRequestRegistry;
26  
27  public class TestSelectionWizardFactory extends TestCase {
28      int wizardId = 0;
29      private EmoSelectionWizardFactory emoWizardFactory = null;
30      private DatabaseTestFixture databaseTestFixture;
31  
32      private WizardTestModel testModel = null;
33  
34      public TestSelectionWizardFactory(String name) {
35          super(name);
36          try {
37              TestSystemInitializer.setUp();
38              new MutableRequestRegistry(TestSystemInitializer.getTestContext(), SuperUser.INSTANCE);
39          } catch (Exception ex) {
40              throw new RuntimeException("Error setting things up",ex);
41          }
42  
43      }
44  
45      public void testBuildWizard() throws WizardException {
46          Wizard wiz = emoWizardFactory.buildWizard();
47          assertEquals(SequentialWizard.class, wiz.getClass());
48          assertEquals(WizardTestModel.WIZ_TITLE + 0, wiz.getTitle());
49          assertEquals(WizardTestModel.WIZ_SUMMARY, wiz.getSummary());
50      }
51  
52  
53      public void testBeginPage() throws WizardException {
54          Wizard wiz = emoWizardFactory.buildWizard();
55          WizardPage page = wiz.begin();
56          assertTrue(page != null);
57          assertEquals(page.getMetadata().getTitle(),
58                  WizardTestModel.WIZ_PAGES[0][WizardTestModel.INDEX_TITLE]);
59          assertEquals(page.getMetadata().getDirective(),
60                  WizardTestModel.WIZ_PAGES[0][WizardTestModel.INDEX_DIRECTIVE]);
61          assertEquals(page.getMetadata().getHelpText(),
62                  WizardTestModel.WIZ_PAGES[0][WizardTestModel.INDEX_HELPTEXT]);
63      }
64  
65  
66      private static final int SINGLE_STEP_SELECTION_WIZARD_ID = 14;
67      public void testBuildSingleStepWizard() throws Exception {
68          databaseTestFixture.setUp();
69  
70          //Wizard 14 on the WizardTestData is a single step wizard.
71          emoWizardFactory = new EmoSelectionWizardFactory();
72          emoWizardFactory.setWizardId(SINGLE_STEP_SELECTION_WIZARD_ID);
73          Wizard wiz = emoWizardFactory.buildWizard();
74          WizardPage page = wiz.begin();
75          assertTrue(page != null);
76          //No longer true assertions because there is another page saying
77          //"Yo, sorry, we can't find a match for you" before the finish
78          //page.
79  //        assertNull(page.getMetadata().getNext());
80  //        assertNotNull(page.getMetadata().getFinish());
81          assertNull(page.getMetadata().getPrevious());
82      }
83  
84  
85      protected void setUp() throws Exception {
86          super.setUp();
87          testModel = new WizardTestModel(TestSystemInitializer.getTestContext());
88          wizardId = testModel.intialize();
89          emoWizardFactory =new EmoSelectionWizardFactory();
90          emoWizardFactory.setWizardId(wizardId);
91          databaseTestFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
92                  EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
93      }
94  
95      protected void tearDown() throws Exception {
96          emoWizardFactory = null;
97          testModel.destroy();
98          testModel = null;
99          wizardId = 0;
100         super.tearDown();
101         databaseTestFixture.tearDown();
102         databaseTestFixture = null;
103     }
104 }