You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2022/01/11 19:40:13 UTC

[incubator-streampipes] branch STREAMPIPES-505 updated: [STREAMPIPES-505] Add test for OPC-UA adapter

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

riemer pushed a commit to branch STREAMPIPES-505
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git


The following commit(s) were added to refs/heads/STREAMPIPES-505 by this push:
     new 32ec0d4  [STREAMPIPES-505] Add test for OPC-UA adapter
32ec0d4 is described below

commit 32ec0d4e066e2ebe70b910f19908195cff2a218c
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Tue Jan 11 20:39:57 2022 +0100

    [STREAMPIPES-505] Add test for OPC-UA adapter
---
 .../iiot/adapters/opcua/utils/OpcUaUtil.java       |  2 +-
 .../support/builder/SpecificAdapterBuilder.ts      |  7 +-
 ui/cypress/support/model/AdapterInput.ts           |  1 +
 ui/cypress/support/model/UserInput.ts              |  2 +-
 ui/cypress/support/utils/ConnectUtils.ts           |  4 ++
 ui/cypress/support/utils/ParameterUtils.ts         |  8 +++
 ui/cypress/support/utils/StaticPropertyUtils.ts    |  8 ++-
 .../adapter/machineDataSimulator.smoke.spec.ts     |  2 -
 ui/cypress/tests/adapter/opcAdapter.ts             | 75 ++++++++++++++++++++++
 .../event-schema/event-schema.component.html       |  2 +-
 .../static-tree-input.component.html               |  3 +
 11 files changed, 106 insertions(+), 8 deletions(-)

diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java
index 7ad4573..38d4d4c 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/opcua/utils/OpcUaUtil.java
@@ -130,7 +130,7 @@ public class OpcUaUtil {
 
         SpOpcUaClient spOpcUaClient = new SpOpcUaClient(SpOpcUaConfigBuilder.from(parameterExtractor));
         try{
-            spOpcUaClient.connect();;
+            spOpcUaClient.connect();
             OpcUaNodeBrowser nodeBrowser = new OpcUaNodeBrowser(spOpcUaClient.getClient(), spOpcUaClient.getSpOpcConfig());
             config.setNodes(nodeBrowser.buildNodeTreeFromOrigin());
             spOpcUaClient.disconnect();
diff --git a/ui/cypress/support/builder/SpecificAdapterBuilder.ts b/ui/cypress/support/builder/SpecificAdapterBuilder.ts
index a542f0a..98a71fb 100644
--- a/ui/cypress/support/builder/SpecificAdapterBuilder.ts
+++ b/ui/cypress/support/builder/SpecificAdapterBuilder.ts
@@ -49,7 +49,12 @@ export class SpecificAdapterBuilder {
     return this;
   }
 
-  public addInput(type: string, selector: string, value: string) {
+  public withAutoAddedTimestamp() {
+    this.specificAdapterInput.autoAddTimestamp = true;
+    return this;
+  }
+
+  public addInput(type: string, selector: string, value?: string) {
     const userInput = new UserInput();
     userInput.type = type;
     userInput.selector = selector;
diff --git a/ui/cypress/support/model/AdapterInput.ts b/ui/cypress/support/model/AdapterInput.ts
index 9964fe2..54bab5d 100644
--- a/ui/cypress/support/model/AdapterInput.ts
+++ b/ui/cypress/support/model/AdapterInput.ts
@@ -22,4 +22,5 @@ export class AdapterInput {
   timestampProperty: string;
   dimensionProperties: string[] = [];
   storeInDataLake: boolean;
+  autoAddTimestamp = false;
 }
diff --git a/ui/cypress/support/model/UserInput.ts b/ui/cypress/support/model/UserInput.ts
index b940a6d..50de86d 100644
--- a/ui/cypress/support/model/UserInput.ts
+++ b/ui/cypress/support/model/UserInput.ts
@@ -17,7 +17,7 @@
  */
 
 export class UserInput {
-    type: 'checkbox' | 'input' | 'file' | 'drop-down' | 'radio' | 'code-input' | 'click';
+    type: 'checkbox' | 'input' | 'file' | 'drop-down' | 'radio' | 'code-input' | 'click' | 'button';
     selector: string;
     value: string;
 }
diff --git a/ui/cypress/support/utils/ConnectUtils.ts b/ui/cypress/support/utils/ConnectUtils.ts
index d457d59..7a9aa0c 100644
--- a/ui/cypress/support/utils/ConnectUtils.ts
+++ b/ui/cypress/support/utils/ConnectUtils.ts
@@ -40,6 +40,10 @@ export class ConnectUtils {
       ConnectEventSchemaUtils.markPropertyAsTimestamp(adapterConfiguration.timestampProperty);
     }
 
+    if (adapterConfiguration.autoAddTimestamp) {
+      ConnectEventSchemaUtils.addTimestampProperty();
+    }
+
     ConnectEventSchemaUtils.finishEventSchemaConfiguration();
 
     ConnectUtils.startStreamAdapter(adapterConfiguration);
diff --git a/ui/cypress/support/utils/ParameterUtils.ts b/ui/cypress/support/utils/ParameterUtils.ts
index 3f6ab48..ba4c8df 100644
--- a/ui/cypress/support/utils/ParameterUtils.ts
+++ b/ui/cypress/support/utils/ParameterUtils.ts
@@ -26,4 +26,12 @@ 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 674c2f2..a8d9f35 100644
--- a/ui/cypress/support/utils/StaticPropertyUtils.ts
+++ b/ui/cypress/support/utils/StaticPropertyUtils.ts
@@ -26,6 +26,8 @@ export class StaticPropertyUtils {
     configs.forEach(config => {
       if (config.type === 'checkbox') {
         cy.dataCy(config.selector).children().click();
+      } else if (config.type === 'button') {
+        cy.dataCy(config.selector).click();
       } else if (config.type === 'drop-down') {
         cy.dataCy(config.selector).click().get('mat-option').contains(config.value).click();
       } else if (config.type === 'radio') {
@@ -35,9 +37,11 @@ export class StaticPropertyUtils {
       } else if (config.type === 'code-input') {
         cy.dataCy('reset-code-' + config.selector).click();
         cy.dataCy('code-editor-' + config.selector).type(config.value);
-      } else {
+      } else if (config.type === 'input') {
+          cy.dataCy(config.selector).type(config.value).blur();
+        } else {
           cy.dataCy(config.selector).type(config.value);
-        }
+      }
     });
   }
 }
diff --git a/ui/cypress/tests/adapter/machineDataSimulator.smoke.spec.ts b/ui/cypress/tests/adapter/machineDataSimulator.smoke.spec.ts
index d908951..6822efc 100644
--- a/ui/cypress/tests/adapter/machineDataSimulator.smoke.spec.ts
+++ b/ui/cypress/tests/adapter/machineDataSimulator.smoke.spec.ts
@@ -31,8 +31,6 @@ describe('Test Random Data Simulator Stream Adapter', () => {
         .addInput('input', 'wait-time-ms', '1000')
         .build();
 
-
-    cy.visit('#/connect');
     ConnectUtils.testSpecificStreamAdapter(adapterInput);
     ConnectUtils.deleteAdapter();
   });
diff --git a/ui/cypress/tests/adapter/opcAdapter.ts b/ui/cypress/tests/adapter/opcAdapter.ts
new file mode 100644
index 0000000..a4190b3
--- /dev/null
+++ b/ui/cypress/tests/adapter/opcAdapter.ts
@@ -0,0 +1,75 @@
+/*
+ * 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/ConnectUtils';
+import { SpecificAdapterBuilder } from '../../support/builder/SpecificAdapterBuilder';
+import { ParameterUtils } from '../../support/utils/ParameterUtils';
+
+describe('Test OPC-UA Adapter Pull Mode', () => {
+  beforeEach('Setup Test', () => {
+    cy.initStreamPipesTest();
+  });
+
+  it('Perform Test', () => {
+    const adapterInput = getAdapterBuilder(true);
+
+    ConnectUtils.testSpecificStreamAdapter(adapterInput);
+  });
+});
+
+describe('Test OPC-UA Adapter Subscription Mode', () => {
+  beforeEach('Setup Test', () => {
+    cy.initStreamPipesTest();
+  });
+
+  it('Perform Test', () => {
+    const adapterInput = getAdapterBuilder(false);
+
+    ConnectUtils.testSpecificStreamAdapter(adapterInput);
+  });
+});
+
+
+const getAdapterBuilder = (pullMode: boolean) => {
+
+  const host: string = ParameterUtils.getEnvOrDefault('OPC_HOST', 'opcua');
+
+  const builder = SpecificAdapterBuilder
+    .create('OPC_UA')
+    .setName('OPC UA Test' + pullMode ? '(Pull)' : '(Subscription');
+
+    if (pullMode) {
+      builder.addInput('select', 'adapter_type-pull_mode', 'check');
+      builder.addInput('input', 'undefined-PULLING_INTERVAL-0', '1000');
+    } else {
+      builder.addInput('select', 'adapter_type-subscription_mode', 'check');
+    }
+    builder.addInput('select', 'access_mode-none', 'check')
+    .addInput('select', 'opc_host_or_url-url', 'check')
+    .addInput('input', 'undefined-OPC_SERVER_URL-0', 'opc.tcp://' + host + ':50000')
+    .addInput('input', 'NAMESPACE_INDEX', '2')
+    .addInput('input', 'NODE_ID', 'Telemetry')
+
+    .addInput('button', 'button-Telemetry')
+    .addInput('button', 'button-Anomaly')
+    .addInput('checkbox', 'DipData', 'check')
+    .addInput('checkbox', 'NegativeTrendData', 'check')
+    .withAutoAddedTimestamp();
+
+  return builder.build();
+};
diff --git a/ui/src/app/connect/components/schema-editor/event-schema/event-schema.component.html b/ui/src/app/connect/components/schema-editor/event-schema/event-schema.component.html
index 3077edf..54c5fee 100644
--- a/ui/src/app/connect/components/schema-editor/event-schema/event-schema.component.html
+++ b/ui/src/app/connect/components/schema-editor/event-schema/event-schema.component.html
@@ -20,7 +20,7 @@
 <div fxLayout="row" fxLayoutAlign="center">
     <div fxFlex="0 1 80%">
 
-        <div class="assemblyOptions sp-blue-bg">
+        <div class="assemblyOptions sp-blue-bg" *ngIf="!isLoading && !isError">
             <sp-schema-editor-header
                     [countSelected]="countSelected"
                     [schemaErrorHints]="schemaErrorHints"
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 1d3f187..753c76a 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
@@ -27,6 +27,7 @@
     <mat-tree [dataSource]="dataSource" [treeControl]="treeControl" class="sp-tree">
         <mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
             <mat-checkbox color="accent"
+                          [attr.data-cy]="node.nodeName"
                           [checked]="node.selected"
                           (change)="toggleNodeSelection(node)">{{node.nodeName}}
             </mat-checkbox>
@@ -34,12 +35,14 @@
         <mat-nested-tree-node *matTreeNodeDef="let node; when: hasChild">
             <div class="mat-tree-node">
                 <button mat-icon-button matTreeNodeToggle
+                        [attr.data-cy]="'button-' +node.nodeName"
                         [attr.aria-label]="'Toggle ' + node.nodeName">
                     <mat-icon class="mat-icon-rtl-mirror">
                         {{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
                     </mat-icon>
                 </button>
                 <mat-checkbox color="accent"
+                              [attr.data-cy]="node.nodeName"
                               [checked]="descendantsAllSelected(node)"
                               [indeterminate]="descendantsPartiallySelected(node)"
                               (change)="toggleAllNodeSelection(node)">{{node.nodeName}}