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

zehnder pushed a commit to branch 
3298-add-cypress-e2e-tests-for-compact-adapter-feature
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/3298-add-cypress-e2e-tests-for-compact-adapter-feature by this push:
     new e4cb854eca feat(#3298): Add test to check rename rule for compact 
adapters
e4cb854eca is described below

commit e4cb854eca203f9813f3ec02e7fd3166bf3f355b
Author: Philipp Zehnder <[email protected]>
AuthorDate: Thu Oct 24 13:44:26 2024 +0200

    feat(#3298): Add test to check rename rule for compact adapters
---
 .../support/builder/CompactAdapterBuilder.ts       |  9 ++++
 .../support/utils/connect/CompactAdapterUtils.ts   | 30 +++++++++++++-
 ui/cypress/support/utils/connect/ConnectUtils.ts   | 16 ++++++++
 ...CompactAdapter.ts => addCompactAdapter.spec.ts} | 19 +++------
 .../compactAdapterWithTransformation.spec.ts       | 48 ++++++++++++++++++++++
 ...{uiConfiguration.ts => uiConfiguration.spec.ts} |  0
 6 files changed, 106 insertions(+), 16 deletions(-)

diff --git a/ui/cypress/support/builder/CompactAdapterBuilder.ts 
b/ui/cypress/support/builder/CompactAdapterBuilder.ts
index 379f38fbf4..4569504b9a 100644
--- a/ui/cypress/support/builder/CompactAdapterBuilder.ts
+++ b/ui/cypress/support/builder/CompactAdapterBuilder.ts
@@ -28,6 +28,10 @@ export class CompactAdapterBuilder {
             persist: false,
             start: false,
         };
+        this.compactAdapter.transform = {
+            rename: {},
+            measurementUnit: {},
+        };
     }
 
     public static create(appId: string) {
@@ -52,6 +56,11 @@ export class CompactAdapterBuilder {
         return this;
     }
 
+    public withRename(from: string, to: string) {
+        this.compactAdapter.transform.rename[from] = to;
+        return this;
+    }
+
     public addConfiguration(key: string, value: string) {
         const configuration = { [key]: value };
         this.compactAdapter.configuration.push(configuration);
diff --git a/ui/cypress/support/utils/connect/CompactAdapterUtils.ts 
b/ui/cypress/support/utils/connect/CompactAdapterUtils.ts
index d6d059950e..43757f580c 100644
--- a/ui/cypress/support/utils/connect/CompactAdapterUtils.ts
+++ b/ui/cypress/support/utils/connect/CompactAdapterUtils.ts
@@ -17,12 +17,20 @@
  */
 
 import { CompactAdapter } from 
'../../../../projects/streampipes/platform-services/src/lib/model/gen/streampipes-model';
+import { CompactAdapterBuilder } from '../../builder/CompactAdapterBuilder';
 
 export class CompactAdapterUtils {
+    /**
+     * Stores a compact adapter by sending a POST request to the backend.
+     *
+     * @param {CompactAdapter} compactAdapter - The compact adapter to be 
stored.
+     * @param {boolean} [failOnStatusCode=true] - Whether to fail the request 
on a non-2xx status code.
+     * @returns {Cypress.Chainable} - The Cypress chainable object 
representing the request.
+     */
     public static storeCompactAdapter(
         compactAdapter: CompactAdapter,
-        failOnStatusCode = true,
-    ) {
+        failOnStatusCode: boolean = true,
+    ): Cypress.Chainable {
         return this.postCompactAdapterRequest(
             'application/json',
             compactAdapter,
@@ -30,6 +38,12 @@ export class CompactAdapterUtils {
         );
     }
 
+    /**
+     * Stores a compact YAML adapter by sending a POST request to the backend.
+     *
+     * @param {string} body - The YAML string representing the compact adapter.
+     * @returns {Cypress.Chainable} - The Cypress chainable object 
representing the request.
+     */
     public static storeCompactYmlAdapter(body: string) {
         return this.postCompactAdapterRequest('application/yml', body);
     }
@@ -52,4 +66,16 @@ export class CompactAdapterUtils {
             },
         });
     }
+
+    /**
+     * Creates a CompactAdapterBuilder instance configured for a machine data 
simulator.
+     */
+    public static getMachineDataSimulator(): CompactAdapterBuilder {
+        return CompactAdapterBuilder.create(
+            'org.apache.streampipes.connect.iiot.adapters.simulator.machine',
+        )
+            .setName('Test')
+            .addConfiguration('wait-time-ms', '1000')
+            .addConfiguration('selected-simulator-option', 'flowrate');
+    }
 }
diff --git a/ui/cypress/support/utils/connect/ConnectUtils.ts 
b/ui/cypress/support/utils/connect/ConnectUtils.ts
index eec016bd61..fb7697992a 100644
--- a/ui/cypress/support/utils/connect/ConnectUtils.ts
+++ b/ui/cypress/support/utils/connect/ConnectUtils.ts
@@ -379,6 +379,22 @@ export class ConnectUtils {
             .then(text => expect(text).not.to.include('no data'));
     }
 
