View Javadoc

1   /*
2    * Copyright 2007 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.objectremoting;
17  
18  import java.util.Map;
19  
20  import javax.xml.namespace.QName;
21  
22  import org.junit.Test;
23  import org.kuali.rice.core.config.Config;
24  import org.kuali.rice.core.config.ConfigContext;
25  import org.kuali.rice.core.reflect.ObjectDefinition;
26  import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
27  import org.kuali.rice.ksb.messaging.RemotedServiceRegistry;
28  import org.kuali.rice.ksb.service.KSBServiceLocator;
29  import org.kuali.rice.ksb.test.KSBTestCase;
30  import org.kuali.rice.ksb.testclient1.RemotedObject;
31  import org.kuali.rice.ksb.testclient1.TestClient1ObjectToBeRemoted;
32  import org.mortbay.jetty.webapp.WebAppClassLoader;
33  import org.springframework.transaction.TransactionStatus;
34  import org.springframework.transaction.support.TransactionCallback;
35  
36  
37  public class ObjectRemotingTest extends KSBTestCase {
38  	
39  	@Override
40  	public boolean startClient1() {
41  		return true;
42  	}
43  
44  	@Test
45  	public void testInvokingRemotedObject() throws Exception {
46  
47  		KSBServiceLocator.getTransactionTemplate().execute(new TransactionCallback() {
48  			public Object doInTransaction(TransactionStatus status) {
49  
50  				ObjectDefinition od = new ObjectDefinition(TestClient1ObjectToBeRemoted.class.getName(), "TestCl1");
51  				RemotedObject remotedOjb = (RemotedObject) GlobalResourceLoader.getObject(od);
52  				String returnParam = remotedOjb.invoke("call1");
53  				assertEquals(TestClient1ObjectToBeRemoted.METHOD_INVOKED, returnParam);
54  				return null;
55  			}
56  		});
57  		
58  		boolean madeTempServicesCheck = false;
59  		for (Map.Entry<ClassLoader, Config> configEntry : ConfigContext.getConfigs()) {
60  			if (configEntry.getKey() instanceof WebAppClassLoader) {
61  				ClassLoader old = Thread.currentThread().getContextClassLoader();
62  				//to make KSBServiceLocator select services from Client1WebApp
63  				Thread.currentThread().setContextClassLoader(configEntry.getKey());
64  				RemotedServiceRegistry serviceRegistry = KSBServiceLocator.getServiceDeployer();
65  				try {
66  					assertTrue(serviceRegistry.getPublishedTempServices().isEmpty());
67  					madeTempServicesCheck = true;
68  				} finally {
69  					Thread.currentThread().setContextClassLoader(old);	
70  				}
71  			}
72  		}
73  		assertTrue(madeTempServicesCheck);
74  		
75  		//verify service worked with bam
76  		assertTrue(verifyServiceCallsViaBam(QName.valueOf("{TestCl1}org.kuali.rice.ksb.testclient1.TestClient1ObjectToBeRemoted0"), "invoke", true));
77  		assertTrue(verifyServiceCallsViaBam(QName.valueOf("{TestCl1}org.kuali.rice.ksb.testclient1.TestClient1ObjectToBeRemoted0"), "invoke", false));
78  		assertTrue(verifyServiceCallsViaBam(QName.valueOf("{TestCl1}ObjectRemoterService"), "getRemotedClassURL", true));
79  		assertTrue(verifyServiceCallsViaBam(QName.valueOf("{TestCl1}ObjectRemoterService"), "getRemotedClassURL", false));
80  		assertTrue(verifyServiceCallsViaBam(QName.valueOf("{TestCl1}ObjectRemoterService"), "removeService", true));
81  	}
82  
83  }