use of io.dropwizard.jersey.jackson.JacksonMessageBodyProvider in project dropwizard by dropwizard.
the class JerseyIntegrationTest method configure.
@Override
protected Application configure() {
forceSet(TestProperties.CONTAINER_PORT, "0");
final MetricRegistry metricRegistry = new MetricRegistry();
final SessionFactoryFactory factory = new SessionFactoryFactory();
final DataSourceFactory dbConfig = new DataSourceFactory();
final HibernateBundle<?> bundle = mock(HibernateBundle.class);
final Environment environment = mock(Environment.class);
final LifecycleEnvironment lifecycleEnvironment = mock(LifecycleEnvironment.class);
when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
when(environment.metrics()).thenReturn(metricRegistry);
dbConfig.setUrl("jdbc:hsqldb:mem:DbTest-" + System.nanoTime() + "?hsqldb.translate_dti_types=false");
dbConfig.setUser("sa");
dbConfig.setDriverClass("org.hsqldb.jdbcDriver");
dbConfig.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
this.sessionFactory = factory.build(bundle, environment, dbConfig, ImmutableList.of(Person.class));
try (Session session = sessionFactory.openSession()) {
Transaction transaction = session.beginTransaction();
session.createNativeQuery("DROP TABLE people IF EXISTS").executeUpdate();
session.createNativeQuery("CREATE TABLE people (name varchar(100) primary key, email varchar(16), birthday timestamp with time zone)").executeUpdate();
session.createNativeQuery("INSERT INTO people VALUES ('Coda', 'coda@example.com', '1979-01-02 00:22:00+0:00')").executeUpdate();
transaction.commit();
}
final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(new MetricRegistry());
config.register(new UnitOfWorkApplicationListener("hr-db", sessionFactory));
config.register(new PersonResource(new PersonDAO(sessionFactory)));
config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper()));
config.register(new PersistenceExceptionMapper());
config.register(new DataExceptionMapper());
config.register(new EmptyOptionalExceptionMapper());
return config;
}
Aggregations