001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package edu.iu.uis.eden.messaging.objectremoting;
017:
018: import java.util.Map;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.junit.Test;
023: import org.kuali.bus.services.KSBServiceLocator;
024: import org.kuali.bus.test.KSBTestCase;
025: import org.kuali.rice.config.Config;
026: import org.kuali.rice.core.Core;
027: import org.kuali.rice.definition.ObjectDefinition;
028: import org.kuali.rice.resourceloader.GlobalResourceLoader;
029: import org.mortbay.jetty.webapp.WebAppClassLoader;
030: import org.springframework.transaction.TransactionStatus;
031: import org.springframework.transaction.support.TransactionCallback;
032:
033: import edu.iu.uis.eden.messaging.RemotedServiceRegistry;
034: import edu.iu.uis.eden.testclient1.RemotedObject;
035: import edu.iu.uis.eden.testclient1.TestClient1ObjectToBeRemoted;
036:
037: public class ObjectRemotingTest extends KSBTestCase {
038:
039: @Override
040: public boolean startClient1() {
041: return true;
042: }
043:
044: @Test
045: public void testInvokingRemotedObject() throws Exception {
046:
047: KSBServiceLocator.getTransactionTemplate().execute(
048: new TransactionCallback() {
049: public Object doInTransaction(
050: TransactionStatus status) {
051:
052: ObjectDefinition od = new ObjectDefinition(
053: TestClient1ObjectToBeRemoted.class
054: .getName(), "TestCl1");
055: RemotedObject remotedOjb = (RemotedObject) GlobalResourceLoader
056: .getObject(od);
057: String returnParam = remotedOjb.invoke("call1");
058: assertEquals(
059: TestClient1ObjectToBeRemoted.METHOD_INVOKED,
060: returnParam);
061: return null;
062: }
063: });
064:
065: Map<ClassLoader, Config> configs = Core.getCONFIGS();
066: boolean madeTempServicesCheck = false;
067: for (Map.Entry<ClassLoader, Config> configEntry : configs
068: .entrySet()) {
069: if (configEntry.getKey() instanceof WebAppClassLoader) {
070: ClassLoader old = Thread.currentThread()
071: .getContextClassLoader();
072: //to make KSBServiceLocator select services from Client1WebApp
073: Thread.currentThread().setContextClassLoader(
074: configEntry.getKey());
075: RemotedServiceRegistry serviceRegistry = KSBServiceLocator
076: .getServiceDeployer();
077: try {
078: assertTrue(serviceRegistry
079: .getPublishedTempServices().isEmpty());
080: madeTempServicesCheck = true;
081: } finally {
082: Thread.currentThread().setContextClassLoader(old);
083: }
084: }
085: }
086: assertTrue(madeTempServicesCheck);
087:
088: //verify service worked with bam
089: assertTrue(verifyServiceCallsViaBam(
090: QName
091: .valueOf("{TestCl1}edu.iu.uis.eden.testclient1.TestClient1ObjectToBeRemoted0"),
092: "invoke", true));
093: assertTrue(verifyServiceCallsViaBam(
094: QName
095: .valueOf("{TestCl1}edu.iu.uis.eden.testclient1.TestClient1ObjectToBeRemoted0"),
096: "invoke", false));
097: assertTrue(verifyServiceCallsViaBam(QName
098: .valueOf("{TestCl1}ObjectRemoterService"),
099: "getRemotedClassURL", true));
100: assertTrue(verifyServiceCallsViaBam(QName
101: .valueOf("{TestCl1}ObjectRemoterService"),
102: "getRemotedClassURL", false));
103: assertTrue(verifyServiceCallsViaBam(QName
104: .valueOf("{TestCl1}ObjectRemoterService"),
105: "removeService", true));
106: }
107:
108: }
|