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 final class UnitTestDataUtils {
28
29 private UnitTestDataUtils() {
30 throw new UnsupportedOperationException("do not call");
31 }
32
33 public static void executeDataLoader(UnitTestData[] data) throws Exception {
34 for (UnitTestData d: data) {
35 executeDataLoader(d);
36 }
37 }
38
39 public static void executeDataLoader(UnitTestData data) throws Exception {
40 SQLDataLoader sqlDataLoader;
41 for (UnitTestData.Type type : data.order()) {
42 switch (type) {
43 case SQL_FILES :
44 for (UnitTestFile file : data.sqlFiles()) {
45 sqlDataLoader = new SQLDataLoader(file.filename(), file.delimiter());
46 sqlDataLoader.runSql();
47 }
48 break;
49 case SQL_STATEMENTS :
50 for (UnitTestSql statement : data.sqlStatements()) {
51 sqlDataLoader = new SQLDataLoader(statement.value());
52 sqlDataLoader.runSql();
53 }
54 break;
55 default: break;
56 }
57 }
58
59 if (!StringUtils.isEmpty(data.filename())) {
60 if (!StringUtils.isEmpty(data.value()))
61 throw new RuntimeException("UnitTestDataArtifact may not specify both SQL file and content");
62 sqlDataLoader = new SQLDataLoader(data.filename(), data.delimiter());
63 sqlDataLoader.runSql();
64 } else if (!StringUtils.isEmpty(data.value())) {
65 sqlDataLoader = new SQLDataLoader(data.value());
66 sqlDataLoader.runSql();
67 }
68 }
69 }