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