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