X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=test%2Fenterprise%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fsupport%2Fpersistence%2FJpaTester.java;h=e74003f126276fc162cfd0085639c873724111cc;hb=c63e76e400f06f51ba235b9e6658bfa3149c1d48;hp=694d46cfa2524eb9238b244720f6719131672df5;hpb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;p=utils diff --git a/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java b/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java index 694d46cf..e74003f1 100644 --- a/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java +++ b/test/enterprise/src/main/java/org/wamblee/support/persistence/JpaTester.java @@ -1,8 +1,26 @@ +/* + * Copyright 2005-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.wamblee.support.persistence; +import javax.naming.InitialContext; +import javax.naming.NamingException; import javax.sql.DataSource; import org.dbunit.IDatabaseTester; +import org.wamblee.support.jndi.StubInitialContextFactory; /** * This class is the entry point for JPA tests. Test code should construct a @@ -65,18 +83,23 @@ public class JpaTester { public void start() throws Exception { db = DatabaseBuilder.getDatabase(); dataSource = db.start(); + + // NOTE: adding datasource to JNDI is no longer needed for + // JPA testing, but is nice to have available for other uses. + StubInitialContextFactory.register(); + try { + InitialContext ctx = new InitialContext(); + ctx.bind(persistenceUnit.getJndiName(), dataSource); + } catch (NamingException e) { + throw new RuntimeException("JNDI problem", e); + } - dbUtils = new DatabaseUtils(dataSource, persistenceUnit.getTables()); - dbUtils.dropTables(); + dbUtils = new DatabaseUtils(dataSource); + dbUtils.start(); dbUtils.dropTables(JpaCustomizerBuilder.getCustomizer().getJpaTables()); - jpaBuilder = new JpaBuilder(dataSource, persistenceUnit); + jpaBuilder = new JpaBuilder(db.getJdbcUrl(), db.getUsername(), db.getPassword(), persistenceUnit); jpaBuilder.start(); - - // db tester should be created after Jpa builder because jpa builder - // creates the - // tables that the tester looks at when it is initialized. - dbTester = dbUtils.createDbTester(); } /** @@ -86,6 +109,9 @@ public class JpaTester { if (jpaBuilder != null) { jpaBuilder.stop(); } + if (dbUtils != null) { + dbUtils.stop(); + } if (db != null) { db.stop(); } @@ -99,10 +125,6 @@ public class JpaTester { return dataSource; } - public IDatabaseTester getDbTester() { - return dbTester; - } - public DatabaseUtils getDbUtils() { return dbUtils; }