001
014
015 package com.liferay.portal.test.rule;
016
017 import com.liferay.portal.kernel.test.rule.AggregateTestRule;
018 import com.liferay.portal.kernel.test.rule.BaseTestRule;
019 import com.liferay.portal.kernel.test.rule.DeleteAfterTestRunTestRule;
020 import com.liferay.portal.kernel.util.ListUtil;
021 import com.liferay.portal.kernel.util.PropsKeys;
022 import com.liferay.portal.kernel.util.ServerDetector;
023 import com.liferay.portal.test.rule.callback.ClearThreadLocalTestCallback;
024 import com.liferay.portal.test.rule.callback.UniqueStringRandomizerBumperTestCallback;
025 import com.liferay.portal.util.InitUtil;
026 import com.liferay.portal.util.PropsUtil;
027
028 import java.util.List;
029
030 import org.junit.rules.TestRule;
031 import org.junit.runner.Description;
032 import org.junit.runners.model.Statement;
033
034
037 public class LiferayIntegrationTestRule extends AggregateTestRule {
038
039 public LiferayIntegrationTestRule() {
040 super(
041 false, CITimeoutTestRule.INSTANCE, LogAssertionTestRule.INSTANCE,
042 _clearThreadLocalTestRule, _uniqueStringRandomizerBumperTestRule,
043 new DeleteAfterTestRunTestRule());
044 }
045
046 @Override
047 public Statement apply(Statement statement, Description description) {
048 if (!InitUtil.isInitialized()) {
049 ServerDetector.init(ServerDetector.TOMCAT_ID);
050
051 List<String> configLocations = ListUtil.fromArray(
052 PropsUtil.getArray(PropsKeys.SPRING_CONFIGS));
053
054 InitUtil.initWithSpring(configLocations, true);
055
056 if (System.getProperty("external-properties") == null) {
057 System.setProperty(
058 "external-properties", "portal-test.properties");
059 }
060 }
061
062 return super.apply(statement, description);
063 }
064
065 private static final TestRule _clearThreadLocalTestRule =
066 new BaseTestRule<>(ClearThreadLocalTestCallback.INSTANCE);
067 private static final TestRule _uniqueStringRandomizerBumperTestRule =
068 new BaseTestRule<>(UniqueStringRandomizerBumperTestCallback.INSTANCE);
069
070 }