Java 类org.junit.rules.RuleChain 实例源码

项目:pay-adminusers    文件:DropwizardAppWithPostgresRule.java   
public DropwizardAppWithPostgresRule(String configPath, ConfigOverride... configOverrides) {
    configFilePath = resourceFilePath(configPath);
    postgres = new PostgresDockerRule();
    List<ConfigOverride> cfgOverrideList = newArrayList(configOverrides);
    cfgOverrideList.add(config("database.url", postgres.getConnectionUrl()));
    cfgOverrideList.add(config("database.user", postgres.getUsername()));
    cfgOverrideList.add(config("database.password", postgres.getPassword()));

    app = new DropwizardAppRule<>(
            AdminUsersApp.class,
            configFilePath,
            cfgOverrideList.toArray(new ConfigOverride[cfgOverrideList.size()])
    );
    createJpaModule(postgres);
    rules = RuleChain.outerRule(postgres).around(app);
    registerShutdownHook();
}
项目:Camel    文件:ExpectedDeploymentException.java   
private ExpectedDeploymentException() {
    chain = RuleChain
        .outerRule(log)
        .around((base, description) -> new Statement() {
            @Override
            public void evaluate() throws Throwable {
                try {
                    base.evaluate();
                } catch (Throwable exception) {
                    assertThat(exception, allOf(pecs(exceptions)));
                    try {
                        // OpenWebBeans logs the deployment exception details
                        // TODO: OpenWebBeans only log the root cause of exception thrown in producer methods
                        //assertThat(log.getMessages(), containsInRelativeOrder(pecs(messages)))
                        assertThat(log.getMessages(), anyOf(hasItems(messages)));
                    } catch (AssertionError error) {
                        // Weld stores the deployment exception details in the exception message
                        assertThat(exception.getMessage(), allOf(pecs(messages)));
                    }
                }
            }
        });
}
项目:jarspec    文件:ExecutableNode.java   
private Statement executionStatement(final RunNotifier notifier, final int minPriority, final RuleChain ruleChain) {
    return new Statement() {
        @Override
        public void evaluate() {
            RuleChain ongoingRuleChain = withRules(ruleChain, specificationNode.rules());
            if (hasOwnTest(minPriority)) {
                evaluateStatementAndNotifyFailures(
                    ongoingRuleChain,
                    specificationNode.test().get().asStatement(),
                    notifier);
            }
            for(ExecutableNode child : children) {
                child.execute(notifier, minPriority, ongoingRuleChain);
            }
        }
    };
}
项目:camel-cdi    文件:ExpectedDeploymentException.java   
private ExpectedDeploymentException() {
    chain = RuleChain
        .outerRule(log)
        .around((base, description) -> new Statement() {
            @Override
            public void evaluate() {
                try {
                    base.evaluate();
                } catch (Throwable exception) {
                    assertThat(exception, allOf(pecs(exceptions)));
                    try {
                        // OpenWebBeans logs the deployment exception details
                        // TODO: OpenWebBeans only log the root cause of exception thrown in producer methods
                        //assertThat(log.getMessages(), containsInRelativeOrder(pecs(messages)))
                        assertThat(log.getMessages(), anyOf(hasItems(messages)));
                    } catch (AssertionError error) {
                        // Weld stores the deployment exception details in the exception message
                        assertThat(exception.getMessage(), allOf(pecs(messages)));
                    }
                }
            }
        });
}
项目:camunda-bpm-platform    文件:JerseySpecifics.java   
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();
      }
    });
}
项目:camunda-bpm-platform    文件:WinkSpecifics.java   
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();
      }
    });
}
项目:camunda-bpm-platform    文件:JerseySpecifics.java   
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();
      }
    });
}
项目:camunda-bpm-platform    文件:CXFSpecifics.java   
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();
      }
    });
}
项目:camunda-bpm-platform    文件:ResteasySpecifics.java   
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();
      }
    });
}
项目:Lagerta    文件:SingleClusterResource.java   
public static RuleChain getAllResourcesRule(int timeout) {
    if (allResourcesRule == null) {
        allResourcesRule = RuleChain
            .outerRule(new Timeout(timeout))
            .around(CLUSTER_RESOURCE);
    }
    return allResourcesRule;
}
项目:Lagerta    文件:FullClusterTestResourcesFactory.java   
public static RuleChain getAllResourcesRule(int timeout) {
    if (allResourcesRule == null) {
        allResourcesRule = RuleChain
            .outerRule(FOLDER)
            .around(new Timeout(timeout))
            .around(new EmbeddedKafkaRule(FOLDER, "mainKafka", 3, 2181, 9092))
            .around(new EmbeddedKafkaRule(FOLDER, "drKafka", 3, 2182, 9096))
            .around(SUPER_CLUSTER_RESOURCE)
            .around(MAIN_CLUSTER_RESOURCE)
            .around(DR_CLUSTER_RESOURCE);
    }
    return allResourcesRule;
}
项目:willtest    文件:SeleniumRule.java   
/**
 * @param parameterObjects objects wich can be injected into {@link SeleniumProvider} implementations.
 *                         See {@link SeleniumProviderFactory}
 */
