/jira-project/jira-functional-tests/jira-func-tests/src/main/java/com/atlassian/jira/functest/framework/FuncTestRuleChain.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core · Java · 62 lines · 56 code · 5 blank · 1 comment · 0 complexity · 2dd19fe68c05a33089a2a0ff2b0aee4b MD5 · raw file

  1. package com.atlassian.jira.functest.framework;
  2. import com.atlassian.jira.functest.rule.BeforeBuildRule;
  3. import com.atlassian.jira.functest.rule.SinceBuildRule;
  4. import com.atlassian.jira.functest.rule.CheckCachesRule;
  5. import com.atlassian.jira.functest.rule.DisableOnboardingRule;
  6. import com.atlassian.jira.functest.rule.EnsureJiraSetupRule;
  7. import com.atlassian.jira.functest.rule.HttpUnitConfigurationRule;
  8. import com.atlassian.jira.functest.rule.InjectFieldsRule;
  9. import com.atlassian.jira.functest.rule.LogTimeRule;
  10. import com.atlassian.jira.functest.rule.LoginAsRule;
  11. import com.atlassian.jira.functest.rule.OutgoingMailTestRule;
  12. import com.atlassian.jira.functest.rule.RestoreDataRule;
  13. import com.atlassian.jira.functest.rule.WebTesterRule;
  14. import com.atlassian.jira.testkit.client.Backdoor;
  15. import com.atlassian.jira.testkit.client.log.FuncTestLogger;
  16. import com.atlassian.jira.testkit.client.log.FuncTestLoggerImpl;
  17. import com.atlassian.jira.testkit.client.xmlbackup.XmlBackupCopier;
  18. import com.atlassian.jira.webtests.util.JIRAEnvironmentData;
  19. import com.google.inject.Guice;
  20. import com.google.inject.Injector;
  21. import org.junit.rules.RuleChain;
  22. import java.util.function.Supplier;
  23. public class FuncTestRuleChain {
  24. public static RuleChain forTest(final Object test) {
  25. final FuncTestWebClientListener webClientListener = new FuncTestWebClientListener();
  26. final BackdoorModule backdoorModule = new BackdoorModule();
  27. final Supplier<FuncTestWebClientListener> clientListenerSupplier = () -> webClientListener;
  28. final Supplier<JIRAEnvironmentData> environmentDataSupplier = backdoorModule::getEnvironmentData;
  29. final WebTesterRule webTesterRule = new WebTesterRule(environmentDataSupplier, clientListenerSupplier);
  30. final Injector injector = Guice.createInjector(
  31. webTesterRule,
  32. backdoorModule,
  33. binder -> binder.bind(FuncTestLogger.class).toProvider(() -> new FuncTestLoggerImpl(3)),
  34. binder -> binder.bind(XmlBackupCopier.class).toProvider(() -> new XmlBackupCopier(backdoorModule.getEnvironmentData().getBaseUrl()))
  35. );
  36. final Supplier<Backdoor> testkitSupplier = injector.getProvider(Backdoor.class)::get;
  37. final Supplier<Navigation> navigationSupplier = injector.getProvider(Navigation.class)::get;
  38. return RuleChain
  39. .emptyRuleChain()
  40. .around(new SinceBuildRule(backdoorModule))
  41. .around(new BeforeBuildRule(backdoorModule))
  42. .around(new LogTimeRule(environmentDataSupplier, clientListenerSupplier, testkitSupplier))
  43. .around(new EnsureJiraSetupRule(backdoorModule, environmentDataSupplier, () -> {
  44. //we need to initialize jwebunit just to click trough setup process
  45. HttpUnitConfigurationRule.restoreDefaults();
  46. return new WebTesterRule(environmentDataSupplier, clientListenerSupplier).get();
  47. }))
  48. .around(new RestoreDataRule(backdoorModule))
  49. .around(new DisableOnboardingRule(backdoorModule))
  50. .around(new HttpUnitConfigurationRule())
  51. .around(webTesterRule)
  52. .around(new OutgoingMailTestRule(backdoorModule))
  53. .around(new LoginAsRule(navigationSupplier))
  54. .around(new CheckCachesRule(backdoorModule))
  55. .around(new InjectFieldsRule(injector, test));
  56. }
  57. }