Author: aadamchik
Date: Tue Oct 10 11:16:53 2006
New Revision: 454858
URL: http://svn.apache.org/viewvc?view=rev&rev=454858
Log:
refactoring itests for better support of JPA vs. Cayenne POJO tests
Added:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java
- copied, changed from r454776,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestDBUtils.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ResultSetTemplate.java
- copied, changed from r454776,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ResultSetTemplate.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java
- copied, changed from r454776,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/RowTemplate.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java
- copied, changed from r454801,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestSetup.java
Removed:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestSetup.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestDBUtils.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ResultSetTemplate.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/RowTemplate.java
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestSetup.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoTestCase.java
Copied:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java
(from r454776,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestDBUtils.java)
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java?view=diff&rev=454858&p1=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestDBUtils.java&r1=454776&p2=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestDBUtils.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestDBUtils.java
Tue Oct 10 11:16:53 2006
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.itest.jpa;
+package org.apache.cayenne.itest;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -26,12 +26,25 @@
import java.sql.Time;
import java.sql.Timestamp;
+import javax.sql.DataSource;
+
+/**
+ * JDBC utilities for integration testing that bypass Cayenne for DB access.
+ *
+ * @author Andrus Adamchik
+ */
public class ItestDBUtils {
+ protected DataSource dataSource;
+
+ public ItestDBUtils(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
+
/**
* Inserts a single row.
*/
- public static void insert(String table, String[] columns, Object[] values)
+ public void insert(String table, String[] columns, Object[] values)
throws SQLException {
if (columns.length != values.length) {
@@ -79,7 +92,7 @@
}
}
- public static int deleteAll(String table) throws SQLException {
+ public int deleteAll(String table) throws SQLException {
String sql = "delete from " + table;
Connection c = getConnection();
@@ -97,11 +110,11 @@
}
}
- public static Object getObject(String table, String column) throws
SQLException {
+ public Object getObject(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final Object[] result = new Object[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -113,12 +126,12 @@
return result[0];
}
- public static byte getByte(String table, String column) throws
SQLException {
+ public byte getByte(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final byte[] result = new byte[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -130,12 +143,12 @@
return result[0];
}
- public static byte[] getBytes(String table, String column) throws
SQLException {
+ public byte[] getBytes(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final byte[][] result = new byte[1][];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -147,12 +160,12 @@
return result[0];
}
- public static int getInt(String table, String column) throws SQLException {
+ public int getInt(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final int[] result = new int[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -164,12 +177,12 @@
return result[0];
}
- public static long getLong(String table, String column) throws
SQLException {
+ public long getLong(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final long[] result = new long[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -181,12 +194,12 @@
return result[0];
}
- public static double getDouble(String table, String column) throws
SQLException {
+ public double getDouble(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final double[] result = new double[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -198,12 +211,12 @@
return result[0];
}
- public static boolean getBoolean(String table, String column) throws
SQLException {
+ public boolean getBoolean(String table, String column) throws SQLException
{
final String sql = "select " + column + " from " + table;
final boolean[] result = new boolean[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -215,19 +228,17 @@
return result[0];
}
- public static java.util.Date getUtilDate(String table, String column)
- throws SQLException {
+ public java.util.Date getUtilDate(String table, String column) throws
SQLException {
Timestamp ts = getTimestamp(table, column);
return ts != null ? new java.util.Date(ts.getTime()) : null;
}
- public static java.sql.Date getSqlDate(String table, String column)
- throws SQLException {
+ public java.sql.Date getSqlDate(String table, String column) throws
SQLException {
final String sql = "select " + column + " from " + table;
final java.sql.Date[] result = new java.sql.Date[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -239,12 +250,12 @@
return result[0];
}
- public static Time getTime(String table, String column) throws
SQLException {
+ public Time getTime(String table, String column) throws SQLException {
final String sql = "select " + column + " from " + table;
final Time[] result = new Time[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -256,12 +267,12 @@
return result[0];
}
- public static Timestamp getTimestamp(String table, String column) throws
SQLException {
+ public Timestamp getTimestamp(String table, String column) throws
SQLException {
final String sql = "select " + column + " from " + table;
final Timestamp[] result = new Timestamp[1];
- RowTemplate template = new RowTemplate() {
+ RowTemplate template = new RowTemplate(this) {
@Override
void readRow(ResultSet rs, String sql) throws SQLException {
@@ -273,7 +284,7 @@
return result[0];
}
- static Connection getConnection() throws SQLException {
- return ItestSetup.getInstance().getDataSource().getConnection();
+ public Connection getConnection() throws SQLException {
+ return dataSource.getConnection();
}
}
Copied:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ResultSetTemplate.java
(from r454776,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ResultSetTemplate.java)
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ResultSetTemplate.java?view=diff&rev=454858&p1=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ResultSetTemplate.java&r1=454776&p2=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ResultSetTemplate.java&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ResultSetTemplate.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ResultSetTemplate.java
Tue Oct 10 11:16:53 2006
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.itest.jpa;
+package org.apache.cayenne.itest;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -25,10 +25,16 @@
abstract class ResultSetTemplate {
+ ItestDBUtils parent;
+
+ public ResultSetTemplate(ItestDBUtils parent) {
+ this.parent = parent;
+ }
+
abstract void readResultSet(ResultSet rs, String sql) throws SQLException;
void execute(String sql) throws SQLException {
- Connection c = ItestDBUtils.getConnection();
+ Connection c = parent.getConnection();
try {
PreparedStatement st = c.prepareStatement(sql);
Copied:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java
(from r454776,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/RowTemplate.java)
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java?view=diff&rev=454858&p1=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/RowTemplate.java&r1=454776&p2=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/RowTemplate.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/RowTemplate.java
Tue Oct 10 11:16:53 2006
@@ -16,12 +16,16 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.itest.jpa;
+package org.apache.cayenne.itest;
import java.sql.ResultSet;
import java.sql.SQLException;
abstract class RowTemplate extends ResultSetTemplate {
+
+ public RowTemplate(ItestDBUtils parent) {
+ super(parent);
+ }
abstract void readRow(ResultSet rs, String sql) throws SQLException;
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestSetup.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestSetup.java?view=diff&rev=454858&r1=454857&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestSetup.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/ItestSetup.java
Tue Oct 10 11:16:53 2006
@@ -27,6 +27,8 @@
import javax.persistence.Persistence;
import javax.sql.DataSource;
+import org.apache.cayenne.itest.ItestDBUtils;
+
import junit.framework.Assert;
public class ItestSetup {
@@ -42,6 +44,7 @@
protected EntityManagerFactory sharedFactory;
protected ItestDataSourceManager dataSourceManager;
protected String jpaUnit;
+ protected ItestDBUtils dbHelper;
public static void initInstance(Properties properties) {
String schemaScript = properties.getProperty(SCHEMA_SCRIPT_URL);
@@ -68,6 +71,7 @@
protected ItestSetup(String schemaScriptUrl, String jpaUnit) {
this.jpaUnit = jpaUnit;
this.dataSourceManager = new ItestDataSourceManager(schemaScriptUrl);
+ this.dbHelper = new ItestDBUtils(dataSourceManager.getDataSource());
}
public DataSource getDataSource() {
@@ -89,5 +93,9 @@
ItestJpaDataSourceFactory.class.getName());
return Persistence.createEntityManagerFactory(jpaUnit, properties);
+ }
+
+ public ItestDBUtils getDbHelper() {
+ return dbHelper;
}
}
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java?view=diff&rev=454858&r1=454857&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
Tue Oct 10 11:16:53 2006
@@ -20,6 +20,8 @@
import java.util.Properties;
+import org.apache.cayenne.itest.ItestDBUtils;
+
import junit.framework.TestCase;
/**
@@ -33,5 +35,9 @@
static {
Properties properties = new Properties();
ItestSetup.initInstance(properties);
+ }
+
+ protected ItestDBUtils getDbHelper() {
+ return ItestSetup.getInstance().getDbHelper();
}
}
Copied:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java
(from r454801,
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestSetup.java)
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java?view=diff&rev=454858&p1=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestSetup.java&r1=454801&p2=incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/ItestSetup.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/ItestSetup.java
Tue Oct 10 11:16:53 2006
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.itest;
+package org.apache.cayenne.itest.pojo;
import java.util.Iterator;
@@ -29,12 +29,14 @@
import org.apache.cayenne.access.DataNode;
import org.apache.cayenne.access.DbGenerator;
import org.apache.cayenne.conf.Configuration;
+import org.apache.cayenne.itest.ItestDBUtils;
import org.apache.cayenne.map.DataMap;
public class ItestSetup {
private static ItestSetup sharedInstance;
+ protected ItestDBUtils dbHelper;
protected DataDomain domain;
public static void initInstance() {
@@ -65,14 +67,21 @@
throw new CayenneRuntimeException("Error generating schema for
DataMap "
+ map.getName(), e);
}
+
+ // only single node is expected...
+ dbHelper = new ItestDBUtils(node.getDataSource());
}
}
-
+
public DataChannel getChannel() {
return domain;
}
public ObjectContext createObjectContext() {
return domain.createDataContext();
+ }
+
+ public ItestDBUtils getDbHelper() {
+ return dbHelper;
}
}
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java?view=diff&rev=454858&r1=454857&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoContextCase.java
Tue Oct 10 11:16:53 2006
@@ -19,7 +19,6 @@
package org.apache.cayenne.itest.pojo;
import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.itest.ItestSetup;
public class PojoContextCase extends PojoTestCase {
Modified:
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoTestCase.java?view=diff&rev=454858&r1=454857&r2=454858
==============================================================================
---
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoTestCase.java
(original)
+++
incubator/cayenne/main/trunk/integration-test/itest-common/src/main/java/org/apache/cayenne/itest/pojo/PojoTestCase.java
Tue Oct 10 11:16:53 2006
@@ -25,7 +25,7 @@
import org.apache.cayenne.DataChannel;
import org.apache.cayenne.enhancer.CayenneEnhancer;
import org.apache.cayenne.instrument.InstrumentUtil;
-import org.apache.cayenne.itest.ItestSetup;
+import org.apache.cayenne.itest.ItestDBUtils;
public class PojoTestCase extends TestCase {
@@ -37,5 +37,9 @@
protected static ClassFileTransformer initEnhancer() {
DataChannel channel = ItestSetup.getInstance().getChannel();
return new CayenneEnhancer(channel.getEntityResolver());
+ }
+
+ protected ItestDBUtils getDbHelper() {
+ return ItestSetup.getInstance().getDbHelper();
}
}