Java Code Examples for io.dropwizard.testing.junit.DropwizardAppRule

The following are top voted examples for showing how to use io.dropwizard.testing.junit.DropwizardAppRule. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: pay-adminusers   File: DropwizardAppWithPostgresRule.java   View source code 6 votes vote down vote up
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();
}
 
Example 2
Project: dropwizard-sundial   File: SundialBundleITBase.java   View source code 6 votes vote down vote up
public static int readTimerCount(DropwizardAppRule<TestConfiguration> app, Client client, String timerName) {
    Response response = client.target(
        String.format(
            "http://localhost:%d/%s/metrics",
            app.getAdminPort(), app.getEnvironment().getAdminContext().getContextPath()
        ))
        .request()
        .get();

    assertThat(response.getStatus()).isEqualTo(200);

    JsonNode body = response.readEntity(JsonNode.class);

    if (!body.get("timers").has(timerName)) {
        return 0;
    }
    return body.get("timers").get(timerName).get("count").intValue();
}
 
Example 3
Project: stroom-query   File: AbstractIT.java   View source code 5 votes vote down vote up
protected AbstractIT(final Class<APP_CLASS> appClass,
                     final Class<DOC_REF_ENTITY> docRefEntityClass,
                     final String docRefType) {
    this.appClass = appClass;
    this.appRule =
            new DropwizardAppRule<>(this.appClass, resourceFilePath("config.yml"));

    this.docRefType = docRefType;
    this.docRefEntityClass = docRefEntityClass;
}
 
Example 4
Project: openregister-java   File: RegisterRule.java   View source code 5 votes vote down vote up
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);
}
 
Example 5
Project: coner-core   File: IntegrationTestUtils.java   View source code 5 votes vote down vote up
public static Client buildClient(DropwizardAppRule<ConerCoreConfiguration> appRule,
                                 String clientNamePrefix) {
    Joiner joiner = Joiner.on("-").skipNulls();
    return new JerseyClientBuilder(appRule.getEnvironment())
            .using(appRule.getConfiguration().getJerseyClientConfiguration())
            .build(joiner.join(clientNamePrefix, TEST_CLIENT_NAME));
}
 
Example 6
Project: coner-core   File: IntegrationTestStandardRequestDelegate.java   View source code 5 votes vote down vote up
public IntegrationTestStandardRequestDelegate(
        DropwizardAppRule<ConerCoreConfiguration> rule,
        Client client
) {
    this.rule = rule;
    this.client = client;
}
 
Example 7
Project: dropwizard-sundial   File: SundialBundleITBase.java   View source code 5 votes vote down vote up
public static DropwizardAppRule<TestConfiguration> buildApp(
    String configFile, final Before before
) {
    return new DropwizardAppRule<>(
        new DropwizardTestSupport<TestConfiguration>(
            TestApp.class, ResourceHelpers.resourceFilePath(configFile)
        ) {
            @Override
            public void before() {
                super.before();
                before.before(getEnvironment());
            }
        }
    );
}
 
Example 8
Project: dropwizard-sundial   File: SundialBundleITBase.java   View source code 5 votes vote down vote up
public static void startJob(DropwizardAppRule<TestConfiguration> app, Client client, String jobName) {
    Response response = client.target(
        String.format(
            "http://localhost:%d/%s/tasks/startjob?JOB_NAME=%s",
            app.getAdminPort(), app.getEnvironment().getAdminContext().getContextPath(), jobName
        ))
        .request()
        .post(Entity.text(""));

    assertThat(response.getStatus()).isEqualTo(200);
}
 
Example 9
Project: dropwizard-sundial   File: SundialBundleITBase.java   View source code 5 votes vote down vote up
public static boolean stopJob(DropwizardAppRule<TestConfiguration> app, Client client, String jobName) {
    Response response = client.target(
        String.format(
            "http://localhost:%d/%s/tasks/stopjob?JOB_NAME=%s",
            app.getAdminPort(), app.getEnvironment().getAdminContext().getContextPath(), jobName
        ))
        .request()
        .post(Entity.text(""));

    return response.getStatus() == 200;
}
 