public SeleniumRule(ParameterObject... parameterObjects) {
    ParameterObject[] allParameterObjects =
            ArrayUtils.addAll(parameterObjects, new ParameterObject(firefoxConfiguration.getClass(), firefoxConfiguration));

    defaultSeleniumProvider = SeleniumProviderFactory.createSeleniumProviderRule(allParameterObjects);
    defaultSeleniumProvider.addWebDriverConfigurationParticipant(new FileDetectorConfigurator<>());
    defaultSeleniumProvider.addWebDriverConfigurationParticipant(timeoutsConfigurationParticipant);

    DefaultFirefoxConfigurationParticipant<D> defaultFirefoxConfigurationParticipant =
            new DefaultFirefoxConfigurationParticipant<>();
    defaultSeleniumProvider.addWebDriverConfigurationParticipant(defaultFirefoxConfigurationParticipant);
    firefoxConfiguration.addFirefoxConfigurationParticipant(defaultFirefoxConfigurationParticipant);

    JavascriptError<P, D> javascriptErrorRule =
            new JavascriptError<>(defaultSeleniumProvider, false);
    firefoxConfiguration.addFirefoxConfigurationParticipant(javascriptErrorRule);
    WebDriverLog<P, D> webDriverLog = new WebDriverLog<>(defaultSeleniumProvider);
    PageSource pageSource = new PageSource(defaultSeleniumProvider);
    screenshotRule = new ScreenshotRule(defaultSeleniumProvider)
            .setScreenshotProvider(new DefaultScreenshotProvider());
    JavascriptAlert javascriptAlert = new JavascriptAlert(defaultSeleniumProvider);

    ruleChain = RuleChain
            .outerRule(defaultSeleniumProvider)
            .around(webDriverLog)
            .around(pageSource)
            .around(screenshotRule)
            .around(javascriptAlert)
            .around(javascriptErrorRule)
            .around(resourceHelper);
}
项目:willtest    文件:SeleniumRule.java   
@Override
public Statement apply(Statement base, Description description) {
    return RuleChain
            .outerRule(logContext)
            .around(ruleChain)
            .apply(base,description);
}
项目:openregister-java    文件:RegisterRule.java   
public RegisterRule() {
    this.appRule = new DropwizardAppRule<>(RegisterApplication.class,
            ResourceHelpers.resourceFilePath("test-app-config.yaml"));
    wipeRule = new WipeDatabaseRule(TestRegister.values());
    wholeRule = RuleChain
            .outerRule(appRule)
            .around(wipeRule);
}
项目:authrite    文件:SystemDriver.java   
public TestRule rules() {
    if (System.getProperty(ACCTEST_BASEURI_PROPERTY) == null) {
        return RuleChain
                .outerRule(databaseContext.rules())
                .around(appRule);
    } else {
        return new TestRule() {
            @Override
            public Statement apply(final Statement base, final Description description) {
                return base;
            }
        };
    }
}
项目:scenarioo-example-swtbot-e4    文件:BaseSWTBotTest.java   
private RuleChain createRuleChain() {
    RuleChain ruleChain = RuleChain.outerRule(new LogTestStartedAndFinishedTestRule());
    ruleChain = ruleChain.around(new OrderOverviewCleanUpRule());
    ruleChain = appendInnerRules(ruleChain);
    ruleChain = appendInnerMostRules(ruleChain);
    return ruleChain;
}
项目:tool.lars    文件:ResourceFilteringTest.java   
/**
 * Create a RuleChain containing a RepositoryFixture for each of the repositories we are testing against
 *
 * @return a RuleChain
 */
@ClassRule
public static TestRule getClassRule() {
    // Put all the fixtures into one chain rule because we want to set up all the repositories at the start of the test, test with them and tear them down at the end
    RuleChain chain = RuleChain.emptyRuleChain();
    for (RepoData repoData : getRepoDataList()) {
        chain = chain.around(repoData.fixture);
    }
    return chain;
}
项目:logback-access-spring-boot-starter    文件:AbstractTestSpringConfigurationFileAutoDetectingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractForwardHeadersUsingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractSecurityAttributesTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractServerPortUnusingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractFallbackConfigurationFileAutoDetectingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule())
            .around(outputCapture);
}
项目:logback-access-spring-boot-starter    文件:TomcatRequestAttributesDisablingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractMainSpringConfigurationFileAutoDetectingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractSpringProfileTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule())
            .around(outputCapture);
}
项目:logback-access-spring-boot-starter    文件:AbstractSpringPropertyTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule())
            .around(outputCapture);
}
项目:logback-access-spring-boot-starter    文件:AbstractLogbackAccessEventsTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractTestConfigurationFileAutoDetectingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractLogbackAccessFilteringTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:logback-access-spring-boot-starter    文件:AbstractMainConfigurationFileAutoDetectingTest.java   
/**
 * Creates a test rule.
 *
 * @return a test rule.
 */
