Package net.fp.rp

Source Code of net.fp.rp.BaseTestCase

/*
* Copyright (C) 2004 Paul Browne, http://www.firstpartners.net
*
* released under terms of the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org)."
*
* This product includes software developed by the
* Spring Framework Project (http://www.springframework.org)."
*
*/
package net.fp.rp;

import java.io.FileNotFoundException;

import junit.framework.TestCase;
import net.fp.rp.search.mid.global.Config;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.util.Log4jConfigurer;


/**
* Base test class. The base class will responsable for setting the context
* configuration.  In case that a sub-test class need to use a specific
* application context, this must to return in getContextConfigLocation the
* context location to be used
*
* @author Firstpartners.net
* @version 1.1
*/
public abstract class BaseTestCase extends TestCase implements IBaseCase {
    public static final String DEFAULT_CONTEXT_CONFIG_LOCATION = "/appContext.xml";
    private AbstractApplicationContext context;
    private String runningContextDir;

    /**
     * Set-up the test case
     *
     * @throws Exception If an error occur
     */
    protected final void setUp() throws Exception {
        super.setUp();
        //The correct set-up is
        //1. set-up the log4j
        //2. load the context
        //set-up the rp.root context
        System.setProperty( Config.RP_ROOT, "./junit-tests");
        //initialization of the log4j
        try {
            Log4jConfigurer.initLogging( Config.LOG4J_XML );
        }
        catch (FileNotFoundException e ){
            e.printStackTrace(System.out);
        }
        //set the context
        context = new ClassPathXmlApplicationContext(getContextConfigLocation());
        onSetup();
    }

    /**
     * Method which must to be implmented by the subtests in case of  use a
     * specific application context file
     *
     * @return
     */
    public String getContextConfigLocation() {
        return DEFAULT_CONTEXT_CONFIG_LOCATION;
    }

    /**
     * Get the a reference to the loaded context
     *
     * @return
     */
    public AbstractApplicationContext getContext() {
        return context;
    }

    /**
     * Get the current running context directory
     *
     * @return
     */
    public String getContexDir() {
        return runningContextDir;
    }
}
TOP

Related Classes of net.fp.rp.BaseTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.