|
| 1 | +/* ======================================================================== |
| 2 | + * Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * OPC Foundation MIT License 1.00 |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person |
| 7 | + * obtaining a copy of this software and associated documentation |
| 8 | + * files (the "Software"), to deal in the Software without |
| 9 | + * restriction, including without limitation the rights to use, |
| 10 | + * copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the |
| 12 | + * Software is furnished to do so, subject to the following |
| 13 | + * conditions: |
| 14 | + * |
| 15 | + * The above copyright notice and this permission notice shall be |
| 16 | + * included in all copies or substantial portions of the Software. |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 19 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 21 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 22 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 23 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 24 | + * OTHER DEALINGS IN THE SOFTWARE. |
| 25 | + * |
| 26 | + * The complete license agreement can be found here: |
| 27 | + * http://opcfoundation.org/License/MIT/1.00/ |
| 28 | + * ======================================================================*/ |
| 29 | + |
| 30 | +using System.Collections.Generic; |
| 31 | +using System.Threading.Tasks; |
| 32 | +using NUnit.Framework; |
| 33 | +using Opc.Ua.Tests; |
| 34 | +using Quickstarts.ReferenceServer; |
| 35 | + |
| 36 | +namespace Opc.Ua.Server.Tests |
| 37 | +{ |
| 38 | + [TestFixture] |
| 39 | + [Category("CoreNodeManager2")] |
| 40 | + [Parallelizable] |
| 41 | + public class CoreNodeManager2Tests |
| 42 | + { |
| 43 | + [Test] |
| 44 | + public async Task ImportNodes_IsInternal_UpdatesDiagnosticsAsync() |
| 45 | + { |
| 46 | + ITelemetryContext telemetry = NUnitTelemetryContext.Create(); |
| 47 | + var fixture = new ServerFixture<StandardServer>(t => new ReferenceServer(t)); |
| 48 | + |
| 49 | + try |
| 50 | + { |
| 51 | + StandardServer server = await fixture.StartAsync().ConfigureAwait(false); |
| 52 | + |
| 53 | + // Create a CoreNodeManager2 |
| 54 | + var config = new ApplicationConfiguration |
| 55 | + { |
| 56 | + ServerConfiguration = new ServerConfiguration |
| 57 | + { |
| 58 | + MaxNotificationQueueSize = 100, |
| 59 | + MaxDurableNotificationQueueSize = 100 |
| 60 | + } |
| 61 | + }; |
| 62 | + var nodeManager = new CoreNodeManager2(server.CurrentInstance, config); |
| 63 | + nodeManager.CreateAddressSpace(new Dictionary<NodeId, IList<IReference>>()); |
| 64 | + |
| 65 | + // Create a node in Namespace 0 that also exists in DiagnosticsNodeManager (e.g. Server Object) |
| 66 | + // Note: We need a node that exists in DiagnosticsNodeManager. StandardServer populates it with BaseNodes. |
| 67 | + // Let's use ObjectIds.Server. |
| 68 | + var serverNode = new BaseObjectState(null) |
| 69 | + { |
| 70 | + NodeId = ObjectIds.Server, |
| 71 | + BrowseName = new QualifiedName(BrowseNames.Server, 0), |
| 72 | + DisplayName = new LocalizedText("Server") |
| 73 | + }; |
| 74 | + |
| 75 | + // Add a reference that we want to check |
| 76 | + var targetNodeId = new NodeId(1234, 1); // Some random target |
| 77 | + serverNode.AddReference(ReferenceTypeIds.HasComponent, false, targetNodeId); |
| 78 | + |
| 79 | + // Act - isInternal = false |
| 80 | + nodeManager.ImportNodes(server.CurrentInstance.DefaultSystemContext, [serverNode], false); |
| 81 | + |
| 82 | + // Assert |
| 83 | + // Check if DiagnosticsNodeManager has the reference |
| 84 | + NodeState diagNode = server.CurrentInstance.DiagnosticsNodeManager.FindPredefinedNode<NodeState>(ObjectIds.Server); |
| 85 | + Assert.That(diagNode, Is.Not.Null, "Diagnostics node should exist"); |
| 86 | + Assert.That(diagNode.ReferenceExists(ReferenceTypeIds.HasComponent, false, targetNodeId), Is.True, "Reference should be added to diagnostics"); |
| 87 | + |
| 88 | + // Cleanup reference to verify isInternal = true |
| 89 | + diagNode.RemoveReference(ReferenceTypeIds.HasComponent, false, targetNodeId); |
| 90 | + Assert.That(diagNode.ReferenceExists(ReferenceTypeIds.HasComponent, false, targetNodeId), Is.False, "Reference should be removed"); |
| 91 | + |
| 92 | + // Act - isInternal = true |
| 93 | + var serverNode2 = new BaseObjectState(null) |
| 94 | + { |
| 95 | + NodeId = ObjectIds.Server, |
| 96 | + BrowseName = new QualifiedName(BrowseNames.Server, 0), |
| 97 | + DisplayName = new LocalizedText("Server") |
| 98 | + }; |
| 99 | + serverNode2.AddReference(ReferenceTypeIds.HasComponent, false, targetNodeId); |
| 100 | + |
| 101 | + nodeManager.ImportNodes(server.CurrentInstance.DefaultSystemContext, [serverNode2], true); |
| 102 | + |
| 103 | + // Assert |
| 104 | + Assert.That(diagNode.ReferenceExists(ReferenceTypeIds.HasComponent, false, targetNodeId), Is.False, |
| 105 | + "Reference should NOT be added to diagnostics when isInternal=true"); |
| 106 | + } |
| 107 | + finally |
| 108 | + { |
| 109 | + await fixture.StopAsync().ConfigureAwait(false); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments