io.dropwizard.testing.DropwizardTestSupport Java Examples

The following examples show how to use io.dropwizard.testing.DropwizardTestSupport. 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: GrpcServerTests.java    From dropwizard-grpc with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #2
Source File: TestGuiceyAppExtension.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "checkstyle:Indentation"})
private <C extends Configuration> DropwizardTestSupport<C> create(
        final ExtensionContext context,
        final Class<? extends Application> app,
        final String configPath,
        final String configPrefix,
        final String... overrides) {
    // NOTE: DropwizardTestSupport.ServiceListener listeners would be called ONLY on start!
    return new DropwizardTestSupport<>((Class<? extends Application<C>>) app,
            configPath,
            configPrefix,
            application -> {
                final TestCommand<C> cmd = new TestCommand<>(application);
                // need to hold command itself in order to properly shutdown it later
                getExtensionStore(context).put(TestCommand.class, cmd);
                return cmd;
            },
            ConfigOverrideUtils.convert(configPrefix, overrides));
}
 
Example #3
Source File: TestGuiceyAppExtension.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
protected DropwizardTestSupport<?> prepareTestSupport(final ExtensionContext context) {
    if (config == null) {
        // Configure from annotation
        // Note that it is impossible to have both manually build config and annotation because annotation
        // will be processed first and manual registration will be simply ignored

        final TestGuiceyApp ann = AnnotationSupport
                // also search annotation inside other annotations (meta)
                .findAnnotation(context.getElement(), TestGuiceyApp.class).orElse(null);

        // catch incorrect usage by direct @ExtendWith(...)
        Preconditions.checkNotNull(ann, "%s annotation not declared: can't work without configuration, "
                        + "so either use annotation or extension with @%s for manual configuration",
                TestGuiceyApp.class.getSimpleName(),
                RegisterExtension.class.getSimpleName());
        config = Config.parse(ann);
    }

    HooksUtil.register(config.hooks);

    // config overrides work through system properties so it is important to have unique prefixes
    final String configPrefix = ConfigOverrideUtils.createPrefix(context.getRequiredTestClass());
    return create(context, config.app, config.configPath, configPrefix, config.configOverrides);
}
 
Example #4
Source File: TestParametersSupport.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("checkstyle:ReturnCount")
public Object resolveParameter(final ParameterContext parameterContext,
                               final ExtensionContext extensionContext) throws ParameterResolutionException {
    final Parameter parameter = parameterContext.getParameter();
    final Class<?> type = parameter.getType();
    if (ClientSupport.class.equals(type)) {
        return getClient(extensionContext);
    }
    final DropwizardTestSupport<?> support = Preconditions.checkNotNull(getSupport(extensionContext));
    if (Application.class.isAssignableFrom(type)) {
        return support.getApplication();
    }
    if (ObjectMapper.class.equals(type)) {
        return support.getObjectMapper();
    }
    return InjectorLookup.getInjector(support.getApplication())
            .map(it -> it.getInstance(getKey(parameter)))
            .get();
}
 
Example #5
Source File: DropwizardAppExtension.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected GuiceyInterceptor.EnvironmentSupport buildSupport(final UseDropwizardApp annotation,
                                                            final Class<?> test) {
    return new GuiceyInterceptor.AbstractEnvironmentSupport(test) {
        @Override
        protected DropwizardTestSupport build() {
            final DropwizardTestSupport support = new DropwizardTestSupport(annotation.value(),
                    annotation.config(),
                    buildConfigOverrides(annotation));

            if (annotation.randomPorts()) {
                support.addListener(new RandomPortsListener());
            }

            return support;
        }
    };
}
 
