From 6f83ae67d4f018ec2bbdb301bf26743d6e3edc12 Mon Sep 17 00:00:00 2001 From: mpostol Date: Sun, 14 Feb 2021 20:11:12 +0100 Subject: [PATCH 1/3] ADI model from Embedded example import fails #509 ValidateAndExportModel Test Name: ADITest Test Outcome: Passed Result StandardOutput: Debug Trace: Trace: Verbose, Error Focus:Diagnostic, ErrorID: P0-0003010000 Info: It is diagnostic information Entering IAddressSpaceContext.ValidateAndExportModel - starting for the http://opcfoundation.org/UA/ADI/ namespace. Trace: Verbose, Error Focus:Diagnostic, ErrorID: P0-0003010000 Info: It is diagnostic information AddressSpaceContext.ValidateAndExportModel - selected 41 nodes to be added to the model. Trace: Information, Error Focus:NodeClass, ErrorID: P3-0502020001 Info: NodeId is not defined. References to node with NodeId: ns=2;i=12386 is omitted during the import. Trace: Information, Error Focus:NodeClass, ErrorID: P3-0502020001 Info: NodeId is not defined. References to node with NodeId: ns=2;i=12386 is omitted during the import. Trace: Information, Error Focus:NodeClass, ErrorID: P3-0502020001 Info: NodeId is not defined. References to node with NodeId: ns=2;i=12386 is omitted during the import. Trace: Verbose, Error Focus:Diagnostic, ErrorID: P0-0003010000 Info: It is diagnostic information Finishing Validator.ValidateExportModel - the model contains 41 nodes. --- .../XMLModelsCorrectModelsUnitTest.cs | 2 +- .../XMLModelsModelsWithErrorsUnitTest.cs | 2 +- .../XMLModelsProblemsToReportUnitTest.cs | 37 +++++------- .../IAddressSpaceURIRecalculate.cs | 29 ++++++++++ .../UANodeSetValidation/UANodeContext.cs | 2 +- .../XML/ModelTableEntry.cs | 56 +++++++++++++++++++ 6 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 SemanticData/UANodeSetValidation/IAddressSpaceURIRecalculate.cs create mode 100644 SemanticData/UANodeSetValidation/XML/ModelTableEntry.cs diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsCorrectModelsUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsCorrectModelsUnitTest.cs index 8c709f68..18305d68 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsCorrectModelsUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsCorrectModelsUnitTest.cs @@ -13,7 +13,7 @@ using UAOOI.SemanticData.BuildingErrorsHandling; using UAOOI.SemanticData.UANodeSetValidation.XML; -namespace UAOOI.SemanticData.UANodeSetValidation.UnitTest +namespace UAOOI.SemanticData.UANodeSetValidation { [TestClass] [DeploymentItem(@"XMLModels\CorrectModels", @"CorrectModels\")] diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsModelsWithErrorsUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsModelsWithErrorsUnitTest.cs index 42eb9ea8..f9eed2c8 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsModelsWithErrorsUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsModelsWithErrorsUnitTest.cs @@ -12,7 +12,7 @@ using System.Linq; using UAOOI.SemanticData.BuildingErrorsHandling; -namespace UAOOI.SemanticData.UANodeSetValidation.UnitTest +namespace UAOOI.SemanticData.UANodeSetValidation { [TestClass] [DeploymentItem(@"XMLModels\ModelsWithErrors\", @"ModelsWithErrors\")] diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs index d56e6818..60dbcaee 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs @@ -27,43 +27,36 @@ public void ADITest() List _trace = new List(); IAddressSpaceContext _as = new AddressSpaceContext(z => _trace.Add(z)); Uri model = _as.ImportUANodeSet(_testDataFileInfo); - Assert.AreEqual(1, _trace.Where(x => x.BuildError.Focus != Focus.Diagnostic).Count()); + _trace.Clear(); _as.ValidateAndExportModel(model); - IEnumerable vitalMessageserrors = _trace.Where(x => x.BuildError.Focus != Focus.Diagnostic); - IEnumerable focusNodeClass = _trace.Where(x => x.BuildError.Focus == Focus.NodeClass); - Assert.IsFalse(focusNodeClass.Where(x => !x.BuildError.Identifier.Trim().Contains("P3-0502020001")).Any()); - - //Assert.Inconclusive("The import returns unexpected errors."); - - Assert.AreEqual(6, vitalMessageserrors.Count()); - - Assert.AreEqual(3, focusNodeClass.Count()); - Debug.WriteLine(nameof(Focus.NodeClass)); - foreach (TraceMessage item in focusNodeClass) - Debug.WriteLine(item.ToString()); - - IEnumerable focusNonCategorized = _trace.Where(x => x.BuildError.Focus == Focus.NonCategorized); - Assert.AreEqual(2, focusNonCategorized.Count()); - Debug.WriteLine(nameof(Focus.NonCategorized)); - foreach (TraceMessage item in focusNonCategorized) + foreach (TraceMessage item in _trace) Debug.WriteLine(item.ToString()); + //TODO ADI model from Embedded example import fails #509 + Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus != Focus.Diagnostic).Count()); + Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus == Focus.NodeClass).Count()); + Assert.AreEqual(3, _trace.Where(x => x.BuildError.Identifier.Trim().Contains("P3-0502020001")).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.NonCategorized).Count()); } + [TestMethod] public void eoursel510Test() { - FileInfo _testDataFileInfo = new FileInfo(@"ProblemsToReport\eoursel510\Opc.Ua.NodeSet2.TriCycleType_V1.1.xml"); Assert.IsTrue(_testDataFileInfo.Exists); List _trace = new List(); IAddressSpaceContext _as = new AddressSpaceContext(z => _trace.Add(z)); Uri model = _as.ImportUANodeSet(_testDataFileInfo); //Extensions is omitted during the import - Assert.AreEqual(10, _trace.Where(x => x.BuildError.Focus == Focus.Diagnostic).Count()); - Assert.AreEqual(1, _trace.Where(x => x.BuildError.Focus == Focus.XML).Count()); + List importUANodeSetXML = _trace.Where(x => x.BuildError.Focus == Focus.XML).ToList(); + Assert.AreEqual(1, importUANodeSetXML.Count); + Assert.AreEqual("", importUANodeSetXML[0].BuildError.Identifier); + Assert.IsTrue(importUANodeSetXML[0].Message.Contains("Extensions is omitted during the import")); + _trace.Clear(); _as.ValidateAndExportModel(model); + foreach (TraceMessage item in _trace) + Debug.WriteLine(item.ToString()); Assert.AreEqual(13, _trace.Where(x => x.BuildError.Focus == Focus.Diagnostic).Count()); Assert.AreEqual(1, _trace.Where(x => x.BuildError.Focus == Focus.XML).Count()); - } } } \ No newline at end of file diff --git a/SemanticData/UANodeSetValidation/IAddressSpaceURIRecalculate.cs b/SemanticData/UANodeSetValidation/IAddressSpaceURIRecalculate.cs new file mode 100644 index 00000000..e1a4bdb7 --- /dev/null +++ b/SemanticData/UANodeSetValidation/IAddressSpaceURIRecalculate.cs @@ -0,0 +1,29 @@ +//___________________________________________________________________________________ +// +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI +//___________________________________________________________________________________ + +using System; + +namespace UAOOI.SemanticData.UANodeSetValidation +{ + /// + /// Interface IAddressSpaceURIRecalculate is used to recalculate indexes in the imported model + /// + internal interface IAddressSpaceURIRecalculate + { + /// + /// Searches for an index that matches the , and returns the zero-based index of the first occurrence within the namespace table. + /// + /// The URI to be glistered in the namespace table. + /// + /// The zero-based index of the first occurrence of + /// + /// URI is null. + ushort GetURIIndexOrAppend(Uri URI); + + void UpadateModelOrAppend(IModelTableEntry model); + } +} \ No newline at end of file diff --git a/SemanticData/UANodeSetValidation/UANodeContext.cs b/SemanticData/UANodeSetValidation/UANodeContext.cs index c2c6e918..84d6dfc0 100644 --- a/SemanticData/UANodeSetValidation/UANodeContext.cs +++ b/SemanticData/UANodeSetValidation/UANodeContext.cs @@ -321,7 +321,7 @@ public bool Equals(IUANodeBase other) return false; //TODO ADI model from Embedded example import fails #509 if (this.BrowseName != other.BrowseName) //1:TransitionNumber vs TransitionNumber; 1:StateNumber vs StateNumber - throw new ArgumentOutOfRangeException("The browse name of compared nodes musty be equal."); + return false; // throw new ArgumentOutOfRangeException("The browse name of compared nodes musty be equal."); return this.UANode.Equals(other.UANode); } diff --git a/SemanticData/UANodeSetValidation/XML/ModelTableEntry.cs b/SemanticData/UANodeSetValidation/XML/ModelTableEntry.cs new file mode 100644 index 00000000..bdfe6bae --- /dev/null +++ b/SemanticData/UANodeSetValidation/XML/ModelTableEntry.cs @@ -0,0 +1,56 @@ +//___________________________________________________________________________________ +// +// Copyright (C) 2021, Mariusz Postol LODZ POLAND. +// +// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI +//___________________________________________________________________________________ + +using System; + +namespace UAOOI.SemanticData.UANodeSetValidation.XML +{ + /// + /// Class ModelTableEntry. + /// Implements the + /// + /// + public partial class ModelTableEntry : IModelTableEntry + { + /// + /// Gets or sets the required model. A list of dependencies for the model. If the model requires a minimum version the PublicationDate shall be specified. + /// Tools which attempt to resolve these dependencies may accept any PublicationDate after this date. + /// + /// The required model. + IModelTableEntry[] IModelTableEntry.RequiredModel => RequiredModel; + + /// + /// Gets or sets the role permissions. The list of default RolePermissions for all Nodes in the model. + /// + /// The role permissions. + IRolePermission[] IModelTableEntry.RolePermissions => RolePermissions; + + /// + /// Gets or sets the access restrictions. The default AccessRestrictions that apply to all Nodes in the model. + /// + /// The access restrictions. + byte IModelTableEntry.AccessRestrictions => AccessRestrictions; + + /// + /// Gets or sets the model URI. The URI for the model. This URI should be one of the entries in the table. + /// + /// The model URI. + Uri IModelTableEntry.ModelUri => new Uri(ModelUri); + + /// + /// Gets or sets the publication date. When the model was published. This value is used for comparisons if the model is defined in multiple UANodeSet files. + /// + /// The publication date. + DateTime? IModelTableEntry.PublicationDate => this.PublicationDateSpecified ? PublicationDate : new Nullable(); + + /// + /// Gets or sets the version. The version of the model defined in the UANodeSet. This is a human readable string and not intended for programmatic comparisons. + /// + /// The version. + string IModelTableEntry.Version => Version; + } +} \ No newline at end of file From da3b577679dc445b495860fcff705b87b0092608 Mon Sep 17 00:00:00 2001 From: mpostol Date: Sun, 14 Feb 2021 20:20:51 +0100 Subject: [PATCH 2/3] Import simple NodeSet2 file is incomplete #510 Test Name: eoursel510Test Test Outcome: Passed Result StandardOutput: Debug Trace: Trace: Verbose, Error Focus:Diagnostic, ErrorID: P0-0003010000 Info: It is diagnostic information Entering IAddressSpaceContext.ValidateAndExportModel - starting for the http://tricycletypev1/ namespace. Trace: Verbose, Error Focus:Diagnostic, ErrorID: P0-0003010000 Info: It is diagnostic information AddressSpaceContext.ValidateAndExportModel - selected 8 nodes to be added to the model. Trace: Verbose, Error Focus:Diagnostic, ErrorID: P0-0003010000 Info: It is diagnostic information Finishing Validator.ValidateExportModel - the model contains 8 nodes. --- .../XMLModelsProblemsToReportUnitTest.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs index 60dbcaee..f746d565 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs @@ -49,14 +49,20 @@ public void eoursel510Test() //Extensions is omitted during the import List importUANodeSetXML = _trace.Where(x => x.BuildError.Focus == Focus.XML).ToList(); Assert.AreEqual(1, importUANodeSetXML.Count); - Assert.AreEqual("", importUANodeSetXML[0].BuildError.Identifier); + Assert.AreEqual("P0-0001010000", importUANodeSetXML[0].BuildError.Identifier); Assert.IsTrue(importUANodeSetXML[0].Message.Contains("Extensions is omitted during the import")); _trace.Clear(); _as.ValidateAndExportModel(model); foreach (TraceMessage item in _trace) Debug.WriteLine(item.ToString()); - Assert.AreEqual(13, _trace.Where(x => x.BuildError.Focus == Focus.Diagnostic).Count()); - Assert.AreEqual(1, _trace.Where(x => x.BuildError.Focus == Focus.XML).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.DataEncoding).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.DataType).Count()); + Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus == Focus.Diagnostic).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.Naming).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.NodeClass).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.NonCategorized).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.Reference).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.XML).Count()); } } } \ No newline at end of file From c7a4cb383544eb06edacec5060b9bd55047f1ca2 Mon Sep 17 00:00:00 2001 From: mpostol Date: Sun, 14 Feb 2021 20:35:07 +0100 Subject: [PATCH 3/3] ADI model from Embedded example import fails #509 - improved UT - UT+1: --- .../XMLModelsProblemsToReportUnitTest.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs index f746d565..42be27a6 100644 --- a/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs +++ b/SemanticData/Tests/USNodeSetValidationUnitTestProject/XMLModelsProblemsToReportUnitTest.cs @@ -32,10 +32,15 @@ public void ADITest() foreach (TraceMessage item in _trace) Debug.WriteLine(item.ToString()); //TODO ADI model from Embedded example import fails #509 - Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus != Focus.Diagnostic).Count()); - Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus == Focus.NodeClass).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.DataEncoding).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.DataType).Count()); + Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus == Focus.Diagnostic).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.Naming).Count()); Assert.AreEqual(3, _trace.Where(x => x.BuildError.Identifier.Trim().Contains("P3-0502020001")).Count()); + Assert.AreEqual(3, _trace.Where(x => x.BuildError.Focus == Focus.NodeClass).Count()); Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.NonCategorized).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.Reference).Count()); + Assert.AreEqual(0, _trace.Where(x => x.BuildError.Focus == Focus.XML).Count()); } [TestMethod]