Question

I'm trying to override my Datasource configuration for unit tests as explained here :

But I'm facing some WARNINGs and some properties are not taking into account properly :

Infos - Cannot find the configuration file [conf/openejb.xml].  Will attempt to create one for the beans deployed.
Infos - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
Infos - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
Infos - Configuring Service(id=customDS, type=Resource, provider-id=Default JDBC Database)
Infos - Creating TransactionManager(id=Default Transaction Manager)
Infos - Creating SecurityService(id=Default Security Service)
Infos - Creating Resource(id=customDS)
WARNING - Property "JdbcUsername " not supported by "customDS"
WARNING - Property "JdbcPassword " not supported by "customDS"
WARNING - Property "JdbcUrl " not supported by "customDS"
WARNING - Property "JdbcDriver " not supported by "customDS"

My custom DS is configured like this :

Properties p = new Properties();
// Datasource
p.put("customDS", "new://Resource?type=javax.sql.DataSource");
p.put("customDS.JdbcDriver ", "org.hsqldb.jdbc.JDBCDriver");
p.put("customDS.JdbcUrl ", "jdbc:hsqldb:file:target/custom");
p.put("customDS.JdbcUsername ", "sa");
p.put("customDS.JdbcPassword ", "");
// JPA
p.put("javax.persistence.jtaDataSource", "openejb:Resource/customDS");
// EclipseLink
p.put("competbet.eclipselink.target-database", "org.eclipse.persistence.platform.database.HSQLPlatform");
p.put("competbet.eclipselink.ddl-generation", "create-or-extend-tables");
context = EJBContainer.createEJBContainer(p).getContext();

The non test config works fine :

<resources>
    <Resource id="JTA_Datasource" type="javax.sql.DataSource">
        # http://tomee.apache.org/containers-and-resources.html
        # configure the pool
        DataSourceCreator = ${bd.datasourceCreator}

        # it is a jta datasource
        JtaManaged = true

        # tomcat pool configuration
        driverClassName = ${bd.driver}
        url = ${bd.url}
        username = ${bd.username}
        password = ${bd.password}
        validationQuery = ${bd.validationQuery}

        # specific to tomcat pooling
        jmxEnabled = true
    </Resource>
</resources>

Any idea on how I can get my custom DS jdbc properties working for my unit tests ?

Was it helpful?

Solution

Did you try to remove the space lines from the properties definition?

WARNING - Property "JdbcUsername " not supported by "customDS"
WARNING - Property "JdbcPassword " not supported by "customDS"
WARNING - Property "JdbcUrl " not supported by "customDS"
WARNING - Property "JdbcDriver " not supported by "customDS"

p.put("customDS.JdbcDriver ", "org.hsqldb.jdbc.JDBCDriver");
p.put("customDS.JdbcUrl ", "jdbc:hsqldb:file:target/custom");
p.put("customDS.JdbcUsername ", "sa");
p.put("customDS.JdbcPassword ", "");

I think this should work (without the spaces).

Hope this helps.

EDIT

Maybe its your property defining the datasource:

p.put("customDS", "new://Resource?type=javax.sql.DataSource");

The documentation specifies to look something like this:

p.put("customDS = new://Resource?type", "DataSource");

EDIT

Right properties to use are listed here : http://tomee.apache.org/containers-and-resources.html

p.put("customDS.JdbcDriver", "org.hsqldb.jdbc.JDBCDriver");
p.put("customDS.JdbcUrl", "jdbc:hsqldb:file:target/custom");
p.put("customDS.UserName", "sa");
p.put("customDS.Password", "");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top