001 /* 002 * Copyright 2007 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in 005 * compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.opensource.org/licenses/ecl2.php 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS 010 * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 011 * language governing permissions and limitations under the License. 012 */ 013 package org.kuali.rice.test.lifecycles; 014 015 import org.kuali.rice.core.api.lifecycle.Lifecycle; 016 import org.kuali.rice.test.RiceTestCase; 017 import org.kuali.rice.test.data.PerSuiteUnitTestData; 018 import org.kuali.rice.test.data.UnitTestData; 019 import org.kuali.rice.test.data.UnitTestDataUtils; 020 021 /** 022 * A lifecycle for loading SQL datasets based on the PerSuiteUnitTestData annotation. The individual SQL statements are 023 * loaded first, followed by the statements inside the files (files are loaded sequentially in the order listed in the 024 * annotation). 025 * 026 * @author Kuali Rice Team (rice.collab@kuali.org) 027 */ 028 public class PerSuiteDataLoaderLifecycle implements Lifecycle { 029 private boolean started; 030 031 private Class<? extends RiceTestCase> annotatedClass; 032 033 public PerSuiteDataLoaderLifecycle(Class<? extends RiceTestCase> annotatedClass) { 034 this.annotatedClass = annotatedClass; 035 } 036 037 public boolean isStarted() { 038 return started; 039 } 040 041 public void start() throws Exception { 042 if (annotatedClass.isAnnotationPresent(PerSuiteUnitTestData.class)) { 043 UnitTestData[] data = annotatedClass.getAnnotation(PerSuiteUnitTestData.class).value(); 044 UnitTestDataUtils.executeDataLoader(data); 045 } 046 started = true; 047 } 048 049 public void stop() throws Exception { 050 started = false; 051 } 052 053 }