geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] 02/02: added test for bad driver
Date Mon, 30 Oct 2017 21:19:41 GMT
This is an automated email from the ASF dual-hosted git repository.

dschneider pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git

commit 2bb441648d30065b29eaba916cda0f45c964f8a1
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Mon Oct 30 14:19:23 2017 -0700

    added test for bad driver
---
 .../apache/geode/connectors/jdbc/JDBCManager.java  |  4 +--
 .../connectors/jdbc/JDBCManagerUnitTestTest.java   | 34 +++++++++++++++++-----
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
index 69d0cdb..4160887 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/JDBCManager.java
@@ -173,7 +173,7 @@ public class JDBCManager {
     return columnNames.append(columnValues).toString();
   }
 
-  private Connection getConnection() {
+  Connection getConnection() {
     Connection result = this.conn;
     try {
       if (result != null && !result.isClosed()) {
@@ -188,7 +188,7 @@ public class JDBCManager {
         Class.forName(this.config.getDriver());
       } catch (ClassNotFoundException e) {
         // TODO: consider a different exception
-        throw new IllegalStateException("Driver class " + this.config.getDriver() + " not
found",
+        throw new IllegalStateException("Driver class \"" + this.config.getDriver() + "\"
not found",
             e);
       }
     }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
index d067898..661d1b6 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/JDBCManagerUnitTestTest.java
@@ -16,6 +16,8 @@ package org.apache.geode.connectors.jdbc;
 
 import static org.assertj.core.api.Assertions.*;
 import static org.mockito.Mockito.*;
+import static com.googlecode.catchexception.CatchException.*;
+import static com.googlecode.catchexception.CatchException.caughtException;
 
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -89,20 +91,27 @@ public class JDBCManagerUnitTestTest {
 
   @Before
   public void setUp() throws Exception {
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  private void createManager(String driver, String url) {
     Properties props = new Properties();
-    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
-    String connectionURL = "jdbc:derby:memory:DerbyTestDB;create=true";
-    props.setProperty("url", connectionURL);
+    props.setProperty("url", url);
     props.setProperty("driver", driver);
     JDBCConfiguration config = new JDBCConfiguration(props);
     this.mgr = new TestableJDBCManager(config);
   }
-
-  @After
-  public void tearDown() throws Exception {}
-
+  
+  private void createDefaultManager() {
+    createManager("java.lang.String", "fakeURL");
+  }
+  
   @Test
   public void verifySimpleCreateCallsExecute() throws SQLException {
+    createDefaultManager();
     GemFireCacheImpl cache = Fakes.cache();
     Region region = Fakes.region(regionName, cache);
     PdxInstanceImpl pdx1 = mockPdxInstance("Emp1", 21);
@@ -115,6 +124,7 @@ public class JDBCManagerUnitTestTest {
 
   @Test
   public void verifySimpleUpdateCallsExecute() throws SQLException {
+    createDefaultManager();
     GemFireCacheImpl cache = Fakes.cache();
     Region region = Fakes.region(regionName, cache);
     PdxInstanceImpl pdx1 = mockPdxInstance("Emp1", 21);
@@ -127,6 +137,7 @@ public class JDBCManagerUnitTestTest {
   
   @Test
   public void verifySimpleDestroyCallsExecute() throws SQLException {
+    createDefaultManager();
     GemFireCacheImpl cache = Fakes.cache();
     Region region = Fakes.region(regionName, cache);
     this.mgr.write(region, Operation.DESTROY, "1", null);
@@ -138,6 +149,7 @@ public class JDBCManagerUnitTestTest {
   
   @Test
   public void verifyTwoCreatesReuseSameStatement() throws SQLException {
+    createDefaultManager();
     GemFireCacheImpl cache = Fakes.cache();
     Region region = Fakes.region(regionName, cache);
     PdxInstanceImpl pdx1 = mockPdxInstance("Emp1", 21);
@@ -158,4 +170,12 @@ public class JDBCManagerUnitTestTest {
     when(pdxInstance.getPdxType()).thenReturn(pdxType);
     return pdxInstance;
   }
+  
+  @Test
+  public void verifyMissingDriverClass() {
+    createManager("non existent driver", "fakeURL");
+    catchException(this.mgr).getConnection();
+    assertThat((Exception)caughtException()).isInstanceOf(IllegalStateException.class);
+    assertThat(caughtException().getMessage()).isEqualTo("Driver class \"non existent driver\"
not found");
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <commits@geode.apache.org>.

Mime
View raw message