1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.event;
25
26 import org.dbforms.config.Interceptor;
27 import org.dbforms.config.Table;
28 import org.dbforms.interfaces.DbEventInterceptorData;
29 import org.dbforms.interfaces.IDbEventInterceptor;
30
31 import org.dbforms.util.AbstractTestCase;
32
33
34
35 /***
36 * DOCUMENT ME!
37 *
38 * @author $author$
39 * @version $Revision: 1.4 $
40 */
41 public class TestInterceptor extends AbstractTestCase {
42 /***
43 * DOCUMENT ME!
44 *
45 * @throws Exception DOCUMENT ME!
46 */
47 public void testInterceptor() throws Exception {
48 Interceptor interceptor = new Interceptor();
49 interceptor.setClassName("interceptors.InterceptorTest");
50 assertTrue("Class name should be interceptors.InterceptorTest",
51 interceptor.getClassName().equals("interceptors.InterceptorTest"));
52
53 Table table = new Table();
54 table.addInterceptor(interceptor);
55
56 int i = table.getInterceptors()
57 .size();
58 assertEquals("count interceptors", i, 1);
59
60 DbEventInterceptorData data = new DbEventInterceptorData(null, null,
61 null, table);
62
63 table.processInterceptors(IDbEventInterceptor.PRE_INSERT, data);
64 assertTrue("preInsert", interceptors.InterceptorTest.preInsertCalled);
65
66 table.processInterceptors(IDbEventInterceptor.POST_INSERT, data);
67 assertTrue("postInsert", interceptors.InterceptorTest.postInsertCalled);
68
69 table.processInterceptors(IDbEventInterceptor.PRE_UPDATE, data);
70 assertTrue("preUpdate", interceptors.InterceptorTest.preUpdateCalled);
71
72 table.processInterceptors(IDbEventInterceptor.POST_UPDATE, data);
73 assertTrue("postUpdate", interceptors.InterceptorTest.postUpdateCalled);
74
75 table.processInterceptors(IDbEventInterceptor.PRE_DELETE, data);
76 assertTrue("preUpdate", interceptors.InterceptorTest.preDeleteCalled);
77
78 table.processInterceptors(IDbEventInterceptor.POST_DELETE, data);
79 assertTrue("postUpdate", interceptors.InterceptorTest.postDeleteCalled);
80
81 table.processInterceptors(IDbEventInterceptor.PRE_SELECT, data);
82 assertTrue("preSelectUpdate", interceptors.InterceptorTest.preSelectCalled);
83
84 table.processInterceptors(IDbEventInterceptor.POST_SELECT, data);
85 assertTrue("postSelectUpdate",
86 interceptors.InterceptorTest.postSelectCalled);
87
88 table.processInterceptors(IDbEventInterceptor.PRE_ADDROW, data);
89 assertTrue("preAddRow", interceptors.InterceptorTest.preAddRowCalled);
90
91 table.processInterceptors(IDbEventInterceptor.POST_ADDROW, data);
92 assertTrue("postAddRow", interceptors.InterceptorTest.postAddRowCalled);
93 }
94
95
96 /***
97 * DOCUMENT ME!
98 *
99 * @throws Exception DOCUMENT ME!
100 */
101 public void testInterceptorClassic() throws Exception {
102 Interceptor interceptor = new Interceptor();
103 interceptor.setClassName("interceptors.InterceptorTestClassic");
104 assertTrue("Class name should be interceptors.InterceptorTestClassic",
105 interceptor.getClassName().equals("interceptors.InterceptorTestClassic"));
106
107 Table table = new Table();
108 table.addInterceptor(interceptor);
109
110 int i = table.getInterceptors()
111 .size();
112 assertEquals("count interceptors", i, 1);
113
114 DbEventInterceptorData data = new DbEventInterceptorData(null, null,
115 null, table);
116
117 table.processInterceptors(IDbEventInterceptor.PRE_INSERT, data);
118 assertTrue("preInsert",
119 interceptors.InterceptorTestClassic.preInsertCalled);
120
121 table.processInterceptors(IDbEventInterceptor.POST_INSERT, data);
122 assertTrue("postInsert",
123 interceptors.InterceptorTestClassic.postInsertCalled);
124
125 table.processInterceptors(IDbEventInterceptor.PRE_UPDATE, data);
126 assertTrue("preUpdate",
127 interceptors.InterceptorTestClassic.preUpdateCalled);
128
129 table.processInterceptors(IDbEventInterceptor.POST_UPDATE, data);
130 assertTrue("postUpdate",
131 interceptors.InterceptorTestClassic.postUpdateCalled);
132
133 table.processInterceptors(IDbEventInterceptor.PRE_DELETE, data);
134 assertTrue("preUpdate",
135 interceptors.InterceptorTestClassic.preDeleteCalled);
136
137 table.processInterceptors(IDbEventInterceptor.POST_DELETE, data);
138 assertTrue("postUpdate",
139 interceptors.InterceptorTestClassic.postDeleteCalled);
140
141 table.processInterceptors(IDbEventInterceptor.PRE_SELECT, data);
142 assertTrue("preSelectUpdate",
143 interceptors.InterceptorTestClassic.preSelectCalled);
144
145 table.processInterceptors(IDbEventInterceptor.POST_SELECT, data);
146 assertTrue("postSelectUpdate",
147 interceptors.InterceptorTestClassic.postSelectCalled);
148 }
149 }