1
2
3
4
5
6
7
8
9 package bexee.dao;
10
11 import junit.framework.TestCase;
12 import bexee.core.ProcessContext;
13
14 /***
15 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:20 $
16 * @author Patric Fornasier
17 * @author Pawel Kowalski
18 */
19 public class MemoryProcessContextDAOTest extends TestCase {
20
21 private ProcessContextDAO dao;
22
23 private ProcessContext ctx;
24
25 private ProcessContext ctxInit;
26
27 private String firstString = "1-string-1";
28 private String secondString = "2-string-2";
29
30 protected void setUp() throws Exception {
31 super.setUp();
32
33 dao = new MemoryProcessContextDAO();
34
35
36 ctx = new ProcessContext();
37 ctx.setResult(firstString);
38
39
40 ctxInit = new ProcessContext();
41 ctxInit.setResult(secondString);
42 }
43
44 /***
45 * Test if we can insert a <code>ProcessContext</code> and find it again.
46 */
47 public void testInsertAndFind() throws Exception {
48
49
50 String id = dao.insert(ctx);
51 String idInit = dao.insert(ctxInit);
52
53
54 dao = null;
55 ctx = null;
56 ctxInit = null;
57
58
59 dao = new MemoryProcessContextDAO();
60 ctx = dao.find(id);
61 ctxInit = dao.find(idInit);
62
63
64 assertEquals(firstString, ctx.getResult());
65 assertEquals(secondString, ctxInit.getResult());
66 }
67
68 /***
69 * Test if we can delete a <code>ProcessContext</code>.
70 */
71 public void testDelete() throws Exception {
72
73
74 String id = dao.insert(ctx);
75
76
77 assertNotNull(dao.find(id));
78 dao.delete(id);
79 assertNull(dao.find(id));
80 }
81
82 /***
83 * Test if we can update a <code>ProcessContext</code>.
84 */
85 public void testUpdate() throws Exception {
86
87 try {
88 dao.update(ctx);
89 fail("Calling update on a non-existing object should not work!");
90 } catch (DAOException e) {
91
92 }
93
94
95 String id = dao.insert(ctx);
96
97
98 String str = "humba-rumba";
99 ctx.setResult(str);
100 dao.update(ctx);
101
102
103 ctx = null;
104 ctx = dao.find(id);
105 assertEquals(str, ctx.getResult());
106 }
107 }