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 */
016package org.kuali.rice.test;
017
018import org.apache.logging.log4j.Level;
019import org.apache.logging.log4j.Logger;
020import org.apache.logging.log4j.LogManager;
021import org.junit.After;
022import org.junit.Before;
023import org.junit.runner.RunWith;
024import org.kuali.rice.test.lifecycles.PerTestDataLoaderLifecycle;
025import org.kuali.rice.test.runners.RiceUnitTestClassRunner;
026
027import java.lang.reflect.Method;
028import java.util.HashMap;
029import java.util.Map;
030
031/**
032 * A generic Rice Unit Test base class.
033 * 
034 * 1) Sets up a generic logger.
035 * 2) Sets the name of the class being run to mimic jUnit 3 functionality.
036 * 3) Stores the name of the method being run for use by subclasses (set by {@link RiceUnitTestClassRunner}
037 * 4) Sets the PerTestDataLoaderLifecycle that will load sql for the currently running test.
038 * 
039 * @author Kuali Rice Team (rice.collab@kuali.org)
040 * @since 0.9
041 */
042@RunWith(RiceUnitTestClassRunner.class)
043public abstract class BaseRiceTestCase implements MethodAware {
044
045        protected final Logger log = LogManager.getLogger(getClass());
046
047        private static final Map<String, Level> changedLogLevels = new HashMap<String, Level>();
048        
049        private String name;
050        private PerTestDataLoaderLifecycle perTestDataLoaderLifecycle;
051        protected Method method;
052
053        public BaseRiceTestCase() {
054                super();
055        }
056
057        public String getName() {
058                return this.name;
059        }
060
061        public void setName(String name) {
062                this.name = name;
063        }
064    
065        @Before
066        public void setUp() throws Exception {
067        }
068        
069    @After
070    public void tearDown() throws Exception {
071        resetLogLevels();
072    }
073    
074
075    protected void setLogLevel(String loggerName, Level newLevel) {
076
077    }
078
079    protected void resetLogLevels() {
080
081    }
082    
083        /**
084         * @see org.kuali.rice.test.MethodAware#setTestMethod(java.lang.reflect.Method)
085         */
086    @Override
087        public void setTestMethod(Method testMethod) {
088        this.method = testMethod;
089
090        perTestDataLoaderLifecycle = new PerTestDataLoaderLifecycle(method);
091    }
092
093    public Method getTestMethod() {
094        return this.method;
095    }
096        
097    protected PerTestDataLoaderLifecycle getPerTestDataLoaderLifecycle() {
098                return this.perTestDataLoaderLifecycle;
099        }
100}