Преглед изворни кода

Fixed integration tests from CLI

Lukas Cerny пре 4 година
родитељ
комит
95440d43e3

+ 12 - 12
build.gradle

@@ -52,10 +52,6 @@ allprojects {
         testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.0-M1'
     }
 
-    test {
-        useJUnitPlatform()
-    }
-
     task unitTest(type: Test) {
         description = 'Runs JUnit tests.'
 
@@ -63,14 +59,6 @@ allprojects {
             excludeTags 'integration'
         }
     }
-
-    task integrationTest(type: Test) {
-        description = 'Runs integration tests.'
-
-        useJUnitPlatform {
-            includeTags 'integration'
-        }
-    }
 }
 
 // settings for all modules
@@ -112,6 +100,18 @@ configure(moduleNames) {
         compile project(":connector-core")
         compile project(":connector-model")
     }
+
+    task integrationTest(type: Test) {
+        description = 'Runs integration tests for ' + project.name
+
+        useJUnitPlatform {
+            includeTags 'integration'
+        }
+
+        filter {
+            includeTestsMatching "io." +project.name.replace("-", ".") + ".*"
+        }
+    }
 }
 
 

+ 31 - 20
connector-module-afarcloud/src/test/java/io/connector/module/afarcloud/OGCSensorThingsOfflineIntegrationTest.java

@@ -5,18 +5,19 @@ import org.junit.jupiter.api.Tag;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
 import static io.connector.module.afarcloud.OGCSensorThingsAssertions.*;
 import static java.nio.file.Files.readAllBytes;
 import static java.nio.file.Paths.get;
