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 08:54:29 UTC

[1/3] cayenne git commit: cleaning up to pass rat checks

Repository: cayenne
Updated Branches:
  refs/heads/master 2b6ef8ea2 -> cce22ae06


cleaning up to pass rat checks

* adding missing license headers
* excluding test data files


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

Branch: refs/heads/master
Commit: e976355d0f5c1b31e759f4d34d7debe2d0383194
Parents: 2b6ef8e
Author: aadamchik <aa...@apache.org>
Authored: Sun Nov 30 10:20:43 2014 +0300
Committer: aadamchik <aa...@apache.org>
Committed: Sun Nov 30 10:43:15 2014 +0300

----------------------------------------------------------------------
 .../apache/cayenne/crypto/key/README-keystore.txt  | 17 +++++++++++++++++
 rat.sh                                             |  1 +
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e976355d/cayenne-crypto/src/test/resources/org/apache/cayenne/crypto/key/README-keystore.txt
----------------------------------------------------------------------
diff --git a/cayenne-crypto/src/test/resources/org/apache/cayenne/crypto/key/README-keystore.txt b/cayenne-crypto/src/test/resources/org/apache/cayenne/crypto/key/README-keystore.txt
index 015deee..1ef4f9a 100644
--- a/cayenne-crypto/src/test/resources/org/apache/cayenne/crypto/key/README-keystore.txt
+++ b/cayenne-crypto/src/test/resources/org/apache/cayenne/crypto/key/README-keystore.txt
@@ -1,3 +1,20 @@
+#	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.   
+
 Contains unit test keystore passwords. Storing in plaintext here, as none of these 
 keystores store any real keys.
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e976355d/rat.sh
----------------------------------------------------------------------
diff --git a/rat.sh b/rat.sh
index 317fb0a..1064c3f 100755
--- a/rat.sh
+++ b/rat.sh
@@ -63,6 +63,7 @@ java -jar $RAT -d $DIR \
 	-e '*.html' \
 	-e '*.css' \
 	-e '*.jceks' \
+	-e 'plain.txt' \
 	-e 'derby.log'
 
 


[2/3] cayenne git commit: minor cleanup

Posted by aa...@apache.org.
minor cleanup


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

Branch: refs/heads/master
Commit: 56f0b5ddef8c66a7c6e12186af13cdd7ed481095
Parents: e976355
Author: aadamchik <aa...@apache.org>
Authored: Sun Nov 30 10:50:54 2014 +0300
Committer: aadamchik <aa...@apache.org>
Committed: Sun Nov 30 10:52:08 2014 +0300

----------------------------------------------------------------------
 .../cayenne/tools/DbImporterTaskTest.java       | 296 ++++++++++---------
 1 file changed, 149 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/56f0b5dd/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 c17cf40..977b9be 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
