org.junit.rules.RuleChain Java Examples

The following examples show how to use org.junit.rules.RuleChain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResteasySpecifics.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      ResteasyTomcatServerBootstrap bootstrap = new ResteasyTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example #2
Source File: FlutterGuiTestRule.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NotNull
@Override
public Statement apply(final Statement base, final Description description) {
  RuleChain chain = RuleChain.emptyRuleChain()
    .around(new AspectsAgentLogger())
    .around(new LogStartAndStop())
    .around(myRobotTestRule)
    .around(myOuterTimeout) // Rules should be inside this timeout when possible
    .around(new IdeControl(myRobotTestRule::getRobot))
    .around(new BlockReloading())
    .around(new BazelUndeclaredOutputs())
    .around(myLeakCheck)
    .around(new FlutterGuiTestRule.IdeHandling())
    .around(new ScreenshotOnFailure())
    .around(myInnerTimeout);

  // Perf logging currently writes data to the Bazel-specific TEST_UNDECLARED_OUTPUTS_DIR. Skipp logging if running outside of Bazel.
  if (TestUtils.runningFromBazel()) {
    chain = chain.around(new GuiPerfLogger(description));
  }

  return chain.apply(base, description);
}
 
Example #3
Source File: CXFSpecifics.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      TomcatServerBootstrap bootstrap = new CXFTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example #4
Source File: JerseySpecifics.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      TomcatServerBootstrap bootstrap = new JerseyTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example #5
Source File: WinkSpecifics.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      WinkTomcatServerBootstrap bootstrap = new WinkTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example #6
Source File: JerseySpecifics.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public TestRule createTestRule() {
  final TemporaryFolder tempFolder = new TemporaryFolder();

  return RuleChain
    .outerRule(tempFolder)
    .around(new ExternalResource() {

      TomcatServerBootstrap bootstrap = new JerseyTomcatServerBootstrap(webXmlResource);

      protected void before() throws Throwable {
        bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
        bootstrap.start();
      }

      protected void after() {
        bootstrap.stop();
      }
    });
}
 
Example #7
Source File: NonMatchingVerifyServiceProviderAppRule.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return RuleChain.outerRule(verifyMetadataServer)
        .around(trustAnchorServer)
        .around(metadataAggregatorServer)
        .around(super::apply).apply(base, description);
}
 
Example #8
Source File: JdbcAppenderMapMessageDataSourceTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
protected JdbcAppenderMapMessageDataSourceTest(final JdbcRule jdbcRule) {
    // @formatter:off
    this.rules = RuleChain.emptyRuleChain()
            .around(new JndiRule("java:/comp/env/jdbc/TestDataSourceAppender", createMockDataSource()))
            .around(jdbcRule)
            .around(new LoggerContextRule("org/apache/logging/log4j/jdbc/appender/log4j2-data-source-map-message.xml"));
    // @formatter:on
    this.jdbcRule = jdbcRule;
}
 
Example #9
Source File: AbstractJdbcAppenderDataSourceTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
protected AbstractJdbcAppenderDataSourceTest(final JdbcRule jdbcRule) {
    this.rules = RuleChain.emptyRuleChain()
        .around(new JndiRule("java:/comp/env/jdbc/TestDataSourceAppender", createMockDataSource()))
        .around(jdbcRule)
        .around(new LoggerContextRule(
            "org/apache/logging/log4j/jdbc/appender/log4j2-data-source.xml"));
    this.jdbcRule = jdbcRule;
}
 
Example #10
Source File: RandomAccessFileAppenderTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public RandomAccessFileAppenderTest(final String testName, final boolean locationEnabled, final String type) {
    this.init = new LoggerContextRule(testName + type);
    this.logFile = new File("target", testName + ".log");
    this.files = new CleanFiles(this.logFile);
    this.locationEnabled = locationEnabled;
    this.chain = RuleChain.outerRule(files).around(init);
}
 
Example #11
Source File: RuleChainFactory.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link RuleChain} where the rules are evaluated in the order you pass in.
 * 
 * @param testRules
 *            test rules to evaluate
 * @return a new rule chain.
 */
public static RuleChain create(final TestRule... testRules) {
    if (testRules == null || testRules.length == 0) {
        return RuleChain.emptyRuleChain();
    }
    RuleChain ruleChain = RuleChain.outerRule(testRules[0]);
    for (int i = 1; i < testRules.length; i++) {
        ruleChain = ruleChain.around(testRules[i]);
    }
    return ruleChain;
}
 
Example #12
Source File: AggregateGuiceModuleTestRule.java    From james-project with Apache License 2.0 5 votes vote down vote up
private AggregateGuiceModuleTestRule(List<GuiceModuleTestRule> subrule) {
    this.subrule = subrule;
    this.chain = subrule
            .stream()
            .reduce(RuleChain.emptyRuleChain(),
                    RuleChain::around,
                    RuleChain::around);
}
 
