@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { when(environment.jersey()).thenReturn(jerseyEnvironment); when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig()); when(environment.healthChecks()).thenReturn(healthChecks); when(factory.build(eq(bundle), any(Environment.class), any(DataSourceFactory.class), anyList(), eq("hibernate-entitymanager"))).thenReturn(entityManagerFactory); when(sharedEntityManagerFactory.build(any(EntityManagerContext.class))) .thenReturn(sharedEntityManager); }
@BeforeMethod protected void beforeTestCase() throws Exception { singletons.clear(); providers.clear(); features.clear(); properties.clear(); setupResources(); test = new JerseyTest() { @Override protected AppDescriptor configure() { final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(metricRegistry); for (Class<?> provider : providers) config.getClasses().add(provider); for (Map.Entry<String, Boolean> feature : features.entrySet()) config.getFeatures().put(feature.getKey(), feature.getValue()); for (Map.Entry<String, Object> property : properties.entrySet()) config.getProperties().put(property.getKey(), property.getValue()); config.getSingletons().add(new JacksonMessageBodyProvider(objectMapper, validator)); config.getSingletons().addAll(singletons); return new LowLevelAppDescriptor.Builder(config).build(); } }; test.setUp(); }
private static AuthenticationBootstrap createTypicalAuthBootstrap() { final UserDAO userDAO = mock(UserDAO.class); final Server s = new Server(0); final Servlet se = new ServletContainer(); final JerseyEnvironment env = new JerseyEnvironment(new JerseyContainerHolder(se), new DropwizardResourceConfig()); return new AuthenticationBootstrap(env, userDAO); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(LazyParamFeature.class) .register(TestResource.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(OptionParamFeature.class) .register(TestResource.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(ValueMessageBodyWriter.class) .register(EmptyValueExceptionMapper.class) .register(TestResource.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(EitherMessageBodyWriter.class) .register(EmptyValueExceptionMapper.class) .register(TestResource.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(EmptyValueExceptionMapper.class) .register(TestResource.class); }
@Before @SuppressWarnings("unchecked") public void setUp() throws Exception { when(environment.healthChecks()).thenReturn(healthChecks); when(environment.jersey()).thenReturn(jerseyEnvironment); when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig()); when(factory.build(eq(bundle), any(Environment.class), any(DataSourceFactory.class), anyList(), eq("hibernate"))).thenReturn(sessionFactory); }
@Before public void setup() throws Exception { testConfig.shards.setShards(ImmutableList.of(createConfig("1"), createConfig("2"))); when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig()); when(environment.jersey()).thenReturn(jerseyEnvironment); when(environment.lifecycle()).thenReturn(lifecycleEnvironment); when(environment.healthChecks()).thenReturn(healthChecks); }
public void setup() throws Exception { singletons.add(new InternalExceptionMapper()); test = new JerseyTest() { @Override protected TestContainerFactory getTestContainerFactory() throws TestContainerException { return new InMemoryTestContainerFactory(); } @Override protected DeploymentContext configureDeployment() { final DropwizardResourceConfig resourceConfig = new DropwizardResourceConfig(); for (Object singleton : singletons) { resourceConfig.register(singleton); } ServletDeploymentContext deploymentContext = ServletDeploymentContext.builder(resourceConfig) .initParam(ServletProperties.JAXRS_APPLICATION_CLASS, DropwizardResourceConfig.class.getName()) .build(); return deploymentContext; } @Override protected void configureClient(ClientConfig config) { JacksonJsonProvider jsonProvider = new JacksonJsonProvider(); jsonProvider.setMapper(Jackson.newObjectMapper()); config.register(jsonProvider); } }; test.setUp(); }
private void initJerseyAdmin(SoaConfiguration configuration, SoaFeaturesImpl features, Ports ports, final Environment environment, AbstractBinder binder) { if ( (configuration.getAdminJerseyPath() == null) || !ports.adminPort.hasPort() ) { return; } String jerseyRootPath = configuration.getAdminJerseyPath(); if ( !jerseyRootPath.endsWith("/*") ) { if ( jerseyRootPath.endsWith("/") ) { jerseyRootPath += "*"; } else { jerseyRootPath += "/*"; } } DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics()); jerseyConfig.setUrlPattern(jerseyRootPath); JerseyContainerHolder jerseyServletContainer = new JerseyContainerHolder(new ServletContainer(jerseyConfig)); environment.admin().addServlet("soa-admin-jersey", jerseyServletContainer.getContainer()).addMapping(jerseyRootPath); JerseyEnvironment jerseyEnvironment = new JerseyEnvironment(jerseyServletContainer, jerseyConfig); features.putNamed(jerseyEnvironment, JerseyEnvironment.class, SoaFeatures.ADMIN_NAME); jerseyEnvironment.register(SoaApis.class); jerseyEnvironment.register(DiscoveryApis.class); jerseyEnvironment.register(DynamicAttributeApis.class); jerseyEnvironment.register(LoggingApis.class); jerseyEnvironment.register(binder); jerseyEnvironment.setUrlPattern(jerseyConfig.getUrlPattern()); jerseyEnvironment.register(new JacksonMessageBodyProvider(environment.getObjectMapper())); checkCorsFilter(configuration, environment.admin()); checkAdminGuiceFeature(environment, jerseyEnvironment); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(OptionalParamFeature.class) .register(OptionalQueryParamResource.class) .register(MyMessageParamConverterProvider.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(OptionalMessageBodyWriter.class) .register(OptionalReturnResource.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(OptionalParamFeature.class) .register(OptionalCookieParamResource.class) .register(MyMessageParamConverterProvider.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(OptionalParamFeature.class) .register(OptionalFormParamResource.class) .register(MyMessageParamConverterProvider.class); }
@Override protected Application configure() { forceSet(TestProperties.CONTAINER_PORT, "0"); return DropwizardResourceConfig.forTesting(new MetricRegistry()) .register(OptionalParamFeature.class) .register(OptionalHeaderParamResource.class) .register(MyMessageParamConverterProvider.class); }
@Override protected Application configure() { final MetricRegistry metricRegistry = new MetricRegistry(); final DataSourceFactory dbConfig = new DataSourceFactory(); final Environment environment = mock(Environment.class); final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class); when(environment.lifecycle()).thenReturn(lifecycleEnvironment); when(environment.metrics()).thenReturn(metricRegistry); String url = "jdbc:hsqldb:mem:dwtest" + System.nanoTime(); Map<String, String> props = new HashMap<String, String>(); props.put("username", "sa"); props.put("password", ""); props.put("url", url); try { HSQLDBInit.initPublic(props); } catch (Exception e) { throw new RuntimeException(e); } dbConfig.setUrl(props.get("url")); dbConfig.setUser(props.get("user")); dbConfig.setDriverClass("org.hsqldb.jdbcDriver"); dbConfig.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS"); final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(new MetricRegistry()); DataSource dataSource = dbConfig.build(metricRegistry, "jooq"); config.register(JooqTransactionalApplicationListener.class); Configuration configuration = new DefaultConfiguration().set(SQLDialect.HSQLDB); configuration.set(new DataSourceConnectionProvider(dataSource)); config.register(new ConfigurationFactoryProvider.Binder(configuration, dataSource, new TestTenantConnectionProvider(dbConfig, metricRegistry, url))); config.register(ExampleResource.class); config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), Validation.buildDefaultValidatorFactory().getValidator())); return config; }
@Override protected DropwizardResourceConfig getDropwizardResourceConfig() { return new ChainedAuthTestResourceConfig(); }
@Override protected DropwizardResourceConfig getDropwizardResourceConfig() { return new BasicAuthTestResourceConfig(); }
@Override protected DropwizardResourceConfig getDropwizardResourceConfig() { return new OAuthProviderTest.BasicAuthTestResourceConfig(); }
@Override @Context public void run(OdsConfig configuration, Environment environment) { Injector injector = Guice.createInjector( new MonitoringModule(environment.metrics()), new ConfigModule(configuration), new ProcessorModule(), new DbModule(configuration.getCouchDb()), new NotificationsModule(), new DataModule(), new AuthModule(configuration.getAuth())); // start data grabbing environment.lifecycle().manage(injector.getInstance(DataSourceManager.class)); environment.jersey().getResourceConfig().register(MultiPartFeature.class); environment.jersey().getResourceConfig().register(injector.getInstance(AuthBinder.class)); environment.jersey().register(injector.getInstance(DataSourceApi.class)); environment.jersey().register(injector.getInstance(DataApi.class)); environment.jersey().register(injector.getInstance(ProcessorChainApi.class)); environment.jersey().register(injector.getInstance(DataViewApi.class)); environment.jersey().register(injector.getInstance(NotificationApi.class)); environment.jersey().register(injector.getInstance(PluginApi.class)); environment.jersey().register(injector.getInstance(ProcessorSpecificationApi.class)); environment.jersey().register(injector.getInstance(VersionApi.class)); environment.jersey().register(injector.getInstance(UserApi.class)); environment.jersey().register(PropertyFilteringMessageBodyWriter.class); environment.jersey().register(new DbExceptionMapper()); environment.jersey().register(new JsonExceptionMapper()); environment.jersey().register(new UnauthorizedExceptionMapper()); environment.jersey().register(new NotFoundExceptionMapper()); // setup users setupDefaultUsers(injector.getInstance(UserManager.class), configuration.getAuth().getUsers()); // setup health checks environment.healthChecks().register(DbHealthCheck.class.getSimpleName(), injector.getInstance(DbHealthCheck.class)); environment.healthChecks().register(PegelOnlineHealthCheck.class.getSimpleName(), injector.getInstance(PegelOnlineHealthCheck.class)); environment.healthChecks().register(DataSourceHealthCheck.class.getSimpleName(), injector.getInstance(DataSourceHealthCheck.class)); environment.healthChecks().register(FilterChainHealthCheck.class.getSimpleName(), injector.getInstance(FilterChainHealthCheck.class)); environment.healthChecks().register(DataHealthCheck.class.getSimpleName(), injector.getInstance(DataHealthCheck.class)); environment.healthChecks().register(CepsClientHealthCheck.class.getSimpleName(), injector.getInstance(CepsClientHealthCheck.class)); // configure administration DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics()); JerseyContainerHolder jerseyContainerHolder = new JerseyContainerHolder(new ServletContainer(jerseyConfig)); jerseyConfig.register(injector.getInstance(AdminFilterChainApi.class)); environment.admin().addServlet("admin resources", jerseyContainerHolder.getContainer()).addMapping("/admin/*"); // setup validation for external classes HibernateValidatorConfiguration validatorContext = Validation.byProvider(HibernateValidator.class).configure(); ConstraintMapping mapping = validatorContext.createConstraintMapping(); mapping.type(ProcessorReferenceChainDescription.class).constraint(new GenericConstraintDef<>(ValidChainReference.class)); // setup Guice DI for hibernate validator environment.setValidator(validatorContext.addMapping(mapping) .constraintValidatorFactory(new GuiceConstraintValidatorFactory(injector)) .buildValidatorFactory() .getValidator()); }
protected abstract DropwizardResourceConfig getDropwizardResourceConfig();