+import static java.util.Objects.requireNonNull;
 
 @Tag(TestType.INTEGRATION)
 class OGCSensorThingsOfflineIntegrationTest {
 
-    private static final String RESOURCES_DIR = "src/test/resources";
-
     private static final Map<String, String> DEFAULT_PROPERTIES;
 
     static {
@@ -25,56 +26,66 @@ class OGCSensorThingsOfflineIntegrationTest {
         DEFAULT_PROPERTIES.put("multiSensorId", "10002222");
     }
 
+    private String readResourceFile(String relativePath) throws IOException {
+        try {
+            URL url = getClass().getClassLoader().getResource(relativePath);
+            byte[] bytes = readAllBytes(get(requireNonNull(url).toURI()));
+            return new String(bytes);
+        } catch (URISyntaxException e) {
+            throw new IOException(e);
+        }
+    }
+
     @Test
     void things() throws IOException {
-        String jsonAFCAllSensors = new String(readAllBytes(get(RESOURCES_DIR,"afc/getAllSensors.json")));
-        String jsonOGCThings = new String(readAllBytes(get(RESOURCES_DIR,"ogc/things.json")));
+        String jsonAFCAllSensors = readResourceFile("afc/getAllSensors.json");
+        String jsonOGCThings = readResourceFile("ogc/things.json");
         assertThings(jsonAFCAllSensors, jsonOGCThings, DEFAULT_PROPERTIES);
     }
 
     @Test
     void sensor() throws IOException {
-        String jsonAFCSensor = new String(readAllBytes(get(RESOURCES_DIR, "afc/getSensor.json")));
-        String jsonOGCDataStream = new String(readAllBytes(get(RESOURCES_DIR,"ogc/sensor.json")));
+        String jsonAFCSensor = readResourceFile("afc/getSensor.json");
+        String jsonOGCDataStream = readResourceFile("ogc/sensor.json");
         assertSensor(jsonAFCSensor, jsonOGCDataStream, DEFAULT_PROPERTIES);
     }
 
     @Test
     void dataStreams() throws IOException {
-        String jsonAFCSensor = new String(readAllBytes(get(RESOURCES_DIR, "afc/getSensor.json")));
-        String jsonAFCData = new String(readAllBytes(get(RESOURCES_DIR, "afc/getObservationsBySensor.json")));
-        String jsonOGC = new String(readAllBytes(get(RESOURCES_DIR,"ogc/datastreams.json")));
+        String jsonAFCSensor = readResourceFile("afc/getSensor.json");
+        String jsonAFCData = readResourceFile("afc/getObservationsBySensor.json");
+        String jsonOGC = readResourceFile("ogc/datastreams.json");
         assertDataStream(jsonAFCSensor, jsonAFCData, jsonOGC, DEFAULT_PROPERTIES);
     }
 
     @Test
     void observationProperty() throws IOException {
-        String jsonAFCSensor = new String(readAllBytes(get(RESOURCES_DIR, "afc/getSensor.json")));
-        String jsonAFCData = new String(readAllBytes(get(RESOURCES_DIR, "afc/getObservationsBySensor.json")));
-        String jsonOGC = new String(readAllBytes(get(RESOURCES_DIR,"ogc/observationProperty.json")));
+        String jsonAFCSensor = readResourceFile("afc/getSensor.json");
+        String jsonAFCData = readResourceFile("afc/getObservationsBySensor.json");
+        String jsonOGC = readResourceFile("ogc/observationProperty.json");
         assertObservedProperty(jsonAFCSensor, jsonAFCData, jsonOGC, DEFAULT_PROPERTIES);
     }
 
     @Test
     void observations() throws IOException {
-        String jsonAFCData = new String(readAllBytes(get(RESOURCES_DIR, "afc/getObservationsBySensor.json")));
-        String jsonOGC = new String(readAllBytes(get(RESOURCES_DIR,"ogc/observations.json")));
+        String jsonAFCData = readResourceFile("afc/getObservationsBySensor.json");
+        String jsonOGC = readResourceFile("ogc/observations.json");
         assertObservation(jsonAFCData, jsonOGC, DEFAULT_PROPERTIES);
     }
 
     @Test
     void locations() throws IOException {
-        String jsonAFCSensor = new String(readAllBytes(get(RESOURCES_DIR, "afc/getSensor.json")));
-        String jsonAFCData = new String(readAllBytes(get(RESOURCES_DIR, "afc/getObservationsBySensor.json")));
-        String jsonOGC = new String(readAllBytes(get(RESOURCES_DIR,"ogc/locations.json")));
+        String jsonAFCSensor = readResourceFile("afc/getSensor.json");
+        String jsonAFCData = readResourceFile("afc/getObservationsBySensor.json");
+        String jsonOGC = readResourceFile("ogc/locations.json");
         assertLocations(jsonAFCSensor, jsonAFCData, jsonOGC, DEFAULT_PROPERTIES);
     }
 
     @Test
     void historicalLocations() throws IOException {
-        String jsonAFCSensor = new String(readAllBytes(get(RESOURCES_DIR, "afc/getSensor.json")));
-        String jsonAFCData = new String(readAllBytes(get(RESOURCES_DIR, "afc/getObservationsBySensor.json")));
-        String jsonOGC = new String(readAllBytes(get(RESOURCES_DIR,"ogc/historicalLocations.json")));
+        String jsonAFCSensor = readResourceFile("afc/getSensor.json");
+        String jsonAFCData = readResourceFile("afc/getObservationsBySensor.json");
+        String jsonOGC = readResourceFile("ogc/historicalLocations.json");
         assertHistoricalLocation(jsonAFCSensor, jsonAFCData, jsonOGC, DEFAULT_PROPERTIES);
     }
 }

+ 2 - 5
connector-module-afarcloud/src/test/java/io/connector/module/afarcloud/OGCSensorThingsOnlineIntegrationTest.java

@@ -222,24 +222,21 @@ class OGCSensorThingsOnlineIntegrationTest {
         return links;
     }
 
-    @BeforeEach
+    @BeforeAll
     @DisplayName("Deploy the module:" + MODULE_ID)
-    void prepare(Vertx vertx, VertxTestContext testContext) {
+    static void prepare(Vertx vertx, VertxTestContext testContext) {
         DefaultConfig serviceConfig = new DefaultConfig(MODULE_ID, AFCModuleProvider.class);
         serviceConfig.setProperty("retrievalApi", new HashMap<String, String>(){{
-       //     put("domain", "http://torcos.etsist.upm.es:9219");
             put("domain", String.format("%s://%s:%d", AFC_RETRIEVAL_HOST.options.isSsl() ? "https" : "http",
                     AFC_RETRIEVAL_HOST.options.getDefaultHost(), AFC_RETRIEVAL_HOST.options.getDefaultPort())
             );
         }});
         serviceConfig.setProperty("telemetryApi", new HashMap<String, String>(){{
-      //      put("domain", "https://torcos.etsist.upm.es:9207");
             put("domain", String.format("%s://%s:%d", AFC_TELEMETRY_HOST.options.isSsl() ? "https" : "http",
                     AFC_TELEMETRY_HOST.options.getDefaultHost(), AFC_TELEMETRY_HOST.options.getDefaultPort())
             );
         }});
         serviceConfig.setProperty("infoApi", new HashMap<String, String>(){{
-        //    put("domain", "https://storage07-afarcloud.qa.pdmfc.com/storage/rest/");
             put("domain", String.format("%s://%s/%s", AFC_INFO_HOST.options.isSsl() ? "https" : "http",
                     AFC_INFO_HOST.options.getDefaultHost(), AFC_INFO_HOST.pathPrefix)
             );

+ 28 - 0
connector-module-ima/src/test/java/io/connector/module/ima/ExampleIntegrationTest.java

@@ -0,0 +1,28 @@
+package io.connector.module.ima;
+
+import io.connector.test.api.TestType;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@Tag(TestType.INTEGRATION)
+public class ExampleIntegrationTest {
+
+    @BeforeEach
+    void setUp() {
+
+    }
+
+    @AfterEach
+    void tearDown() {
+
+    }
+
+    @Test
+    void run() {
+        assertTrue(true, "This is example of an integration test.");
+    }
+}