001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.test;
016    
017    import org.junit.runners.BlockJUnit4ClassRunner;
018    import org.junit.runners.model.FrameworkMethod;
019    import org.junit.runners.model.InitializationError;
020    import org.junit.runners.model.Statement;
021    
022    /**
023     * @author Miguel Pastor
024     */
025    public abstract class AbstractIntegrationJUnitTestRunner
026            extends BlockJUnit4ClassRunner {
027    
028            public AbstractIntegrationJUnitTestRunner(Class<?> clazz)
029                    throws InitializationError {
030    
031                    super(clazz);
032    
033                    initApplicationContext();
034    
035                    if (System.getProperty("external-properties") == null) {
036                            System.setProperty("external-properties", "portal-test.properties");
037                    }
038    
039                    _testContextHandler = new TestContextHandler(clazz);
040            }
041    
042            public abstract void initApplicationContext();
043    
044            @Override
045            protected Statement withAfterClasses(Statement statement) {
046                    Statement withAfterClassesStatement = super.withAfterClasses(statement);
047    
048                    return new RunAfterTestClassesCallback(
049                            withAfterClassesStatement, _testContextHandler);
050            }
051    
052            /**
053             * @deprecated
054             */
055            @Override
056            protected Statement withAfters(
057                    FrameworkMethod frameworkMethod, Object instance, Statement statement) {
058    
059                    Statement withAftersStatement = super.withAfters(
060                            frameworkMethod, instance, statement);
061    
062                    return new RunAfterTestMethodCallback(
063                            instance, frameworkMethod.getMethod(), withAftersStatement,
064                            _testContextHandler);
065            }
066    
067            @Override
068            protected Statement withBeforeClasses(Statement statement) {
069                    Statement withBeforeClassesStatement = super.withBeforeClasses(
070                            statement);
071    
072                    return new RunBeforeTestClassesCallback(
073                            withBeforeClassesStatement, _testContextHandler);
074            }
075    
076            /**
077             * @deprecated
078             */
079            @Override
080            protected Statement withBefores(
081                    FrameworkMethod frameworkMethod, Object instance, Statement statement) {
082    
083                    Statement withBeforesStatement = super.withBefores(
084                            frameworkMethod, instance, statement);
085    
086                    return new RunBeforeTestMethodCallback(
087                            instance, frameworkMethod.getMethod(), withBeforesStatement,
088                            _testContextHandler);
089            }
090    
091            private TestContextHandler _testContextHandler;
092    
093    }