1   /* ===================================================================
2    * Copyright 2002-04 SRI International.
3    * Released under the MOZILLA PUBLIC LICENSE Version 1.1
4    * which can be obtained at http://www.mozilla.org/MPL/MPL-1.1.html
5    * This software is distributed on an "AS IS"
6    * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
7    * See the License for the specific language governing rights and
8    * limitations under the License.
9    * =================================================================== */
10  package com.sri.emo.wizard.completion.persistence;
11  
12  import java.util.List;
13  import java.util.logging.Logger;
14  import com.jcorporate.expresso.core.db.DBException;
15  import com.jcorporate.expresso.services.test.TestSystemInitializer;
16  import com.sri.emo.dbobj.WizDefinition;
17  import com.sri.emo.test.DatabaseTestFixture;
18  import com.sri.emo.test.EmoTestSuite;
19  import junit.framework.TestCase;
20  
21  public class TestWizDefinition extends TestCase {
22      private WizDefinition wizDefinition = null;
23      private DatabaseTestFixture testFixture = null;
24  
25      protected void setUp() throws Exception {
26          super.setUp();
27          wizDefinition = new WizDefinition();
28          testFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
29                  EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
30          testFixture.setUp();
31  
32      }
33  
34      protected void tearDown() throws Exception {
35          wizDefinition = null;
36          testFixture.tearDown();
37          testFixture = null;
38          super.tearDown();
39      }
40  
41      public void testWizardFieldClassInheritenceTest() throws Exception {
42          wizDefinition.checkField(WizDefinition.FLD_WIZARD,
43                  com.sri.emo.wizard.defaults.SequentialWizard.class.getName());
44  
45          try {
46              wizDefinition.checkField(WizDefinition.FLD_WIZARD,
47                      "dummyclass");
48              fail("Checkfield legit wizard should have thrown exception");
49          } catch (DBException ex) {
50              //a-ok
51          	assertNotNull(ex.getMessage());
52          }
53  
54  
55          try {
56              wizDefinition.checkField(WizDefinition.FLD_WIZARD,
57                      java.lang.Object.class.getName());
58              fail("Checkfield legit wizard should have thrown exception");
59          } catch (DBException ex) {
60              //a-ok
61          	assertNotNull(ex.getMessage());
62          }
63  
64      }
65  
66      public void testFixtureWizard() throws Exception {
67          WizDefinition wizdef = new WizDefinition();
68          wizdef.setField(WizDefinition.FLD_ID, DatabaseTestFixture.DEFAULT_WIZ_ID);
69          wizdef.retrieve();
70          assertEquals(DatabaseTestFixture.DEFAULT_WIZ_ID, wizdef.getFieldInt(WizDefinition.FLD_ID));
71          assertEquals(DatabaseTestFixture.DEFAULT_WIZ_TITLE, wizdef.getWizName());
72      }
73  
74      public void testDefinedSteps() throws Exception {
75          WizDefinition wizdef = new WizDefinition();
76          wizdef.setField(WizDefinition.FLD_ID, DatabaseTestFixture.DEFAULT_WIZ_ID);
77          wizdef.retrieve();
78  
79          List results = wizdef.getPageDefinitions();
80          assertTrue(results != null);
81          assertEquals(DatabaseTestFixture.DEFAULT_WIZ_STEPS, results.size());
82  
83      }
84  
85      public void testPertinentSteps() throws Exception {
86          WizDefinition wizdef = new WizDefinition();
87          wizdef.setField(WizDefinition.FLD_ID, DatabaseTestFixture.DEFAULT_WIZ_ID);
88          wizdef.retrieve();
89  
90          List results = wizdef.getPertinentDecisionSteps();
91          assertTrue(results != null);
92          assertEquals(DatabaseTestFixture.DEFAULT_WIZ_PERTINENT_STEPS, results.size());
93      }
94  
95      public void testPertinentStepsForWizardWithNone() throws Exception {
96          WizDefinition wizdef = new WizDefinition();
97          wizdef.setField(WizDefinition.FLD_ID, 14);
98          wizdef.retrieve();
99  
100         List results = wizdef.getPertinentDecisionSteps();
101         assertTrue(results != null);
102         assertEquals(0, results.size());
103     }
104 
105     public void testIllegalPertinentSteps() throws DBException {
106         WizDefinition wizdef = new WizDefinition();
107         try {
108             wizdef.getPageDefinitions();
109             fail("getPageDefinitions() should have thrown an IllegalStateException");
110         } catch (IllegalStateException ex) {
111         	assertNotNull(ex.getMessage());
112             //A-Ok
113         }
114 
115         try {
116             wizdef.getPertinentDecisionSteps();
117             fail("getPertinentDecisionSteps() should have thrown an IllegalStateException");
118         } catch (IllegalStateException ex) {
119         	assertNotNull(ex.getMessage());
120             //A-Ok
121         }
122     }
123 
124     /***
125      * @todo Implement Me!
126      * @throws DBException
127      */
128     public void testDeleteWizardDeletesAssociatedObjectsAsWell() throws DBException {
129         Logger.getLogger(TestWizDefinition.class.getName()).severe("testDeleteWizardDeletesAssociatedObjectsAsWell still must be implemented");
130     }
131 
132 }