View Javadoc

1   /**
2    * Copyright 2005-2013 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.kim.test;
17  
18  import org.junit.Test;
19  import org.junit.runner.RunWith;
20  import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
21  import org.kuali.rice.core.api.lifecycle.Lifecycle;
22  import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
23  import org.kuali.rice.krad.data.platform.MaxValueIncrementerFactory;
24  import org.kuali.rice.test.BaselineTestCase;
25  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
26  import org.kuali.rice.test.BaselineTestCase.Mode;
27  import org.kuali.rice.test.SQLDataLoader;
28  import org.kuali.rice.test.TestHarnessServiceLocator;
29  import org.kuali.rice.test.lifecycles.KEWXmlDataLoaderLifecycle;
30  import org.kuali.rice.test.runners.BootstrapTest;
31  import org.kuali.rice.test.runners.LoadTimeWeavableTestRunner;
32  
33  import javax.xml.namespace.QName;
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * This is test base that should be used for all KIM unit tests. All non-web unit tests for KIM should extend this base
39   * class.
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @BaselineMode(Mode.ROLLBACK_CLEAR_DB)
44  @RunWith(LoadTimeWeavableTestRunner.class)
45  @BootstrapTest(KIMTestCase.BootstrapTest.class)
46  public abstract class KIMTestCase extends BaselineTestCase {
47  
48  	private static final String KIM_MODULE_NAME = "kim";
49  	
50  	public KIMTestCase() {
51  		super(KIM_MODULE_NAME);
52  	}
53  	
54  	@Override
55  	protected List<Lifecycle> getSuiteLifecycles() {
56  		List<Lifecycle> suiteLifecycles = super.getSuiteLifecycles();
57  		suiteLifecycles.add(new KEWXmlDataLoaderLifecycle("classpath:org/kuali/rice/kim/test/DefaultSuiteTestData.xml"));
58  		return suiteLifecycles;
59  	}
60  	
61  	@Override
62  	protected void loadSuiteTestData() throws Exception {
63  		super.loadSuiteTestData();
64  		new SQLDataLoader("classpath:org/kuali/rice/kim/test/DefaultSuiteTestData.sql", "/").runSql();
65  		new SQLDataLoader("classpath:org/kuali/rice/kim/test/CircularRolesTestData.sql", "/").runSql();
66  		new SQLDataLoader("classpath:org/kuali/rice/kim/test/CircularGroupsTestData.sql", "/").runSql();
67          new SQLDataLoader("classpath:org/kuali/rice/kim/test/DefaultSuiteLDAPTestData.sql", "/").runSql();
68  	}
69  	
70  	@Override
71  	protected Lifecycle getLoadApplicationLifecycle() {
72      	SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("KIMTestHarnessApplicationResourceLoader"), "classpath:KIMTestHarnessSpringBeans.xml", null);
73      	springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
74      	return springResourceLoader;
75  	}
76  	
77  	/**
78  	 * Override the standard per-test lifecycles to prepend ClearDatabaseLifecycle and ClearCacheLifecycle
79  	 * @see org.kuali.rice.test.RiceTestCase#getPerTestLifecycles()
80  	 */
81  	@Override
82  	protected List<Lifecycle> getPerTestLifecycles() {
83  		List<Lifecycle> lifecycles = super.getPerTestLifecycles();
84  		lifecycles.add(new ClearCacheLifecycle());
85  		return lifecycles;
86  	}
87  	
88  	public class ClearCacheLifecycle extends BaseLifecycle {
89  		@Override
90  		public void stop() throws Exception {
91  			//KimApiServiceLocator.getIdentityManagementService().flushAllCaches();
92  			//KimApiServiceLocator.getRoleService().flushRoleCaches();
93  			super.stop();
94  		}
95  
96  	}
97  	
98  	protected List<String> getPerTestTablesNotToClear() {
99  		List<String> tablesNotToClear = new ArrayList<String>();
100 		tablesNotToClear.add("KRIM_.*");
101 		tablesNotToClear.add("KRNS_.*");
102         tablesNotToClear.add("KRCR_.*");
103         tablesNotToClear.add("KREW_.*");
104 		return tablesNotToClear;
105 	}
106 
107 
108 	/**
109      * @see org.kuali.rice.test.RiceTestCase#getModuleName()
110      */
111 	@Override
112 	protected String getModuleName() {
113 		return KIM_MODULE_NAME;
114 	}
115 
116     protected String getNextSequenceStringValue(String sequenceName) {
117         return MaxValueIncrementerFactory.getIncrementer(TestHarnessServiceLocator.getDataSource(), sequenceName).nextStringValue();
118     }
119 
120     public static final class BootstrapTest extends KIMTestCase {
121         @Test
122         public void bootstrapTest() {};
123     }
124 
125 }