Repository: nifi
Updated Branches:
  refs/heads/master f53aaed12 -> 9e9182aa6


- Unit test creates resources in HOME directory This closes #174

Signed-off-by: Matt Gilman <[email protected]>


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

Branch: refs/heads/master
Commit: 9e9182aa639fb2358c950a19cb87d1ad3ddf67ab
Parents: f53aaed
Author: smarthi <[email protected]>
Authored: Sat Jan 16 01:48:06 2016 -0500
Committer: Matt Gilman <[email protected]>
Committed: Tue Jan 19 09:44:03 2016 -0500

----------------------------------------------------------------------
 .../standard/util/TestJdbcTypesH2.java          | 25 +++++++++-----------
 1 file changed, 11 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/9e9182aa/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesH2.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesH2.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesH2.java
index e3041b6..7d31c21 100644
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesH2.java
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/util/TestJdbcTypesH2.java
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertNotNull;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.sql.Connection;
@@ -34,11 +33,14 @@ import org.apache.avro.generic.GenericDatumReader;
 import org.apache.avro.generic.GenericRecord;
 import org.apache.avro.io.DatumReader;
 import org.junit.BeforeClass;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 public class TestJdbcTypesH2 {
 
-    final static String DB_LOCATION = "~/var/test/h2";
+    @Rule
+    public TemporaryFolder folder = new TemporaryFolder();
 
     @BeforeClass
     public static void setup() {
@@ -75,11 +77,7 @@ public class TestJdbcTypesH2 {
 
     @Test
     public void testSQLTypesMapping() throws ClassNotFoundException, 
SQLException, IOException {
-       // remove previous test database, if any
-        final File dbLocation = new File(DB_LOCATION);
-        dbLocation.delete();
-
-        final Connection con = createConnection();
+        final Connection con = 
createConnection(folder.getRoot().getAbsolutePath());
         final Statement st = con.createStatement();
 
         try {
@@ -114,8 +112,8 @@ public class TestJdbcTypesH2 {
 
         final InputStream instream = new ByteArrayInputStream(serializedBytes);
 
-        final DatumReader<GenericRecord> datumReader = new 
GenericDatumReader<GenericRecord>();
-        try (final DataFileStream<GenericRecord> dataFileReader = new 
DataFileStream<GenericRecord>(instream, datumReader)) {
+        final DatumReader<GenericRecord> datumReader = new 
GenericDatumReader<>();
+        try (final DataFileStream<GenericRecord> dataFileReader = new 
DataFileStream<>(instream, datumReader)) {
             GenericRecord record = null;
             while (dataFileReader.hasNext()) {
                 // Reuse record object by passing it to next(). This saves us 
from
@@ -132,18 +130,17 @@ public class TestJdbcTypesH2 {
     public void testDriverLoad() throws ClassNotFoundException, SQLException {
 //        final Class<?> clazz = 
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
 
-        Connection con = createConnection();
+        Connection con = createConnection(folder.getRoot().getAbsolutePath());
 
         assertNotNull(con);
         con.close();
     }
 
-    private Connection createConnection() throws ClassNotFoundException, 
SQLException {
+    private Connection createConnection(String location) throws 
ClassNotFoundException, SQLException {
 
 //        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
-        String connectionString = "jdbc:h2:file:" + DB_LOCATION + "/testdb7";
-        final Connection con = DriverManager.getConnection(connectionString, 
"SA", "");
-        return con;
+        String connectionString = "jdbc:h2:file:" + location + "/testdb7";
+        return DriverManager.getConnection(connectionString, "SA", "");
     }
 
 }

Reply via email to