1
2
3
4
5
6
7
8
9
10
11
12
13 package org.kuali.rice.ksb.messaging;
14
15 import javax.xml.namespace.QName;
16
17 import org.junit.Test;
18 import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
19 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
20 import org.kuali.rice.ksb.service.KSBServiceLocator;
21 import org.kuali.rice.ksb.test.KSBTestCase;
22
23
24
25
26
27
28
29
30
31
32 public class ContextObjectMessagingTest extends KSBTestCase {
33
34 public boolean startClient1() {
35 return true;
36 }
37
38 @Test
39 public void testCallingQueueAsnyc() throws Exception {
40
41 KSBTestUtils.setMessagingToAsync();
42 QName serviceName = new QName("testAppsSharedQueue", "sharedQueue");
43 String contextObject = "my_context_object";
44 SimpleCallback callback = new SimpleCallback();
45
46 KSBJavaService testJavaAsyncService = (KSBJavaService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback, contextObject);
47
48 synchronized (callback) {
49 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
50 callback.waitForAsyncCall();
51 }
52
53 Object contextAfterMessaging = callback.getMethodCall().getContext();
54 assertEquals(contextObject, contextAfterMessaging);
55 }
56
57 @Test
58 public void testCallingAsyncTopics() throws Exception {
59 KSBTestUtils.setMessagingToAsync();
60 QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
61
62 SimpleCallback callback = new SimpleCallback();
63 String contextObject = "my_context_object";
64 KSBJavaService testJavaAsyncService = (KSBJavaService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback, contextObject);
65
66 synchronized (callback) {
67 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
68 callback.waitForAsyncCall();
69 }
70
71 Object contextAfterMessaging = callback.getMethodCall().getContext();
72 assertEquals(contextObject, contextAfterMessaging);
73 }
74
75 }