001/** 002 * Copyright 2005-2014 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 */ 016package org.kuali.rice.test; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.util.ClasspathOrFileResourceLoader; 020 021import java.io.BufferedReader; 022import java.io.InputStreamReader; 023 024/** 025 * A TestCase superclass to be used internally by Rice for tests that need to 026 * load all of the Rice suite-level test data. 027 * 028 * @author Kuali Rice Team (rice.collab@kuali.org) 029 */ 030public abstract class RiceInternalSuiteDataTestCase extends RiceTestCase { 031 private static final String HASH_PREFIX = "#"; 032 private static final String SLASH_PREFIX = "//"; 033 034 /** 035 * Loads the suite test data from the shared DefaultSuiteTestData.sql 036 */ 037 @Override 038 protected void loadSuiteTestData() throws Exception { 039 new SQLDataLoader(getKRADDefaultSuiteTestData(), "/").runSql(); 040 041 //ClassPathResource cpr = new ClassPathResource(getKIMDataLoadOrderFile()); 042 ClasspathOrFileResourceLoader resourceLoader = new ClasspathOrFileResourceLoader(); 043 //BufferedReader reader = new BufferedReader(new FileReader(cpr.getFile())); 044 //BufferedReader reader = new BufferedReader(new FileReader(cpr.getFile())); 045 BufferedReader reader = new BufferedReader(new InputStreamReader(resourceLoader.getResource(getKIMDataLoadOrderFile()).getInputStream())); 046 String line = null; 047 while ((line = reader.readLine()) != null) { 048 if (!StringUtils.isBlank(line) && !line.startsWith(HASH_PREFIX) && !line.startsWith(SLASH_PREFIX)) { 049 try { 050 new SQLDataLoader(getKIMSqlFileBaseLocation() + "/" + line, "/").runSql(); 051 } catch (Exception e) { 052 LOG.error("Exception during loadSuiteTestData: " + e); 053 } 054 } 055 } 056 } 057 058 protected String getKRADDefaultSuiteTestData() { 059 return "classpath:/config/data/DefaultSuiteTestDataKRAD.sql"; 060 } 061 062 protected String getKIMDataLoadOrderFile() { 063 return "classpath:/config/data/KIMDataLoadOrder.txt"; 064 } 065 066 protected String getKIMSqlFileBaseLocation() { 067 return "classpath:/config/data"; 068 } 069}