1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.test.data;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.test.SQLDataLoader;
20
21
22
23
24
25
26
27 public class UnitTestDataUtils {
28
29 public static void executeDataLoader(UnitTestData[] data) throws Exception {
30 for (UnitTestData d: data) {
31 executeDataLoader(d);
32 }
33 }
34
35 public static void executeDataLoader(UnitTestData data) throws Exception {
36 SQLDataLoader sqlDataLoader;
37 for (UnitTestData.Type type : data.order()) {
38 switch (type) {
39 case SQL_FILES :
40 for (UnitTestFile file : data.sqlFiles()) {
41 sqlDataLoader = new SQLDataLoader(file.filename(), file.delimiter());
42 sqlDataLoader.runSql();
43 }
44 break;
45 case SQL_STATEMENTS :
46 for (UnitTestSql statement : data.sqlStatements()) {
47 sqlDataLoader = new SQLDataLoader(statement.value());
48 sqlDataLoader.runSql();
49 }
50 break;
51 default: break;
52 }
53 }
54
55 if (!StringUtils.isEmpty(data.filename())) {
56 if (!StringUtils.isEmpty(data.value()))
57 throw new RuntimeException("UnitTestDataArtifact may not specify both SQL file and content");
58 sqlDataLoader = new SQLDataLoader(data.filename(), data.delimiter());
59 sqlDataLoader.runSql();
60 } else if (!StringUtils.isEmpty(data.value())) {
61 sqlDataLoader = new SQLDataLoader(data.value());
62 sqlDataLoader.runSql();
63 }
64 }
65 }