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
48
49
50
51 @Test
52 public void testToStringOnService() {
53 KSBTestUtils.setMessagingToAsync();
54 QName serviceName = new QName("TestCl1", "testJavaAsyncService");
55 SimpleCallback callback = new SimpleCallback();
56 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName, callback);
57 String toStringValue = testJavaAsyncService.toString();
58 System.out.println("toString value on async service: " + toStringValue);
59 assertTrue("toString should have started with 'Service call proxy' but was instead: " + toStringValue, toStringValue.startsWith("Service call proxy"));
60 }
61
62 @Test
63 public void testAsyncJavaCall() throws Exception {
64 KSBTestUtils.setMessagingToAsync();
65
66 QName serviceName = new QName("TestCl1", "testJavaAsyncService");
67 SimpleCallback callback = new SimpleCallback();
68 KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper()
69 .getServiceAsynchronously(serviceName, callback);
70 synchronized (callback) {
71 testJavaAsyncService.invoke(new MessagingTestObject("message content"));
72 callback.waitForAsyncCall();
73 }
74 verifyServiceCalls(serviceName);
75 }
76
77 @Test
78 public void testAsyncXmlCall() throws Exception {
79 KSBTestUtils.setMessagingToAsync();
80
81 QName serviceName = new QName("TestCl1", "testXmlAsyncService");
82 SimpleCallback callback = new SimpleCallback();
83 KSBXMLService testXmlAsyncService = (KSBXMLService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(
84 serviceName, callback);
85 synchronized (callback) {
86 testXmlAsyncService.invoke("message content");
87 callback.waitForAsyncCall();
88 }
89 verifyServiceCalls(serviceName);
90 }
91
92 private void verifyServiceCalls(QName serviceName) throws Exception {
93 BAMService bamService = KSBServiceLocator.getBAMService();
94 List<BAMTargetEntry> bamCalls = bamService.getCallsForService(serviceName);
95 assertTrue("No service call recorded", bamCalls.size() > 0);
96 boolean foundClientCall = false;
97 boolean foundServiceCall = false;
98 for (BAMTargetEntry bamEntry : bamCalls) {
99 if (bamEntry.getServerInvocation()) {
100 foundServiceCall = true;
101 } else {
102 foundClientCall = true;
103 }
104 }
105 assertTrue("No client call recorded", foundClientCall);
106 assertTrue("No service call recorded", foundServiceCall);
107 }
108
109 }