View Javadoc
1   /**
2    * Copyright 2005-2013 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 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   * Tests that queues work over soap
38   * 
39   * @author Kuali Rice Team (rice.collab@kuali.org)
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  	// ensure test harness has entries for TestClient1
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  }