Example #6
Source File: GuiceyExtensionsSupport.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
public void beforeAll(final ExtensionContext context) throws Exception {
    final ExtensionContext.Store store = getExtensionStore(context);
    if (store.get(DW_SUPPORT) == null) {
        final DropwizardTestSupport<?> support = prepareTestSupport(context);
        store.put(DW_SUPPORT, support);
        // for pure guicey tests client may seem redundant, but it can be used for calling other services
        store.put(DW_CLIENT, new ClientSupport(support));

        // find and activate hooks declared in test static fields (impossible to do with an extension)
        activateFieldHooks(context.getRequiredTestClass());

        support.before();
    } else {
        // in case of nested test, beforeAll for root extension will be called second time (because junit keeps
        // only one extension instance!) and this means we should not perform initialization, but we also must
        // prevent afterAll call for this nested test too and so need to store marker value!

        final ExtensionContext.Store localStore = getLocalExtensionStore(context);
        // just in case
        Preconditions.checkState(localStore.get(INHERITED_DW_SUPPORT) == null,
                "Storage assumptions were wrong or unexpected junit usage appear. "
                        + "Please report this case to guicey developer.");
        localStore.put(INHERITED_DW_SUPPORT, true);
    }
}
 
Example #7
Source File: GuiceyExtensionsSupport.java    From dropwizard-guicey with MIT License 6 votes vote down vote up
@Override
public void afterAll(final ExtensionContext context) throws Exception {
    // just in case, normally hooks cleared automatically after appliance
    ConfigurationHooksSupport.reset();

    final ExtensionContext.Store localExtensionStore = getLocalExtensionStore(context);
    if (localExtensionStore.get(INHERITED_DW_SUPPORT) != null) {
        localExtensionStore.remove(INHERITED_DW_SUPPORT);
        // do nothing: extension managed on upper context
        return;
    }

    final DropwizardTestSupport<?> support = getSupport(context);
    if (support != null) {
        support.after();
    }
    final ClientSupport client = getClient(context);
    if (client != null) {
        client.close();
    }
    onShutdown(context);
}
 
Example #8
Source File: GrpcServerTests.java    From dropwizard-grpc with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #9
Source File: GrpcServerTests.java    From dropwizard-grpc with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #10
Source File: DatabaseApplicationTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
DropwizardTestSupport<AppConfiguration> getApp() {
    final String jdbcDriver = getConfig().getOptionalValue("trellis.test.jdbc-driver-class", String.class)
        .orElse("org.h2.Driver");
    final String jdbcUrl = getConfig().getOptionalValue("trellis.test.jdbc-url", String.class)
        .orElseGet(() -> "jdbc:h2:" + resourceFilePath("app-data") + "/database");
    final String jdbcUser = getConfig().getOptionalValue("trellis.test.jdbc-user", String.class)
        .orElse("trellis");
    final String jdbcPassword = getConfig().getOptionalValue("trellis.test.jdbc-password", String.class)
        .orElse("");

    return new DropwizardTestSupport<>(TrellisApplication.class,
            resourceFilePath("trellis-config.yml"),
            config("notifications.type", "JMS"),
            config("notifications.connectionString", "vm://localhost"),
            config("auth.basic.usersFile", resourceFilePath("users.auth")),
            config("database.driverClass", jdbcDriver),
            config("database.url", jdbcUrl),
            config("database.user", jdbcUser),
            config("database.password", jdbcPassword),
            config("binaries", resourceFilePath("app-data") + "/binaries"),
            config("mementos", resourceFilePath("app-data") + "/mementos"),
            config("namespaces", resourceFilePath("app-data/namespaces.json")));
}
 
Example #11
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    rabbitmq = new GenericContainer("rabbitmq:3.7.8-management-alpine").withExposedPorts(5672, 15672);
    rabbitmq.start();

    SealtielConfiguration sealtielConfig = new SealtielConfiguration.Builder()
            .addClients(CLIENT_1, CLIENT_2)
            .rabbitMQConfig(new RabbitMQConfiguration.Builder()
                    .host(rabbitmq.getContainerIpAddress())
                    .port(rabbitmq.getMappedPort(5672))
                    .managementPort(rabbitmq.getMappedPort(15672))
                    .username("guest")
                    .password("guest")
                    .virtualHost("/")
                    .build())
            .build();
    SealtielApplicationConfiguration config = new SealtielApplicationConfiguration(sealtielConfig);
    support = new DropwizardTestSupport<>(SealtielApplication.class, config);
    support.before();
}
 