Example 10
Project: coner-core   File: IntegrationTestUtils.java   View source code 5 votes vote down vote up
public static Client buildClient(DropwizardAppRule<ConerCoreConfiguration> appRule,
                                 String clientNamePrefix) {
    Joiner joiner = Joiner.on("-").skipNulls();
    return new JerseyClientBuilder(appRule.getEnvironment())
            .using(appRule.getConfiguration().getJerseyClientConfiguration())
            .build(joiner.join(clientNamePrefix, TEST_CLIENT_NAME));
}
 
Example 11
Project: coner-core   File: IntegrationTestStandardRequestDelegate.java   View source code 5 votes vote down vote up
public IntegrationTestStandardRequestDelegate(
        DropwizardAppRule<ConerCoreConfiguration> rule,
        Client client
) {
    this.rule = rule;
    this.client = client;
}
 
Example 12
Project: tenacity   File: TenacityConfiguredBundleTest.java   View source code 5 votes vote down vote up
private static void validateAppIsRunning(DropwizardAppRule<Configuration> app) {
    final Client client = new JerseyClientBuilder(app.getEnvironment()).build("appOne");
    final Response response = client
            .target(String.format("http://localhost:%d", app.getLocalPort()))
            .request()
            .get();
    assertThat(response.getStatus()).isEqualTo(Response.Status.NO_CONTENT.getStatusCode());

    response.close();
}
 
Example 13
Project: stroom-stats   File: AbstractAppIT.java   View source code 4 votes vote down vote up
public static DropwizardAppRule<Config> getAppRule() {
    return RULE;
}
 
Example 14
Project: jobson   File: SystemTestHelpers.java   View source code 4 votes vote down vote up
public static DropwizardAppRule<ApplicationConfig> createStandardRule() {
    return createStandardRuleWithTemplate("fixtures/systemtests/application-config-template.yml");
}
 
Example 15
Project: jobson   File: SystemTestHelpers.java   View source code 4 votes vote down vote up
public static DropwizardAppRule<ApplicationConfig> createStandardRuleWithTemplate(String fixture) {
    try {
        final Path usersFilePath = Files.createTempFile(SystemTestHelpers.class.getSimpleName(), "user-file");
        final String users = fixture("fixtures/systemtests/users");
        Files.write(usersFilePath, users.getBytes());

        final Path sessionsFilePath = Files.createTempFile(SystemTestHelpers.class.getSimpleName(), "sessions-file");

        final Path jobSpecsDir = Files.createTempDirectory(TestJobSpecsAPI.class.getSimpleName());
        final List<JobSpec> specs =
                Arrays.asList(
                        TestHelpers.YAML_MAPPER.readValue(
                                fixture("fixtures/systemtests/jobspecs.yml"),
                                JobSpec[].class));
        for (JobSpec spec : specs) {
            Files.createDirectory(jobSpecsDir.resolve(spec.getId().toString()));

            final String specYAML = TestHelpers.YAML_MAPPER.writeValueAsString(spec);

            Files.write(jobSpecsDir.resolve(spec.getId().toString()).resolve(Constants.SPEC_DIR_SPEC_FILENAME), specYAML.getBytes());
        }

        // This is used by the second spec
        final String secondSpecScript = fixture("fixtures/systemtests/script.sh");
        Files.write(jobSpecsDir.resolve("second-spec").resolve("script.sh"), secondSpecScript.getBytes());

        final Path jobDataDir = Files.createTempDirectory(SystemTestHelpers.class.getSimpleName());
        final Path workingDirsDir = Files.createTempDirectory(SystemTestHelpers.class.getSimpleName());

        final String resolvedAppConfigText =
                fixture(fixture)
                        .replaceAll("\\$userFile", usersFilePath.toAbsolutePath().toString())
                        .replaceAll("\\$sessionsFile", sessionsFilePath.toAbsolutePath().toString())
                        .replaceAll("\\$jobSpecDir", jobSpecsDir.toAbsolutePath().toString())
                        .replaceAll("\\$jobDataDir", jobDataDir.toAbsolutePath().toString())
                        .replaceAll("\\$workingDirsDir", workingDirsDir.toAbsolutePath().toString());


        final Path resolvedAppConfigPath = Files.createTempFile(TestJobSpecsAPI.class.getSimpleName(), "config");

        Files.write(resolvedAppConfigPath, resolvedAppConfigText.getBytes());

        return new DropwizardAppRule<>(App.class, resolvedAppConfigPath.toString());
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 16
Project: jobson   File: SystemTestHelpers.java   View source code 4 votes vote down vote up
public static Invocation.Builder generateRequest(DropwizardAppRule<ApplicationConfig> rule, String absPath) {
    final String path = String.format("http://localhost:%d" + absPath, rule.getLocalPort());
    return rule.client().target(path).request();
}
 
Example 17
Project: jobson   File: SystemTestHelpers.java   View source code 4 votes vote down vote up
public static Invocation.Builder generateAuthenticatedRequest(DropwizardAppRule<ApplicationConfig> rule, String absPath) {
    final Invocation.Builder ret = generateRequest(rule, absPath);
    authenticate(ret);
    return ret;
}
 
Example 18
Project: verify-service-provider   File: ApplicationConfigurationFeatureTests.java   View source code 4 votes vote down vote up
@Before
public void setUp() {
    KeyStoreResource keyStoreResource = aKeyStoreResource()
        .withCertificate("any-alias", aCertificate().build().getCertificate())
        .build();
    keyStoreResource.create();
    application = new DropwizardAppRule<>(
        VerifyServiceProviderApplication.class,
        "verify-service-provider.yml",
        ConfigOverride.config("logging.loggers.uk\\.gov", "DEBUG"),
        ConfigOverride.config("verifyHubConfiguration.metadata.trustStore.path", keyStoreResource.getAbsolutePath()),
        ConfigOverride.config("verifyHubConfiguration.metadata.trustStore.password", keyStoreResource.getPassword())
    );
}
 
Example 19
Project: keywhiz   File: IntegrationTestRule.java   View source code 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));
}
 
