View Javadoc
1   /**
2    * Copyright 2005-2014 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.lifecycles;
17  
18  import org.kuali.rice.core.api.lifecycle.Lifecycle;
19  import org.kuali.rice.core.api.lifecycle.Lifecycle;
20  import org.kuali.rice.test.RiceTestCase;
21  import org.kuali.rice.test.data.PerSuiteUnitTestData;
22  import org.kuali.rice.test.data.UnitTestData;
23  import org.kuali.rice.test.data.UnitTestDataUtils;
24  
25  /**
26   * A lifecycle for loading SQL datasets based on the PerSuiteUnitTestData annotation. The individual SQL statements are
27   * loaded first, followed by the statements inside the files (files are loaded sequentially in the order listed in the
28   * annotation).
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class PerSuiteDataLoaderLifecycle implements Lifecycle {
33  	private boolean started;
34  
35  	private Class<? extends RiceTestCase> annotatedClass;
36  
37  	public PerSuiteDataLoaderLifecycle(Class<? extends RiceTestCase> annotatedClass) {
38  		this.annotatedClass = annotatedClass;
39  	}
40  
41  	public boolean isStarted() {
42  		return started;
43  	}
44  
45  	public void start() throws Exception {
46  		if (annotatedClass.isAnnotationPresent(PerSuiteUnitTestData.class)) {
47  			UnitTestData[] data = annotatedClass.getAnnotation(PerSuiteUnitTestData.class).value();
48              UnitTestDataUtils.executeDataLoader(data);
49  		}
50  		started = true;
51  	}
52  
53  	public void stop() throws Exception {
54  		started = false;
55  	}
56  
57  }