View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
6    * compliance with the License. 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 distributed under the License is distributed on an "AS
11   * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12   * language governing permissions and limitations under the License.
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   * Tests that queues work over soap
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
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  	// ensure test harness has entries for TestClient1
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  }