Example 20
Project: coner-core   File: IntegrationTestUtils.java   View source code 4 votes vote down vote up
public static DropwizardAppRule<ConerCoreConfiguration> buildAppRule() {
    return new DropwizardAppRule<>(
            ConerCoreApplication.class,
            ResourceHelpers.resourceFilePath("config/test.yml")
    );
}
 
Example 21
Project: coner-core   File: IntegrationTestUtils.java   View source code 4 votes vote down vote up
public static Client buildClient(DropwizardAppRule<ConerCoreConfiguration> appRule) {
    return buildClient(appRule, null);
}
 
Example 22
Project: coner-core   File: IntegrationTestUtils.java   View source code 4 votes vote down vote up
public static JerseyUriBuilder jerseyUriBuilderForApp(DropwizardAppRule<ConerCoreConfiguration> appRule) {
    return new JerseyUriBuilder()
            .scheme("http")
            .host("localhost")
            .port(appRule.getLocalPort());
}
 
Example 23
Project: dropwizard-cassandra   File: SmokeIntegrationTest.java   View source code 4 votes vote down vote up
public SmokeIntegrationTest(String configPath) {
    this.app = new DropwizardAppRule<>(SmokeTestApp.class, Resources.getResource(configPath).getPath());
}
 
Example 24
Project: coner-core   File: IntegrationTestUtils.java   View source code 4 votes vote down vote up
public static DropwizardAppRule<ConerCoreConfiguration> buildAppRule() {
    return new DropwizardAppRule<>(
            ConerCoreApplication.class,
            ResourceHelpers.resourceFilePath("config/test.yml")
    );
}
 
Example 25
Project: coner-core   File: IntegrationTestUtils.java   View source code 4 votes vote down vote up
public static Client buildClient(DropwizardAppRule<ConerCoreConfiguration> appRule) {
    return buildClient(appRule, null);
}
 
Example 26
Project: coner-core   File: IntegrationTestUtils.java   View source code 4 votes vote down vote up
public static JerseyUriBuilder jerseyUriBuilderForApp(DropwizardAppRule<ConerCoreConfiguration> appRule) {
    return new JerseyUriBuilder()
            .scheme("http")
            .host("localhost")
            .port(appRule.getLocalPort());
}
 
Example 27
Project: timbuctoo   File: DropwizardMaker.java   View source code 4 votes vote down vote up
public static DropwizardAppRule<TimbuctooConfiguration> makeTimbuctoo() {
  return new DropwizardAppRule<>(
    TimbuctooV4.class,
    "example_config.yaml"
  );
}