View Javadoc

1   /**
2    * Copyright 2005-2011 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.service.KSBJavaService;
24  import org.kuali.rice.ksb.messaging.service.KSBXMLService;
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.assertTrue;
32  
33  
34  /**
35   * Tests calling services in a very simple scenario. This test could probably go now that more 'feature-full' tests are out
36   * there.
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   *
40   */
41  public class SimpleServiceCallTest extends KSBTestCase {
42  
43  	public boolean startClient1() {
44  		return true;
45  	}
46  	
47      @Test
48      public void testAsyncJavaCall() throws Exception {
49  	    KSBTestUtils.setMessagingToAsync();
50  		
51  		QName serviceName = new QName("TestCl1", "testJavaAsyncService");
52  		SimpleCallback callback = new SimpleCallback();
53  	KSBJavaService testJavaAsyncService = (KSBJavaService) KsbApiServiceLocator.getMessageHelper()
54  		.getServiceAsynchronously(serviceName, callback);
55  	    synchronized (callback) {
56  	        testJavaAsyncService.invoke(new MessagingTestObject("message content"));
57  	        callback.waitForAsyncCall();
58  	    }
59  		verifyServiceCalls(serviceName);
60  	}
61  	
62      @Test
63      public void testAsyncXmlCall() throws Exception {
64  	    KSBTestUtils.setMessagingToAsync();
65  		
66  		QName serviceName = new QName("TestCl1", "testXmlAsyncService");
67  		SimpleCallback callback = new SimpleCallback();
68  	KSBXMLService testXmlAsyncService = (KSBXMLService) KsbApiServiceLocator.getMessageHelper().getServiceAsynchronously(
69  		serviceName, callback);
70  	    synchronized (callback) {	
71  	        testXmlAsyncService.invoke("message content");
72  	        callback.waitForAsyncCall();
73  	    }
74  		verifyServiceCalls(serviceName);
75  	}
76  	
77  	private void verifyServiceCalls(QName serviceName) throws Exception {
78  		BAMService bamService = KSBServiceLocator.getBAMService();
79  		List<BAMTargetEntry> bamCalls = bamService.getCallsForService(serviceName);
80  		assertTrue("No service call recorded", bamCalls.size() > 0);
81  		boolean foundClientCall = false;
82  		boolean foundServiceCall = false;
83  		for (BAMTargetEntry bamEntry : bamCalls) {
84  			if (bamEntry.getServerInvocation()) {
85  				foundServiceCall = true;
86  			} else {
87  				foundClientCall = true;
88  			}
89  		}
90  		assertTrue("No client call recorded", foundClientCall);
91  		assertTrue("No service call recorded", foundServiceCall);
92  	}
93  	
94  }