001    /**
002     * Copyright 2005-2014 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.core.test;
017    
018    import java.lang.annotation.Documented;
019    import java.lang.annotation.ElementType;
020    import java.lang.annotation.Inherited;
021    import java.lang.annotation.Retention;
022    import java.lang.annotation.RetentionPolicy;
023    import java.lang.annotation.Target;
024    
025    import org.junit.After;
026    import org.junit.Before;
027    import org.junit.BeforeClass;
028    import org.junit.Test;
029    import org.kuali.rice.core.api.lifecycle.BaseLifecycle;
030    import org.kuali.rice.test.BaselineTestCase;
031    import org.kuali.rice.test.ClearDatabaseLifecycle;
032    import org.kuali.rice.test.data.PerSuiteUnitTestData;
033    import org.kuali.rice.test.data.PerTestUnitTestData;
034    import org.kuali.rice.test.data.UnitTestData;
035    
036    import static org.junit.Assert.assertNotNull;
037    import static org.junit.Assert.fail;
038    
039    /**
040     * DataLoaderAnnotationOverrideTest is used to test the annotation data entry provided by {@link UnitTestData}, {@link PerTestUnitTestData}, and {@link PerSuiteUnitTestData}
041     * 
042     * @author Kuali Rice Team (rice.collab@kuali.org)
043     *
044     */
045    @PerSuiteUnitTestData(
046            overrideSuperClasses = true,
047            value = {@UnitTestData("insert into " + AnnotationTestParent.TEST_TABLE_NAME + " (COL) values ('3')"),
048            @UnitTestData(filename = "classpath:org/kuali/rice/test/DataLoaderAnnotationTestData.sql")
049    })
050    //@BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
051    @DataLoaderAnnotationOverrideTest.Nothing
052    public class DataLoaderAnnotationOverrideTest extends AnnotationTestParent {
053        // a dummy annotation to test that data loading annotations work in presence of
054        // other annotations
055        @Documented
056        @Target({ElementType.TYPE, ElementType.METHOD})
057        @Retention(RetentionPolicy.RUNTIME)
058        @Inherited
059        public static @interface Nothing {
060        }
061    
062        @Override
063        protected void setUpInternal() throws Exception {
064            try{
065                resetDb();
066            } catch (Exception e) {
067               // Will error of db not previously loaded, ignore reset error
068            }
069            super.setUpInternal();
070        }
071    
072        @Test public void testParentAndSubClassImplementation() throws Exception {
073            // verify that the sql only ran once...
074    
075            // check sql statement from this class
076            verifyCount("3", 1, "https://jira.kuali.org/browse/KULRICE-9283");
077    
078            // check sql file from this class
079            verifyCount("4", 1);
080    
081            // check sql statement from parent class
082            verifyNonExistent("1");
083    
084            // check sql file from parent class
085            verifyNonExistent("2");
086    
087        }
088    
089    }