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

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new f5dfa33df7 refactor(#3061): Reactivate test for opc ua (#3062)
f5dfa33df7 is described below

commit f5dfa33df708d3e6bd6284e4a90629a0bef0306b
Author: Philipp Zehnder <[email protected]>
AuthorDate: Wed Jul 24 08:07:16 2024 +0200

    refactor(#3061): Reactivate test for opc ua (#3062)
---
 docker-compose.yml                                 |  7 +++
 ui/cypress/support/builder/AdapterBuilder.ts       | 12 ++++-
 ui/cypress/support/builder/TreeNodeBuilder.ts      | 49 ++++++++++++++++++++
 ui/cypress/support/model/TreeNode.ts               | 21 +++++++++
 ui/cypress/support/model/UserInput.ts              |  2 +
 ui/cypress/support/model/UserInputType.ts          |  3 +-
 ui/cypress/support/utils/ParameterUtils.ts         |  8 ----
 ui/cypress/support/utils/StaticPropertyUtils.ts    | 15 +++++-
 .../connect/{opcAdapter.ts => opcAdapter.spec.ts}  | 54 ++++++++++++++--------
 ui/package.json                                    |  2 +-
 .../static-tree-input.component.html               |  3 +-
 11 files changed, 144 insertions(+), 32 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index dfb554bc19..5ea7f82b45 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -135,6 +135,13 @@ services:
     networks:
       spnet:
 
+  opcua:
+    image: mcr.microsoft.com/iotedge/opc-plc
+    logging: *default-logging
+    command: --ut=true
+    networks:
+      spnet:
+
 volumes:
   kafka:
   files:
diff --git a/ui/cypress/support/builder/AdapterBuilder.ts 
b/ui/cypress/support/builder/AdapterBuilder.ts
index d590d95005..cb42932da1 100644
--- a/ui/cypress/support/builder/AdapterBuilder.ts
+++ b/ui/cypress/support/builder/AdapterBuilder.ts
@@ -19,6 +19,7 @@
 import { UserInput } from '../model/UserInput';
 import { UserInputType } from '../model/UserInputType';
 import { AdapterInput } from '../model/AdapterInput';
+import { TreeNodeBuilder } from './TreeNodeBuilder';
 
 export class AdapterBuilder {
     adapterInput: AdapterInput;
@@ -41,7 +42,6 @@ export class AdapterBuilder {
 
     public setTimestampProperty(timestsmpProperty: string) {
         this.adapterInput.timestampProperty = timestsmpProperty;
-        this.adapterInput.autoAddTimestamp;
         return this;
     }
 
@@ -71,6 +71,16 @@ export class AdapterBuilder {
         return this;
     }
 
+    public addTreeNode(treeNode: TreeNodeBuilder) {
+        const userInput = new UserInput();
+        userInput.type = 'tree';
+        userInput.treeNode = treeNode.build();
+
+        this.adapterInput.adapterConfiguration.push(userInput);
+
+        return this;
+    }
+
     public setStartAdapter(startAdapter: boolean) {
         this.adapterInput.startAdapter = startAdapter;
         return this;
diff --git a/ui/cypress/support/builder/TreeNodeBuilder.ts 
b/ui/cypress/support/builder/TreeNodeBuilder.ts
new file mode 100644
index 0000000000..0dd04ff1c7
--- /dev/null
+++ b/ui/cypress/support/builder/TreeNodeBuilder.ts
@@ -0,0 +1,49 @@
+/*
+ *  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 { TreeNode } from '../model/TreeNode';
+
+export class TreeNodeBuilder {
+    private readonly node: TreeNode;
+
+    constructor(name: string) {
+        this.node = { name, children: [] };
+    }
+
+    addChildren(...childrenBuilders: TreeNodeBuilder[]): TreeNodeBuilder {
+        for (const childBuilder of childrenBuilders) {
+            this.node.children!.push(childBuilder.build());
+        }
+        return this;
+    }
+
+    static create(
+        name: string,
+        ...children: TreeNodeBuilder[]
+    ): TreeNodeBuilder {
+        const builder = new TreeNodeBuilder(name);
+        if (children.length > 0) {
+            builder.addChildren(...children);
+        }
+        return builder;
+    }
+
+    build(): TreeNode {
+        return this.node;
+    }
+}
diff --git a/ui/cypress/support/model/TreeNode.ts 
b/ui/cypress/support/model/TreeNode.ts
new file mode 100644
index 0000000000..49c717c0d3
--- /dev/null
+++ b/ui/cypress/support/model/TreeNode.ts
@@ -0,0 +1,21 @@
+/*
+ *  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 TreeNode {
+    name: String;
+    children?: TreeNode[];
+}
diff --git a/ui/cypress/support/model/UserInput.ts 
b/ui/cypress/support/model/UserInput.ts
index 1c9c675c78..175a3abe97 100644
--- a/ui/cypress/support/model/UserInput.ts
+++ b/ui/cypress/support/model/UserInput.ts
@@ -17,9 +17,11 @@
  */
 
 import { UserInputType } from './UserInputType';
+import { TreeNode } from './TreeNode';
 
 export class UserInput {
     type: UserInputType;
     selector: string;
     value: string;
+    treeNode?: TreeNode;
 }
diff --git a/ui/cypress/support/model/UserInputType.ts 
b/ui/cypress/support/model/UserInputType.ts
index a5d4ba26ad..2acc41eabb 100644
--- a/ui/cypress/support/model/UserInputType.ts
+++ b/ui/cypress/support/model/UserInputType.ts
@@ -26,4 +26,5 @@ export type UserInputType =
     | 'click'
     | 'button'
     | 'slider'
-    | 'select';
+    | 'select'
+    | 'tree';
diff --git a/ui/cypress/support/utils/ParameterUtils.ts 
b/ui/cypress/support/utils/ParameterUtils.ts
index 4ac5663c21..7d12a53fdd 100644
--- a/ui/cypress/support/utils/ParameterUtils.ts
+++ b/ui/cypress/support/utils/ParameterUtils.ts
@@ -27,12 +27,4 @@ export class ParameterUtils {
             return containerVariable;
         }
     }
-
-    public static getEnvOrDefault(envVariableName, defaultValue): string {
-        if (Cypress.env(envVariableName)) {
-            return Cypress.env(envVariableName);
-        } else {
-            return defaultValue;
-        }
-    }
 }
diff --git a/ui/cypress/support/utils/StaticPropertyUtils.ts 
b/ui/cypress/support/utils/StaticPropertyUtils.ts
index 13f38a64f0..25b2d200e5 100644
--- a/ui/cypress/support/utils/StaticPropertyUtils.ts
+++ b/ui/cypress/support/utils/StaticPropertyUtils.ts
@@ -17,7 +17,7 @@
  */
 
 import { UserInput } from '../model/UserInput';
-import { userInfo } from 'os';
+import { TreeNode } from '../model/TreeNode';
 
 export class StaticPropertyUtils {
     public static input(configs: UserInput[]) {
@@ -44,6 +44,8 @@ export class StaticPropertyUtils {
                 cy.dataCy(config.selector).clear().type(config.value).blur();
             } else if (config.type === 'slider') {
                 cy.dataCy(config.selector).type(config.value);
+            } else if (config.type === 'tree') {
+                this.handleTreeNode(config.treeNode);
             } else {
                 cy.dataCy(config.selector).type(config.value);
             }
@@ -68,4 +70,15 @@ export class StaticPropertyUtils {
             cy.get(cssClassName).click();
         });
     }
+
+    private static handleTreeNode(treeNode: TreeNode) {
+        if (treeNode.children && treeNode.children.length > 0) {
+            cy.dataCy('expand-' + treeNode.name).click();
+            treeNode.children.forEach(child => {
+                this.handleTreeNode(child);
+            });
+        } else {
+            cy.dataCy('select-' + treeNode.name).click();
+        }
+    }
 }
diff --git a/ui/cypress/tests/connect/opcAdapter.ts 
b/ui/cypress/tests/connect/opcAdapter.spec.ts
similarity index 55%
rename from ui/cypress/tests/connect/opcAdapter.ts
rename to ui/cypress/tests/connect/opcAdapter.spec.ts
index a2d3203750..f7addefa16 100644
--- a/ui/cypress/tests/connect/opcAdapter.ts
+++ b/ui/cypress/tests/connect/opcAdapter.spec.ts
@@ -19,25 +19,20 @@
 import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
 import { ParameterUtils } from '../../support/utils/ParameterUtils';
 import { AdapterBuilder } from '../../support/builder/AdapterBuilder';
+import { TreeNodeBuilder } from '../../support/builder/TreeNodeBuilder';
 
 describe('Test OPC-UA Adapter Pull Mode', () => {
     beforeEach('Setup Test', () => {
         cy.initStreamPipesTest();
     });
 
-    it('Perform Test', () => {
+    it('Test OPC-UA Adapter Pull Mode', () => {
         const adapterInput = getAdapterBuilder(true);
 
         ConnectUtils.testAdapter(adapterInput);
     });
-});
-
-describe('Test OPC-UA Adapter Subscription Mode', () => {
-    beforeEach('Setup Test', () => {
-        cy.initStreamPipesTest();
-    });
 
-    it('Perform Test', () => {
+    it('Test OPC-UA Adapter Subscription Mode', () => {
         const adapterInput = getAdapterBuilder(false);
 
         ConnectUtils.testAdapter(adapterInput);
@@ -52,26 +47,47 @@ const getAdapterBuilder = (pullMode: boolean) => {
     );
 
     if (pullMode) {
-        builder.addInput('select', 'adapter_type-pull_mode', 'check');
+        builder.addInput('radio', 'adapter_type-pull_mode', '');
         builder.addInput('input', 'undefined-PULLING_INTERVAL-0', '1000');
     } else {
-        builder.addInput('select', 'adapter_type-subscription_mode', 'check');
+        builder.addInput('radio', 'adapter_type-subscription_mode', '');
     }
+
     builder
-        .addInput('select', 'access_mode-none', 'check')
-        .addInput('select', 'opc_host_or_url-url', 'check')
+        .addInput('radio', 'access_mode-none', '')
+        .addInput('radio', 'opc_host_or_url-url', '')
         .addInput(
             'input',
             'undefined-OPC_SERVER_URL-0',
             'opc.tcp://' + host + ':50000',
-        )
-        .addInput('input', 'NAMESPACE_INDEX', '2')
-        .addInput('input', 'NODE_ID', 'Telemetry')
+        );
+
+    builder.addTreeNode(
+        TreeNodeBuilder.create(
+            'Objects',
+            TreeNodeBuilder.create(
+                'OpcPlc',
+                TreeNodeBuilder.create(
+                    'Telemetry',
+                    TreeNodeBuilder.create('Basic').addChildren(
+                        TreeNodeBuilder.create('AlternatingBoolean'),
+                        TreeNodeBuilder.create('StepUp'),
+                        TreeNodeBuilder.create('RandomSignedInt32'),
+                        TreeNodeBuilder.create('RandomUnsignedInt32'),
+                    ),
+                    // TreeNodeBuilder.create('Anomaly')
+                    //     .addChildren(
+                    //         TreeNodeBuilder.create('DipData'),
+                    //         TreeNodeBuilder.create('NegativeTrendData'),
+                    //         TreeNodeBuilder.create('PositiveTrendData'),
+                    //         TreeNodeBuilder.create('SpikeData'),
+                    //     ),
+                ),
+            ),
+        ),
+    );
 
-        .addInput('button', 'button-Telemetry')
-        .addInput('button', 'button-Anomaly')
-        .addInput('checkbox', 'DipData', 'check')
-        .addInput('checkbox', 'NegativeTrendData', 'check');
+    builder.setAutoAddTimestampPropery();
 
     return builder.build();
 };
diff --git a/ui/package.json b/ui/package.json
index 8daa212094..a0b9eb57ff 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -23,7 +23,7 @@
     "format": "prettier --check .",
     "format:fix": "prettier --write .",
     "lint-staged": "lint-staged",
-    "test-cypress-open": "cypress open",
+    "test-cypress-open": "cypress open --env DEVELOPMENT=true",
     "test-cypress-smoke": "npx cypress run --spec 
'cypress/tests/**/*.smoke.spec.ts'",
     "test-cypress-all": "npx cypress run --spec 'cypress/tests/**/*.spec.ts'",
     "prepare": "cd ../ && husky install ./ui/.husky"
diff --git 
a/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
 
b/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
index b3bc952595..1ca90b6a11 100644
--- 
a/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
+++ 
b/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
@@ -93,6 +93,7 @@
                             class="material-icons pr-5 icon-button"
                             *ngIf="node.dataNode && !isNodeSelected(node)"
                             (click)="addNode(node)"
+                            [attr.data-cy]="'select-' + node.nodeName"
                             matTooltip="Add node"
                             >add_circle</i
                         >
@@ -133,7 +134,7 @@
                         <button
                             mat-icon-button
                             matTreeNodeToggle
-                            [attr.data-cy]="'button-' + node.nodeName"
+                            [attr.data-cy]="'expand-' + node.nodeName"
                             [attr.aria-label]="'Toggle ' + node.nodeName"
                             (click)="
                                 loadChildren(node, 
treeControl.isExpanded(node))

Reply via email to