View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests that queues work over soap
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
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          // ensure test harness has entries for TestClient1
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  }