Coverage Report - org.kuali.rice.test.lifecycles.PerTestDataLoaderLifecycle
 
Classes in this File Line Coverage Branch Coverage Complexity
PerTestDataLoaderLifecycle
0%
0/17
0%
0/6
1.75
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.data.PerTestUnitTestData;
 21  
 import org.kuali.rice.test.data.UnitTestData;
 22  
 import org.kuali.rice.test.data.UnitTestDataUtils;
 23  
 
 24  
 import java.lang.reflect.Method;
 25  
 
 26  
 /**
 27  
  * A lifecycle for loading SQL datasets based on the PerSuiteUnitTestData annotation. The individual SQL statements are
 28  
  * loaded first, followed by the statements inside the files (files are loaded sequentially in the order listed in the
 29  
  * annotation).
 30  
  * 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  
 public class PerTestDataLoaderLifecycle implements Lifecycle {
 34  
         private boolean started;
 35  
         private Method method;
 36  
 
 37  0
         public PerTestDataLoaderLifecycle(Method method) {
 38  0
                 this.method = method;
 39  0
         }
 40  
 
 41  
         public boolean isStarted() {
 42  0
                 return started;
 43  
         }
 44  
 
 45  
         public void start() throws Exception {
 46  0
                 if (method.getDeclaringClass().isAnnotationPresent(PerTestUnitTestData.class)) {
 47  0
                         UnitTestData[] data = method.getDeclaringClass().getAnnotation(PerTestUnitTestData.class).value();
 48  0
             UnitTestDataUtils.executeDataLoader(data);
 49  
                 }
 50  0
                 if (method.isAnnotationPresent(UnitTestData.class)) {
 51  0
                         UnitTestData data = method.getAnnotation(UnitTestData.class);
 52  0
             UnitTestDataUtils.executeDataLoader(data);
 53  
                 }
 54  0
                 started = true;
 55  0
         }
 56  
 
 57  
         public void stop() throws Exception {
 58  0
             if (method.getDeclaringClass().isAnnotationPresent(PerTestUnitTestData.class)) {
 59  0
             UnitTestData[] data = method.getDeclaringClass().getAnnotation(PerTestUnitTestData.class).tearDown();
 60  0
             UnitTestDataUtils.executeDataLoader(data);
 61  
         }
 62  0
                 started = false;
 63  0
         }
 64  
 }