io.dropwizard.testing.junit.DropwizardAppRule Java Examples

The following examples show how to use io.dropwizard.testing.junit.DropwizardAppRule. 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: SystemTestHelpers.java    From jobson with Apache License 2.0 5 votes vote down vote up
public static void waitUntilJobTerminates(DropwizardAppRule<ApplicationConfig> rule, JobId jobId) throws InterruptedException {
    int maxAttempts = 50;
    while (maxAttempts-- > 0) {
        final APIJobDetails resp =
                generateAuthenticatedRequest(rule, jobResourceSubpath(jobId)).get().readEntity(APIJobDetails.class);
        if (resp.latestStatus().isFinal()) {
            break;
        } else {
            Thread.sleep(50);
        }
    }

}
 
Example #2
Source File: ApplicationConfigurationFeatureTests.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    application = new DropwizardAppRule<>(
        VerifyServiceProviderApplication.class,
            "verify-service-provider.yml",
        ConfigOverride.config("logging.loggers.uk\\.gov", "DEBUG")
    );
}
 
Example #3
Source File: TenacityConfiguredBundleTest.java    From tenacity with Apache License 2.0 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 #4
Source File: SystemTestHelpers.java    From jobson with Apache License 2.0 4 votes vote down vote up
public static DropwizardAppRule<ApplicationConfig> createStandardRule() {
    return createStandardRuleWithTemplate("fixtures/systemtests/application-config-template.yml");
}
 
Example #5
Source File: SystemTestHelpers.java    From jobson with Apache License 2.0 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());
        }

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

        final String eighthSpecDependency = fixture("fixtures/systemtests/eighth-spec-dependency");
        Files.write(jobSpecsDir.resolve("eighth-spec").resolve("eighth-spec-dependency"), eighthSpecDependency.getBytes());

        final Path jobDataDir = Files.createTempDirectory(SystemTestHelpers.class.getSimpleName());
        final Path workingDirsDir = Paths.get(".").toAbsolutePath().relativize(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.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 #6
Source File: SystemTestHelpers.java    From jobson with Apache License 2.0 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 #7
Source File: SystemTestHelpers.java    From jobson with Apache License 2.0 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 #8
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));
}
 
Example #9
Source File: SmokeIntegrationTest.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
public SmokeIntegrationTest(String configPath) {
    this.app = new DropwizardAppRule<>(SmokeTestApp.class, Resources.getResource(configPath).getPath());
}
 
Example #10
Source File: DropwizardMaker.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
public static DropwizardAppRule<TimbuctooConfiguration> makeTimbuctoo() {
  return new DropwizardAppRule<>(
    TimbuctooV4.class,
    "example_config.yaml"
  );
}