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