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.remotedservices.SOAPService;
24 import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
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.assertEquals;
32 import static org.junit.Assert.assertTrue;
33
34
35
36
37
38
39 public class SOAPMessagingTest extends KSBTestCase {
40
41 public boolean startClient1() {
42 return true;
43 }
44
45 @Test
46 public void testSuccessfullyCallingSOAPTopic() throws Exception {
47
48 KsbApiServiceLocator.getServiceBus().synchronize();
49
50 QName serviceName = new QName("testNameSpace", "soap-repeatTopic");
51
52 SOAPService testJavaAsyncService = KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
53 testJavaAsyncService.doTheThing("The param");
54 verifyServiceCalls(serviceName);
55
56 assertTrue("Test harness topic never called", (ServiceCallInformationHolder.flags.get(
57 "TestHarnessCalled")).booleanValue());
58 assertTrue("Cliet1 app topic never called", (ServiceCallInformationHolder.flags.get(
59 "Client1SOAPServiceCalled")).booleanValue());
60 }
61
62 @Test
63 public void testSuccessfullyCallingSOAPTopicAsync() throws Exception {
64 KSBTestUtils.setMessagingToAsync();
65
66 QName serviceName = new QName("testNameSpace", "soap-repeatTopic");
67
68 SimpleCallback callback = new SimpleCallback();
69 SOAPService testJavaAsyncService = KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(
70 serviceName);
71 synchronized (callback) {
72 testJavaAsyncService.doTheThing("The param");
73 callback.waitForAsyncCall(3000);
74 }
75 verifyServiceCalls(serviceName);
76 assertTrue("Test harness topic never called", (ServiceCallInformationHolder.flags.get(
77 "TestHarnessCalled")).booleanValue());
78 assertTrue("Cliet1 app topic never called", (ServiceCallInformationHolder.flags.get(
79 "Client1SOAPServiceCalled")).booleanValue());
80 }
81
82 private void verifyServiceCalls(QName serviceName) throws Exception {
83 BAMService bamService = KSBServiceLocator.getBAMService();
84 List<BAMTargetEntry> bamCalls = bamService.getCallsForService(serviceName);
85 assertTrue("No service call recorded", bamCalls.size() > 0);
86 boolean foundClientCall = false;
87 boolean foundServiceCall = false;
88 for (BAMTargetEntry bamEntry : bamCalls) {
89 if (bamEntry.getServerInvocation()) {
90 foundServiceCall = true;
91 } else {
92 foundClientCall = true;
93 }
94 }
95 assertTrue("No client call recorded", foundClientCall);
96 assertTrue("No service call recorded", foundServiceCall);
97 assertEquals("Wrong number of calls recorded", 2, bamCalls.size());
98 }
99 }