I want to create some integration tests for the following class:
public class MyDao {
@Inject
@Postgres
private DataSource dataSource;
getSomething() {
//do something with dataSource
}
}
I have the qualifier:
@Qualifier
@Target({ TYPE, METHOD, FIELD, PARAMETER })
@Retention(RUNTIME)
public @interface Postgres {
}
And also I have a producer:
public class PostgresDataSourceProducer {
@Resource(mappedName = "java:jboss/PostgresDS")
private DataSource ds;
@Produces
@Postgres
DataSource postgresDataSouce() {
return ds;
}
}
I'm using wildfly 14. Data source was defined in the standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<datasources>
<datasource jta="false" jndi-name="java:jboss/PostgresDS" pool-name="postgres" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://${production.postgres.url}</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql-8.0-310.jdbc3.jar</driver>
<security>
<user-name>${db.username}</user-name>
<password>${db.userpass}</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
</datasources>
</subsystem>
To create integration tests, I will need to change the datasource to point to my test database. How to do that?
Because it'a a legacy code, I'm reserved to switch from @Resource
to @PersistenceContext
.