001    /**
002     * Copyright (c) 2000-2013 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.runner.manipulation.Sorter;
018    import org.junit.runners.BlockJUnit4ClassRunner;
019    import org.junit.runners.model.FrameworkMethod;
020    import org.junit.runners.model.InitializationError;
021    import org.junit.runners.model.Statement;
022    
023    /**
024     * @author Miguel Pastor
025     */
026    public abstract class AbstractIntegrationJUnitTestRunner
027            extends BlockJUnit4ClassRunner {
028    
029            public AbstractIntegrationJUnitTestRunner(Class<?> clazz)
030                    throws InitializationError {
031    
032                    super(clazz);
033    
034                    initApplicationContext();
035    
036                    if (System.getProperty("external-properties") == null) {
037                            System.setProperty("external-properties", "portal-test.properties");
038                    }
039    
040                    _testContextHandler = new TestContextHandler(clazz);
041    
042                    sort(new Sorter(new DescriptionComparator()));
043            }
044    
045            public abstract void initApplicationContext();
046    
047            @Override
048            protected Statement withAfterClasses(Statement statement) {
049                    Statement withAfterClassesStatement = super.withAfterClasses(statement);
050    
051                    return new RunAfterTestClassesCallback(
052                            withAfterClassesStatement, _testContextHandler);
053            }
054    
055            /**
056             * @deprecated As of 6.2.0
057             */
058            @Override
059            protected Statement withAfters(
060                    FrameworkMethod frameworkMethod, Object instance, Statement statement) {
061    
062                    Statement withAftersStatement = super.withAfters(
063                            frameworkMethod, instance, statement);
064    
065                    return new RunAfterTestMethodCallback(
066                            instance, frameworkMethod.getMethod(), withAftersStatement,
067                            _testContextHandler);
068            }
069    
070            @Override
071            protected Statement withBeforeClasses(Statement statement) {
072                    Statement withBeforeClassesStatement = super.withBeforeClasses(
073                            statement);
074    
075                    return new RunBeforeTestClassesCallback(
076                            withBeforeClassesStatement, _testContextHandler);
077            }
078    
079            /**
080             * @deprecated As of 6.2.0
081             */
082            @Override
083            protected Statement withBefores(
084                    FrameworkMethod frameworkMethod, Object instance, Statement statement) {
085    
086                    Statement withBeforesStatement = super.withBefores(
087                            frameworkMethod, instance, statement);
088    
089                    return new RunBeforeTestMethodCallback(
090                            instance, frameworkMethod.getMethod(), withBeforesStatement,
091                            _testContextHandler);
092            }
093    
094            private TestContextHandler _testContextHandler;
095    
096    }