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