You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/11/30 13:33:03 UTC

cayenne git commit: switching tests to SQLReader

Repository: cayenne
Updated Branches:
  refs/heads/master 47c4c014f -> 11d8465f4


switching tests to SQLReader

this allows us to add license headers to the unit test SQL files


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/11d8465f
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/11d8465f
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/11d8465f

Branch: refs/heads/master
Commit: 11d8465f41bf7f8811a7fa537a297538c64373e9
Parents: 47c4c01
Author: aadamchik <aa...@apache.org>
Authored: Sun Nov 30 15:00:47 2014 +0300
Committer: aadamchik <aa...@apache.org>
Committed: Sun Nov 30 15:32:03 2014 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/test/jdbc/SQLReader.java |  6 +--
 .../cayenne/tools/DbImporterTaskTest.java       | 57 ++++++++++++--------
 .../tools/dbimport/build-include-table.xml.sql  | 18 +++++++
 3 files changed, 55 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/11d8465f/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/SQLReader.java
----------------------------------------------------------------------
diff --git a/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/SQLReader.java b/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/SQLReader.java
index d5992d5..12afef2 100644
--- a/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/SQLReader.java
+++ b/build-tools/cayenne-test-utilities/src/main/java/org/apache/cayenne/test/jdbc/SQLReader.java
@@ -37,11 +37,11 @@ import java.util.Collection;
  */
 public class SQLReader {
 
-	public Collection<String> statements(URL sqlSource) throws Exception {
+	public static Collection<String> statements(URL sqlSource) throws Exception {
 		return statements(sqlSource, null);
 	}
 
-	public Collection<String> statements(URL sqlSource, String separator) throws Exception {
+	public static Collection<String> statements(URL sqlSource, String separator) throws Exception {
 
 		Collection<String> statements = new ArrayList<String>();
 
@@ -68,7 +68,7 @@ public class SQLReader {
 		return statements;
 	}
 
-	private boolean appendLine(StringBuilder statement, String line, String separator) {
+	private static boolean appendLine(StringBuilder statement, String line, String separator) {
 		if (line.startsWith("-- ")) {
 			return false;
 		}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/11d8465f/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
index 177d878..7a0f7d1 100644
--- a/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
+++ b/cayenne-tools/src/test/java/org/apache/cayenne/tools/DbImporterTaskTest.java
@@ -18,7 +18,27 @@
  ****************************************************************/
 package org.apache.cayenne.tools;
 
+import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.assertCatalog;
+import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.assertCatalogAndSchema;
+import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.assertFlat;
+import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.assertSchema;
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
 import org.apache.cayenne.test.file.FileUtil;
+import org.apache.cayenne.test.jdbc.SQLReader;
 import org.apache.cayenne.test.resource.ResourceUtil;
 import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
 import org.apache.tools.ant.Project;
@@ -31,22 +51,6 @@ import org.custommonkey.xmlunit.XMLUnit;
 import org.junit.Test;
 import org.xml.sax.SAXException;
 
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import static org.apache.cayenne.tools.dbimport.config.DefaultReverseEngineeringLoaderTest.*;
-import static org.apache.commons.lang.StringUtils.isBlank;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 // TODO: we are only testing on Derby. We may need to dynamically switch between DBs 
 // based on "cayenneTestConnection", like we do in cayenne-server, etc.
 public class DbImporterTaskTest {
@@ -183,13 +187,10 @@ public class DbImporterTaskTest {
 		}
 	}
 
-	private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration)
-			throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException,
-			URISyntaxException {
+	private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration) throws Exception {
 
-		String name = "dbimport/" + sqlFile + ".sql";
-		File file = distDir(name);
-		ResourceUtil.copyResourceToFile(getPackagePath() + "/" + name, file);
+		URL sqlUrl = getClass().getResource("dbimport/" + sqlFile + ".sql");
+		assertNotNull(sqlUrl);
 
 		Class.forName(dbImportConfiguration.getDriver()).newInstance();
 
@@ -198,8 +199,18 @@ public class DbImporterTaskTest {
 
 			Statement stmt = c.createStatement();
 
+			// TODO: move parsing SQL files to a common utility (DBHelper?) .
+			// ALso see UnitDbApater.executeDDL - this should use the same
+			// utility
+
 			try {
-				for (String sql : FileUtils.readFully(new FileReader(file)).split(";")) {
+				for (String sql : SQLReader.statements(sqlUrl, ";")) {
+
+					// skip comments
+					if (sql.startsWith("-- ")) {
+						continue;
+					}
+
 					stmt.execute(sql);
 				}
 			} finally {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/11d8465f/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
----------------------------------------------------------------------
diff --git a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
index fb820b7..e392d08 100644
--- a/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
+++ b/cayenne-tools/src/test/resources/org/apache/cayenne/tools/dbimport/build-include-table.xml.sql
@@ -1,3 +1,21 @@
+--  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.
+ 
+
 CREATE TABLE Parent (
   id INTEGER NOT NULL,
   COL2 CHAR(25),