Make possible to use with Weld rule
andham opened this issue · 1 comments
andham commented
I'm trying to use Weld to get the DataSource resource injected in my bean, utilizing EmbeddedDatabaseRule. It should look something like this (might be typos as I'm trying to strip out unrelated things):
private final EmbeddedDatabaseRule smsProDbRule = EmbeddedDatabaseRule.builder()
.withInitialSqlFromResource("classpath:create_tables.sql").build();
private final WeldInitiator weld = WeldInitiator
.from(WeldInitiator.createWeld().addBeanClass(MyDbBean.class))
.bindResource("java:/jdbc/AppDataSource", dbRule.getDataSource())
.inject(this)
.build();
@Rule
public TestRule chain = RuleChain.outerRule(weld).around(dbRule);
@Inject
MyDbBean bean;
The problem here though is that dbRule.getDataSource() will create a DataSource that has a null connection. Is it possible to somehow make this use case work?
zapodot commented
As the test rules are not initialized before test execution it can not be integrated with weld in that way. In order to get this to work you will need to create a Weld TestRule. As this is not in scope for this library I consider this issue to be resolved