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 2024/03/19 08:41:35 UTC

(streampipes) branch 2577-pipeline-element-templates-do-not-work updated: fix(#2577): Add test case for templates in a pipeline

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

zehnder pushed a commit to branch 2577-pipeline-element-templates-do-not-work
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/2577-pipeline-element-templates-do-not-work by this push:
     new ae36e3ef7b fix(#2577): Add test case for templates in a pipeline
ae36e3ef7b is described below

commit ae36e3ef7b7e905523b5919088cea32465022dd7
Author: Philipp Zehnder <te...@users.noreply.github.com>
AuthorDate: Tue Mar 19 09:41:22 2024 +0100

    fix(#2577): Add test case for templates in a pipeline
---
 .../support/utils/PipelineElementTemplateUtils.ts  | 40 +++++++++++
 ui/cypress/support/utils/PipelineUtils.ts          | 40 +++++++----
 .../connectConfigurationTemplate.spec.ts           | 21 +++---
 .../pipelineElementConfigurationTemplate.ts        | 81 ++++++++++++++++++++++
 .../adapter-settings.component.html                |  4 +-
 .../adapter-template-dialog.component.html         |  2 +-
 .../pipeline-assembly.component.html               |  1 +
 .../dialog/customize/customize.component.html      |  4 ++
 8 files changed, 165 insertions(+), 28 deletions(-)

diff --git a/ui/cypress/support/utils/PipelineElementTemplateUtils.ts b/ui/cypress/support/utils/PipelineElementTemplateUtils.ts
new file mode 100644
index 0000000000..2f4855efdd
--- /dev/null
+++ b/ui/cypress/support/utils/PipelineElementTemplateUtils.ts
@@ -0,0 +1,40 @@
+/*
+ *  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.
+ *
+ */
+
+export class PipelineElementTemplateUtils {
+    public static addTemplate(templateName: string) {
+        cy.dataCy('use-template').should('not.exist');
+        cy.dataCy('create-template').click();
+        cy.dataCy('template-name').type(templateName);
+        cy.dataCy('template-description').type(templateName);
+        cy.dataCy('save-template').click();
+    }
+
+    public static selectTemplate(templateName: string) {
+        cy.dataCy('use-template').should('exist');
+        cy.dataCy('use-template').click({ force: true });
+        cy.get('mat-option').contains(templateName).click({ force: true });
+    }
+
+    public static deleteTemplate() {
+        cy.dataCy('create-template').click();
+        cy.dataCy('delete-pipeline-element-template').should('have.length', 1);
+        cy.dataCy('delete-pipeline-element-template').click();
+        cy.dataCy('delete-pipeline-element-template').should('have.length', 0);
+    }
+}
diff --git a/ui/cypress/support/utils/PipelineUtils.ts b/ui/cypress/support/utils/PipelineUtils.ts
index 42cfcc45e9..39324a0217 100644
--- a/ui/cypress/support/utils/PipelineUtils.ts
+++ b/ui/cypress/support/utils/PipelineUtils.ts
@@ -19,6 +19,7 @@
 import { PipelineInput } from '../model/PipelineInput';
 import { StaticPropertyUtils } from './StaticPropertyUtils';
 import { OutputStrategyUtils } from './OutputStrategyUtils';
+import { PipelineElementInput } from '../model/PipelineElementInput';
 
 export class PipelineUtils {
     public static addPipeline(pipelineInput: PipelineInput) {
@@ -37,7 +38,7 @@ export class PipelineUtils {
 
     private static goToPipelineEditor() {
         // Go to StreamPipes editor
-        cy.visit('#/pipelines');
+        this.goToPipelines();
         cy.dataCy('pipelines-navigate-to-editor').click();
     }
 
@@ -50,22 +51,37 @@ export class PipelineUtils {
         cy.dataCy(pipelineInput.dataSource, { timeout: 10000 }).click();
     }
 
-    private static configurePipeline(pipelineInput: PipelineInput) {
-        // Open possible elements menu
-        cy.dataCy('sp-possible-elements-' + pipelineInput.dataSource, {
+    public static openPossibleElementsMenu(dataSourceName: string) {
+        cy.dataCy('sp-possible-elements-' + dataSourceName, {
             timeout: 10000,
         }).click();
+    }
+
+    public static selectCompatibleElement(elementName: string) {
+        cy.dataCy('sp-compatible-elements-' + elementName).click();
+    }
+
+    public static configureProcessingElement(
+        processingElement: PipelineElementInput,
+    ) {
+        this.selectCompatibleElement(processingElement.name);
+        StaticPropertyUtils.input(processingElement.config);
+        OutputStrategyUtils.input(processingElement.output);
+    }
+
+    private static savePipelineElementConfiguration() {
+        cy.dataCy('sp-element-configuration-save').click();
+    }
+
+    private static configurePipeline(pipelineInput: PipelineInput) {
+        this.openPossibleElementsMenu(pipelineInput.dataSource);
 
         // Select processor
         if (pipelineInput.processingElement) {
-            cy.dataCy(
-                'sp-compatible-elements-' +
-                    pipelineInput.processingElement.name,
-            ).click();
-            StaticPropertyUtils.input(pipelineInput.processingElement.config);
-            OutputStrategyUtils.input(pipelineInput.processingElement.output);
-            // Save configuration
-            cy.dataCy('sp-element-configuration-save').click();
+            this.configureProcessingElement(pipelineInput.processingElement);
+
+            this.savePipelineElementConfiguration();
+
             // Select sink
             cy.dataCy(
                 'sp-possible-elements-' + pipelineInput.processingElement.name,
diff --git a/ui/cypress/tests/adapter/connectConfigurationTemplate.spec.ts b/ui/cypress/tests/pipelineElementConfigurationTemplate/connectConfigurationTemplate.spec.ts
similarity index 75%
rename from ui/cypress/tests/adapter/connectConfigurationTemplate.spec.ts
rename to ui/cypress/tests/pipelineElementConfigurationTemplate/connectConfigurationTemplate.spec.ts
index c8eb5a9493..76eb8d8e56 100644
--- a/ui/cypress/tests/adapter/connectConfigurationTemplate.spec.ts
+++ b/ui/cypress/tests/pipelineElementConfigurationTemplate/connectConfigurationTemplate.spec.ts
@@ -19,6 +19,7 @@
 import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
 import { StaticPropertyUtils } from '../../support/utils/StaticPropertyUtils';
 import { AdapterBuilder } from '../../support/builder/AdapterBuilder';
+import { PipelineElementTemplateUtils } from '../../support/utils/PipelineElementTemplateUtils';
 
 describe('Test Edit Adapter', () => {
     beforeEach('Setup Test', () => {
@@ -28,7 +29,7 @@ describe('Test Edit Adapter', () => {
         ConnectUtils.goToNewAdapterPage();
     });
 
-    it('Successfully edit adapter', () => {
+    it('Create and use configuration templates for adapters', () => {
         const WAIT_TIME_MS = 'wait-time-ms';
         const SIMULATOR_OPTION_PRESSURE = 'simulator-option-pressure';
         const TEMPLATE_NAME = 'Test Template';
@@ -44,19 +45,16 @@ describe('Test Edit Adapter', () => {
         StaticPropertyUtils.input(adapterTemplateInput.adapterConfiguration);
 
         // store adapter template
-        cy.dataCy('connect-use-template').should('not.exist');
-        cy.dataCy('store-config-as-template').click();
-        cy.dataCy('template-name').type(TEMPLATE_NAME);
-        cy.dataCy('template-description').type('Test Description');
-        cy.dataCy('create-template').click();
+        PipelineElementTemplateUtils.addTemplate(TEMPLATE_NAME);
+
         cy.dataCy('connect-new-adapter-cancel').click();
 
         // Reload template configuration
         ConnectUtils.goToNewAdapterPage();
         ConnectUtils.selectAdapter(adapterTemplateInput.adapterType);
-        cy.dataCy('connect-use-template').should('exist');
-        cy.dataCy('connect-use-template').click({ force: true });
-        cy.get('mat-option').contains('Test Template').click();
+
+        // Select template
+        PipelineElementTemplateUtils.selectTemplate(TEMPLATE_NAME);
 
         // validate that the template values are selected
         cy.dataCy(WAIT_TIME_MS).should('have.value', '3000');
@@ -66,9 +64,6 @@ describe('Test Edit Adapter', () => {
         );
 
         // Delete the template
-        cy.dataCy('store-config-as-template').click();
-        cy.dataCy('delete-pipeline-element-template').should('have.length', 1);
-        cy.dataCy('delete-pipeline-element-template').click();
-        cy.dataCy('delete-pipeline-element-template').should('have.length', 0);
+        PipelineElementTemplateUtils.deleteTemplate();
     });
 });
diff --git a/ui/cypress/tests/pipelineElementConfigurationTemplate/pipelineElementConfigurationTemplate.ts b/ui/cypress/tests/pipelineElementConfigurationTemplate/pipelineElementConfigurationTemplate.ts
new file mode 100644
index 0000000000..85fc089a38
--- /dev/null
+++ b/ui/cypress/tests/pipelineElementConfigurationTemplate/pipelineElementConfigurationTemplate.ts
@@ -0,0 +1,81 @@
+/*
+ *  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 { PipelineUtils } from '../../support/utils/PipelineUtils';
+import { PipelineBuilder } from '../../support/builder/PipelineBuilder';
+import { PipelineElementBuilder } from '../../support/builder/PipelineElementBuilder';
+import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
+import { PipelineElementTemplateUtils } from '../../support/utils/PipelineElementTemplateUtils';
+
+describe('Test Edit Adapter', () => {
+    const TEMPLATE_NAME = 'Test Template';
+    const adapterName = 'simulator';
+
+    beforeEach('Setup Test', () => {
+        cy.initStreamPipesTest();
+        ConnectUtils.addMachineDataSimulator(adapterName);
+    });
+
+    it('Create and use configuration templates for processing elements', () => {
+        PipelineUtils.goToPipelineEditor();
+
+        const pipelineInput = PipelineBuilder.create('Pipeline Test')
+            .addSource(adapterName)
+            .addProcessingElement(
+                PipelineElementBuilder.create('numerical_filter')
+                    .addInput('drop-down', 'number-mapping', 'temperature')
+                    .addInput('radio', 'operation', '\\=\\=')
+                    .addInput('input', 'value', '20')
+                    .build(),
+            )
+            .build();
+
+        // Create pipeline element template
+        PipelineUtils.selectDataStream(pipelineInput);
+        PipelineUtils.openPossibleElementsMenu(adapterName);
+        PipelineUtils.configureProcessingElement(
+            pipelineInput.processingElement,
+        );
+
+        // Add new template
+        PipelineElementTemplateUtils.addTemplate(TEMPLATE_NAME);
+
+        cy.dataCy('cancel-customize').click();
+
+        PipelineUtils.goToPipelineEditor();
+        PipelineUtils.selectDataStream(pipelineInput);
+        PipelineUtils.openPossibleElementsMenu(adapterName);
+        PipelineUtils.selectCompatibleElement(
+            pipelineInput.processingElement.name,
+        );
+
+        // Select template
+        PipelineElementTemplateUtils.selectTemplate(TEMPLATE_NAME);
+
+        // validate that selection is correct
+        cy.dataCy('value').should('have.value', '20');
+        cy.dataCy('operation-\\=\\=').should(
+            'have.class',
+            'mat-mdc-radio-checked',
+        );
+        cy.dataCy('number-mapping').contains('temperature');
+
+        // delete template
+        PipelineElementTemplateUtils.deleteTemplate();
+    });
+});
diff --git a/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.html b/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.html
index 7fa0308abd..4b3be6f469 100644
--- a/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.html
+++ b/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.html
@@ -41,7 +41,7 @@
                             <mat-select
                                 (selectionChange)="loadTemplate($event)"
                                 [(value)]="selectedTemplate"
-                                data-cy="connect-use-template"
+                                data-cy="use-template"
                             >
                                 <mat-option>--</mat-option>
                                 <mat-option
@@ -78,7 +78,7 @@
             mat-button
             mat-raised-button
             class="mat-basic"
-            data-cy="store-config-as-template"
+            data-cy="create-template"
             (click)="openTemplateDialog()"
         >
             Store config as template
diff --git a/ui/src/app/connect/dialog/adapter-template/adapter-template-dialog.component.html b/ui/src/app/connect/dialog/adapter-template/adapter-template-dialog.component.html
index 6c81d0a7b3..1c00d85ade 100644
--- a/ui/src/app/connect/dialog/adapter-template/adapter-template-dialog.component.html
+++ b/ui/src/app/connect/dialog/adapter-template/adapter-template-dialog.component.html
@@ -36,7 +36,7 @@
             color="accent"
             (click)="saveTemplate()"
             style="margin-right: 10px"
-            data-cy="create-template"
+            data-cy="save-template"
         >
             Create template
         </button>
diff --git a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html
index 05da14a5d4..592cc32b32 100644
--- a/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html
+++ b/ui/src/app/editor/components/pipeline-assembly/pipeline-assembly.component.html
@@ -125,6 +125,7 @@
                 [matTooltipPosition]="'above'"
                 [disabled]="editorService.pipelineAssemblyEmpty"
                 (click)="showClearAssemblyConfirmDialog($event)"
+                data-cy="clear-assembly-area"
             >
                 <i class="material-icons">clear</i>
             </button>
diff --git a/ui/src/app/editor/dialog/customize/customize.component.html b/ui/src/app/editor/dialog/customize/customize.component.html
index 89d9c051be..70080ddde1 100644
--- a/ui/src/app/editor/dialog/customize/customize.component.html
+++ b/ui/src/app/editor/dialog/customize/customize.component.html
@@ -38,6 +38,7 @@
                         <mat-select
                             (selectionChange)="loadTemplate($event)"
                             [(value)]="selectedTemplate"
+                            data-cy="use-template"
                         >
                             <mat-option>--</mat-option>
                             <mat-option
@@ -160,6 +161,7 @@
                 mat-raised-button
                 class="mat-basic"
                 (click)="close()"
+                data-cy="cancel-customize"
             >
                 Cancel
             </button>
@@ -169,6 +171,7 @@
                 mat-raised-button
                 color="accent"
                 [disabled]="!formValid"
+                data-cy="create-template"
                 (click)="triggerTemplateMode()"
             >
                 <i class="material-icons">add_circle_outline</i
@@ -183,6 +186,7 @@
                 (click)="saveTemplate()"
                 style="margin-right: 10px"
                 [disabled]="!formValid"
+                data-cy="save-template"
             >
                 <i class="material-icons">save</i
                 ><span>&nbsp;Save template</span>