Example #12
Source File: AbstractApplicationTest.java    From dropwizard-pac4j with Apache License 2.0 5 votes vote down vote up
public void setup(
        Class<? extends Application<TestConfiguration>> applicationClass,
        String configPath, ConfigOverride... configOverrides) {
    dropwizardTestSupport = new DropwizardTestSupport<>(applicationClass,
            ResourceHelpers.resourceFilePath(configPath), configOverrides);
    dropwizardTestSupport.before();
}
 
Example #13
Source File: TestDropwizardAppExtension.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected DropwizardTestSupport<?> prepareTestSupport(final ExtensionContext context) {
    if (config == null) {
        // Configure from annotation
        // Note that it is impossible to have both manually build config and annotation because annotation
        // will be processed first and manual registration will be simply ignored

        final TestDropwizardApp ann = AnnotationSupport
                // also search annotation inside other annotations (meta)
                .findAnnotation(context.getElement(), TestDropwizardApp.class).orElse(null);

        // catch incorrect usage by direct @ExtendWith(...)
        Preconditions.checkNotNull(ann, "%s annotation not declared: can't work without configuration, "
                        + "so either use annotation or extension with @%s for manual configuration",
                TestDropwizardApp.class.getSimpleName(),
                RegisterExtension.class.getSimpleName());

        config = Config.parse(ann);
    }

    HooksUtil.register(config.hooks);

    // config overrides work through system properties so it is important to have unique prefixes
    final String configPrefix = ConfigOverrideUtils.createPrefix(context.getRequiredTestClass());
    final DropwizardTestSupport support = new DropwizardTestSupport(config.app,
            config.configPath,
            configPrefix,
            buildConfigOverrides(configPrefix));

    if (config.randomPorts) {
        support.addListener(new RandomPortsListener());
    }
    return support;
}
 
Example #14
Source File: Utils.java    From dropwizard-grpc with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #15
Source File: RandomPortsListener.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
public void onRun(final Configuration configuration,
                  final Environment environment,
                  final DropwizardTestSupport<Configuration> rule) throws Exception {
    final ServerFactory server = configuration.getServerFactory();
    if (server instanceof SimpleServerFactory) {
        ((HttpConnectorFactory) ((SimpleServerFactory) server).getConnector()).setPort(0);
    } else {
        final DefaultServerFactory dserv = (DefaultServerFactory) server;
        ((HttpConnectorFactory) dserv.getApplicationConnectors().get(0)).setPort(0);
        ((HttpConnectorFactory) dserv.getAdminConnectors().get(0)).setPort(0);
    }
}
 
Example #16
Source File: TriplestoreApplicationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
DropwizardTestSupport<AppConfiguration> getApp() {
    return new DropwizardTestSupport<>(TrellisApplication.class,
            resourceFilePath("trellis-config.yml"),
            config("notifications.type", "JMS"),
            config("notifications.connectionString", "vm://localhost"),
            config("auth.basic.usersFile", resourceFilePath("users.auth")),
            config("database.driverClass", "org.h2.Driver"),
            config("database.url", "jdbc:h2:" + resourceFilePath("app-data") + "/embeddeddb"),
            config("binaries", resourceFilePath("app-data") + "/binaries"),
            config("mementos", resourceFilePath("app-data") + "/mementos"),
            config("resources", resourceFilePath("app-data") + "/resources"),
            config("namespaces", resourceFilePath("app-data/namespaces.json")));
}
 
Example #17
Source File: SundialBundleITBase.java    From dropwizard-sundial with Apache License 2.0 5 votes vote down vote up
public static DropwizardAppExtension<TestConfiguration> buildApp(
    String configFile, final Before before
) {
    return new DropwizardAppExtension<TestConfiguration>(
        new DropwizardTestSupport<TestConfiguration>(
            TestApp.class, ResourceHelpers.resourceFilePath(configFile)
        ) {
            @Override
            public void before() throws Exception {
                super.before();
                before.before(getEnvironment());
            }
        }
    );
}
 
