001 /* 002 * Copyright 2007-2008 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 */ 016 package org.kuali.rice.test.data; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.test.SQLDataLoader; 020 021 /** 022 * Utilities for unit test data annotations. 023 * 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 * 026 */ 027 public class UnitTestDataUtils { 028 029 public static void executeDataLoader(UnitTestData[] data) throws Exception { 030 for (UnitTestData d: data) { 031 executeDataLoader(d); 032 } 033 } 034 035 public static void executeDataLoader(UnitTestData data) throws Exception { 036 SQLDataLoader sqlDataLoader; 037 for (UnitTestData.Type type : data.order()) { 038 switch (type) { 039 case SQL_FILES : 040 for (UnitTestFile file : data.sqlFiles()) { 041 sqlDataLoader = new SQLDataLoader(file.filename(), file.delimiter()); 042 sqlDataLoader.runSql(); 043 } 044 break; 045 case SQL_STATEMENTS : 046 for (UnitTestSql statement : data.sqlStatements()) { 047 sqlDataLoader = new SQLDataLoader(statement.value()); 048 sqlDataLoader.runSql(); 049 } 050 break; 051 default: break; 052 } 053 } 054 055 if (!StringUtils.isEmpty(data.filename())) { 056 if (!StringUtils.isEmpty(data.value())) 057 throw new RuntimeException("UnitTestDataArtifact may not specify both SQL file and content"); 058 sqlDataLoader = new SQLDataLoader(data.filename(), data.delimiter()); 059 sqlDataLoader.runSql(); 060 } else if (!StringUtils.isEmpty(data.value())) { 061 sqlDataLoader = new SQLDataLoader(data.value()); 062 sqlDataLoader.runSql(); 063 } 064 } 065 }