You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2023/06/05 12:11:13 UTC

[streampipes] branch fix-adapter-cypress-tests created (now 2e535e33b)

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a change to branch fix-adapter-cypress-tests
in repository https://gitbox.apache.org/repos/asf/streampipes.git


      at 2e535e33b [hotfix] Fix e2e tests after adapter refactoring

This branch includes the following new commits:

     new 2e535e33b [hotfix] Fix e2e tests after adapter refactoring

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[streampipes] 01/01: [hotfix] Fix e2e tests after adapter refactoring

Posted by ri...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch fix-adapter-cypress-tests
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit 2e535e33beb40777c971b97bba80cfb0817d5fd5
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Mon Jun 5 14:10:49 2023 +0200

    [hotfix] Fix e2e tests after adapter refactoring
---
 .../connect/adapter/parser/xml/XmlParser.java      |   2 +
 .../connect/adapter/parser/XmlParserTest.java      |  53 ++++++---
 ui/cypress/fixtures/connect/format/geoJson.json    |  23 ++--
 ui/cypress/support/builder/AdapterBuilder.ts       |   4 +-
 .../support/utils/ProcessingElementTestUtils.ts    |   8 +-
 ui/cypress/support/utils/StaticPropertyUtils.ts    |   2 +-
 ui/cypress/support/utils/connect/ConnectBtns.ts    |   8 ++
 ui/cypress/tests/adapter/formats/format.spec.ts    | 121 ++++++++++-----------
 .../tests/pipelineElement/SinglePipelineElement.ts |   2 +-
 9 files changed, 130 insertions(+), 93 deletions(-)

