001 /** 002 * Copyright 2010 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016 package org.kuali.rice.student; 017 018 import java.io.BufferedReader; 019 import java.io.FileReader; 020 import java.util.List; 021 022 import javax.xml.namespace.QName; 023 024 import org.apache.commons.lang.StringUtils; 025 import org.kuali.rice.core.lifecycle.BaseLifecycle; 026 import org.kuali.rice.core.lifecycle.Lifecycle; 027 import org.kuali.rice.core.resourceloader.SpringResourceLoader; 028 import org.kuali.rice.kew.batch.KEWXmlDataLoader; 029 import org.kuali.rice.kew.exception.WorkflowRuntimeException; 030 import org.kuali.rice.kim.service.KIMServiceLocator; 031 import org.kuali.rice.test.BaselineTestCase; 032 import org.kuali.rice.test.SQLDataLoader; 033 034 /** 035 * @author delyea 036 * 037 */ 038 public class StudentStandaloneTestBase extends BaselineTestCase { 039 040 private static final String MODULE_NAME = "standalone"; 041 042 public StudentStandaloneTestBase() { 043 super(MODULE_NAME); 044 } 045 046 /* (non-Javadoc) 047 * @see org.kuali.rice.test.RiceTestCase#getLoadApplicationLifecycle() 048 */ 049 @Override 050 protected Lifecycle getLoadApplicationLifecycle() { 051 SpringResourceLoader springResourceLoader = new SpringResourceLoader(new QName("StudentStandaloneTestResourceLoader"), "classpath:StandaloneTestSpringBeans.xml"); 052 springResourceLoader.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader()); 053 return springResourceLoader; 054 } 055 056 /** 057 * Override the standard per-test lifecycles to prepend ClearDatabaseLifecycle and ClearCacheLifecycle 058 * @see org.kuali.rice.test.RiceTestCase#getPerTestLifecycles() 059 */ 060 @Override 061 protected List<Lifecycle> getPerTestLifecycles() { 062 List<Lifecycle> lifecycles = super.getPerTestLifecycles(); 063 // lifecycles.add(new KEWXmlDataLoaderLifecycle("file:" + getBaseDir() + "/../src/main/config/workflowXml/searchAttributes.xml")); 064 // lifecycles.add(new KEWXmlDataLoaderLifecycle("file:" + getBaseDir() + "/../src/main/config/workflowXml/documentType.xml")); 065 lifecycles.add(new ClearCacheLifecycle()); 066 return lifecycles; 067 } 068 069 public class ClearCacheLifecycle extends BaseLifecycle { 070 public void stop() throws Exception { 071 KIMServiceLocator.getIdentityManagementService().flushAllCaches(); 072 KIMServiceLocator.getRoleManagementService().flushRoleCaches(); 073 super.stop(); 074 } 075 } 076 077 // below method to be removed when moving to Rice 1.0.1 078 @Override 079 protected void loadSuiteTestData() throws Exception { 080 new SQLDataLoader(getKNSDefaultSuiteTestData(), "/").runSql(); 081 BufferedReader reader = null; 082 try{ 083 reader = new BufferedReader(new FileReader(getKIMDataLoadOrderFile())); 084 String line = null; 085 while ((line = reader.readLine()) != null) { 086 if (!StringUtils.isBlank(line)) { 087 new SQLDataLoader(getKIMSqlFileBaseLocation() + "/" + line, "/").runSql(); 088 } 089 } 090 }finally{ 091 if(reader!=null){ 092 reader.close(); 093 } 094 } 095 096 new SQLDataLoader("file:" + getBaseDir() + "/src/main/config/sql/kim.sql", ";").runSql(); 097 } 098 099 protected String getKNSDefaultSuiteTestData() { 100 return "file:" + getBaseDir() + "/src/test/config/data/DefaultSuiteTestDataKNS.sql"; 101 } 102 103 protected String getKIMDataLoadOrderFile() { 104 return getBaseDir() + "/src/test/config/data/KIMDataLoadOrder.txt"; 105 } 106 107 protected String getKIMSqlFileBaseLocation() { 108 return "file:" + getBaseDir() + "/src/test/config/data"; 109 } 110 111 protected void loadXmlFile(String fileName) { 112 try { 113 KEWXmlDataLoader.loadXmlClassLoaderResource(getClass(), fileName); 114 } catch (Exception e) { 115 throw new WorkflowRuntimeException(e); 116 } 117 } 118 119 protected void loadXmlFileFromFileSystem(String fileName) { 120 try { 121 KEWXmlDataLoader.loadXmlFile(fileName); 122 } catch (Exception e) { 123 throw new WorkflowRuntimeException(e); 124 } 125 } 126 127 }