using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Configuration.Entities; using ZB.MOM.WW.OtOpcUa.Configuration.Enums; using ZB.MOM.WW.OtOpcUa.Configuration.Validation; using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections; namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections; /// /// #942: an export rooted at an alarm-bearing raw tag (or a UNS reference to one) grants nothing — the tag is an /// unsupported value node (#917) and its condition placements sit under its folder / the referencing equipment. The /// authoring + deploy-gate validator refuses such a root; node-side re-validation of a deployed artifact tolerates it. /// [Trait("Category", "Unit"), Trait("Feature", "GrpcData")] public sealed class GrpcDataExportRootValidationTests { private const string AlarmConfig = "{\"alarm\":{\"alarmType\":\"AlarmCondition\",\"severity\":700}}"; private const string Code = "DataExportRootAlarmBearing"; [Theory] [InlineData(DataRealm.Raw, "RawTag", "alarm-tag")] [InlineData(DataRealm.Uns, "UnsTagReference", "ref-alarm")] public void An_export_rooted_at_an_alarm_bearing_tag_is_refused_at_authoring_and_the_deploy_gate(DataRealm realm, string kind, string id) { var draft = Snapshot(realm, kind, id); var error = DataConnectionValidator.Validate(draft).ShouldHaveSingleItem(); error.Code.ShouldBe(Code); error.Context.ShouldBe("export"); DraftValidator.Validate(draft).ShouldContain(x => x.Code == Code && x.Context == "export"); // Node-side re-validation of an already-deployed artifact stays tolerant (a refusal there would fail the whole set). DataConnectionValidator.ValidateDeployed(draft).ShouldNotContain(x => x.Code == Code); } [Theory] [InlineData(DataRealm.Raw, "RawTag", "plain-tag")] [InlineData(DataRealm.Uns, "UnsTagReference", "ref-plain")] [InlineData(DataRealm.Raw, "RawDevice", "device")] [InlineData(DataRealm.Uns, "Equipment", "eq")] public void A_value_tag_or_a_container_holding_the_alarm_is_still_a_valid_root(DataRealm realm, string kind, string id) => DataConnectionValidator.Validate(Snapshot(realm, kind, id)).ShouldBeEmpty(); [Fact] public void A_disabled_export_is_not_checked() => DataConnectionValidator.Validate(Snapshot(DataRealm.Raw, "RawTag", "alarm-tag", enabled: false)).ShouldBeEmpty(); private static DraftSnapshot Snapshot(DataRealm realm, string rootKind, string rootId, bool enabled = true) => new() { GenerationId = 1, ClusterId = "local", ServerClusters = [new() { ClusterId = "local", Name = "Local", Enterprise = "E", Site = "S", CreatedBy = "test", RedundancyMode = RedundancyMode.None }], RawFolders = [new() { RawFolderId = "folder", ClusterId = "local", Name = "Plant" }], DriverInstances = [new() { DriverInstanceId = "driver", ClusterId = "local", RawFolderId = "folder", Name = "Driver", DriverType = "Modbus", DriverConfig = "{}" }], Devices = [new() { DeviceId = "device", DriverInstanceId = "driver", Name = "Device", DeviceConfig = "{}" }], Tags = [new() { TagId = "plain-tag", DeviceId = "device", Name = "Speed", DataType = "Int32", AccessLevel = TagAccessLevel.Read, TagConfig = "{}" }, new() { TagId = "alarm-tag", DeviceId = "device", Name = "OverTemp", DataType = "Boolean", AccessLevel = TagAccessLevel.Read, TagConfig = AlarmConfig }], UnsAreas = [new() { UnsAreaId = "area", ClusterId = "local", Name = "Area" }], UnsLines = [new() { UnsLineId = "line", UnsAreaId = "area", Name = "Line" }], Equipment = [new() { EquipmentId = "eq", UnsLineId = "line", Name = "Filler", MachineCode = "E1" }], UnsTagReferences = [new() { UnsTagReferenceId = "ref-plain", EquipmentId = "eq", TagId = "plain-tag" }, new() { UnsTagReferenceId = "ref-alarm", EquipmentId = "eq", TagId = "alarm-tag" }], DataExports = [new DataExport { DataExportId = "export", ClusterId = "local", Enabled = enabled, Revision = 1, Realm = realm, RootKind = rootKind, RootEntityId = rootId, PrincipalId = "peer", AllowedOperations = DataOperations.Browse | DataOperations.Read, }], }; }