java ee - OpenEJB - configuring datasource for JUnit -
i have problem proper configuration of datasource openejb 3.1.3. try configure connection postgres db, hen debug test default hsql connection parameters.
here test class:
@runwith(applicationcomposer.class) public class openejbtest { @ejb files fb; @test public void teststh() { list<uploadsession> uploadnotfinishedsessions = fb.getuploadnotfinishedsessions(); } @module public ejbjar beans() { ejbjar ejbjar = new ejbjar("beans"); ejbjar.addenterprisebean(new statelessbean(filesbean.class)); ejbjar.addenterprisebean(new statelessbean(filesutilbean.class)); ejbjar.addenterprisebean(new statelessbean(serverfilesbean.class)); ejbjar.addenterprisebean(new statelessbean(userutilbean.class)); return ejbjar; } @module public persistenceunit persistence() { persistenceunit unit = new persistenceunit("postgrespu", hibernatepersistence.class.getname()); string simplexml = simplexmlutil.tosimplexml(unit); system.out.println(simplexml); unit.setjtadatasource("postgresds"); unit.setnonjtadatasource("postgresdsunmanaged"); return unit; } } i tried to:
- add jndi.properties classpath:
postgrespu=new://resource?type=datasource postgrespu.jdbcdriver=org.postgresql.driver postgrespu.jdbcurl=jdbc:postgresql:/localhost:5433/pdb postgrespu.jtamanaged=true postgrespu.defaultautocommit=false postgrespu.username=...
- configure datasources via openejb.xml (located on classpath)
<resource id="postgresds" type="datasource"> jdbcdriver org.postgresql.driver jdbcurl jdbc:postgresql://localhost:5433/pdb username user password pass jtamanaged true </resource> <resource id="postgresdsunmanaged" type="datasource"> jdbcdriver org.postgresql.driver jdbcurl jdbc:postgresql://localhost:5433/pdb username user password pass jtamanaged false </resource>
but neither of works - datasources not being configured @ all, default version of datasource remains. because of default hsql connection following bug:
warn - sql error: -22, sqlstate: s0002 error - table not found in statement [select top ? user0_.id col_0_0_ tusers user0_ user0_.login=?] what possibly doing wrong?
the applicationcomposer doesn't use jndi bootstrap container jndi.properties file never seen.
what can instead use org.apache.openejb.junit.configuration annotation on method have return properties want use configure test.
@configuration public properties properties() { //... } i'd rename jndi.properties else isn't confusing, can use code find in classpath.
final url url = this.getclass().getresource("/config.properties"); final properties props = new properties(); final inputstream in = url.openstream(); try { props.load(in); } { close(in); }
Comments
Post a Comment