Example #13
Source File: AbstractMainConfigurationFileAutoDetectingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #14
Source File: AbstractLogbackAccessFilteringTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #15
Source File: AbstractTestConfigurationFileAutoDetectingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #16
Source File: AbstractSpringPropertyTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule())
            .around(outputCapture);
}
 
Example #17
Source File: MailActionExecuterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Sets up both users and the RuleChain.
 * 
 * @return RuleChain
 */
private static RuleChain setupRuleChain()
{
    BRITISH_USER = new AlfrescoPerson(APP_CONTEXT_INIT, "[email protected]");
    FRENCH_USER = new AlfrescoPerson(APP_CONTEXT_INIT, "[email protected]");
    AUSTRALIAN_USER = new AlfrescoPerson(APP_CONTEXT_INIT, "[email protected]");
    EXTERNAL_USER = new AlfrescoPerson(APP_CONTEXT_INIT, "[email protected]");

    return RuleChain.outerRule(APP_CONTEXT_INIT).around(AUSTRALIAN_USER).around(BRITISH_USER).around(FRENCH_USER).around(EXTERNAL_USER);
}
 
Example #18
Source File: JpaTestRules.java    From nomulus with Apache License 2.0 5 votes vote down vote up
JpaIntegrationWithCoverageRule(JpaIntegrationTestRule integrationTestRule) {
  TestCaseWatcher watcher = new TestCaseWatcher();
  this.ruleChain =
      RuleChain.outerRule(watcher)
          .around(integrationTestRule)
          .around(new JpaEntityCoverage(watcher::getTestClass));
}
 
Example #19
Source File: DynamicConfigIT.java    From terracotta-platform with Apache License 2.0 5 votes vote down vote up
public DynamicConfigIT(Duration testTimeout, Path parentTmpDir) {
  ClusterDefinition clusterDef = getClass().getAnnotation(ClusterDefinition.class);
  this.timeout = testTimeout.toMillis();
  this.rules = RuleChain.emptyRuleChain()
      .around(tmpDir = new TmpDir(parentTmpDir, false))
      .around(angela = new AngelaRule(createConfigurationContext(clusterDef.stripes(), clusterDef.nodesPerStripe()), clusterDef.autoStart(), clusterDef.autoActivate()) {
        @Override
        public void startNode(int stripeId, int nodeId) {
          // let the subclasses control the node startup
          DynamicConfigIT.this.startNode(stripeId, nodeId);
        }
      })
      .around(Timeout.millis(testTimeout.toMillis()))
      .around(new ExtendedTestRule() {
        @Override
        protected void before(Description description) throws Throwable {
          // upload tc logging config, but ONLY IF EXISTS !
          URL tcLoggingConfig = this.getClass().getResource("/tc-logback.xml");
          if (tcLoggingConfig != null) {
            List<TerracottaServer> servers = angela.tsa().getTsaConfigurationContext().getTopology().getServers();
            for (TerracottaServer s : servers) {
              try {
                RemoteFolder folder = angela.tsa().browse(s, "");
                folder.upload("logback-test.xml", tcLoggingConfig);
              } catch (IOException exp) {
                LOGGER.warn("unable to upload logback configuration", exp);
              }
            }
          }
          // wait for server startup if auto-activated
          if (clusterDef.autoStart() && clusterDef.autoActivate()) {
            for (int stripeId = 1; stripeId <= clusterDef.stripes(); stripeId++) {
              waitForActive(stripeId);
              waitForPassives(stripeId);
            }
          }
        }
      });
}
 
Example #20
Source File: AbstractTestSpringConfigurationFileAutoDetectingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #21
Source File: AbstractForwardHeadersUsingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #22
Source File: AbstractSecurityAttributesTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #23
Source File: AbstractServerPortUnusingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #24
Source File: AbstractFallbackConfigurationFileAutoDetectingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule())
            .around(outputCapture);
}
 
Example #25
Source File: AbstractLogbackAccessEventsTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #26
Source File: AbstractSpringProfileTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule())
            .around(outputCapture);
}
 
Example #27
Source File: AbstractMainSpringConfigurationFileAutoDetectingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #28
Source File: TomcatRequestAttributesDisablingTest.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
 
Example #29
Source File: RuleChains.java    From jenkins-build-monitor-plugin with MIT License 4 votes vote down vote up
public static <R extends TestRule> RuleChain chained(List<R> customRules) {
    return chained(RuleChain.emptyRuleChain(), customRules);
}
 
Example #30
Source File: IntegrationTestRule.java    From keywhiz with Apache License 2.0 4 votes vote down vote up
public static RuleChain rule() {
  String configPath = Resources.getResource("keywhiz-test.yaml").getPath();
  return RuleChain
      .outerRule(new MigrationsRule())
      .around(new DropwizardAppRule<>(KeywhizService.class, configPath));
}