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.remotedservices.ServiceCallInformationHolder;
22 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
23 import org.kuali.rice.ksb.test.KSBTestCase;
24
25 import javax.xml.namespace.QName;
26
27 import static org.junit.Assert.assertTrue;
28
29
30
31
32
33
34
35
36 public class DistributedTopicTest extends KSBTestCase {
37
38 public boolean startClient1() {
39 return true;
40 }
41
42 @Test
43 public void testSuccessfullyCallingSyncTopics() throws Exception {
44
45 KsbApiServiceLocator.getServiceBus().synchronize();
46 QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
47
48 KSBJavaService testJavaAsyncService = KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
49 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
50
51 assertTrue("Test harness topic never called", (ServiceCallInformationHolder.flags.get("TestHarnessCalled")).booleanValue());
52 assertTrue("Client1 app topic never called", (ServiceCallInformationHolder.flags.get("Client1Called")).booleanValue());
53 }
54
55 @Test public void testCallingAsyncTopics() throws Exception {
56 KSBTestUtils.setMessagingToAsync();
57
58 QName serviceName = new QName("testAppsSharedTopic", "sharedTopic");
59
60 SimpleCallback simpleCallback = new SimpleCallback();
61 KSBJavaService testJavaAsyncService = KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, simpleCallback);
62 synchronized (simpleCallback) {
63 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
64 simpleCallback.waitForAsyncCall();
65 }
66
67
68
69 int i = 0;
70 while (i < 100) {
71 if (ServiceCallInformationHolder.flags.get("Client1Called") != null) {
72 break;
73 }
74 Thread.sleep(1000);
75 i++;
76 }
77
78 assertTrue("Test harness topic never called", (ServiceCallInformationHolder.flags.get("TestHarnessCalled")).booleanValue());
79 assertTrue("Client1 app topic never called", (ServiceCallInformationHolder.flags.get("Client1Called"))
80 .booleanValue());
81
82 }
83
84 }