+    /**
+     * Validates the event schema for an adapter by checking the amount of 
properties
+     * and the runtime names of the event properties
+     * @param runtimeNames runtime names of the event properties
+     */
+    public static validateEventSchema(runtimeNames: string[]) {
+        ConnectUtils.goToConnect();
+        ConnectBtns.detailsAdapter().click();
+
+        cy.get('tr.mat-mdc-row').should('have.length', runtimeNames.length);
+
+        runtimeNames.forEach(name => {
+            cy.get('td.mat-column-runtimeName').contains(name).should('exist');
+        });
+    }
+
     public static tearDownPreprocessingRuleTest(
         adapterConfiguration: AdapterInput,
         expectedFile: string,
diff --git a/ui/cypress/tests/connect/compact/addCompactAdapter.ts 
b/ui/cypress/tests/connect/compact/addCompactAdapter.spec.ts
similarity index 82%
rename from ui/cypress/tests/connect/compact/addCompactAdapter.ts
rename to ui/cypress/tests/connect/compact/addCompactAdapter.spec.ts
index fe1c38f891..c19e345f8d 100644
--- a/ui/cypress/tests/connect/compact/addCompactAdapter.ts
+++ b/ui/cypress/tests/connect/compact/addCompactAdapter.spec.ts
@@ -18,7 +18,6 @@
 
 import { ConnectUtils } from '../../../support/utils/connect/ConnectUtils';
 import { CompactAdapterUtils } from 
'../../../support/utils/connect/CompactAdapterUtils';
-import { CompactAdapterBuilder } from 
'../../../support/builder/CompactAdapterBuilder';
 import { PipelineUtils } from '../../../support/utils/pipeline/PipelineUtils';
 
 describe('Add Compact Adapters', () => {
@@ -27,7 +26,8 @@ describe('Add Compact Adapters', () => {
     });
 
     it('Add an adapter via the compact API. Do not start', () => {
-        const compactAdapter = getBasicCompactMachineDataSimulator().build();
+        const compactAdapter =
+            CompactAdapterUtils.getMachineDataSimulator().build();
 
         CompactAdapterUtils.storeCompactAdapter(compactAdapter).then(() => {
             ConnectUtils.validateAdapterIsStopped();
@@ -37,7 +37,7 @@ describe('Add Compact Adapters', () => {
     });
 
     it('Add an adapter via the compact API. Start Adapter', () => {
-        const compactAdapter = getBasicCompactMachineDataSimulator()
+        const compactAdapter = CompactAdapterUtils.getMachineDataSimulator()
             .setStart()
             .build();
 
@@ -49,7 +49,7 @@ describe('Add Compact Adapters', () => {
     });
 
     it('Add an adapter via the compact API. Start Adapter and start persist 
pipeline', () => {
-        const compactAdapter = getBasicCompactMachineDataSimulator()
+        const compactAdapter = CompactAdapterUtils.getMachineDataSimulator()
             .setStart()
             .setPersist()
             .build();
@@ -74,7 +74,7 @@ describe('Add Compact Adapters', () => {
     });
 
     it('Ensure correct error code when adapter with the same id already 
exists', () => {
-        const compactAdapter = getBasicCompactMachineDataSimulator()
+        const compactAdapter = CompactAdapterUtils.getMachineDataSimulator()
             .setStart()
             .setPersist()
             .build();
@@ -96,13 +96,4 @@ describe('Add Compact Adapters', () => {
             },
         );
     });
-
-    const getBasicCompactMachineDataSimulator = () => {
-        return CompactAdapterBuilder.create(
-            'org.apache.streampipes.connect.iiot.adapters.simulator.machine',
-        )
-            .setName('Test')
-            .addConfiguration('wait-time-ms', '1000')
-            .addConfiguration('selected-simulator-option', 'flowrate');
-    };
 });
diff --git 
a/ui/cypress/tests/connect/compact/compactAdapterWithTransformation.spec.ts 
b/ui/cypress/tests/connect/compact/compactAdapterWithTransformation.spec.ts
new file mode 100644
index 0000000000..c48bee6760
--- /dev/null
+++ b/ui/cypress/tests/connect/compact/compactAdapterWithTransformation.spec.ts
@@ -0,0 +1,48 @@
+/*
+ *  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.
+ *
+ */
+
+import { ConnectUtils } from '../../../support/utils/connect/ConnectUtils';
+import { CompactAdapterUtils } from 
'../../../support/utils/connect/CompactAdapterUtils';
+
+describe('Add Compact Adapters', () => {
+    beforeEach('Setup Test', () => {
+        cy.initStreamPipesTest();
+    });
+
+    it('Add an adapter and rename a property', () => {
+        const newPropertyName = 'temperature_renamed';
+        const compactAdapter = CompactAdapterUtils.getMachineDataSimulator()
+            .withRename('temperature', newPropertyName)
+            .setStart()
+            .build();
+
+        CompactAdapterUtils.storeCompactAdapter(compactAdapter).then(() => {
+            const runtimeNames = [
+                'density',
+                'mass_flow',
+                'sensor_fault_flags',
+                'sensorId',
+                newPropertyName,
+                'timestamp',
+                'volume_flow',
+            ];
+
+            ConnectUtils.validateEventSchema(runtimeNames);
+        });
+    });
+});
diff --git a/ui/cypress/tests/connect/compact/uiConfiguration.ts 
b/ui/cypress/tests/connect/compact/uiConfiguration.spec.ts
similarity index 100%
rename from ui/cypress/tests/connect/compact/uiConfiguration.ts
rename to ui/cypress/tests/connect/compact/uiConfiguration.spec.ts

Reply via email to