You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2023/01/10 09:47:31 UTC
[streampipes] branch SP-1065 updated: [SP-1065] Add e2e test for xml format
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch SP-1065
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/SP-1065 by this push:
new 898ad6c0f [SP-1065] Add e2e test for xml format
898ad6c0f is described below
commit 898ad6c0f00ae69ea35c52f89887df5115f5efda
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Tue Jan 10 10:47:02 2023 +0100
[SP-1065] Add e2e test for xml format
---
.../adapter/format/geojson/GeoJsonParser.java | 1 -
.../adapter/format/xml/XmlMapConverter.java | 20 +++++++-
.../adapter/format/xml/XmlMapConverterTest.java | 56 ++++++++++++++++++++++
.../connect/{formatTests => format}/geoJson.json | 0
.../connect/{formatTests => format}/jsonArray.json | 0
.../{formatTests => format}/jsonArrayField.json | 0
.../{formatTests => format}/jsonObject.json | 0
ui/cypress/fixtures/connect/format/xmlObject.xml | 10 ++++
...ctFormat.smoke.spec.ts => format.smoke.spec.ts} | 26 ++++++++--
9 files changed, 107 insertions(+), 6 deletions(-)
diff --git a/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonParser.java b/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonParser.java
index 632f93a00..63478688c 100644
--- a/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonParser.java
+++ b/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/geojson/GeoJsonParser.java
@@ -164,7 +164,6 @@ public class GeoJsonParser extends Parser {
eventProperties.forEach(eventProperty -> resultSchema.addEventProperty(eventProperty));
return new AdapterGuessInfo(resultSchema, sampleValues);
-
}
private EventProperty getEventPropertyGeoJson(String name, Object value, String domain) {
diff --git a/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverter.java b/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverter.java
index d75894e2e..490d70e13 100644
--- a/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverter.java
+++ b/streampipes-extensions-management/src/main/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverter.java
@@ -44,7 +44,12 @@ public class XmlMapConverter {
convert((Map<String, Object>) map.get(key));
} else if (value instanceof String) {
String stringValue = String.valueOf(value);
- if (isInteger(stringValue)) {
+
+ if (isBoolean(stringValue)) {
+ map.put(key, Boolean.parseBoolean(stringValue));
+ } else if (isLong(stringValue)) {
+ map.put(key, Long.parseLong(stringValue));
+ } else if (isInteger(stringValue)) {
map.put(key, Integer.parseInt(stringValue));
} else if (isFloat(stringValue)) {
map.put(key, Float.parseFloat(stringValue));
@@ -100,4 +105,17 @@ public class XmlMapConverter {
return false;
}
}
+
+ private Boolean isLong(String value) {
+ try {
+ Long.parseLong(value);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ private Boolean isBoolean(String value) {
+ return value.toLowerCase().equals("true") || value.toLowerCase().equals("false");
+ }
}
diff --git a/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverterTest.java b/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverterTest.java
new file mode 100644
index 000000000..fa999e2af
--- /dev/null
+++ b/streampipes-extensions-management/src/test/java/org/apache/streampipes/extensions/management/connect/adapter/format/xml/XmlMapConverterTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.extensions.management.connect.adapter.format.xml;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+
+import static org.junit.Assert.assertEquals;
+
+public class XmlMapConverterTest {
+
+ private String eventKey = "key";
+
+ @Test
+ public void convertLongValue() {
+ var event = new HashMap<String, Object>();
+ event.put(eventKey, "1667904471000");
+
+ XmlMapConverter xmlMapConverter = new XmlMapConverter(event);
+
+ var result = xmlMapConverter.convert();
+ assertEquals(1, result.size());
+ assertEquals(1667904471000L, result.get(eventKey));
+ }
+
+ @Test
+ public void convertBooleanValue() {
+ var event = new HashMap<String, Object>();
+ event.put(eventKey, "false");
+
+ XmlMapConverter xmlMapConverter = new XmlMapConverter(event);
+
+ var result = xmlMapConverter.convert();
+ assertEquals(1, result.size());
+ assertEquals(false, result.get(eventKey));
+ }
+
+
+}
\ No newline at end of file
diff --git a/ui/cypress/fixtures/connect/formatTests/geoJson.json b/ui/cypress/fixtures/connect/format/geoJson.json
similarity index 100%
rename from ui/cypress/fixtures/connect/formatTests/geoJson.json
rename to ui/cypress/fixtures/connect/format/geoJson.json
diff --git a/ui/cypress/fixtures/connect/formatTests/jsonArray.json b/ui/cypress/fixtures/connect/format/jsonArray.json
similarity index 100%
rename from ui/cypress/fixtures/connect/formatTests/jsonArray.json
rename to ui/cypress/fixtures/connect/format/jsonArray.json
diff --git a/ui/cypress/fixtures/connect/formatTests/jsonArrayField.json b/ui/cypress/fixtures/connect/format/jsonArrayField.json
similarity index 100%
rename from ui/cypress/fixtures/connect/formatTests/jsonArrayField.json
rename to ui/cypress/fixtures/connect/format/jsonArrayField.json
diff --git a/ui/cypress/fixtures/connect/formatTests/jsonObject.json b/ui/cypress/fixtures/connect/format/jsonObject.json
similarity index 100%
rename from ui/cypress/fixtures/connect/formatTests/jsonObject.json
rename to ui/cypress/fixtures/connect/format/jsonObject.json
diff --git a/ui/cypress/fixtures/connect/format/xmlObject.xml b/ui/cypress/fixtures/connect/format/xmlObject.xml
new file mode 100644
index 000000000..67efdbb86
--- /dev/null
+++ b/ui/cypress/fixtures/connect/format/xmlObject.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<events>
+ <event>
+ <timestamp>1667904471000</timestamp>
+ <v1>4.1</v1>
+ <v2>abc</v2>
+ <v3>true</v3>
+ <v4>1</v4>
+ </event>
+</events>
diff --git a/ui/cypress/tests/adapter/formats/jsonObjectFormat.smoke.spec.ts b/ui/cypress/tests/adapter/formats/format.smoke.spec.ts
similarity index 83%
rename from ui/cypress/tests/adapter/formats/jsonObjectFormat.smoke.spec.ts
rename to ui/cypress/tests/adapter/formats/format.smoke.spec.ts
index cc8d40c38..df48f0cf7 100644
--- a/ui/cypress/tests/adapter/formats/jsonObjectFormat.smoke.spec.ts
+++ b/ui/cypress/tests/adapter/formats/format.smoke.spec.ts
@@ -27,6 +27,8 @@ describe('Test adapter formats', () => {
cy.initStreamPipesTest();
});
+ const baseDir = 'connect/format/';
+
const expected = {
timestamp: 1667904471000,
v1: 4.1,
@@ -37,7 +39,7 @@ describe('Test adapter formats', () => {
it('Test json object format', () => {
// Set up test
- FileManagementUtils.addFile('connect/formatTests/jsonObject.json');
+ FileManagementUtils.addFile(baseDir + 'jsonObject.json');
navigateToFormatSelection();
@@ -51,7 +53,7 @@ describe('Test adapter formats', () => {
it('Test array with json objects', () => {
// Set up test
- FileManagementUtils.addFile('connect/formatTests/jsonArray.json');
+ FileManagementUtils.addFile('connect/format/jsonArray.json');
navigateToFormatSelection();
// Set format configuration
@@ -64,7 +66,7 @@ describe('Test adapter formats', () => {
it('Test json with a field of type array', () => {
// Set up test
- FileManagementUtils.addFile('connect/formatTests/jsonArrayField.json');
+ FileManagementUtils.addFile(baseDir + 'jsonArrayField.json');
navigateToFormatSelection();
// Set format configuration
@@ -87,7 +89,7 @@ describe('Test adapter formats', () => {
timestamp: 1667904471000,
v1: 4.1,
};
- FileManagementUtils.addFile('connect/formatTests/geoJson.json');
+ FileManagementUtils.addFile(baseDir + 'geoJson.json');
navigateToFormatSelection();
// Set format configuration
@@ -97,6 +99,22 @@ describe('Test adapter formats', () => {
// Validate result
validateResult(geoJsonResultEvent);
});
+
+ it('Test xml format', () => {
+ // Set up test
+ FileManagementUtils.addFile(baseDir + 'xmlObject.xml');
+ navigateToFormatSelection();
+
+ // Set format configuration
+ ConnectBtns.xml().click();
+ const tagInputField = UserInputBuilder.create()
+ .add('input', 'tag', 'event')
+ .build();
+ StaticPropertyUtils.input(tagInputField);
+
+ // Validate result
+ validateResult(expected);
+ });
});
const navigateToFormatSelection = () => {