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.controller.NonHandleableException;
8 import com.jcorporate.expresso.core.db.DBException;
9 import com.jcorporate.expresso.core.db.exception.DBRecordNotFoundException;
10 import com.jcorporate.expresso.services.test.ControllerTestFixture;
11 import com.jcorporate.expresso.services.test.TestSystemInitializer;
12 import com.sri.emo.dbobj.WizDefinition;
13 import com.sri.emo.test.DatabaseTestFixture;
14 import com.sri.emo.test.EmoTestSuite;
15 import com.sri.emo.wizard.expressoimpl.WizardController;
16 import junit.framework.TestCase;
17
18 /***
19 * <p>Title: EMO</p>
20 *
21 * <p>Description: </p>
22 *
23 * <p>Copyright: Copyright (c) 2003</p>
24 *
25 * <p>Company: </p>
26 * @todo Modify and Add to test suite.
27 * @author Michael Rimov
28 * @version 1.0
29 */
30 public class TestDoDeleteWizard extends TestCase {
31
32
33 /***
34 * DBUnit wrapping test fixture.
35 */
36 private DatabaseTestFixture databaseTestFixture;
37
38 /***
39 * Controller test fixture. Used for invoking controllers.
40 */
41 private ControllerTestFixture testFixture;
42
43 protected void setUp() throws Exception {
44 databaseTestFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
45 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
46
47 databaseTestFixture.setUp();
48
49 testFixture = new ControllerTestFixture();
50 testFixture.setUp();
51 }
52
53 protected void tearDown() throws Exception {
54 databaseTestFixture.tearDown();
55 databaseTestFixture = null;
56
57 testFixture.tearDown();
58 testFixture = null;
59 super.tearDown();
60 }
61
62 /***
63 * Retrieve the default defined wizard.
64 * @return WizDefinition
65 * @throws DBException
66 */
67 private WizDefinition getDefinedWizard() throws DBException {
68 WizDefinition def = new WizDefinition();
69 def.setField(WizDefinition.FLD_ID, DatabaseTestFixture.DEFAULT_WIZ_ID);
70 def.retrieve();
71 return def;
72 }
73
74
75 public void testDeleteSelectionWizard() throws ControllerException,
76 NonHandleableException, DBException {
77 String wizardParameter = getDefinedWizard().getId();
78 Map params = new HashMap();
79 params.put(WizardController.WIZ_PARAMETER_ID, wizardParameter);
80
81 ExpressoResponse response = testFixture.invokeFacade(WizardGatewayController.class, params,
82 DoDeleteWizard.STATE_NAME);
83
84 assertTrue(response != null);
85 assertTrue(response.getErrors() == null || response.getErrors().size() == 0);
86
87
88 assertEquals(ListWizards.STATE_NAME,
89 response.getCurrentState().getName());
90 try {
91 getDefinedWizard();
92 fail("Retrieved a model of id: "
93 + wizardParameter
94 + " it should have been deleted");
95 } catch (DBRecordNotFoundException ex) {
96
97 assertNotNull(ex.getMessage());
98 }
99
100 }
101
102
103 }