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