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