View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  /**
17   * 
18   */
19  package org.kuali.rice.student;
20  
21  import java.io.BufferedReader;
22  import java.io.FileReader;
23  import java.util.List;
24  
25  import javax.xml.namespace.QName;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.rice.core.lifecycle.BaseLifecycle;
29  import org.kuali.rice.core.lifecycle.Lifecycle;
30  import org.kuali.rice.core.resourceloader.SpringResourceLoader;
31  import org.kuali.rice.kew.batch.KEWXmlDataLoader;
32  import org.kuali.rice.kew.exception.WorkflowRuntimeException;
33  import org.kuali.rice.kim.service.KIMServiceLocator;
34  import org.kuali.rice.test.BaselineTestCase;
35  import org.kuali.rice.test.SQLDataLoader;
36  
37  /**
38   * @author delyea
39   *
40   */
41  public class StudentStandaloneTestBase extends BaselineTestCase {
42  
43      private static final String MODULE_NAME = "standalone";
44  
45      public StudentStandaloneTestBase() {
46          super(MODULE_NAME);
47      }
48  
49      /* (non-Javadoc)
50       * @see org.kuali.rice.test.RiceTestCase#getLoadApplicationLifecycle()
51       */
52      @Override
53      protected Lifecycle getLoadApplicationLifecycle() {
54          SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("StudentStandaloneTestResourceLoader"), "classpath:StandaloneTestSpringBeans.xml");
55          springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
56          return springResourceLoader;
57      }
58  
59  	/**
60  	 * Override the standard per-test lifecycles to prepend ClearDatabaseLifecycle and ClearCacheLifecycle
61  	 * @see org.kuali.rice.test.RiceTestCase#getPerTestLifecycles()
62  	 */
63  	@Override
64  	protected List<Lifecycle> getPerTestLifecycles() {
65  		List<Lifecycle> lifecycles = super.getPerTestLifecycles();
66  //		lifecycles.add(new KEWXmlDataLoaderLifecycle("file:" + getBaseDir() + "/../src/main/config/workflowXml/searchAttributes.xml"));
67  //		lifecycles.add(new KEWXmlDataLoaderLifecycle("file:" + getBaseDir() + "/../src/main/config/workflowXml/documentType.xml"));
68  		lifecycles.add(new ClearCacheLifecycle());
69  		return lifecycles;
70  	}
71  	
72  	public class ClearCacheLifecycle extends BaseLifecycle {
73  		public void stop() throws Exception {
74  			KIMServiceLocator.getIdentityManagementService().flushAllCaches();
75  			KIMServiceLocator.getRoleManagementService().flushRoleCaches();
76  			super.stop();
77  		}
78  	}
79  	
80  	// below method to be removed when moving to Rice 1.0.1
81  	@Override
82  	protected void loadSuiteTestData() throws Exception {
83  		new SQLDataLoader(getKNSDefaultSuiteTestData(), "/").runSql();
84  		BufferedReader reader = new BufferedReader(new FileReader(getKIMDataLoadOrderFile()));
85  		String line = null;
86  		while ((line = reader.readLine()) != null) {
87  			if (!StringUtils.isBlank(line)) {
88  				new SQLDataLoader(getKIMSqlFileBaseLocation() + "/" + line, "/").runSql();
89  			}
90  		}
91  		new SQLDataLoader("file:" + getBaseDir() + "/../src/main/config/sql/kim.sql", ";").runSql();
92  	}
93  	
94      protected String getKNSDefaultSuiteTestData() {
95          return "file:" + getBaseDir() + "/../src/test/config/data/DefaultSuiteTestDataKNS.sql";
96      }
97  
98      protected String getKIMDataLoadOrderFile() {
99          return getBaseDir() + "/../src/test/config/data/KIMDataLoadOrder.txt";
100     }
101 
102     protected String getKIMSqlFileBaseLocation() {
103         return "file:" + getBaseDir() + "/../src/test/config/data";
104     }
105 
106 	protected void loadXmlFile(String fileName) {
107 		try {
108 			KEWXmlDataLoader.loadXmlClassLoaderResource(getClass(), fileName);
109 		} catch (Exception e) {
110 			throw new WorkflowRuntimeException(e);
111 		}
112 	}
113 
114 	protected void loadXmlFileFromFileSystem(String fileName) {
115 		try {
116 			KEWXmlDataLoader.loadXmlFile(fileName);
117 		} catch (Exception e) {
118 			throw new WorkflowRuntimeException(e);
119 		}
120 	}
121 
122 }