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.test;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.springframework.context.ConfigurableApplicationContext;
20  import org.springframework.transaction.jta.JtaTransactionManager;
21  
22  import javax.sql.DataSource;
23  import javax.transaction.UserTransaction;
24  
25  /**
26   * Locator that sits on the testharness SpringContext.
27   * 
28   * This doesn't defer to the {@link GlobalResourceLoader} because I'm not sure 
29   * the test harness justifies the extra setup at the moment.  If/when the 
30   * testharness {@link org.kuali.rice.core.framework.resourceloader.SpringResourceLoader} is placed in the {@link GlobalResourceLoader}
31   * this can delegate to that {@link GlobalResourceLoader}.
32   * 
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   *
35   */
36  public class TestHarnessServiceLocator {
37  
38  	private static ConfigurableApplicationContext context;
39  	
40  	public static final String USER_TRANSACTION = "userTransaction";
41  	public static final String TRANSACTON_MANAGER = "transactionManager";
42  	public static final String DATA_SOURCE = "dataSource";
43  	
44  	public static Object getService(String serviceName) {
45  		return getContext().getBean(serviceName);
46  	}
47  	
48  	public static DataSource getDataSource() {
49  		return (DataSource)getService(DATA_SOURCE);
50  	}
51  	
52  	public static JtaTransactionManager getJtaTransactionManager() {
53  		return (JtaTransactionManager)getService(TRANSACTON_MANAGER);
54  	}
55  	
56  	public static UserTransaction getUserTransaction() {
57  		return (UserTransaction)getService(USER_TRANSACTION);
58  	}
59  	
60  	public static ConfigurableApplicationContext getContext() {
61  		return context;
62  	}
63  
64  	public static void setContext(ConfigurableApplicationContext context) {
65  		TestHarnessServiceLocator.context = context;
66  	}	
67  }