1 package com.sri.emo.wizard.completion;
2
3 import com.jcorporate.expresso.core.controller.Transition;
4 import com.jcorporate.expresso.core.registry.MutableRequestRegistry;
5 import com.jcorporate.expresso.core.security.SuperUser;
6 import com.jcorporate.expresso.services.test.TestSystemInitializer;
7 import com.sri.emo.controller.CompletionWizardAction;
8 import com.sri.emo.test.DatabaseTestFixture;
9 import com.sri.emo.test.EmoTestSuite;
10 import com.sri.emo.wizard.WizardException;
11 import com.sri.emo.wizard.expressoimpl.WizardController;
12 import junit.framework.TestCase;
13
14 /***
15 *
16 * @author Michael Rimov
17 */
18 public class TestCompletionWizardSelector extends TestCase {
19 private CompletionWizardSelector completionWizardSelector = null;
20
21 private DatabaseTestFixture databaseFixture = null;
22
23
24
25 public TestCompletionWizardSelector() {
26 super();
27 try {
28 TestSystemInitializer.setUp();
29 new MutableRequestRegistry(TestSystemInitializer.getTestContext(), SuperUser.INSTANCE);
30 } catch (Exception ex) {
31 throw new RuntimeException("Error setting things up",ex);
32 }
33 }
34
35
36 protected void setUp() throws Exception {
37 super.setUp();
38 completionWizardSelector = new CompletionWizardSelector();
39 databaseFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
40 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
41 databaseFixture.setUp();
42 }
43
44 protected void tearDown() throws Exception {
45 completionWizardSelector = null;
46 databaseFixture.tearDown();
47 databaseFixture = null;
48 super.tearDown();
49 }
50
51
52 private static final String STARWARS_NEW_HOPE = "4";
53 public void testLocateCompletionWizardForNode() throws WizardException {
54 Transition result = completionWizardSelector.locateCompletionWizardForNode(STARWARS_NEW_HOPE,null);
55 assertNotNull(result);
56 assertEquals(Integer.toString(TestEmoCompletionFactory.PLAY_GEORGE_LUCAS), result.getParam(WizardController.WIZ_PARAMETER_ID));
57 assertNull(result.getAllParameters().get(CompletionWizardAction.PARAM_TARGET_ID));
58
59 }
60
61 private static final String DUMMY_TARGET = "19191";
62 public void testLocateCompletionWizardForNodeWithTargetNodeSetsProperParameters() {
63 Transition result = completionWizardSelector.locateCompletionWizardForNode(STARWARS_NEW_HOPE,DUMMY_TARGET);
64 assertEquals(DUMMY_TARGET, result.getParam(CompletionWizardAction.PARAM_TARGET_ID));
65 }
66
67
68 public void testNoMatchReturnsNull() {
69 Transition result = completionWizardSelector.locateCompletionWizardForNode(DUMMY_TARGET,null);
70 assertNull(result);
71 }
72
73 }