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 static org.junit.Assert.assertTrue;
19
20 import javax.xml.namespace.QName;
21
22 import org.junit.Test;
23 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
24 import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
25 import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
26 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
27 import org.kuali.rice.ksb.test.KSBTestCase;
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 = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
49 testJavaAsyncService.invoke(new ClientAppServiceSharedPayloadObj("message content", false));
50
51 assertTrue("Test harness topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
52 assertTrue("Client1 app topic never called", ((Boolean)ServiceCallInformationHolder.stuff.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 = (KSBJavaService) 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.stuff.get("Client1Called") != null) {
72 break;
73 }
74 Thread.sleep(1000);
75 i++;
76 }
77
78 assertTrue("Test harness topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
79 assertTrue("Client1 app topic never called", ((Boolean)ServiceCallInformationHolder.stuff.get("Client1Called")).booleanValue());
80
81 }
82
83 }