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.bam.BAMTargetEntry;
21 import org.kuali.rice.ksb.messaging.bam.service.BAMService;
22 import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
23 import org.kuali.rice.ksb.messaging.service.KSBJavaService;
24 import org.kuali.rice.ksb.messaging.service.KSBXMLService;
25 import org.kuali.rice.ksb.service.KSBServiceLocator;
26 import org.kuali.rice.ksb.test.KSBTestCase;
27
28 import javax.xml.namespace.QName;
29 import java.util.List;
30
31 import static org.junit.Assert.assertTrue;
32
33
34
35
36
37
38
39
40
41 public class SimpleServiceCallTest extends KSBTestCase {
42
43 public boolean startClient1() {
44 return true;
45 }
46
47 @Test
48 public void testAsyncJavaCall() throws Exception {
49 KSBTestUtils.setMessagingToAsync();
50
51 QName serviceName = new QName("TestCl1", "testJavaAsyncService");
52 SimpleCallback callback = new SimpleCallback();
53 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper()
54 .getServiceAsynchronously(serviceName, callback);
55 synchronized (callback) {
56 testJavaAsyncService.invoke(new MessagingTestObject("message content"));
57 callback.waitForAsyncCall();
58 }
59 verifyServiceCalls(serviceName);
60 }
61
62 @Test
63 public void testAsyncXmlCall() throws Exception {
64 KSBTestUtils.setMessagingToAsync();
65
66 QName serviceName = new QName("TestCl1", "testXmlAsyncService");
67 SimpleCallback callback = new SimpleCallback();
68 KSBXMLService testXmlAsyncService = (KSBXMLService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(
69 serviceName, callback);
70 synchronized (callback) {
71 testXmlAsyncService.invoke("message content");
72 callback.waitForAsyncCall();
73 }
74 verifyServiceCalls(serviceName);
75 }
76
77 private void verifyServiceCalls(QName serviceName) throws Exception {
78 BAMService bamService = KSBServiceLocator.getBAMService();
79 List<BAMTargetEntry> bamCalls = bamService.getCallsForService(serviceName);
80 assertTrue("No service call recorded", bamCalls.size() > 0);
81 boolean foundClientCall = false;
82 boolean foundServiceCall = false;
83 for (BAMTargetEntry bamEntry : bamCalls) {
84 if (bamEntry.getServerInvocation()) {
85 foundServiceCall = true;
86 } else {
87 foundClientCall = true;
88 }
89 }
90 assertTrue("No client call recorded", foundClientCall);
91 assertTrue("No service call recorded", foundServiceCall);
92 }
93
94 }