diff --git a/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/parser/xml/XmlParser.java b/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/parser/xml/XmlParser.java
index 095481726..9013d6be7 100644
--- a/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/parser/xml/XmlParser.java
+++ b/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/parser/xml/XmlParser.java
@@ -106,6 +106,8 @@ public class XmlParser implements IParser {
         if (key.equals(tag)) {
           if (xml.get(tag) instanceof List) {
             return (List<Map<String, Object>>) xml.get(tag);
+          } else if (xml.get(tag) instanceof Map) {
+            return List.of((Map<String, Object>) xml.get(tag));
           } else {
             throw new ParseException("Could not parse %s with tag %s".formatted(xml, tag));
           }
diff --git a/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/parser/XmlParserTest.java b/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/parser/XmlParserTest.java
index aa6d66425..b12e7ef32 100644
--- a/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/parser/XmlParserTest.java
+++ b/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/parser/XmlParserTest.java
@@ -20,6 +20,7 @@ package org.apache.streampipes.extensions.management.connect.adapter.parser;
 
 import org.apache.streampipes.extensions.api.connect.IParserEventHandler;
 import org.apache.streampipes.extensions.management.connect.adapter.parser.xml.XmlParser;
+import org.apache.streampipes.model.connect.guess.GuessSchema;
 import org.apache.streampipes.model.schema.PropertyScope;
 import org.apache.streampipes.sdk.builder.PrimitivePropertyBuilder;
 import org.apache.streampipes.sdk.builder.adapter.GuessSchemaBuilder;
@@ -48,24 +49,18 @@ public class XmlParserTest extends ParserTest {
                                + "</enclosing>"
                                + "</list>";
 
+  private final String sampleEventWithSingleObject = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
+      + "<list>"
+      + "<enclosing>"
+      + "<k1>v1</k1><k2>1.0</k2>"
+      + "</enclosing>"
+      + "</list>";
+
   private final String tag = "enclosing";
 
   @Test
   public void getGuessSchema() {
-    var expected = GuessSchemaBuilder.create()
-        .property(PrimitivePropertyBuilder
-            .create(Datatypes.String, K1)
-            .description("")
-            .scope(PropertyScope.MEASUREMENT_PROPERTY)
-            .build())
-        .property(PrimitivePropertyBuilder
-            .create(Datatypes.Float, K2)
-            .scope(PropertyScope.MEASUREMENT_PROPERTY)
-            .description("")
-            .build())
-        .sample(K1, "v1")
-        .sample(K2, 1.0f)
-        .build();
+    var expected = getExpectedSchema();
 
     var parser = new XmlParser(tag);
 
@@ -76,6 +71,19 @@ public class XmlParserTest extends ParserTest {
     assertEquals(expected, result);
   }
 
+  @Test
+  public void getGuessSchemaWithSingleObjectInArray() {
+    var expected = getExpectedSchema();
+
+    var parser = new XmlParser(tag);
+
+    InputStream event = toStream(sampleEventWithSingleObject);
+
+    var result = parser.getGuessSchema(event);
+
+    assertEquals(expected, result);
+  }
+
   @Test
   public void parse() {
     var event = toStream(sampleEvent);
@@ -93,4 +101,21 @@ public class XmlParserTest extends ParserTest {
     expectedEvent.put(K2, 2.0f);
     verify(mockEventHandler, times(1)).handle(expectedEvent);
   }
+
+  private GuessSchema getExpectedSchema() {
+    return GuessSchemaBuilder.create()
+        .property(PrimitivePropertyBuilder
+            .create(Datatypes.String, K1)
+            .description("")
+            .scope(PropertyScope.MEASUREMENT_PROPERTY)
+            .build())
+        .property(PrimitivePropertyBuilder
+            .create(Datatypes.Float, K2)
+            .scope(PropertyScope.MEASUREMENT_PROPERTY)
+            .description("")
+            .build())
+        .sample(K1, "v1")
+        .sample(K2, 1.0f)
+        .build();
+  }
 }
diff --git a/ui/cypress/fixtures/connect/format/geoJson.json b/ui/cypress/fixtures/connect/format/geoJson.json
index 047e60497..97e202ba7 100644
--- a/ui/cypress/fixtures/connect/format/geoJson.json
+++ b/ui/cypress/fixtures/connect/format/geoJson.json
@@ -1,16 +1,11 @@
 {
-  "type": "FeatureCollection",
-  "features": [
-    {
-      "type": "Feature",
-      "geometry": {
-        "type": "Point",
-        "coordinates": [125.6, 10.1]
-      },
-      "properties": {
-        "timestamp": 1667904471000,
-        "v1": 4.1
-      }
-    }
-  ]
+  "type": "Feature",
+  "geometry": {
+    "type": "Point",
+    "coordinates": [125.6, 10.1]
+  },
+  "properties": {
+    "timestamp": 1667904471000,
+    "v1": 4.1
+  }
 }
diff --git a/ui/cypress/support/builder/AdapterBuilder.ts b/ui/cypress/support/builder/AdapterBuilder.ts
index d317079a5..c8c029c59 100644
--- a/ui/cypress/support/builder/AdapterBuilder.ts
+++ b/ui/cypress/support/builder/AdapterBuilder.ts
@@ -85,7 +85,9 @@ export class AdapterBuilder {
         return this;
     }
 
-    public setFormat(format: 'csv' | 'json' | 'json_array' | 'json_object') {
+    public setFormat(
+        format: 'csv' | 'json' | 'json_array' | 'json_object' | 'xml',
+    ) {
         this.adapterInput.format = format;
         return this;
     }
diff --git a/ui/cypress/support/utils/ProcessingElementTestUtils.ts b/ui/cypress/support/utils/ProcessingElementTestUtils.ts
index c42b661d0..b892de761 100644
--- a/ui/cypress/support/utils/ProcessingElementTestUtils.ts
+++ b/ui/cypress/support/utils/ProcessingElementTestUtils.ts
@@ -39,7 +39,7 @@ export class ProcessingElementTestUtils {
         let formatType;
         pipelineElementTest.inputFile.endsWith('.csv')
             ? (formatType = 'csv')
-            : (formatType = 'json_array');
+            : (formatType = 'json');
 
         FileManagementUtils.addFile(inputFile);
 
@@ -64,6 +64,12 @@ export class ProcessingElementTestUtils {
             adapterInputBuilder
                 .addFormatInput('input', ConnectBtns.csvDelimiter(), ';')
                 .addFormatInput('checkbox', ConnectBtns.csvHeader(), 'check');
+        } else if (formatType === 'json') {
+            adapterInputBuilder.addFormatInput(
+                'checkbox',
+                'json_options-array',
+                '',
+            );
         }
 
         const adapterInput = adapterInputBuilder.build();
diff --git a/ui/cypress/support/utils/StaticPropertyUtils.ts b/ui/cypress/support/utils/StaticPropertyUtils.ts
index 7a5d418c0..367302086 100644
--- a/ui/cypress/support/utils/StaticPropertyUtils.ts
+++ b/ui/cypress/support/utils/StaticPropertyUtils.ts
@@ -23,7 +23,7 @@ export class StaticPropertyUtils {
         // Configure Properties
         configs.forEach(config => {
             if (config.type === 'checkbox') {
-                cy.dataCy(config.selector).children().click();
+                cy.dataCy(config.selector).children().click({ force: true });
             } else if (config.type === 'button') {
                 cy.dataCy(config.selector).click();
             } else if (config.type === 'drop-down') {
diff --git a/ui/cypress/support/utils/connect/ConnectBtns.ts b/ui/cypress/support/utils/connect/ConnectBtns.ts
index 9841047d6..0fab8973c 100644
--- a/ui/cypress/support/utils/connect/ConnectBtns.ts
+++ b/ui/cypress/support/utils/connect/ConnectBtns.ts
@@ -69,5 +69,13 @@ export class ConnectBtns {
         return 'undefined-org.apache.streampipes.extensions.management.connect.adapter.parser.csv-1-header-1';
     }
 
+    public static jsonArrayFieldKey() {
+        return 'undefined-arrayFieldConfig-2-key-0';
+    }
+
+    public static xmlTag() {
+        return 'undefined-org.apache.streampipes.extensions.management.connect.adapter.parser.xml-2-tag-0';
+    }
+
     // ========================================================================
 }
diff --git a/ui/cypress/tests/adapter/formats/format.spec.ts b/ui/cypress/tests/adapter/formats/format.spec.ts
index 7e615e869..c91303123 100644
--- a/ui/cypress/tests/adapter/formats/format.spec.ts
+++ b/ui/cypress/tests/adapter/formats/format.spec.ts
@@ -21,6 +21,8 @@ import { ConnectUtils } from '../../../support/utils/connect/ConnectUtils';
 import { ConnectBtns } from '../../../support/utils/connect/ConnectBtns';
 import { StaticPropertyUtils } from '../../../support/utils/StaticPropertyUtils';
 import { UserInputBuilder } from '../../../support/builder/UserInputBuilder';
+import { AdapterInput } from '../../../support/model/AdapterInput';
+import { AdapterBuilder } from '../../../support/builder/AdapterBuilder';
 
 describe('Test adapter formats', () => {
     beforeEach('Setup Test', () => {
@@ -40,12 +42,13 @@ describe('Test adapter formats', () => {
     it('Test json object format', () => {
         // Set up test
         FileManagementUtils.addFile(baseDir + 'jsonObject.json');
+        const template = makeAdapterInputTemplate();
 
-        navigateToFormatSelection();
+        template
+            .setFormat('json')
+            .addFormatInput('checkbox', 'json_options-single_object', '');
 
-        // Set format configuration
-        ConnectBtns.json().click();
-        ConnectBtns.jsonObject().click();
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(expected);
@@ -54,11 +57,13 @@ describe('Test adapter formats', () => {
     it('Test array with json objects', () => {
         // Set up test
         FileManagementUtils.addFile('connect/format/jsonArray.json');
-        navigateToFormatSelection();
+        const template = makeAdapterInputTemplate();
 
-        // Set format configuration
-        ConnectBtns.json().click();
-        ConnectBtns.jsonArray().click();
+        template
+            .setFormat('json')
+            .addFormatInput('checkbox', 'json_options-array', '');
+
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(expected);
@@ -67,15 +72,14 @@ describe('Test adapter formats', () => {
     it('Test json with a field of type array', () => {
         // Set up test
         FileManagementUtils.addFile(baseDir + 'jsonArrayField.json');
-        navigateToFormatSelection();
+        const template = makeAdapterInputTemplate();
+
+        template
+            .setFormat('json')
+            .addFormatInput('checkbox', 'json_options-array_field', '')
+            .addFormatInput('input', ConnectBtns.jsonArrayFieldKey(), 'field');
 
-        // Set format configuration
-        ConnectBtns.json().click();
-        ConnectBtns.jsonArrayField().click();
-        const arrayFieldInput = UserInputBuilder.create()
-            .add('input', 'key', 'field')
-            .build();
-        StaticPropertyUtils.input(arrayFieldInput);
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(expected);
@@ -90,11 +94,13 @@ describe('Test adapter formats', () => {
             v1: 4.1,
         };
         FileManagementUtils.addFile(baseDir + 'geoJson.json');
-        navigateToFormatSelection();
+        const template = makeAdapterInputTemplate();
 
-        // Set format configuration
-        ConnectBtns.json().click();
-        ConnectBtns.geoJson().click();
+        template
+            .setFormat('json')
+            .addFormatInput('checkbox', 'json_options-geojson', '');
+
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(geoJsonResultEvent);
@@ -103,14 +109,12 @@ describe('Test adapter formats', () => {
     it('Test xml format', () => {
         // Set up test
         FileManagementUtils.addFile(baseDir + 'xmlObject.xml');
-        navigateToFormatSelection();
+        const template = makeAdapterInputTemplate();
+        template
+            .setFormat('xml')
+            .addFormatInput('input', ConnectBtns.xmlTag(), 'event');
 
-        // Set format configuration
-        ConnectBtns.xml().click();
-        const tagInputField = UserInputBuilder.create()
-            .add('input', 'tag', 'event')
-            .build();
-        StaticPropertyUtils.input(tagInputField);
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(expected);
@@ -119,18 +123,13 @@ describe('Test adapter formats', () => {
     it('Test csv format with header', () => {
         // Set up test
         FileManagementUtils.addFile(baseDir + 'csvWithHeader.csv');
-        navigateToFormatSelection();
-
-        // Set format configuration
-        ConnectBtns.csv().click();
-        const delimiterInputField = UserInputBuilder.create()
-            .add('input', 'delimiter', ';')
-            .build();
-        StaticPropertyUtils.input(delimiterInputField);
-        const headerInputField = UserInputBuilder.create()
-            .add('checkbox', 'header', 'check')
-            .build();
-        StaticPropertyUtils.input(headerInputField);
+        const template = makeAdapterInputTemplate();
+        template
+            .setFormat('csv')
+            .addFormatInput('input', ConnectBtns.csvDelimiter(), ';')
+            .addFormatInput('checkbox', ConnectBtns.csvHeader(), 'check');
+
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(expected);
@@ -139,14 +138,12 @@ describe('Test adapter formats', () => {
     it('Test csv format without header', () => {
         // Set up test
         FileManagementUtils.addFile(baseDir + 'csvWithoutHeader.csv');
-        navigateToFormatSelection();
+        const template = makeAdapterInputTemplate();
+        template
+            .setFormat('csv')
+            .addFormatInput('input', ConnectBtns.csvDelimiter(), ';');
 
-        // Set format configuration
-        ConnectBtns.csv().click();
-        const delimiterInputField = UserInputBuilder.create()
-            .add('input', 'delimiter', ';')
-            .build();
-        StaticPropertyUtils.input(delimiterInputField);
+        navigateToFormatSelection(template.build());
 
         const expectedNoHeader = {
             key_0: 1667904471000,
@@ -163,36 +160,38 @@ describe('Test adapter formats', () => {
     it('Test csv format with comma', () => {
         // Set up test
         FileManagementUtils.addFile(baseDir + 'csvWithComma.csv');
-        navigateToFormatSelection();
-
-        // Set format configuration
-        ConnectBtns.csv().click();
-        const delimiterInputField = UserInputBuilder.create()
-            .add('input', 'delimiter', ',')
-            .build();
-        StaticPropertyUtils.input(delimiterInputField);
-        const headerInputField = UserInputBuilder.create()
-            .add('checkbox', 'header', 'check')
-            .build();
-        StaticPropertyUtils.input(headerInputField);
+        const template = makeAdapterInputTemplate();
+        template
+            .setFormat('csv')
+            .addFormatInput('input', ConnectBtns.csvDelimiter(), ',')
+            .addFormatInput('checkbox', ConnectBtns.csvHeader(), 'check');
+
+        navigateToFormatSelection(template.build());
 
         // Validate result
         validateResult(expected);
     });
 });
 
-const navigateToFormatSelection = () => {
+const navigateToFormatSelection = (adapterInput: AdapterInput) => {
     ConnectUtils.goToConnect();
 
     ConnectUtils.goToNewAdapterPage();
 
     ConnectUtils.selectAdapter('File_Stream');
 
-    ConnectUtils.configureAdapter([]);
+    ConnectUtils.configureAdapter(adapterInput);
+};
+
+const makeAdapterInputTemplate = (): AdapterBuilder => {
+    return AdapterBuilder.create('File_Stream')
+        .setName('File Stream Adapter Test')
+        .setTimestampProperty('timestamp')
+        .addProtocolInput('checkbox', 'replaceTimestamp', 'check');
 };
 
 const validateResult = expected => {
-    ConnectBtns.formatSelectionNextBtn().click();
+    //ConnectBtns.formatSelectionNextBtn().click();
     cy.dataCy('schema-preview-original-event', { timeout: 10000 }).then(
         value => {
             const jsonResult = removeWhitespaceExceptInQuotes(value.text());
diff --git a/ui/cypress/tests/pipelineElement/SinglePipelineElement.ts b/ui/cypress/tests/pipelineElement/SinglePipelineElement.ts
index 46b6c8565..3bdac4f86 100644
--- a/ui/cypress/tests/pipelineElement/SinglePipelineElement.ts
+++ b/ui/cypress/tests/pipelineElement/SinglePipelineElement.ts
@@ -22,7 +22,7 @@ import { ProcessorTest } from '../../support/model/ProcessorTest';
 const allTests = Cypress.env('processingElements');
 
 allTests.forEach(test => {
-    const testNames = ['staticmath1'];
+    const testNames = ['splitArray1'];
 
     const processorTest = test as ProcessorTest;