1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.kuali.rice.ksb.messaging;
15
16 import java.util.List;
17
18 import javax.xml.namespace.QName;
19
20 import org.junit.Test;
21 import org.kuali.rice.ksb.messaging.bam.BAMTargetEntry;
22 import org.kuali.rice.ksb.messaging.bam.service.BAMService;
23 import org.kuali.rice.ksb.messaging.callbacks.SimpleCallback;
24 import org.kuali.rice.ksb.messaging.remotedservices.SOAPService;
25 import org.kuali.rice.ksb.messaging.remotedservices.ServiceCallInformationHolder;
26 import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
27 import org.kuali.rice.ksb.service.KSBServiceLocator;
28 import org.kuali.rice.ksb.test.KSBTestCase;
29
30
31
32
33
34
35
36 public class SOAPMessagingTest extends KSBTestCase {
37
38 public boolean startClient1() {
39 return true;
40 }
41
42 @Test
43 public void testSuccessfullyCallingSOAPTopic() throws Exception {
44
45 ((Runnable) KSBResourceLoaderFactory.getRemoteResourceLocator()).run();
46
47 QName serviceName = new QName("testNameSpace", "soap-repeatTopic");
48
49 SOAPService testJavaAsyncService = (SOAPService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
50 testJavaAsyncService.doTheThing("The param");
51 verifyServiceCalls(serviceName);
52
53 assertTrue("Test harness topic never called", ((Boolean) ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
54 assertTrue("Cliet1 app topic never called", ((Boolean) ServiceCallInformationHolder.stuff.get("Client1SOAPServiceCalled")).booleanValue());
55 }
56
57 @Test
58 public void testSuccessfullyCallingSOAPTopicAsync() throws Exception {
59 KSBTestUtils.setMessagingToAsync();
60
61 QName serviceName = new QName("testNameSpace", "soap-repeatTopic");
62
63 SimpleCallback callback = new SimpleCallback();
64 SOAPService testJavaAsyncService = (SOAPService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
65 synchronized (callback) {
66 testJavaAsyncService.doTheThing("The param");
67 callback.waitForAsyncCall(3000);
68 }
69 verifyServiceCalls(serviceName);
70 assertTrue("Test harness topic never called", ((Boolean) ServiceCallInformationHolder.stuff.get("TestHarnessCalled")).booleanValue());
71 assertTrue("Cliet1 app topic never called", ((Boolean) ServiceCallInformationHolder.stuff.get("Client1SOAPServiceCalled")).booleanValue());
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 assertEquals("Wrong number of calls recorded", 2, bamCalls.size());
90 }
91 }