1 package com.sri.emo.controller;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import com.jcorporate.expresso.core.db.DBException;
6 import com.jcorporate.expresso.services.test.TestSystemInitializer;
7 import com.sri.emo.dbobj.WizDecisionSet;
8 import com.sri.emo.test.DatabaseTestFixture;
9 import com.sri.emo.test.EmoTestSuite;
10 import junit.framework.TestCase;
11
12 /***
13 * Tests the Decision Matrix.
14 *
15 * @author Michael Rimov
16 */
17 public class TestDecisionMatrix extends TestCase {
18 private DecisionMatrix decisionMatrix = null;
19 private DatabaseTestFixture testFixture = null;
20
21 protected void setUp() throws Exception {
22 super.setUp();
23 testFixture = new DatabaseTestFixture(TestSystemInitializer.getTestContext(),
24 EmoTestSuite.class.getResourceAsStream("WizardTestData.xml"));
25 testFixture.setUp();
26
27
28 decisionMatrix = new DecisionMatrix(12);
29
30 }
31
32 protected void tearDown() throws Exception {
33 testFixture.tearDown();
34 testFixture = null;
35 }
36
37 public void testGetDecisionThatReturnsDecisionSet() throws DBException {
38 Map decisionRow = new HashMap();
39 decisionRow.put(new Integer(22), new Integer(11));
40 decisionRow.put(new Integer(23), new Integer(17));
41 WizDecisionSet expectedReturn = new WizDecisionSet();
42 expectedReturn.setField(WizDecisionSet.FLD_ID, 1);
43 expectedReturn.retrieve();
44 WizDecisionSet actualReturn = decisionMatrix.getDecision(decisionRow);
45 assertEquals("return value", 1,
46 actualReturn.getFieldInt(WizDecisionSet.FLD_ID));
47 }
48
49 public void testDecisionMatrixWithNoResult() throws DBException {
50 Map decisionRow = new HashMap();
51 decisionRow.put(new Integer(22), new Integer(13));
52 decisionRow.put(new Integer(23), new Integer(20));
53 WizDecisionSet expectedReturn = null;
54 WizDecisionSet actualReturn = decisionMatrix.getDecision(decisionRow);
55 assertEquals("return value", expectedReturn, actualReturn);
56
57 }
58
59 public void testDecisionMatrixWithNoPertinentSteps() throws DBException {
60 Map decisionRow = new HashMap();
61 decisionMatrix = new DecisionMatrix(14);
62 WizDecisionSet actualReturn = decisionMatrix.getDecision(decisionRow);
63 assertTrue(actualReturn == null);
64 }
65
66 public void testBadConstructors() throws DBException {
67 try {
68 new DecisionMatrix(-32767);
69 fail("Should have thrown an exception because");
70 } catch (Throwable ex) {
71 assertNotNull(ex.getMessage());
72
73 }
74
75 }
76
77 public void testBadArgumentRecovery() throws DBException {
78 Map badDecisionRow = new HashMap();
79 badDecisionRow.put("Abcd", "efgh");
80 badDecisionRow.put("gdfk", "sakd");
81 try {
82 decisionMatrix.getDecision(badDecisionRow);
83 fail("Should have thrown an exception");
84 } catch (Throwable ex) {
85 assertNotNull(ex.getMessage());
86
87 }
88
89 Map badDecisionRow2 = new HashMap();
90 badDecisionRow2.put(new Integer(22), new Integer(11));
91 badDecisionRow2.put(new Integer(23), new Integer(17));
92 badDecisionRow2.put(new Integer(21), new Integer(17));
93 try {
94 decisionMatrix.getDecision(badDecisionRow2);
95 fail("Should have thrown an exception");
96 } catch (Throwable ex) {
97 assertNotNull(ex.getMessage());
98 }
99
100
101 Map decisionRow = new HashMap();
102 decisionRow.put(new Integer(22), new Integer(11));
103 decisionRow.put(new Integer(23), new Integer(17));
104 WizDecisionSet expectedReturn = new WizDecisionSet();
105 expectedReturn.setField(WizDecisionSet.FLD_ID, 1);
106 expectedReturn.retrieve();
107 WizDecisionSet actualReturn = decisionMatrix.getDecision(decisionRow);
108 assertEquals("return value", 1,
109 actualReturn.getFieldInt(WizDecisionSet.FLD_ID));
110 }
111
112 }