1 /*------------------------------------------------------------------------------
2 Name: TestInvocationRecorder.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Testing the InvocationRecorder
6 Version: $Id: TestInvocationRecorder.java 15151 2006-05-13 13:05:20Z laghi $
7 ------------------------------------------------------------------------------*/
8 package org.xmlBlaster.test.qos;
9
10 import java.util.logging.Logger;
11 import java.util.logging.Level;
12 import org.xmlBlaster.util.Global;
13 import org.xmlBlaster.util.XmlBlasterException;
14 import org.xmlBlaster.util.recorder.ram.RamRecorder;
15 import org.xmlBlaster.client.protocol.I_XmlBlaster;
16 import org.xmlBlaster.client.qos.PublishReturnQos;
17 import org.xmlBlaster.client.qos.SubscribeReturnQos;
18 import org.xmlBlaster.client.qos.UnSubscribeReturnQos;
19 import org.xmlBlaster.client.qos.EraseReturnQos;
20 import org.xmlBlaster.util.MsgUnit;
21
22 import junit.framework.*;
23
24
25 /**
26 * This client tests the RamRecorder.
27 * <p />
28 * This test invokes every method, and compares the values of the playback
29 * messages with their originals.
30 * This test needs no running xmlBlaster.
31 * <br />
32 * Invoke examples:<br />
33 * <pre>
34 * java junit.textui.TestRunner org.xmlBlaster.test.qos.TestInvocationRecorder
35 * java junit.swingui.TestRunner org.xmlBlaster.test.qos.TestInvocationRecorder
36 * </pre>
37 */
38 public class TestInvocationRecorder extends TestCase implements I_XmlBlaster {
39 private final Global glob;
40 private static Logger log = Logger.getLogger(TestInvocationRecorder.class.getName());
41
42 private RamRecorder recorder = null;
43
44 private int numSubscribe, numUnSubscribe, numPublish, numPublishArr, numErase, numGet, numUpdate;
45 private MsgUnit[] dummyMArr = new MsgUnit[0];
46 private String xmlKey_get = "<key oid='HelloGet' queryType='EXACT'>\n</key>";
47 private String qos_get = "<qos><get /></qos>";
48
49 private String xmlKey_subscribe = "<key oid='HelloSubscribe' queryType='EXACT'>\n</key>";
50 private String qos_subscribe = "<qos><subscribe /></qos>";
51
52 /**
53 * Constructs the TestInvocationRecorder object.
54 * <p />
55 * @param testName The name used in the test suite
56 */
57 public TestInvocationRecorder(Global glob, String testName)
58 {
59 super(testName);
60 this.glob = glob;
61
62 }
63
64
65 /**
66 * Sets up the fixture.
67 * <p />
68 * Connect to xmlBlaster and login
69 */
70 protected void setUp()
71 {
72 log.info("setup test");
73 numSubscribe = numUnSubscribe = numPublish = numPublishArr = numErase = numGet = numUpdate = 0;
74 recorder = new RamRecorder();
75 recorder.initialize(glob, (String)null, 1000, this);//, this);
76 }
77
78
79 /**
80 * Tears down the fixture.
81 * <p />
82 * cleaning up .... erase() the previous message OID and logout
83 */
84 protected void tearDown()
85 {
86 log.info("testing done");
87 }
88
89
90 /**
91 * This test invokes every method, and compares the values of the playback
92 * messages with their originals
93 */
94 public void test()
95 {
96 String xmlKey = "<key oid='Hello' queryType='XPATH'>\n //TestInvocationRecorder-AGENT\n</key>";
97 String qos = "<qos></qos>";
98 String content = "The content";
99
100 try {
101 MsgUnit msgUnit = new MsgUnit(xmlKey, content.getBytes(), qos);
102 MsgUnit[] msgUnitArr = { msgUnit };
103 recorder.subscribe(xmlKey_subscribe, qos_subscribe);
104 recorder.get(xmlKey_get, qos_get);
105 recorder.unSubscribe(xmlKey, qos);
106 recorder.publish(msgUnit);
107 recorder.publishArr(msgUnitArr);
108 recorder.erase(xmlKey, qos);
109 //recorder.update(clientName, msgUnitArr);
110 }
111 catch(XmlBlasterException e) {
112 log.severe("problems feeding the recorder: " + e.getMessage());
113 assertTrue("problems feeding the recorder: " + e.getMessage(), false);
114 }
115
116 try {
117 recorder.pullback(0L, 0L, (float)1.0);
118 }
119 catch(XmlBlasterException e) {
120 log.severe("problems with recorder.pullback: " + e.getMessage());
121 assertTrue("problems recorder pullback: " + e.getMessage(), false);
122 }
123
124 assertEquals("numSubscribe: ", 1, numSubscribe);
125 assertEquals("numUnSubscribe: ", 1, numUnSubscribe);
126 assertEquals("numPublish: ", 1, numPublish);
127 assertEquals("numPublishArr: ", 1, numPublishArr);
128 assertEquals("numErase: ", 1, numErase);
129 assertEquals("numGet: ", 1, numGet);
130 //assertEquals("numUpdate: ", 1, numUpdate);
131 }
132
133
134 /**
135 * @return dummy to match I_InvocationRecorder interface
136 */
137 public SubscribeReturnQos subscribe(String xmlKey_literal, String qos_literal) throws XmlBlasterException
138 {
139 if (log.isLoggable(Level.FINER)) log.finer("subscribe() ...");
140 numSubscribe++;
141 assertEquals("subscribe(xmlKey): ", xmlKey_subscribe, xmlKey_literal);
142 assertEquals("subscribe(xmlKey): ", qos_subscribe, qos_literal);
143 return null;
144 }
145
146
147 /**
148 * For I_InvocationRecorder interface
149 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
150 */
151 public UnSubscribeReturnQos[] unSubscribe(String xmlKey_literal, String qos_literal) throws XmlBlasterException
152 {
153 if (log.isLoggable(Level.FINER)) log.finer("unSubscribe() ...");
154 numUnSubscribe++;
155 return null;
156 }
157
158
159 /**
160 * @return dummy to match I_InvocationRecorder interface
161 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
162 */
163 public PublishReturnQos publish(MsgUnit msgUnit) throws XmlBlasterException
164 {
165 if (log.isLoggable(Level.FINER)) log.finer("publish() ...");
166 numPublish++;
167 return null;
168 }
169
170
171 /**
172 * @return dummy to match I_InvocationRecorder interface
173 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
174 */
175 public void publishOneway(MsgUnit [] msgUnitArr)
176 {
177 if (log.isLoggable(Level.FINER)) log.finer("publishOneway() ...");
178 numPublishArr++;
179 }
180
181
182 /**
183 * @return dummy to match I_InvocationRecorder interface
184 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
185 */
186 public PublishReturnQos[] publishArr(MsgUnit [] msgUnitArr) throws XmlBlasterException
187 {
188 if (log.isLoggable(Level.FINER)) log.finer("publishArr() ...");
189 numPublishArr++;
190 return new PublishReturnQos[0];
191 }
192
193
194 /**
195 * @return dummy to match I_InvocationRecorder interface
196 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
197 */
198 public EraseReturnQos[] erase(String xmlKey_literal, String qos_literal) throws XmlBlasterException
199 {
200 if (log.isLoggable(Level.FINER)) log.finer("erase() ...");
201 numErase++;
202 return new EraseReturnQos[0];
203 }
204
205
206 /**
207 * @return dummy to match I_InvocationRecorder interface
208 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/src/java/org/xmlBlaster/protocol/corba/xmlBlaster.idl" target="others">CORBA xmlBlaster.idl</a>
209 */
210 public MsgUnit[] get(String xmlKey_literal, String qos_literal) throws XmlBlasterException
211 {
212 if (log.isLoggable(Level.FINER)) log.finer("get() ...");
213 numGet++;
214 assertEquals("get(xmlKey): ", xmlKey_get, xmlKey_literal);
215 assertEquals("get(xmlKey): ", qos_get, qos_literal);
216 return dummyMArr;
217 }
218
219
220 /**
221 * This is the callback method enforced by interface I_CallbackRaw.
222 * <p />
223 * @param MsgUnit Container for the Message
224 public String[] update(String cbSessionId, org.xmlBlaster.util.MsgUnit[] msgUnitArr)
225 {
226 if (log.isLoggable(Level.FINER)) log.finer("update(" + cbSessionId + ") ...");
227 numUpdate++;
228 String[] retArr = new String[msgUnitArr.length];
229 for (int ii=0; ii<retArr.length; ii++) retArr[ii] = "";
230 return retArr;
231 }
232
233 public void updateOneway(String cbSessionId, org.xmlBlaster.util.MsgUnit[] msgUnitArr)
234 {
235 if (log.isLoggable(Level.FINER)) log.finer("update(" + cbSessionId + ") ...");
236 numUpdate++;
237 }
238 */
239
240 /**
241 * Method is used by TestRunner to load these tests
242 */
243 public static Test suite()
244 {
245 TestSuite suite= new TestSuite();
246 suite.addTest(new TestInvocationRecorder(new Global(), "test"));
247 return suite;
248 }
249
250
251 /**
252 * Invoke: java org.xmlBlaster.test.qos.TestInvocationRecorder -logging FINEST
253 */
254 public static void main(String args[])
255 {
256 TestInvocationRecorder testSub = new TestInvocationRecorder(new Global(args), "test");
257 testSub.setUp();
258 testSub.test();
259 testSub.tearDown();
260 }
261 }
syntax highlighted by Code2HTML, v. 0.9.1