View Javadoc

1   package org.kuali.student.common.test;
2   
3   import org.kuali.rice.core.api.config.property.Config;
4   import org.kuali.rice.core.api.config.property.ConfigContext;
5   import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
6   
7   import java.io.IOException;
8   import java.util.List;
9   
10  /**
11   * Created with IntelliJ IDEA.
12   * User: gtaylor
13   * Date: 11/21/12
14   * Time: 3:08 PM
15   * This class is used to initialize the config context from a spring beans file. It was originally created
16   * to allow us to load Rice validation config files for our validation tests.
17   *
18   * In the spring file create a bean with this name and pass in via spring constructor args a list of
19   * rice config file locations. it will load those into the spring context.
20   */
21  public class KSTestConfigContextLoader {
22  
23      List<String> configLocations = null;
24  
25      public KSTestConfigContextLoader() {
26  
27          Config config = getTestHarnessConfig();
28          ConfigContext.init(config);
29      }
30  
31      public KSTestConfigContextLoader(List<String> configLocations) {
32          this.configLocations = configLocations;
33  
34          Config config = getTestHarnessConfig();
35          ConfigContext.init(config);
36      }
37  
38      protected Config getTestHarnessConfig() {
39          Config config = new JAXBConfigImpl(getConfigLocations(), System.getProperties());
40          try {
41              config.parseConfig();
42          } catch (IOException ex) {
43              throw new RuntimeException(ex);
44          }
45          return config;
46      }
47  
48      /**
49       * Subclasses may override this method to customize the location(s) of the Rice configuration.
50       * By default it is: classpath:META-INF/" + getModuleName().toLowerCase() + "-test-config.xml"
51       *
52       * @return List of config locations to add to this tests config location.
53       */
54      protected List<String> getConfigLocations() {
55          //List<String> configLocations = new ArrayList<String>();
56          //configLocations.add("classpath:META-INF/course-offering-test-config.xml");
57          return configLocations;
58      }
59  
60      public void setConfigLocations(List<String> configLocations){
61          this.configLocations = configLocations;
62      }
63  }
64  
65