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

zehnder pushed a commit to branch 3112-opc-ua-multi-node-selection-editor
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/3112-opc-ua-multi-node-selection-editor by this push:
     new ce79b2030f feat(#3112): Handle broken node ids
ce79b2030f is described below

commit ce79b2030fa5758166563c89f858ffba99baa108
Author: Philipp Zehnder <[email protected]>
AuthorDate: Tue Aug 13 13:51:52 2024 +0200

    feat(#3112): Handle broken node ids
---
 .../connectors/opcua/adapter/OpcUaNodeBrowser.java |  8 ++++++-
 ui/cypress/support/utils/ErrorMessageUtils.ts      | 26 ++++++++++++++++++++++
 ui/cypress/support/utils/connect/ConnectUtils.ts   |  7 ++++++
 .../connect/opcua/opcAdapterConfiguration.spec.ts  | 22 +++++++++++++++++-
 .../sp-exception-message.component.html            |  2 +-
 5 files changed, 62 insertions(+), 3 deletions(-)

diff --git 
a/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/adapter/OpcUaNodeBrowser.java
 
b/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/adapter/OpcUaNodeBrowser.java
index fa33a2896e..ead655d021 100644
--- 
a/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/adapter/OpcUaNodeBrowser.java
+++ 
b/streampipes-extensions/streampipes-connectors-opcua/src/main/java/org/apache/streampipes/extensions/connectors/opcua/adapter/OpcUaNodeBrowser.java
@@ -86,7 +86,13 @@ public class OpcUaNodeBrowser {
   private OpcNode toOpcNode(String nodeName) throws UaException {
     AddressSpace addressSpace = getAddressSpace();
     NodeId nodeId = NodeId.parse(nodeName);
-    UaNode node = addressSpace.getNode(nodeId);
+
+    UaNode node;
+    try {
+      node = addressSpace.getNode(nodeId);
+    } catch (UaException e) {
+      throw new UaException(StatusCode.BAD.getValue(), "Node with ID " + 
nodeId + " is not present in the OPC UA server.", e);
+    }
 
     LOG.info("Using node of type {}", node.getNodeClass().toString());
 
diff --git a/ui/cypress/support/utils/ErrorMessageUtils.ts 
b/ui/cypress/support/utils/ErrorMessageUtils.ts
new file mode 100644
index 0000000000..31aa9baa3a
--- /dev/null
+++ b/ui/cypress/support/utils/ErrorMessageUtils.ts
@@ -0,0 +1,26 @@
+/*
+ *  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 ErrorMessageUtils {
+    /**
+     * Validates that an error message is displayed and that this message 
contains the @param message
+     */
+    public static containsMessage(message: string) {
+        cy.dataCy('exception-message-title').should('contain.text', message);
+    }
+}
diff --git a/ui/cypress/support/utils/connect/ConnectUtils.ts 
b/ui/cypress/support/utils/connect/ConnectUtils.ts
index 67556897e9..d4c7091a69 100644
--- a/ui/cypress/support/utils/connect/ConnectUtils.ts
+++ b/ui/cypress/support/utils/connect/ConnectUtils.ts
@@ -129,6 +129,13 @@ export class ConnectUtils {
 
         this.configureFormat(adapterInput);
 
+        ConnectUtils.finishAdapterSettings();
+    }
+
+    /**
+     * Clicks next on the adapter settings page
+     */
+    public static finishAdapterSettings() {
         // Next Button should not be disabled
         cy.get('button').contains('Next').parent().should('not.be.disabled');
 
diff --git a/ui/cypress/tests/connect/opcua/opcAdapterConfiguration.spec.ts 
b/ui/cypress/tests/connect/opcua/opcAdapterConfiguration.spec.ts
index d6578b247e..b52715d834 100644
--- a/ui/cypress/tests/connect/opcua/opcAdapterConfiguration.spec.ts
+++ b/ui/cypress/tests/connect/opcua/opcAdapterConfiguration.spec.ts
@@ -22,6 +22,7 @@ import { AdapterBuilder } from 
'../../../support/builder/AdapterBuilder';
 import { TreeNodeUserInputBuilder } from 
'../../../support/builder/TreeNodeUserInputBuilder';
 import { StaticPropertyUtils } from 
'../../../support/utils/userInput/StaticPropertyUtils';
 import { TreeStaticPropertyUtils } from 
'../../../support/utils/userInput/TreeStaticPropertyUtils';
+import { ErrorMessageUtils } from '../../../support/utils/ErrorMessageUtils';
 
 describe('Test OPC-UA Adapter Configuration', () => {
     beforeEach('Setup Test', () => {
@@ -82,7 +83,7 @@ describe('Test OPC-UA Adapter Configuration', () => {
         TreeStaticPropertyUtils.validateAmountOfSelectedNodes(0);
     });
 
-    it('Test OPC-UA Code Editor', () => {
+    it('Test OPC-UA Text Editor', () => {
         const adapterConfiguration = getAdapterBuilder().build();
 
         // Set up initial configuration
@@ -123,6 +124,25 @@ describe('Test OPC-UA Adapter Configuration', () => {
             'ns=3;s=StepUp' + 'ns=3;s=AlternatingBoolean',
         );
     });
+
+    it('Test OPC-UA Node does not exist', () => {
+        const adapterConfiguration = getAdapterBuilder().build();
+
+        // Set up initial configuration
+        ConnectUtils.goToConnect();
+        ConnectUtils.goToNewAdapterPage();
+        ConnectUtils.selectAdapter(adapterConfiguration.adapterType);
+        StaticPropertyUtils.input(adapterConfiguration.adapterConfiguration);
+
+        // Switch to text editor
+        TreeStaticPropertyUtils.switchToTextEditor();
+        TreeStaticPropertyUtils.typeInTextEditor('ns=3;s=NodeDoesNotExist');
+
+        ConnectUtils.finishAdapterSettings();
+
+        // validate that an error is shown with node id
+        ErrorMessageUtils.containsMessage('NodeDoesNotExist');
+    });
 });
 
 const getAdapterBuilder = () => {
diff --git 
a/ui/projects/streampipes/shared-ui/src/lib/components/sp-exception-message/sp-exception-message.component.html
 
b/ui/projects/streampipes/shared-ui/src/lib/components/sp-exception-message/sp-exception-message.component.html
index 04493f10e3..741bc96a9f 100644
--- 
a/ui/projects/streampipes/shared-ui/src/lib/components/sp-exception-message/sp-exception-message.component.html
+++ 
b/ui/projects/streampipes/shared-ui/src/lib/components/sp-exception-message/sp-exception-message.component.html
@@ -30,7 +30,7 @@
                     <h5 *ngIf="messageTimestamp" class="mr-15">
                         {{ messageTimestamp | date: 'short' }}
                     </h5>
-                    <h5 fxFlex>
+                    <h5 data-cy="exception-message-title" kfxFlex>
                         {{ message.title || 'Error' }}
                     </h5>
                 </div>

Reply via email to