001    /**
002     * Copyright (c) 2000-present 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            @Deprecated
059            @Override
060            protected Statement withAfters(
061                    FrameworkMethod frameworkMethod, Object instance, Statement statement) {
062    
063                    Statement withAftersStatement = super.withAfters(
064                            frameworkMethod, instance, statement);
065    
066                    return new RunAfterTestMethodCallback(
067                            instance, frameworkMethod.getMethod(), withAftersStatement,
068                            _testContextHandler);
069            }
070    
071            @Override
072            protected Statement withBeforeClasses(Statement statement) {
073                    Statement withBeforeClassesStatement = super.withBeforeClasses(
074                            statement);
075    
076                    return new RunBeforeTestClassesCallback(
077                            withBeforeClassesStatement, _testContextHandler);
078            }
079    
080            /**
081             * @deprecated As of 6.2.0
082             */
083            @Deprecated
084            @Override
085            protected Statement withBefores(
086                    FrameworkMethod frameworkMethod, Object instance, Statement statement) {
087    
088                    Statement withBeforesStatement = super.withBefores(
089                            frameworkMethod, instance, statement);
090    
091                    return new RunBeforeTestMethodCallback(
092                            instance, frameworkMethod.getMethod(), withBeforesStatement,
093                            _testContextHandler);
094            }
095    
096            private final TestContextHandler _testContextHandler;
097    
098    }