Example #18
Source File: SetUpTest.java    From oxd with Apache License 2.0 5 votes vote down vote up
@Parameters({"host", "opHost", "redirectUrls"})
@BeforeSuite
public static void beforeSuite(String host, String opHost, String redirectUrls) {
    try {
        LOG.debug("Running beforeSuite ...");
        ServerLauncher.setSetUpSuite(true);

        SUPPORT = new DropwizardTestSupport<OxdServerConfiguration>(OxdServerApplication.class,
                ResourceHelpers.resourceFilePath("oxd-server-jenkins.yml"),
                ConfigOverride.config("server.applicationConnectors[0].port", "0") // Optional, if not using a separate testing-specific configuration file, use a randomly selected port
        );
        SUPPORT.before();
        LOG.debug("HTTP server started.");

        removeExistingRps();
        LOG.debug("Existing RPs are removed.");

        RegisterSiteResponse setupClient = SetupClientTest.setupClient(Tester.newClient(host), opHost, redirectUrls);
        Tester.setSetupClient(setupClient, host, opHost);
        LOG.debug("SETUP_CLIENT is set in Tester.");

        Preconditions.checkNotNull(Tester.getAuthorization());
        LOG.debug("Tester's authorization is set.");

        setupSwaggerSuite(Tester.getTargetHost(host), opHost, redirectUrls);
        LOG.debug("Finished beforeSuite!");
    } catch (Exception e) {
        LOG.error("Failed to start suite.", e);
        throw new AssertionError("Failed to start suite.");
    }
}
 
Example #19
Source File: GuiceyAppExtension.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "checkstyle:Indentation"})
private <C extends Configuration> DropwizardTestSupport<C> create(
        final Class<? extends Application> app,
        final String configPath,
        final ConfigOverride... overrides) {
    return new DropwizardTestSupport<C>((Class<? extends Application<C>>) app,
            configPath,
            (String) null,
            application -> {
                command = new TestCommand<>(application);
                return command;
            },
            overrides);
}
 
Example #20
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    DataSourceFactory dbConfig = new DataSourceFactory();
    dbConfig.setDriverClass(Driver.class.getName());
    dbConfig.setUrl("jdbc:h2:mem:./" + URIEL_JDBC_SUFFIX);
    dbConfig.setProperties(ImmutableMap.<String, String>builder()
            .put(DIALECT, H2Dialect.class.getName())
            .put(HBM2DDL_AUTO, "create")
            .put(GENERATE_STATISTICS, "false")
            .build());

    baseDataDir = Files.createTempDirectory("uriel");

    UrielApplicationConfiguration config = new UrielApplicationConfiguration(
            dbConfig,
            WebSecurityConfiguration.DEFAULT,
            new UrielConfiguration.Builder()
                    .baseDataDir(baseDataDir.toString())
                    .jophielConfig(JophielClientConfiguration.DEFAULT)
                    .sandalphonConfig(SandalphonClientConfiguration.DEFAULT)
                    .sealtielConfig(SealtielClientConfiguration.DEFAULT)
                    .gabrielConfig(GabrielClientConfiguration.DEFAULT)
                    .submissionConfig(SubmissionConfiguration.DEFAULT)
                    .fileConfig(FileConfiguration.DEFAULT)
                    .build());

    support = new DropwizardTestSupport<>(UrielApplication.class, config);
    support.before();
}
 
Example #21
Source File: GuiceyExtensionsSupport.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@Override
public void postProcessTestInstance(final Object testInstance, final ExtensionContext context) throws Exception {
    final DropwizardTestSupport<?> support = Preconditions.checkNotNull(getSupport(context));
    final Optional<Injector> injector = InjectorLookup.getInjector(support.getApplication());
    Preconditions.checkState(injector.isPresent(),
            "Can't find guicey injector to process test fields injections");
    injector.get().injectMembers(testInstance);
}
 
Example #22
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    DataSourceFactory dbConfig = new DataSourceFactory();
    dbConfig.setDriverClass(Driver.class.getName());
    dbConfig.setUrl("jdbc:h2:mem:./" + JERAHMEEL_JDBC_SUFFIX);
    dbConfig.setProperties(ImmutableMap.<String, String>builder()
            .put(DIALECT, H2Dialect.class.getName())
            .put(HBM2DDL_AUTO, "create")
            .put(GENERATE_STATISTICS, "false")
            .build());

    baseDataDir = Files.createTempDirectory("jerahmeel");

    JerahmeelApplicationConfiguration config = new JerahmeelApplicationConfiguration(
            dbConfig,
            WebSecurityConfiguration.DEFAULT,
            new JerahmeelConfiguration.Builder()
                    .baseDataDir(baseDataDir.toString())
                    .jophielConfig(JophielClientConfiguration.DEFAULT)
                    .sandalphonConfig(SandalphonClientConfiguration.DEFAULT)
                    .gabrielConfig(GabrielClientConfiguration.DEFAULT)
                    .submissionConfig(SubmissionConfiguration.DEFAULT)
                    .build());

    support = new DropwizardTestSupport<>(JerahmeelApplication.class, config);
    support.before();
}
 
