@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(); }
@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); } }
@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); } }
@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); } }
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; }
@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(); }
public void setup( Class<? extends Application<TestConfiguration>> applicationClass, String configPath, ConfigOverride... configOverrides) { dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass, ResourceHelpers.resourceFilePath(configPath), configOverrides); dropwizardTestSupport.before(); }
/** * 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(); }
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()); } } ); }
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(); }
public final DropwizardTestSupport<DashboardTestConfiguration> getSupport() { return SUPPORT; }
/** * 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(); }