@@ -48,154 +48,156 @@ 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 {
 
-    static {
-        XMLUnit.setIgnoreWhitespace(true);
-    }
-
-    @Test
-    public void testLoadCatalog() throws Exception {
-        assertCatalog(getCdbImport("build-catalog.xml").getReverseEngineering());
-    }
-
-    @Test
-    public void testLoadSchema() throws Exception {
-        assertSchema(getCdbImport("build-schema.xml").getReverseEngineering());
-    }
-
-    @Test
-    public void testLoadCatalogAndSchema() throws Exception {
-        assertCatalogAndSchema(getCdbImport("build-catalog-and-schema.xml").getReverseEngineering());
-    }
-
-    @Test
-    public void testLoadFlat() throws Exception {
-        assertFlat(getCdbImport("build-flat.xml").getReverseEngineering());
-    }
-
-    @Test
-    public void testIncludeTable() throws Exception {
-        test("build-include-table.xml");
-    }
-
-
-    private DbImporterTask getCdbImport(String buildFile) {
-        Project project = new Project();
-
-        File map = distDir(buildFile);
-        ResourceUtil.copyResourceToFile(getPackagePath() + "/" + buildFile, map);
-        ProjectHelper.configureProject(project, map);
-
-        UnknownElement task = (UnknownElement) project.getTargets().get("dist").getTasks()[0];
-        task.maybeConfigure();
-
-        return (DbImporterTask) task.getRealThing();
-    }
-
-    private static File distDir(String name) {
-        File distDir = new File(FileUtil.baseTestDirectory(), "cdbImport");
-        File file = new File(distDir, name);
-        distDir = file.getParentFile();
-        // prepare destination directory
-        if (!distDir.exists()) {
-            assertTrue(distDir.mkdirs());
-        }
-        return file;
-    }
-
-    private String getPackagePath() {
-        return getClass().getPackage().getName().replace('.', '/');
-    }
-
-    private void test(String name) throws Exception {
-        DbImporterTask cdbImport = getCdbImport("dbimport/" + name);
-        File mapFile = cdbImport.getMap();
-        URL mapUrl = this.getClass().getResource("dbimport/" + mapFile.getName());
-        if (mapUrl != null && new File(mapUrl.toURI()).exists()) {
-            ResourceUtil.copyResourceToFile(mapUrl, mapFile);
-        }
-
-        URL mapUrlRes = this.getClass().getResource("dbimport/" + mapFile.getName() + "-result");
-        if (mapUrlRes != null && new File(mapUrlRes.toURI()).exists()) {
-            ResourceUtil.copyResourceToFile(mapUrlRes, new File(mapFile.getParentFile(), mapFile.getName() + "-result"));
-        }
-
-        File mapFileCopy = distDir("copy-" + mapFile.getName());
-        if (mapFile.exists()) {
-            FileUtils.getFileUtils().copyFile(mapFile, mapFileCopy);
-            cdbImport.setMap(mapFileCopy);
-        } else {
-            mapFileCopy = mapFile;
-        }
-
-        prepareDatabase(name, cdbImport.toParameters());
-
-        try {
-            cdbImport.execute();
-            verifyResult(mapFile, mapFileCopy);
-        } finally {
-            cleanDb(cdbImport.toParameters());
-        }
-    }
-
-    private void cleanDb(DbImportConfiguration dbImportConfiguration) throws ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException {
-        Class.forName(dbImportConfiguration.getDriver()).newInstance();
-        // Get a connection
-        Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl());
-        Statement stmt = connection.createStatement();
-
-        ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"});
-        while (tables.next()) {
-            String schema = tables.getString("TABLE_SCHEM");
-            System.out.println("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME"));
-            stmt.execute("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME"));
-        }
-
-        ResultSet schemas = connection.getMetaData().getSchemas();
-        while (schemas.next()) {
-            String schem = schemas.getString("TABLE_SCHEM");
-            if (schem.startsWith("SCHEMA")) {
-                System.out.println("DROP SCHEMA " + schem);
-                stmt.execute("DROP SCHEMA " + schem + " RESTRICT");
-            }
-        }
-    }
-
-    private void verifyResult(File map, File mapFileCopy) {
-        try {
-            FileReader control = new FileReader(map.getAbsolutePath() + "-result");
-            FileReader test = new FileReader(mapFileCopy);
-
-            DetailedDiff diff = new DetailedDiff(new Diff(control, test));
-            if (!diff.similar()) {
-                System.out.println(" >>>> " + map.getAbsolutePath() + "-result");
-                System.out.println(" >>>> " + mapFileCopy);
-                fail(diff.toString());
-            }
-
-        } catch (SAXException e) {
-            e.printStackTrace();
-            fail();
-        } catch (IOException e) {
-            e.printStackTrace();
-            fail();
-        }
-    }
-
-    private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, URISyntaxException {
-        Class.forName(dbImportConfiguration.getDriver()).newInstance();
-        // Get a connection
-        Statement stmt = DriverManager.getConnection(dbImportConfiguration.getUrl()).createStatement();
-
-
-        String name = "dbimport/" + sqlFile + ".sql";
-        File file = distDir(name);
-        ResourceUtil.copyResourceToFile(getPackagePath() + "/" + name, file);
-
-        for (String sql : FileUtils.readFully(new FileReader(file)).split(";")) {
-            stmt.execute(sql);
-        }
-    }
+	static {
+		XMLUnit.setIgnoreWhitespace(true);
+	}
+
+	@Test
+	public void testLoadCatalog() throws Exception {
+		assertCatalog(getCdbImport("build-catalog.xml").getReverseEngineering());
+	}
+
+	@Test
+	public void testLoadSchema() throws Exception {
+		assertSchema(getCdbImport("build-schema.xml").getReverseEngineering());
+	}
+
+	@Test
+	public void testLoadCatalogAndSchema() throws Exception {
+		assertCatalogAndSchema(getCdbImport("build-catalog-and-schema.xml").getReverseEngineering());
+	}
+
+	@Test
+	public void testLoadFlat() throws Exception {
+		assertFlat(getCdbImport("build-flat.xml").getReverseEngineering());
+	}
+
+	@Test
+	public void testIncludeTable() throws Exception {
+		test("build-include-table.xml");
+	}
+
+	private DbImporterTask getCdbImport(String buildFile) {
+		Project project = new Project();
+
+		File map = distDir(buildFile);
+		ResourceUtil.copyResourceToFile(getPackagePath() + "/" + buildFile, map);
+		ProjectHelper.configureProject(project, map);
+
+		UnknownElement task = (UnknownElement) project.getTargets().get("dist").getTasks()[0];
+		task.maybeConfigure();
+
+		return (DbImporterTask) task.getRealThing();
+	}
+
+	private static File distDir(String name) {
+		File distDir = new File(FileUtil.baseTestDirectory(), "cdbImport");
+		File file = new File(distDir, name);
+		distDir = file.getParentFile();
+		// prepare destination directory
+		if (!distDir.exists()) {
+			assertTrue(distDir.mkdirs());
+		}
+		return file;
+	}
+
+	private String getPackagePath() {
+		return getClass().getPackage().getName().replace('.', '/');
+	}
+
+	private void test(String name) throws Exception {
+		DbImporterTask cdbImport = getCdbImport("dbimport/" + name);
+		File mapFile = cdbImport.getMap();
+		URL mapUrl = this.getClass().getResource("dbimport/" + mapFile.getName());
+		if (mapUrl != null && new File(mapUrl.toURI()).exists()) {
+			ResourceUtil.copyResourceToFile(mapUrl, mapFile);
+		}
+
+		URL mapUrlRes = this.getClass().getResource("dbimport/" + mapFile.getName() + "-result");
+		if (mapUrlRes != null && new File(mapUrlRes.toURI()).exists()) {
+			ResourceUtil
+					.copyResourceToFile(mapUrlRes, new File(mapFile.getParentFile(), mapFile.getName() + "-result"));
+		}
+
+		File mapFileCopy = distDir("copy-" + mapFile.getName());
+		if (mapFile.exists()) {
+			FileUtils.getFileUtils().copyFile(mapFile, mapFileCopy);
+			cdbImport.setMap(mapFileCopy);
+		} else {
+			mapFileCopy = mapFile;
+		}
+
+		prepareDatabase(name, cdbImport.toParameters());
+
+		try {
+			cdbImport.execute();
+			verifyResult(mapFile, mapFileCopy);
+		} finally {
+			cleanDb(cdbImport.toParameters());
+		}
+	}
+
+	private void cleanDb(DbImportConfiguration dbImportConfiguration) throws ClassNotFoundException,
+			IllegalAccessException, InstantiationException, SQLException {
+		Class.forName(dbImportConfiguration.getDriver()).newInstance();
+		// Get a connection
+		Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl());
+		Statement stmt = connection.createStatement();
+
+		ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[] { "TABLE" });
+		while (tables.next()) {
+			String schema = tables.getString("TABLE_SCHEM");
+			System.out.println("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME"));
+			stmt.execute("DROP TABLE " + (isBlank(schema) ? "" : schema + ".") + tables.getString("TABLE_NAME"));
+		}
+
+		ResultSet schemas = connection.getMetaData().getSchemas();
+		while (schemas.next()) {
+			String schem = schemas.getString("TABLE_SCHEM");
+			if (schem.startsWith("SCHEMA")) {
+				System.out.println("DROP SCHEMA " + schem);
+				stmt.execute("DROP SCHEMA " + schem + " RESTRICT");
+			}
+		}
+	}
+
+	private void verifyResult(File map, File mapFileCopy) {
+		try {
+			FileReader control = new FileReader(map.getAbsolutePath() + "-result");
+			FileReader test = new FileReader(mapFileCopy);
+
+			DetailedDiff diff = new DetailedDiff(new Diff(control, test));
+			if (!diff.similar()) {
+				fail(diff.toString());
+			}
+
+		} catch (SAXException e) {
+			e.printStackTrace();
+			fail();
+		} catch (IOException e) {
+			e.printStackTrace();
+			fail();
+		}
+	}
+
+	private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration)
+			throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException,
+			URISyntaxException {
+		Class.forName(dbImportConfiguration.getDriver()).newInstance();
+		// Get a connection
+		Statement stmt = DriverManager.getConnection(dbImportConfiguration.getUrl()).createStatement();
+
+		String name = "dbimport/" + sqlFile + ".sql";
+		File file = distDir(name);
+		ResourceUtil.copyResourceToFile(getPackagePath() + "/" + name, file);
+
+		for (String sql : FileUtils.readFully(new FileReader(file)).split(";")) {
+			stmt.execute(sql);
+		}
+	}
 
 }
