Java 类io.dropwizard.testing.DropwizardTestSupport 实例源码

项目:verify-service-provider    文件:HubMetadataFeatureTest.java   
@Before
public void setUp() {
    KeyStoreResource verifyHubKeystoreResource = aKeyStoreResource()
        .withCertificate("VERIFY-FEDERATION", aCertificate().withCertificate(METADATA_SIGNING_A_PUBLIC_CERT).build().getCertificate())
        .build();
    verifyHubKeystoreResource.create();
    applicationTestSupport = new DropwizardTestSupport<>(
        VerifyServiceProviderApplication.class,
        "verify-service-provider.yml",
        config("verifyHubConfiguration.environment", "COMPLIANCE_TOOL"),
        config("verifyHubConfiguration.metadata.uri", () -> String.format("http://localhost:%s/SAML2/metadata", wireMockServer.port())),
        config("msaMetadata.uri", msaServer::getUri),
        config("msaMetadata.expectedEntityId", MockMsaServer.MSA_ENTITY_ID),
        config("verifyHubConfiguration.metadata.expectedEntityId", HUB_ENTITY_ID),
        config("verifyHubConfiguration.metadata.trustStore.path", verifyHubKeystoreResource.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.trustStore.password", verifyHubKeystoreResource.getPassword()),
        config("serviceEntityIds", "[\"http://some-service-entity-id\"]"),
        config("samlSigningKey", TEST_RP_PRIVATE_SIGNING_KEY),
        config("samlPrimaryEncryptionKey", TEST_RP_PRIVATE_ENCRYPTION_KEY)
    );

    IdaSamlBootstrap.bootstrap();
    wireMockServer.start();
    msaServer.serveDefaultMetadata();
}
项目:dropwizard-grpc    文件:GrpcServerTests.java   
@Test
public void createsPlainTextServer() throws Exception {
    final DropwizardTestSupport<TestConfiguration> testSupport =
            new DropwizardTestSupport<>(TestApplication.class, resourceFilePath("grpc-test-config.yaml"));

    ManagedChannel channel = null;
    try {
        testSupport.before();
        channel = createPlaintextChannel(testSupport);
        final PersonServiceGrpc.PersonServiceBlockingStub client = PersonServiceGrpc.newBlockingStub(channel);

        final GetPersonResponse resp =
                client.getPerson(GetPersonRequest.newBuilder().setName(TEST_PERSON_NAME).build());
        assertEquals(TEST_PERSON_NAME, resp.getPerson().getName());
    } finally {
        testSupport.after();
        shutdownChannel(channel);
    }
}
项目:dropwizard-grpc    文件:GrpcServerTests.java   
@Test
public void createsServerWithTls() throws Exception {
    final DropwizardTestSupport<TestConfiguration> testSupport = new DropwizardTestSupport<>(TestApplication.class,
        resourceFilePath("grpc-test-config.yaml"), Optional.empty(),
        ConfigOverride.config("grpcServer.certChainFile", getURIForResource("cert/server.crt")),
        ConfigOverride.config("grpcServer.privateKeyFile", getURIForResource("cert/server.key")));

    ManagedChannel channel = null;
    try {
        testSupport.before();
        channel = createClientChannelForEncryptedServer(testSupport);
        final PersonServiceGrpc.PersonServiceBlockingStub client = PersonServiceGrpc.newBlockingStub(channel);

        final GetPersonResponse resp =
                client.getPerson(GetPersonRequest.newBuilder().setName(TEST_PERSON_NAME).build());
        assertEquals(TEST_PERSON_NAME, resp.getPerson().getName());
    } finally {
        testSupport.after();
        shutdownChannel(channel);
    }
}
项目:dropwizard-grpc    文件:GrpcServerTests.java   
@Test
public void grpcServerGetsStopped() {
    final DropwizardTestSupport<TestConfiguration> testSupport =
            new DropwizardTestSupport<>(TestApplication.class, resourceFilePath("grpc-test-config.yaml"));

    ManagedChannel channel = null;
    try {
        testSupport.before();
        channel = createPlaintextChannel(testSupport);
        final PersonServiceGrpc.PersonServiceBlockingStub client = PersonServiceGrpc.newBlockingStub(channel);

        testSupport.after();

        try {
            // this should fail as the server is now stopped
            client.getPerson(GetPersonRequest.newBuilder().setName("blah").build());
            fail("Request should have failed.");
        } catch (final Exception e) {
            assertEquals(StatusRuntimeException.class, e.getClass());
            assertEquals(Code.UNAVAILABLE, ((StatusRuntimeException) e).getStatus().getCode());
        }
    } finally {
        testSupport.after();
        shutdownChannel(channel);
    }
}
项目:atam4j    文件:Atam4jApplicationStarter.java   
public static DropwizardTestSupport<ApplicationConfiguration> startApplicationWith(
        int initialDelayInMillis, Class testClass, int periodInMillis) {

    ConfigOverride[] configOverrides = {
        ConfigOverride.config("testClasses", testClass.getName()),
        ConfigOverride.config("initialDelayInMillis", String.valueOf(initialDelayInMillis)),
        ConfigOverride.config("periodInMillis", String.valueOf(periodInMillis))
    };

    DropwizardTestSupport<ApplicationConfiguration> applicationConfigurationDropwizardTestSupport =
            new DropwizardTestSupport<>(Atam4jTestApplication.class,
                    ResourceHelpers.resourceFilePath("atam4j-config.yml"),
                    configOverrides);

    applicationConfigurationDropwizardTestSupport.before();
    return applicationConfigurationDropwizardTestSupport;
}
项目:verify-service-provider    文件:MsaMetadataFeatureTest.java   
@Before
public void setUp() {
    KeyStoreResource verifyHubKeystoreResource = aKeyStoreResource()
        .withCertificate("VERIFY-FEDERATION", aCertificate().withCertificate(METADATA_SIGNING_A_PUBLIC_CERT).build().getCertificate())
        .build();
    verifyHubKeystoreResource.create();
    this.applicationTestSupport = new DropwizardTestSupport<>(
        VerifyServiceProviderApplication.class,
        "verify-service-provider.yml",
        config("verifyHubConfiguration.metadata.uri", () -> String.format("http://localhost:%s/SAML2/metadata", hubServer.port())),
        config("msaMetadata.uri", () -> String.format("http://localhost:%s/matching-service/metadata", wireMockServer.port())),
        config("verifyHubConfiguration.metadata.expectedEntityId", HUB_ENTITY_ID),
        config("msaMetadata.expectedEntityId", MockMsaServer.MSA_ENTITY_ID),
        config("verifyHubConfiguration.metadata.trustStore.path", verifyHubKeystoreResource.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.trustStore.password", verifyHubKeystoreResource.getPassword())
    );

    environmentHelper.setEnv(new HashMap<String, String>() {{
        put("VERIFY_ENVIRONMENT", "COMPLIANCE_TOOL");
        put("MSA_METADATA_URL", "some-msa-metadata-url");
        put("MSA_ENTITY_ID", "some-msa-entity-id");
        put("SERVICE_ENTITY_IDS", "[\"http://some-service-entity-id\"]");
        put("SAML_SIGNING_KEY", TEST_RP_PRIVATE_SIGNING_KEY);
        put("SAML_PRIMARY_ENCRYPTION_KEY", TEST_RP_PRIVATE_ENCRYPTION_KEY);
    }});

    IdaSamlBootstrap.bootstrap();
    wireMockServer.start();
    hubServer.serveDefaultMetadata();
}
项目:dropwizard-pac4j    文件:AbstractApplicationTest.java   
public void setup(
        Class<? extends Application<TestConfiguration>> applicationClass,
        String configPath, ConfigOverride... configOverrides) {
    dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass,
            ResourceHelpers.resourceFilePath(configPath), configOverrides);
    dropwizardTestSupport.before();
}
项目:dropwizard-grpc    文件:Utils.java   
/**
 * Creates a <code>ManagedChannel</code> connecting to an <b>encrypted</b> gRPC server in
 * <code>TestApplication</code> in <code>testSupport</code>. The certificate is taken from the
 * <code>GrpcServerFactory</code> in the configuration.
 *
 * @param testSupport the already initialised (started) <code>DropwizardTestSupport</code> instance
 * @return the channel connecting to the server (to be used in a client)
 */
public static ManagedChannel createClientChannelForEncryptedServer(
        final DropwizardTestSupport<TestConfiguration> testSupport) throws SSLException {
    final SslContext sslContext = GrpcSslContexts.forClient()
        .trustManager(testSupport.getConfiguration().getGrpcServerFactory().getCertChainFile().toFile()).build();
    final TestApplication application = testSupport.getApplication();
    return NettyChannelBuilder.forAddress("localhost", application.getServer().getPort()).sslContext(sslContext)
        .overrideAuthority("grpc-dropwizard.example.com").build();
}
项目:dropwizard-sundial    文件:SundialBundleITBase.java   
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());
            }
        }
    );
}
项目:dropwizard-entitymanager    文件:AbstractIntegrationTest.java   
protected void setup(Class<? extends Application<TestConfiguration>> applicationClass) {
    dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath("integration-test.yaml"),
            ConfigOverride.config("dataSource.url", "jdbc:hsqldb:mem:DbTest" + System.nanoTime() + "?hsqldb.translate_dti_types=false"));
    dropwizardTestSupport.before();
}
项目:SeaCloudsPlatform    文件:AbstractProxyTest.java   
public final DropwizardTestSupport<DashboardTestConfiguration> getSupport() {
    return SUPPORT;
}
项目:dropwizard-grpc    文件:Utils.java   
/**
 * Creates a <code>ManagedChannel</code> connecting to the <b>plaintext</b> gRPC server in
 * <code>TestApplication</code> in <code>testSupport</code>.
 *
 * @param testSupport the already initialised (started) <code>DropwizardTestSupport</code> instance
 * @return the channel connecting to the server (to be used in a client)
 */
public static ManagedChannel createPlaintextChannel(final DropwizardTestSupport<TestConfiguration> testSupport) {
    final TestApplication application = testSupport.getApplication();
    return ManagedChannelBuilder.forAddress("localhost", application.getServer().getPort()).usePlaintext(true)
        .build();
}