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 */
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 final class UnitTestDataUtils {
028
029 private UnitTestDataUtils() {
030 throw new UnsupportedOperationException("do not call");
031 }
032
033 public static void executeDataLoader(UnitTestData[] data) throws Exception {
034 for (UnitTestData d: data) {
035 executeDataLoader(d);
036 }
037 }
038
039 public static void executeDataLoader(UnitTestData data) throws Exception {
040 SQLDataLoader sqlDataLoader;
041 for (UnitTestData.Type type : data.order()) {
042 switch (type) {
043 case SQL_FILES :
044 for (UnitTestFile file : data.sqlFiles()) {
045 sqlDataLoader = new SQLDataLoader(file.filename(), file.delimiter());
046 sqlDataLoader.runSql();
047 }
048 break;
049 case SQL_STATEMENTS :
050 for (UnitTestSql statement : data.sqlStatements()) {
051 sqlDataLoader = new SQLDataLoader(statement.value());
052 sqlDataLoader.runSql();
053 }
054 break;
055 default: break;
056 }
057 }
058
059 if (!StringUtils.isEmpty(data.filename())) {
060 if (!StringUtils.isEmpty(data.value()))
061 throw new RuntimeException("UnitTestDataArtifact may not specify both SQL file and content");
062 sqlDataLoader = new SQLDataLoader(data.filename(), data.delimiter());
063 sqlDataLoader.runSql();
064 } else if (!StringUtils.isEmpty(data.value())) {
065 sqlDataLoader = new SQLDataLoader(data.value());
066 sqlDataLoader.runSql();
067 }
068 }
069 }