\ No newline at end of file


[3/3] cayenne git commit: resource leak in unit tests

Posted by aa...@apache.org.
resource leak in unit tests


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

Branch: refs/heads/master
Commit: cce22ae065ce2437b69b73d6e7a2bd76272d0e3b
Parents: 56f0b5d
Author: aadamchik <aa...@apache.org>
Authored: Sun Nov 30 10:54:21 2014 +0300
Committer: aadamchik <aa...@apache.org>
Committed: Sun Nov 30 10:54:21 2014 +0300

----------------------------------------------------------------------
 .../cayenne/tools/DbImporterTaskTest.java       | 21 +++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/cce22ae0/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 977b9be..5e284ac 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
@@ -187,16 +187,27 @@ public class DbImporterTaskTest {
 	private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration)
 			throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException,
 			URISyntaxException {
-		Class.forName(dbImportConfiguration.getDriver()).newInstance();
-		// Get a connection
-		Statement stmt = DriverManager.getConnection(dbImportConfiguration.getUrl()).createStatement();
 
 		String name = "dbimport/" + sqlFile + ".sql";
 		File file = distDir(name);
 		ResourceUtil.copyResourceToFile(getPackagePath() + "/" + name, file);
 
-		for (String sql : FileUtils.readFully(new FileReader(file)).split(";")) {
-			stmt.execute(sql);
+		Class.forName(dbImportConfiguration.getDriver()).newInstance();
+
+		Connection c = DriverManager.getConnection(dbImportConfiguration.getUrl());
+		try {
+
+			Statement stmt = c.createStatement();
+
+			try {
+				for (String sql : FileUtils.readFully(new FileReader(file)).split(";")) {
+					stmt.execute(sql);
+				}
+			} finally {
+				stmt.close();
+			}
+		} finally {
+			c.close();
 		}
 	}