View Javadoc

1   /*
2    * Copyright 2007-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Utilities for unit test data annotations. 
23   * 
24   * @author Kuali Rice Team (rice.collab@kuali.org)
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  }