1 package com.sri.emo.wizard.selection;
2
3
4
5
6
7
8
9
10
11
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
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
77
78
79
80
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 }