View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.ksb.messaging;
18  
19  import java.util.List;
20  
21  import javax.xml.namespace.QName;
22  
23  import org.junit.Test;
24  import org.kuali.rice.core.config.Config;
25  import org.kuali.rice.core.config.ConfigContext;
26  import org.kuali.rice.ksb.messaging.bam.BAMTargetEntry;
27  import org.kuali.rice.ksb.messaging.bam.service.BAMService;
28  import org.kuali.rice.ksb.messaging.service.KSBXMLService;
29  import org.kuali.rice.ksb.service.KSBServiceLocator;
30  import org.kuali.rice.ksb.test.KSBTestCase;
31  
32  
33  /**
34   * Test store and forward capabilities in calling services
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   */
38  public class StoreAndForwardTest extends KSBTestCase {
39  
40  	public boolean startClient1() {
41  		return true;
42  	}
43  	
44  
45  	@Test public void testServiceCall() throws Exception {
46  		ConfigContext.getCurrentContextConfig().putProperty(Config.STORE_AND_FORWARD, "true");
47  		QName serviceName = new QName("TestCl1", "testXmlAsyncService");
48  		KSBXMLService testXmlAsyncService = (KSBXMLService) KSBServiceLocator.getMessageHelper().getServiceAsynchronously(serviceName);
49  		testXmlAsyncService.invoke("message content");
50  		verifyServiceCalls();
51  	}
52  	
53  	private void verifyServiceCalls() throws Exception {
54  		BAMService bamService = KSBServiceLocator.getBAMService();
55  		List<BAMTargetEntry> bamCalls = bamService.getCallsForService(QName.valueOf("{TestCl1}testXmlAsyncService-forwardHandler"));
56  		assertTrue("No service call recorded", bamCalls.size() > 0);
57  		boolean foundClientCall = false;
58  		boolean foundServiceCall = false;
59  		for (BAMTargetEntry bamEntry : bamCalls) {
60  			if (bamEntry.getServerInvocation()) {
61  				foundServiceCall = true;
62  			} else {
63  				foundClientCall = true;
64  			}
65  		}
66  		assertTrue("No client call recorded", foundClientCall);
67  		assertTrue("No service call recorded", foundServiceCall);
68  	}
69  }