cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r609208 - in /cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest: ItestTableUtils.java jpa/JpaTestCase.java
Date Sat, 05 Jan 2008 20:33:03 GMT
Author: aadamchik
Date: Sat Jan  5 12:33:03 2008
New Revision: 609208

URL: http://svn.apache.org/viewvc?rev=609208&view=rev
Log:
new itest db utilities to simplify single table operations

Added:
    cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/ItestTableUtils.java
Modified:
    cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java

Added: cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/ItestTableUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/ItestTableUtils.java?rev=609208&view=auto
==============================================================================
--- cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/ItestTableUtils.java
(added)
+++ cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/ItestTableUtils.java
Sat Jan  5 12:33:03 2008
@@ -0,0 +1,63 @@
+/*****************************************************************
+ *   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.itest;
+
+import java.sql.SQLException;
+
+/**
+ * JDBC utilities for integration testing that bypass Cayenne for DB access.
+ * 
+ * @author Andrus Adamchik
+ */
+public class ItestTableUtils {
+
+    protected String tableName;
+    protected ItestDBUtils dbUtils;
+    protected String[] columns;
+
+    public ItestTableUtils(ItestDBUtils dbUtils, String tableName) {
+        this.dbUtils = dbUtils;
+        this.tableName = tableName;
+    }
+
+    public ItestTableUtils deleteAll() throws SQLException {
+        dbUtils.deleteAll(tableName);
+        return this;
+    }
+
+    public ItestTableUtils setColumns(String... columns) {
+        this.columns = columns;
+        return this;
+    }
+
+    public ItestTableUtils insert(Object... values) throws SQLException {
+        if (this.columns == null) {
+            throw new IllegalStateException("Call 'helper' to prepare insert");
+        }
+
+        if (this.columns.length != values.length) {
+            throw new IllegalArgumentException(
+                    "Columns and values arrays are of different size");
+        }
+
+        dbUtils.insert(tableName, columns, values);
+        return this;
+    }
+
+}

Modified: cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java?rev=609208&r1=609207&r2=609208&view=diff
==============================================================================
--- cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
(original)
+++ cayenne/main/trunk/itests/itest-common/src/main/java/org/apache/cayenne/itest/jpa/JpaTestCase.java
Sat Jan  5 12:33:03 2008
@@ -21,6 +21,7 @@
 import junit.framework.TestCase;
 
 import org.apache.cayenne.itest.ItestDBUtils;
+import org.apache.cayenne.itest.ItestTableUtils;
 
 /**
  * Abstract test case that bootstraps default JPA unit called "itest" and a schema script
@@ -32,5 +33,9 @@
 
     protected ItestDBUtils getDbHelper() {
         return ItestSetup.getInstance().getDbHelper();
+    }
+    
+    protected ItestTableUtils getTableHelper(String tableName) {
+        return new ItestTableUtils(getDbHelper(), tableName);
     }
 }



Mime
View raw message