001 /**
002 * Copyright 2005-2011 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 */
016 package org.kuali.rice.test;
017
018 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
019 import org.springframework.context.ConfigurableApplicationContext;
020 import org.springframework.transaction.jta.JtaTransactionManager;
021
022 import javax.sql.DataSource;
023 import 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 */
036 public 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 }