Author: aadamchik
Date: Sun Sep 10 15:33:35 2006
New Revision: 442018
URL: http://svn.apache.org/viewvc?view=rev&rev=442018
Log:
extracting common jpa integration tests in the common itest module
Added:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java
- copied, changed from r438515,
incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/JpaTestCase.java
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestDataSourceManager.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestSetup.java
Copied:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java
(from r438515,
incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java)
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java?view=diff&rev=442018&p1=incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java&r1=438515&p2=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java&r2=442018
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/EntityManagerCase.java
Sun Sep 10 15:33:35 2006
@@ -22,7 +22,12 @@
import org.apache.cayenne.jpa.itest.ItestSetup;
-public class EntityManagerCase extends Unit1Case {
+/**
+ * A TestCase superclass that provides an entity manager and transaction
management.
+ *
+ * @author Andrus Adamchik
+ */
+public class EntityManagerCase extends JpaTestCase {
protected EntityManager entityManager;
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestDataSourceManager.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestDataSourceManager.java?view=diff&rev=442018&r1=442017&r2=442018
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestDataSourceManager.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestDataSourceManager.java
Sun Sep 10 15:33:35 2006
@@ -39,11 +39,13 @@
private DataSource dataSource;
private String schemaScriptUrl;
- private String jpaUnit;
+ private String dbName;
- ItestDataSourceManager(String schemaScriptUrl, String jpaUnit) {
+ ItestDataSourceManager(String schemaScriptUrl) {
this.schemaScriptUrl = schemaScriptUrl;
- this.jpaUnit = jpaUnit;
+
+ // create pseudo random DB name
+ this.dbName = "d" + System.currentTimeMillis();
}
public DataSource getDataSource() {
@@ -54,10 +56,6 @@
return dataSource;
}
- String getJpaUnit() {
- return jpaUnit;
- }
-
String getSchemaScriptUrl() {
return schemaScriptUrl;
}
@@ -69,7 +67,7 @@
DataSource dataSource;
try {
dataSource = new PoolManager("org.hsqldb.jdbcDriver",
"jdbc:hsqldb:mem:"
- + jpaUnit, 1, 2, "sa", null);
+ + dbName, 1, 2, "sa", null);
}
catch (SQLException e) {
throw new RuntimeException("Error creating DataSource", e);
@@ -103,6 +101,11 @@
.currentThread()
.getContextClassLoader()
.getResourceAsStream(schemaFile);
+
+ if (in == null) {
+ throw new SQLException("No SQL script found in classpath: " +
schemaFile);
+ }
+
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
try {
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestSetup.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestSetup.java?view=diff&rev=442018&r1=442017&r2=442018
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestSetup.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/ItestSetup.java
Sun Sep 10 15:33:35 2006
@@ -32,19 +32,27 @@
public class ItestSetup {
public static final String SCHEMA_SCRIPT_URL = "itest.schema.script";
+ public static final String DEFAULT_SCHEMA_SCRIPT = "schema-hsqldb.sql";
+
public static final String JPA_UNIT_NAME = "itest.jpa.unit";
+ public static final String DEFAULT_UNIT_NAME = "itest";
private static ItestSetup sharedInstance;
protected EntityManagerFactory sharedFactory;
protected ItestDataSourceManager dataSourceManager;
+ protected String jpaUnit;
public static void initInstance(Properties properties) {
String schemaScript = properties.getProperty(SCHEMA_SCRIPT_URL);
- Assert.assertNotNull("Null schema script", schemaScript);
+ if (schemaScript == null) {
+ schemaScript = DEFAULT_SCHEMA_SCRIPT;
+ }
String jpaUnit = properties.getProperty(JPA_UNIT_NAME);
- Assert.assertNotNull("Null jpaUnit", jpaUnit);
+ if (jpaUnit == null) {
+ jpaUnit = DEFAULT_UNIT_NAME;
+ }
sharedInstance = new ItestSetup(schemaScript, jpaUnit);
}
@@ -58,7 +66,8 @@
}
protected ItestSetup(String schemaScriptUrl, String jpaUnit) {
- this.dataSourceManager = new ItestDataSourceManager(schemaScriptUrl,
jpaUnit);
+ this.jpaUnit = jpaUnit;
+ this.dataSourceManager = new ItestDataSourceManager(schemaScriptUrl);
}
public DataSource getDataSource() {
@@ -79,8 +88,6 @@
"org.apache.cayenne.jpa.jpaDataSourceFactory",
ItestJpaDataSourceFactory.class.getName());
- return Persistence.createEntityManagerFactory(
- dataSourceManager.getJpaUnit(),
- properties);
+ return Persistence.createEntityManagerFactory(jpaUnit, properties);
}
}
Added:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/JpaTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/JpaTestCase.java?view=auto&rev=442018
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/JpaTestCase.java
(added)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/jpa/itest/JpaTestCase.java
Sun Sep 10 15:33:35 2006
@@ -0,0 +1,37 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.cayenne.jpa.itest;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+/**
+ * Abstract test case that bootstraps default JPA unit called "itest" and a
schema script
+ * called "schema-hsqldb.sql".
+ *
+ * @author Andrus Adamchik
+ */
+public abstract class JpaTestCase extends TestCase {
+
+ static {
+ Properties properties = new Properties();
+ ItestSetup.initInstance(properties);
+ }
+}