001/**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.rice.test;
017
018import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
019import org.springframework.context.ConfigurableApplicationContext;
020import org.springframework.transaction.jta.JtaTransactionManager;
021
022import javax.sql.DataSource;
023import javax.transaction.UserTransaction;
024
025/**
026 * Locator that sits on the testharness SpringContext.
027 * 
028 * This doesn't defer to the {@link GlobalResourceLoader} because I'm not sure 
029 * the test harness justifies the extra setup at the moment.  If/when the 
030 * testharness {@link org.kuali.rice.core.framework.resourceloader.SpringResourceLoader} is placed in the {@link GlobalResourceLoader}
031 * this can delegate to that {@link GlobalResourceLoader}.
032 * 
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 *
035 */
036public class TestHarnessServiceLocator {
037
038        private static ConfigurableApplicationContext context;
039        
040        public static final String USER_TRANSACTION = "userTransaction";
041        public static final String TRANSACTON_MANAGER = "transactionManager";
042        public static final String DATA_SOURCE = "dataSource";
043        
044        public static Object getService(String serviceName) {
045                return getContext().getBean(serviceName);
046        }
047        
048        public static DataSource getDataSource() {
049                return (DataSource)getService(DATA_SOURCE);
050        }
051        
052        public static JtaTransactionManager getJtaTransactionManager() {
053                return (JtaTransactionManager)getService(TRANSACTON_MANAGER);
054        }
055        
056        public static UserTransaction getUserTransaction() {
057                return (UserTransaction)getService(USER_TRANSACTION);
058        }
059        
060        public static ConfigurableApplicationContext getContext() {
061                return context;
062        }
063
064        public static void setContext(ConfigurableApplicationContext context) {
065                TestHarnessServiceLocator.context = context;
066        }       
067}