小さな REST アプリケーションをテストするために、Jersey の InMemoryTestContainer を使用しています。今、データソース オブジェクトを作成し、以下のようstart()
にInMemoryTestContainerのコンテキストにバインドしています。
@Override
public void start() {
if (!webApp.isInitiated()) {
logger.info("Starting low level InMemory test container");
try {
//Create datasource and bind it
initDataSource();
} catch (ClassNotFoundException | NamingException e) {
e.printStackTrace();
}
webApp.initiate(resourceConfig, new GuiceComponentProviderFactory(resourceConfig, injector) {
@Override
public Map<Scope, ComponentScope> createScopeMap() {
Map<Scope, ComponentScope> m = super.createScopeMap();
m.put(ServletScopes.REQUEST, ComponentScope.PerRequest);
return m;
}
});
}
}
tomcat では、context.xml に情報を入力してデータソースを作成します。InMemoryTestContainer でそのような標準的な方法はありますか?