Example #23
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    DataSourceFactory dbConfig = new DataSourceFactory();
    dbConfig.setDriverClass(Driver.class.getName());
    dbConfig.setUrl("jdbc:h2:mem:./" + UUID.randomUUID().toString());
    dbConfig.setProperties(ImmutableMap.<String, String>builder()
            .put(DIALECT, H2Dialect.class.getName())
            .put(HBM2DDL_AUTO, "create")
            .put(GENERATE_STATISTICS, "false")
            .build());

    baseDataDir = Files.createTempDirectory("jophiel");

    JophielConfiguration jophielConfig = new JophielConfiguration.Builder()
            .baseDataDir(baseDataDir.toString())
            .mailerConfig(new MailerConfiguration.Builder()
                    .host("localhost")
                    .port(2500)
                    .useSsl(false)
                    .username("wiser")
                    .password("wiser")
                    .sender("[email protected]")
                    .build())
            .userRegistrationConfig(UserRegistrationConfiguration.DEFAULT)
            .userResetPasswordConfig(UserResetPasswordConfiguration.DEFAULT)
            .userAvatarConfig(UserAvatarConfiguration.DEFAULT)
            .superadminCreatorConfig(SuperadminCreatorConfiguration.DEFAULT)
            .build();

    JophielApplicationConfiguration config = new JophielApplicationConfiguration(
            dbConfig,
            WebSecurityConfiguration.DEFAULT,
            jophielConfig);

    support = new DropwizardTestSupport<>(JophielApplication.class, config);
    support.before();

    adminHeader = AuthHeader.of(createService(SessionService.class)
            .logIn(Credentials.of("superadmin", "superadmin"))
            .getToken());
}
 
Example #24
Source File: GuiceyExtensionsSupport.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
@Override
protected DropwizardTestSupport<?> getSupport(final ExtensionContext extensionContext) {
    return lookupSupport(extensionContext).orElse(null);
}
 
Example #25
Source File: AbstractProxyTest.java    From SeaCloudsPlatform with Apache License 2.0 4 votes vote down vote up
public final DropwizardTestSupport<DashboardTestConfiguration> getSupport() {
    return SUPPORT;
}
 
Example #26
Source File: GuiceyAppExtension.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
@Override
protected DropwizardTestSupport build() {
    return create(annotation.value(),
            annotation.config(),
            convertOverrides(annotation.configOverride()));
}
 
Example #27
Source File: ClientSupport.java    From dropwizard-guicey with MIT License 4 votes vote down vote up
public ClientSupport(final DropwizardTestSupport<?> support) {
    this.support = support;
}
 
