This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch
2894-deletetransformationrulespects-test-is-flaky
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to
refs/heads/2894-deletetransformationrulespects-test-is-flaky by this push:
new 7fce3690d8 fix(#2894): Fix flaky e2e test
7fce3690d8 is described below
commit 7fce3690d8059af64bfe6eb9346919bb95ed468f
Author: Philipp Zehnder <[email protected]>
AuthorDate: Wed May 22 22:01:16 2024 +0200
fix(#2894): Fix flaky e2e test
---
.../SupportsNestedTransformationRule.java | 2 +-
.../schema/DeleteTransformationRuleTest.java | 89 ++++++++++++++++++----
.../deleteTransformationRule/nestedInput.json | 3 +-
.../support/utils/ConnectEventSchemaUtils.ts | 9 ++-
.../adapter/rules/deleteTransformationRule.spec.ts | 30 ++++++++
5 files changed, 114 insertions(+), 19 deletions(-)
diff --git
a/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
b/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
index a0494cff34..86a36b7d6c 100644
---
a/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
+++
b/streampipes-connect-shared/src/main/java/org/apache/streampipes/connect/shared/preprocessing/SupportsNestedTransformationRule.java
@@ -43,7 +43,7 @@ public abstract class SupportsNestedTransformationRule
implements Transformation
event.remove(key);
- if (newSubEvent != null && !newSubEvent.isEmpty()) {
+ if (newSubEvent != null) {
event.put(key, newSubEvent);
}
}
diff --git
a/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
b/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
index e8d5e1feb8..28d8ffb20e 100644
---
a/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
+++
b/streampipes-connect-shared/src/test/java/org/apache/streampipes/connect/shared/preprocessing/transform/schema/DeleteTransformationRuleTest.java
@@ -18,16 +18,22 @@
package org.apache.streampipes.connect.shared.preprocessing.transform.schema;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class DeleteTransformationRuleTest {
+
+ private ObjectMapper objectMapper = new ObjectMapper();
+
@Test
public void transformSimple() {
var event = new HashMap<String, Object>();
@@ -37,25 +43,63 @@ public class DeleteTransformationRuleTest {
var result = deleteRule.apply(event);
- assertEquals(0, result.keySet().size());
+ assertEquals(0,
+ result.keySet()
+ .size()
+ );
}
@Test
- public void transformNested() {
- var child = new HashMap<String, Object>();
- child.put("child", "value");
- child.put("secondChild", "value");
- var event = new HashMap<String, Object>();
- event.put("parent", child);
- event.put("keepProperty", "test");
+ public void transformNested() throws JsonProcessingException {
+ var jsonString = """
+ {
+ "parent": {
+ "child": "value",
+ "child2": "value2"
+ },
+ "keepProperty": "test"
+ }
+ """;
+
+ var event = getEvent(jsonString);
var deleteRule = new DeleteTransformationRule(List.of("parent", "child"));
var result = deleteRule.apply(event);
- assertEquals(2, result.keySet().size());
+ assertEquals(2,
+ result.keySet()
+ .size()
+ );
+ assertEquals(1, ((Map) result.get("parent")).size());
+ }
+
+ @Test
+ public void testRemoveParent() throws JsonProcessingException {
+ var jsonString = """
+ {
+ "parent": {
+ "child": "value",
+ "child2": "value2"
+ },
+ "keepProperty": "test"
+ }
+ """;
+
+ var event = getEvent(jsonString);
+
+ var deleteRule = new DeleteTransformationRule(List.of("parent"));
+
+ var result = deleteRule.apply(event);
+
+ assertEquals(1,
+ result.keySet()
+ .size()
+ );
+ assertEquals("test", result.get("keepProperty"));
}
+
@Test
// verifying that mathod applyTransformation method works when passed a null
event.
public void applyTransformationWithNullParameter() {
@@ -64,19 +108,32 @@ public class DeleteTransformationRuleTest {
}
@Test
- public void deleteNestedChildWithParentProperty() {
- var child = new HashMap<String, Object>();
- child.put("child", "value");
- var event = new HashMap<String, Object>();
- event.put("parent", child);
- event.put("keepProperty", "test");
+ public void deleteNestedChildWithParentProperty() throws
JsonProcessingException {
+
+ var jsonString = """
+ {
+ "parent": {
+ "child": "value"
+ },
+ "keepProperty": "test"
+ }
+ """;
+
+ var event = getEvent(jsonString);
var deleteRule = new DeleteTransformationRule(Arrays.asList("parent",
"child"));
var result = deleteRule.apply(event);
- assertEquals(1, result.keySet().size());
+ assertEquals(2,
+ result.keySet()
+ .size()
+ );
assertEquals("test", result.get("keepProperty"));
}
+ private Map<String, Object> getEvent(String eventJson) throws
JsonProcessingException {
+ return objectMapper.readValue(eventJson, HashMap.class);
+ }
+
}
diff --git
a/ui/cypress/fixtures/connect/deleteTransformationRule/nestedInput.json
b/ui/cypress/fixtures/connect/deleteTransformationRule/nestedInput.json
index 92177c23ed..5456e65cbb 100644
--- a/ui/cypress/fixtures/connect/deleteTransformationRule/nestedInput.json
+++ b/ui/cypress/fixtures/connect/deleteTransformationRule/nestedInput.json
@@ -1,6 +1,7 @@
{
"timestamp": 1667904471000,
"parent": {
- "child": "text"
+ "child": "text",
+ "child_two": "textTwo"
}
}
diff --git a/ui/cypress/support/utils/ConnectEventSchemaUtils.ts
b/ui/cypress/support/utils/ConnectEventSchemaUtils.ts
index 495a47c738..663a42edbf 100644
--- a/ui/cypress/support/utils/ConnectEventSchemaUtils.ts
+++ b/ui/cypress/support/utils/ConnectEventSchemaUtils.ts
@@ -183,7 +183,14 @@ export class ConnectEventSchemaUtils {
.click({ force: true });
cy.dataCy('connect-schema-delete-properties-btn', {
timeout: 10000,
- }).click();
+ }).click({ force: true });
+
+ // The following two commands are required to fix flaky tests
+ // if another solution can be found, it can be removed
+ cy.wait(200);
+ cy.dataCy('connect-schema-update-preview-btn', {
+ timeout: 10000,
+ }).click({ force: true });
}
public static changePropertyDataType(
diff --git a/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
b/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
index 2ece7e9a38..6ecb38744b 100644
--- a/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
+++ b/ui/cypress/tests/adapter/rules/deleteTransformationRule.spec.ts
@@ -69,6 +69,25 @@ describe('Connect delete rule transformation', () => {
ConnectEventSchemaUtils.deleteProperty('child');
// The resulting string contains non-breaking spaces character (\u00A0)
+ cy.dataCy('schema-preview-result-event').should(
+ 'have.text',
+
'{\u00A0\u00A0\u00A0\u00A0"parent":\u00A0{\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0"child_two":\u00A0"textTwo"\u00A0\u00A0\u00A0\u00A0},\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
+ );
+
+ ConnectBtns.refreshSchema().click();
+
+ // Test to delete the parent property
+ ConnectEventSchemaUtils.deleteProperty('parent');
+ cy.dataCy('schema-preview-result-event').should(
+ 'have.text',
+
+ '{\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
+ );
+
+ ConnectBtns.refreshSchema().click();
+ ConnectEventSchemaUtils.deleteProperty('child');
+ ConnectEventSchemaUtils.deleteProperty('child_two');
+
cy.dataCy('schema-preview-result-event').should(
'have.text',
'{\u00A0\u00A0\u00A0\u00A0"parent":\u00A0{},\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
@@ -83,5 +102,16 @@ describe('Connect delete rule transformation', () => {
'{\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
);
+
+ ConnectBtns.refreshSchema().click();
+
+ // Test to delete both child properties
+ ConnectEventSchemaUtils.deleteProperty('child');
+ ConnectEventSchemaUtils.deleteProperty('child_two');
+
+ cy.dataCy('schema-preview-result-event').should(
+ 'have.text',
+
'{\u00A0\u00A0\u00A0\u00A0"parent":\u00A0{},\u00A0\u00A0\u00A0\u00A0"timestamp":\u00A01667904471000}',
+ );
});
});