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(); }
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))); } } } }); }
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); } } }; }
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))); } } } }); }
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(); } }); }
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(); } }); }
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(); } }); }
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(); } }); }
public static RuleChain getAllResourcesRule(int timeout) { if (allResourcesRule == null) { allResourcesRule = RuleChain .outerRule(new Timeout(timeout)) .around(CLUSTER_RESOURCE); } return allResourcesRule; }
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; }
/** * @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); }
@Override public Statement apply(Statement base, Description description) { return RuleChain .outerRule(logContext) .around(ruleChain) .apply(base,description); }
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); }
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; } }; } }
private RuleChain createRuleChain() { RuleChain ruleChain = RuleChain.outerRule(new LogTestStartedAndFinishedTestRule()); ruleChain = ruleChain.around(new OrderOverviewCleanUpRule()); ruleChain = appendInnerRules(ruleChain); ruleChain = appendInnerMostRules(ruleChain); return ruleChain; }
/** * 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; }
/** * Creates a test rule. * * @return a test rule. */ @Rule public TestRule rule() { return RuleChain .outerRule(new LogbackAccessEventQueuingAppenderRule()) .around(new LogbackAccessEventQueuingListenerRule()); }
/** * Creates a test rule. * * @return a test rule. */ @Rule public TestRule rule() { return RuleChain .outerRule(new LogbackAccessEventQueuingAppenderRule()) .around(new LogbackAccessEventQueuingListenerRule()) .around(outputCapture); }
/** * 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()); }
@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()); }
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); } }
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(); }
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; } }
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); }
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); }
/** * 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; }