01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.transaction.UserTransaction;
19:
20: import org.kuali.rice.database.XAPoolDataSource;
21: import org.kuali.rice.resourceloader.GlobalResourceLoader;
22: import org.kuali.rice.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 (kuali-rice@googlegroups.com)
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 XAPoolDataSource getDataSource() {
50: return (XAPoolDataSource) 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: }
|