@Rule
public TestRule rule() {
    return RuleChain
            .outerRule(new LogbackAccessEventQueuingAppenderRule())
            .around(new LogbackAccessEventQueuingListenerRule());
}
项目:atg-tdd    文件:NucleusAwareJunit4ClassRunner.java   
/**
 * Creates a {@link RuleChain} with {@link NucleusWithModules} as the first rule, so 
 * that it gets started before any attempt to load test data, or resolve components. 
 * Subsequent @NucleusWithXXX annotations, used for setting up test data, are added after 
 * {@link NucleusWithModules}, as are {@link NucleusComponent} rules.
 * 
 * @param statement
 * @param testNucleus
 * @return
 */
protected Statement createRuleChain(Statement statement, NucleusRequired testNucleus) {
    List<TestRule> chainedRules = new ArrayList<TestRule>(1);       
    RuleChain chain = RuleChain.outerRule(new NucleusWithModules(testNucleus.modules(), testNucleus.isUseTestConfigLayer(), getTestClass().getJavaClass()));

    for (TestRule dataRule : classDataRules()) {
        chain = chain.around(dataRule);
    }

    chainedRules.add(chain);        
    return new RunRules(statement, chainedRules, getDescription());
}
项目:atg-tdd    文件:NucleusAwareJunit4ClassRunner.java   
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
    @SuppressWarnings("deprecation")
    Statement junitBefores = super.withBefores(method, target, statement);

    List<TestRule> chainedRules = new ArrayList<TestRule>(1);
    RuleChain chain = RuleChain.emptyRuleChain();

    for (TestRule nucleusComponentInjectionRule : nucleusComponenInjectionRules()) {
        chain = chain.around(nucleusComponentInjectionRule);
    }

    chainedRules.add(chain);        
    return new RunRules(junitBefores, chainedRules, getDescription());
}
项目:jarspec    文件:ExecutableNode.java   
private void execute(RunNotifier notifier, int minPriority, RuleChain ruleChain) {
    if (hasOwnTest(minPriority)) {
        notifier.fireTestStarted(description);
    } else if (children.isEmpty()) {
        notifier.fireTestIgnored(description);
        return;
    }
    evaluateStatementAndNotifyFailures(
            withRules(RuleChain.emptyRuleChain(), this.specificationNode.blockRules()),
            executionStatement(notifier, minPriority, ruleChain),
            notifier);
    if (hasOwnTest(minPriority)) {
        notifier.fireTestFinished(description);
    }
}
项目:jarspec    文件:ExecutableNode.java   
private RuleChain withRules(RuleChain ruleChain, Stream<TestRule> rules) {
    // We really just want foldLeft here, but the closest equivalent in the Java 8 Streams API is reduce, which
    // doesn't allow us to assume the stream is sequential, so we implement foldLeft using forEachOrdered.
    // See http://stackoverflow.com/questions/29210176/can-a-collectors-combiner-function-ever-be-used-on-sequential-streams
    final AtomicReference<RuleChain> accumulator = new AtomicReference<>(ruleChain);
    rules.forEachOrdered(rule ->
            accumulator.getAndUpdate(acc -> acc.around(rule))
    );
    return accumulator.get();
}
项目:liquiunit    文件:LiquiunitRule.java   
public static final TestRule newInstance(final Iterable<? extends String> changeLogResourceNames, DataSource dataSource, final String... contexts) {
  if (dataSource == null) {
    dataSource = new H2Rule();
  }
  final LiquiunitRule liquibase = new LiquiunitRule(dataSource, contexts);
  if (changeLogResourceNames != null) {
    liquibase.setChangeLogResourceNames(changeLogResourceNames);
  }    
  if (dataSource instanceof TestRule) {
    return RuleChain.outerRule((TestRule)dataSource).around(liquibase);
  } else {
    return liquibase;
  }
}
项目:liquiunit    文件:TestCaseDataSourceDatabaseTesterRule.java   
public TestCaseDataSourceDatabaseTesterRule() {
  super();
  final H2Rule h2 = new H2Rule();
  final LiquiunitRule liquibase = new LiquiunitRule(h2);
  final DataSourceDatabaseTesterRule dbUnit = new DataSourceDatabaseTesterRule(h2, new H2DataTypeFactory());
  this.rule = RuleChain.outerRule(h2).around(liquibase).around(dbUnit);
}
项目:liquiunit    文件:TestCaseJPARule.java   
public TestCaseJPARule() {
  super();
  final H2Rule h2 = new H2Rule(archive);
  final LiquiunitRule liquibase = new LiquiunitRule(h2);
  final DataSourceDatabaseTesterRule dbUnit = new DataSourceDatabaseTesterRule(h2, new H2DataTypeFactory());
  final TestRule jpaRule = new JPARule(this, "test", h2);
  this.rule = RuleChain.outerRule(h2).around(liquibase).around(dbUnit).around(jpaRule);
}
项目:logging-log4j2    文件:RuleChainFactory.java   
/**
 * 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;
}