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 SybaseDumpTransactionLogTestRule.INSTANCE,
043 _clearThreadLocalTestRule, _uniqueStringRandomizerBumperTestRule,
044 new DeleteAfterTestRunTestRule());
045 }
046
047 @Override
048 public Statement apply(Statement statement, Description description) {
049 if (!InitUtil.isInitialized()) {
050 ServerDetector.init(ServerDetector.TOMCAT_ID);
051
052 List<String> configLocations = ListUtil.fromArray(
053 PropsUtil.getArray(PropsKeys.SPRING_CONFIGS));
054
055 InitUtil.initWithSpring(configLocations, true);
056
057 if (System.getProperty("external-properties") == null) {
058 System.setProperty(
059 "external-properties", "portal-test.properties");
060 }
061 }
062
063 return super.apply(statement, description);
064 }
065
066 private static final TestRule _clearThreadLocalTestRule =
067 new BaseTestRule<>(ClearThreadLocalTestCallback.INSTANCE);
068 private static final TestRule _uniqueStringRandomizerBumperTestRule =
069 new BaseTestRule<>(UniqueStringRandomizerBumperTestCallback.INSTANCE);
070
071 }