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