Example #28
Source File: HubMetadataFeatureTest.java    From verify-service-provider with MIT License 4 votes vote down vote up
@Before
public void setUp() {
    IdaSamlBootstrap.bootstrap();
    wireMockServer.start();
    msaServer.serveDefaultMetadata();

    KeyStoreResource metadataTrustStore = aKeyStoreResource()
        .withCertificate("VERIFY-FEDERATION", aCertificate().withCertificate(METADATA_SIGNING_A_PUBLIC_CERT).build().getCertificate())
        .build();
    KeyStoreResource hubTrustStore = aKeyStoreResource()
            .withCertificate("VERIFY-HUB", aCertificate().withCertificate(TEST_CORE_CA).build().getCertificate())
            .build();
    KeyStoreResource idpTrustStore = aKeyStoreResource()
            .withCertificate("VERIFY-IDP", aCertificate().withCertificate(TEST_IDP_CA).build().getCertificate())
            .build();

    metadataTrustStore.create();
    hubTrustStore.create();
    idpTrustStore.create();

    applicationTestSupport = new DropwizardTestSupport<>(
        VerifyServiceProviderApplication.class,
        "verify-service-provider.yml",
        config("server.connector.port", "0"),
        config("verifyHubConfiguration.environment", "COMPLIANCE_TOOL"),
        config("verifyHubConfiguration.metadata.uri", getHubMetadataUrl()),
        config("verifyHubConfiguration.metadata.expectedEntityId", HUB_ENTITY_ID),
        config("verifyHubConfiguration.metadata.trustStore.path", metadataTrustStore.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.trustStore.password", metadataTrustStore.getPassword()),
        config("verifyHubConfiguration.metadata.hubTrustStore.path", hubTrustStore.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.hubTrustStore.password", hubTrustStore.getPassword()),
        config("verifyHubConfiguration.metadata.idpTrustStore.path", idpTrustStore.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.idpTrustStore.password", idpTrustStore.getPassword()),
        config("serviceEntityIds", "[\"http://some-service-entity-id\"]"),
        config("samlSigningKey", TEST_RP_PRIVATE_SIGNING_KEY),
        config("samlPrimaryEncryptionKey", TEST_RP_PRIVATE_ENCRYPTION_KEY),
        config("europeanIdentity.enabled", "false"),
        config("europeanIdentity.hubConnectorEntityId", "dummyEntity"),
        config("europeanIdentity.trustAnchorUri", "http://dummy.com"),
        config("europeanIdentity.metadataSourceUri", "http://dummy.com"),
        config("europeanIdentity.trustStore.path", metadataTrustStore.getAbsolutePath()),
        config("europeanIdentity.trustStore.password", metadataTrustStore.getPassword())
    );
}
 
Example #29
Source File: MsaMetadataFeatureTest.java    From verify-service-provider with MIT License 4 votes vote down vote up
@Before
public void setUp() {
    IdaSamlBootstrap.bootstrap();
    wireMockServer.start();
    hubServer.serveDefaultMetadata();

    KeyStoreResource metadataTrustStore = aKeyStoreResource()
            .withCertificate("VERIFY-FEDERATION", aCertificate().withCertificate(METADATA_SIGNING_A_PUBLIC_CERT).build().getCertificate())
            .build();
    KeyStoreResource hubTrustStore = aKeyStoreResource()
            .withCertificate("VERIFY-HUB", aCertificate().withCertificate(TEST_CORE_CA).build().getCertificate())
            .build();
    KeyStoreResource idpTrustStore = aKeyStoreResource()
            .withCertificate("VERIFY-IDP", aCertificate().withCertificate(TEST_IDP_CA).build().getCertificate())
            .build();

    metadataTrustStore.create();
    hubTrustStore.create();
    idpTrustStore.create();

    this.applicationTestSupport = new DropwizardTestSupport<>(
        VerifyServiceProviderApplication.class,
            ResourceHelpers.resourceFilePath("verify-service-provider-with-msa.yml"),
        config("server.connector.port", "0"),
        config("verifyHubConfiguration.metadata.uri", format("http://localhost:%s/SAML2/metadata", hubServer.port())),
        config("msaMetadata.uri", getMsaMetadataUrl()),
        config("verifyHubConfiguration.metadata.expectedEntityId", HUB_ENTITY_ID),
        config("msaMetadata.expectedEntityId", MockMsaServer.MSA_ENTITY_ID),
        config("verifyHubConfiguration.metadata.trustStore.path", metadataTrustStore.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.trustStore.password", metadataTrustStore.getPassword()),
        config("verifyHubConfiguration.metadata.hubTrustStore.path", hubTrustStore.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.hubTrustStore.password", hubTrustStore.getPassword()),
        config("verifyHubConfiguration.metadata.idpTrustStore.path", idpTrustStore.getAbsolutePath()),
        config("verifyHubConfiguration.metadata.idpTrustStore.password", idpTrustStore.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);
    }});
}
 
Example #30
Source File: TestParametersSupport.java    From dropwizard-guicey with MIT License 2 votes vote down vote up
/**
 * @param extensionContext junit extension context
 * @return dropwizard test support object assigned to test instance or null
 */
protected abstract DropwizardTestSupport<?> getSupport(ExtensionContext extensionContext);