View Javadoc

1   /*
2    * Copyright 2007-2009 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.kim.test.service;
17  
18  import java.util.List;
19  
20  import javax.xml.namespace.QName;
21  
22  import org.kuali.rice.core.config.ConfigContext;
23  import org.kuali.rice.core.lifecycle.BaseLifecycle;
24  import org.kuali.rice.core.lifecycle.Lifecycle;
25  import org.kuali.rice.ksb.messaging.RemoteResourceServiceLocator;
26  import org.kuali.rice.ksb.messaging.RemotedServiceHolder;
27  import org.kuali.rice.ksb.messaging.ServiceInfo;
28  import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
29  import org.kuali.rice.ksb.messaging.serviceconnectors.SOAPConnector;
30  import org.kuali.rice.test.lifecycles.JettyServerLifecycle;
31  
32  /**
33   * Test the PermissionService via remote calls
34   * 
35   * @author Kuali Rice Team (kuali-rice@googlegroups.com)
36   *
37   */
38  public class PermissionServiceRemoteTest extends PermissionServiceTest {
39  
40  	public void setUp() throws Exception {
41  		super.setUp();
42  	}
43  
44  	@Override
45  	protected Lifecycle getLoadApplicationLifecycle() {
46  		return new BaseLifecycle() {
47  			public void start() throws Exception {
48  				new JettyServerLifecycle(getConfigIntProp("kim.test.port"), "/" + getConfigProp("app.context.name"), "/../kim/src/test/webapp").start();
49  				super.start();
50  			}
51  		};	
52  	}
53  	
54  	private int getConfigIntProp(String intPropKey) {
55  		return Integer.parseInt(getConfigProp(intPropKey));
56  	}
57  
58  	private String getConfigProp(String propKey) {
59  		return ConfigContext.getCurrentContextConfig().getProperty(propKey);
60  	}
61  	
62  	/**
63  	 * This method tries to get a client proxy for the specified KIM service
64  	 * 
65  	 * @param  svcName - name of the KIM service desired
66  	 * @return the proxy object
67  	 * @throws Exception 
68  	 */
69  	protected Object getKimService(String svcName) throws Exception {
70  		RemoteResourceServiceLocator rrl = KSBResourceLoaderFactory.getRemoteResourceLocator();
71  		List<RemotedServiceHolder> svcHolders = rrl.getAllServices(new QName("KIM", svcName));
72  		if (svcHolders.size() > 1) {
73  			fail("Found more than one RemotedServiceHolder for " + svcName);
74  		}
75  		ServiceInfo svcInfo = svcHolders.get(0).getServiceInfo();
76  		SOAPConnector connector = new SOAPConnector(svcInfo);
77  		return connector.getService();
78  	}
79  }