Repository: Vantiq/vantiq-extension-sources (language: python)

Issue:
Testing: Improve testing by including all modules possible
Make ones with specialized drivers dependent on those drivers only for running.  Some simple tests and compilation, etc., can be done without the drivers.


Discussion / hints:

Fix patch:
diff --git a/jdbcSource/build.gradle b/jdbcSource/build.gradle
index d00b5058..0aeacef9 100644
--- a/jdbcSource/build.gradle
+++ b/jdbcSource/build.gradle
@@ -72,7 +72,9 @@ dependencies {
     testImplementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
 
     //  Compiling relevant JDBC Driver .jar file
-    runtimeOnly files("${System.env.JDBC_DRIVER_LOC}")
+    if (System.env.JDBC_DRIVER_LOC != null) {
+        runtimeOnly files("${System.env.JDBC_DRIVER_LOC}")
+    }
     
     // Used in tests that check VANTIQ date format behavior
     testImplementation "io.vantiq:vantiq-sdk:${vantiqSDKVersion}"
diff --git a/jmsSource/build.gradle b/jmsSource/build.gradle
index 12cd0036..04a61aaf 100644
--- a/jmsSource/build.gradle
+++ b/jmsSource/build.gradle
@@ -55,8 +55,11 @@ dependencies {
     // Used for for standard JMS utility
     implementation group: 'javax.jms', name: 'javax.jms-api', version: '2.0.1'
 
-    // Compiling relevant JMS Driver .jar file
-    implementation files("${System.env.JMS_DRIVER_LOC}")
+    if (System.env.JMS_DRIVER_LOC != null) {
+
+        // Compiling relevant JMS Driver .jar file
+        runtimeOnly files("${System.env.JMS_DRIVER_LOC}")
+    }
 
     // Used for testing extension source in VANTIQ
     testImplementation "io.vantiq:vantiq-sdk:${vantiqSDKVersion}"
diff --git a/settings.gradle b/settings.gradle
index 45e2c85a..62d4c857 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -9,12 +9,8 @@ include 'udpSource'
 include 'CSVSource'
 include 'testConnector'
 include 'objectRecognitionSource'
+include 'jdbcSource'
+include 'jmsSource'
 if (System.env.EASY_MODBUS_LOC) {
     include 'EasyModbusSource' 
 }
-if (System.env.JDBC_DRIVER_LOC) {
-    include 'jdbcSource'
-}
-if (System.env.JMS_DRIVER_LOC) {
-    include 'jmsSource'
-}


Test patch:
diff --git a/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java b/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java
index abba2266..0709e305 100644
--- a/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java
+++ b/jdbcSource/src/test/java/io/vantiq/extsrc/jdbcSource/TestJDBC.java
@@ -188,13 +188,15 @@ public class TestJDBC extends TestJDBCBase {
     
     @Before
     public void setup() {
-        jdbc = new JDBC();
-        vantiq = new io.vantiq.client.Vantiq(testVantiqServer);
-        vantiq.setAccessToken(testAuthToken);
-        try {
-            createSourceImpl(vantiq);
-        } catch (Exception e) {
-            fail("Could not create sourceImpl: " + e.getMessage());
+        if (testDBUsername != null && testDBPassword != null && testDBURL != null && jdbcDriverLoc != null) {
+            jdbc = new JDBC();
+            vantiq = new io.vantiq.client.Vantiq(testVantiqServer);
+            vantiq.setAccessToken(testAuthToken);
+            try {
+                createSourceImpl(vantiq);
+            } catch (Exception e) {
+                fail("Could not create sourceImpl: " + e.getMessage());
+            }
         }
     }
 
@@ -209,23 +211,25 @@ public static void setupEnv() throws IOException {
     
     @After
     public void postTestCleanup() {
-        // Delete the Source/Type/Topic/Procedure/Rule from VANTIQ
-        deleteType();
-        deleteTopic();
-        deleteProcedure();
-        deleteRule();
-        if (core != null) {
-            core.close();
-            core = null;
-        }
-        
-        if (jdbc != null) {
-            jdbc.close();
-            jdbc = null;
+        if (testDBUsername != null && testDBPassword != null && testDBURL != null && jdbcDriverLoc != null) {
+            // Delete the Source/Type/Topic/Procedure/Rule from VANTIQ
+            deleteType();
+            deleteTopic();
+            deleteProcedure();
+            deleteRule();
+            if (core != null) {
+                core.close();
+                core = null;
+            }
+    
+            if (jdbc != null) {
+                jdbc.close();
+                jdbc = null;
+            }
+            // Don't delete the source until you've shut down the connector. Otherwise, a bunch of spurious errors appear
+            // in the test log as it tries to reconnect.
+            deleteSource();
         }
-        // Don't delete the source until you've shut down the connector. Otherwise, a bunch of spurious errors appear
-        // in the test log as it tries to reconnect.
-        deleteSource();
     }
 
     @SuppressWarnings({"PMD.JUnit4TestShouldUseAfterAnnotation", "PMD.CognitiveComplexity", "PMD.EmptyCatchBlock"})
diff --git a/jmsSource/src/test/java/io/vantiq/extsrc/jmsSource/TestJMS.java b/jmsSource/src/test/java/io/vantiq/extsrc/jmsSource/TestJMS.java
index 9f660fa0..67f7c32f 100644
--- a/jmsSource/src/test/java/io/vantiq/extsrc/jmsSource/TestJMS.java
+++ b/jmsSource/src/test/java/io/vantiq/extsrc/jmsSource/TestJMS.java
@@ -56,23 +56,33 @@ public class TestJMS extends TestJMSBase {
     
     @Before
     public void setup() {
-        vantiq = new Vantiq(testVantiqServer);
-        vantiq.setAccessToken(testAuthToken);
-        
-        // Create a subscription to source in order to check if message was received as a notification
-        vantiq.subscribe("sources", testSourceName, null, sourceNotificationCallback);
+        // Only do this setup where feasible.
+        if (jmsDriverLoc != null &&
+                testJMSURL != null &&
+                testJMSConnectionFactory != null &&
+                testJMSInitialContext != null) {
+            vantiq = new Vantiq(testVantiqServer);
+            vantiq.setAccessToken(testAuthToken);
+    
+            // Create a subscription to source in order to check if message was received as a notification
+            vantiq.subscribe("sources", testSourceName, null, sourceNotificationCallback);
+        }
     }
     
     @After
     public void unsubscribe() {
-        vantiq.unsubscribeAll();
+        if (jmsDriverLoc != null &&
+                testJMSURL != null &&
+                testJMSConnectionFactory != null &&
+                testJMSInitialContext != null) {
+    
+            vantiq.unsubscribeAll();
+        }
     }
 
     @SuppressWarnings("PMD.JUnit4TestShouldUseAfterAnnotation")
     @AfterClass
     public static void tearDown() {
-        // Delete source from VANTIQ
-        deleteSource();
         
         // Close JMSCore if still open
         if (core != null) {
@@ -84,6 +94,9 @@ public static void tearDown() {
             jms.close();
             jms = null;
         }
+        // Delete source from VANTIQ
+        deleteSource();
+    
     }
     
     @Test
@@ -705,9 +718,11 @@ public static Map<String,Object> createSourceDefWithMessageHandler(String msgHan
     }
     
     public static void deleteSource() {
-        Map<String,Object> where = new LinkedHashMap<String,Object>();
-        where.put("name", testSourceName);
-        vantiq.delete("system.sources", where);
+        if (vantiq != null && vantiq.isAuthenticated()) {
+            Map<String, Object> where = new LinkedHashMap<String, Object>();
+            where.put("name", testSourceName);
+            vantiq.delete("system.sources", where);
+        }
     }
     
     public class StandardOutputCallback implements SubscriptionCallback {