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