Merge feat/803-heidenhain-lsv2
This commit is contained in:
@@ -41,6 +41,9 @@ public sealed class DriverPageJsonConverterTests
|
||||
new Dictionary<Type, JsonSerializerOptions>
|
||||
{
|
||||
[typeof(MqttDriverForm)] = MqttJson.Options,
|
||||
// HeidenhainDriverForm (#803) is a shell over HeidenhainDriverFormModel, which writes through its own
|
||||
// JsonOptions (a JsonObject bag that preserves the Devices collection) — the same pattern as MQTT.
|
||||
[typeof(HeidenhainDriverForm)] = HeidenhainDriverFormModel.JsonOptions,
|
||||
};
|
||||
|
||||
/// <summary>Every concrete <c>*DriverForm</c> in the AdminUI assembly.</summary>
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.DeviceForms;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Drivers.Forms;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns.TagEditors;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#803: the Heidenhain authoring surfaces (driver form, device form, tag editor, CSV, browse commit)
|
||||
/// write exactly what the driver factory and the deploy gate accept — the "registered but unauthorable" and
|
||||
/// "numerically-serialized enum" defect classes.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class HeidenhainAuthoringTests
|
||||
{
|
||||
[Fact]
|
||||
public void Every_authoring_seam_is_registered()
|
||||
{
|
||||
DriverConfigFormMap.Resolve(DriverTypeNames.Heidenhain).ShouldBe(typeof(HeidenhainDriverForm));
|
||||
DeviceFormMap.Resolve(DriverTypeNames.Heidenhain).ShouldBe(typeof(HeidenhainDeviceForm));
|
||||
TagConfigEditorMap.Resolve(DriverTypeNames.Heidenhain).ShouldBe(typeof(Components.Shared.Uns.TagEditors.HeidenhainTagConfigEditor));
|
||||
TagConfigValidator.Validate(DriverTypeNames.Heidenhain, "{}").ShouldNotBeNull();
|
||||
CsvColumnMap.Resolve(DriverTypeNames.Heidenhain).ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_default_driver_form_save_is_accepted_by_the_factory_and_preserves_devices()
|
||||
{
|
||||
var authored = """{"Devices":[{"Host":"10.0.0.5","DeviceName":"m1"}],"Custom":42}""";
|
||||
var m = HeidenhainDriverFormModel.FromJson(authored);
|
||||
m.Validate().ShouldBeNull();
|
||||
m.InspectPassword = "secret:heidenhain/inspect";
|
||||
m.TimersEnabled = true;
|
||||
var json = m.ToJson();
|
||||
var o = HeidenhainOptionsParser.Parse(json);
|
||||
HeidenhainOptionsParser.Validate(o).ShouldBeEmpty(); // the factory's ParseOptions gate
|
||||
o.Devices.Single().Host.ShouldBe("10.0.0.5");
|
||||
o.Access.InspectPassword.ShouldBe("secret:heidenhain/inspect");
|
||||
o.Polling.TimersEnabled.ShouldBeTrue();
|
||||
JsonNode.Parse(json)!["Custom"]!.GetValue<int>().ShouldBe(42);
|
||||
// no field is ever written as a number where the parser expects a name — there are no enums at all
|
||||
HeidenhainDriverFormModel.FromJson(json).ToJson().ShouldBe(json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Driver_form_refuses_literal_passwords_and_out_of_range_values()
|
||||
{
|
||||
var m = HeidenhainDriverFormModel.FromJson("{}");
|
||||
m.DncPassword = "hunter2";
|
||||
m.Validate()!.ShouldNotContain("hunter2");
|
||||
m.DncPassword = null;
|
||||
m.StatusMs = 10;
|
||||
m.Validate().ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Device_form_round_trips_and_validates_with_the_driver_rule()
|
||||
{
|
||||
var d = HeidenhainDeviceModel.FromJson("""{"Host":"cnc-7","Note":"keep"}""");
|
||||
d.Port.ShouldBe(19000);
|
||||
d.Validate().ShouldBeNull();
|
||||
d.DataPassword = "plain";
|
||||
d.Validate().ShouldNotBeNull();
|
||||
d.DataPassword = "env:OTOPCUA_HEIDENHAIN_DATA";
|
||||
var json = d.ToJson();
|
||||
JsonNode.Parse(json)!["Note"]!.GetValue<string>().ShouldBe("keep");
|
||||
var opts = HeidenhainOptionsParser.Parse($$"""{"Devices":[{{json}}]}""");
|
||||
opts.Devices.Single().DataPassword.ShouldBe("env:OTOPCUA_HEIDENHAIN_DATA");
|
||||
HeidenhainDeviceModel.FromJson("{}").Validate().ShouldNotBeNull(); // host required
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Axes/Positions")]
|
||||
[InlineData("Alarms/Messages")]
|
||||
[InlineData("Status/ExecutionState")]
|
||||
[InlineData("Capabilities/DncLogin")]
|
||||
public void Catalog_addresses_derive_type_and_rank_so_the_driver_accepts_them(string address)
|
||||
{
|
||||
var json = new HeidenhainTagConfigModel { Address = address }.ToJson();
|
||||
HeidenhainTagDefinitionFactory.TryFromTagConfig("p", "d", json, out var def, out var error).ShouldBeTrue(error);
|
||||
HeidenhainCatalog.TryGet(address, out var e).ShouldBeTrue();
|
||||
def!.DataType.ShouldBe(e!.DataType);
|
||||
def.IsArray.ShouldBe(e.IsArray);
|
||||
TagConfigValidator.Validate(DriverTypeNames.Heidenhain, json).ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Editor_writes_the_data_type_as_a_name_and_drops_a_stray_writable_flag()
|
||||
{
|
||||
var m = HeidenhainTagConfigModel.FromJson("""{"address":"PLC:WORD:2","dataType":"Int64","writable":true,"isHistorized":true}""");
|
||||
m.Validate().ShouldNotBeNull(); // as loaded: the driver refuses writable:true
|
||||
var json = m.ToJson();
|
||||
var o = JsonNode.Parse(json)!.AsObject();
|
||||
o["dataType"]!.GetValue<string>().ShouldBe("Int64");
|
||||
o.ContainsKey("writable").ShouldBeFalse();
|
||||
o["isHistorized"]!.GetValue<bool>().ShouldBeTrue();
|
||||
HeidenhainTagConfigModel.FromJson(json).Validate().ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Editor_refuses_a_narrowing_binding()
|
||||
{
|
||||
var m = new HeidenhainTagConfigModel { Address = "PLC:DWORD:0", DataType = DriverDataType.Int16 };
|
||||
m.Validate().ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Status/ExecutionState")]
|
||||
[InlineData("Axes/Names")]
|
||||
public void Browse_committed_leaves_open_in_the_editor_and_pass_the_driver_gate(string address)
|
||||
{
|
||||
var json = RawBrowseCommitMapper.BuildTagConfig(DriverTypeNames.Heidenhain, address);
|
||||
TagConfigValidator.Validate(DriverTypeNames.Heidenhain, json).ShouldBeNull();
|
||||
HeidenhainTagConfigModel.FromJson(json).Address.ShouldBe(address);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Uns;
|
||||
|
||||
/// <summary>
|
||||
/// #803 review findings 1 + 8 at the SAVE path (RawTreeService), not just the editor models: a literal or
|
||||
/// out-of-namespace Heidenhain password never reaches the config DB, and a Heidenhain tag row is refused when it
|
||||
/// is ReadWrite or carries a data type the driver does not publish — through every authoring entry point
|
||||
/// (modal create/update, manual entry = CreateTagAsync, CSV/browse = ImportTagsAsync).
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class HeidenhainSavePathTests
|
||||
{
|
||||
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
||||
|
||||
private static async Task<(RawTreeService Svc, string Db, string DriverId, string DeviceId)> HeidenhainAsync()
|
||||
{
|
||||
var name = RawTreeTestDb.SeedFresh();
|
||||
var svc = new RawTreeService(RawTreeTestDb.Factory(name));
|
||||
var created = await svc.CreateDriverAsync(RawTreeTestDb.ClusterId, null, "hh1", DriverTypeNames.Heidenhain, "{}", Ct);
|
||||
created.Ok.ShouldBeTrue(created.Error);
|
||||
using var db = RawTreeTestDb.CreateNamed(name);
|
||||
var device = db.Devices.Single(d => d.DriverInstanceId == created.CreatedId);
|
||||
return (svc, name, created.CreatedId!, device.DeviceId);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ finding 1: credentials never persisted
|
||||
|
||||
[Theory]
|
||||
[InlineData("""{"Access":{"InspectPassword":"hunter2"}}""")]
|
||||
[InlineData("""{"access":{"dncpassword":"hunter2"}}""")]
|
||||
[InlineData("""{"Access":{"DataPassword":"env:ConnectionStrings__ConfigDb"}}""")]
|
||||
[InlineData("""{"Devices":[{"Host":"h","InspectPassword":"secret:galaxy/inst1/apikey"}]}""")]
|
||||
public async Task CreateDriver_refuses_a_literal_or_out_of_namespace_password_and_persists_nothing(string config)
|
||||
{
|
||||
var name = RawTreeTestDb.SeedFresh();
|
||||
var svc = new RawTreeService(RawTreeTestDb.Factory(name));
|
||||
var result = await svc.CreateDriverAsync(RawTreeTestDb.ClusterId, null, "hh1", DriverTypeNames.Heidenhain, config, Ct);
|
||||
result.Ok.ShouldBeFalse();
|
||||
result.Error!.ShouldNotContain("hunter2");
|
||||
using var db = RawTreeTestDb.CreateNamed(name);
|
||||
db.DriverInstances.ShouldNotContain(d => d.Name == "hh1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateDriver_refuses_a_literal_password_and_keeps_the_stored_config()
|
||||
{
|
||||
var (svc, dbName, driverId, _) = await HeidenhainAsync();
|
||||
byte[] rv;
|
||||
using (var db = RawTreeTestDb.CreateNamed(dbName)) rv = db.DriverInstances.Single(d => d.DriverInstanceId == driverId).RowVersion;
|
||||
var result = await svc.UpdateDriverAsync(driverId, "hh1", """{"Access":{"InspectPassword":"hunter2"}}""", null, rv, Ct);
|
||||
result.Ok.ShouldBeFalse();
|
||||
using var check = RawTreeTestDb.CreateNamed(dbName);
|
||||
check.DriverInstances.Single(d => d.DriverInstanceId == driverId).DriverConfig.ShouldNotContain("hunter2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateDevice_and_UpdateDevice_refuse_a_literal_password()
|
||||
{
|
||||
var (svc, dbName, driverId, deviceId) = await HeidenhainAsync();
|
||||
(await svc.CreateDeviceAsync(driverId, "cnc2", """{"Host":"10.0.0.5","DncPassword":"hunter2"}""", Ct)).Ok.ShouldBeFalse();
|
||||
byte[] rv;
|
||||
using (var db = RawTreeTestDb.CreateNamed(dbName)) rv = db.Devices.Single(d => d.DeviceId == deviceId).RowVersion;
|
||||
(await svc.UpdateDeviceAsync(deviceId, "Device1x", """{"Host":"10.0.0.5","DataPassword":"hunter2"}""", true, rv, Ct)).Ok.ShouldBeFalse();
|
||||
using var check = RawTreeTestDb.CreateNamed(dbName);
|
||||
check.Devices.Where(d => d.DriverInstanceId == driverId).ShouldAllBe(d => !d.DeviceConfig.Contains("hunter2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Namespaced_references_save_and_other_drivers_are_unaffected()
|
||||
{
|
||||
var (svc, _, driverId, _) = await HeidenhainAsync();
|
||||
(await svc.CreateDeviceAsync(driverId, "cnc2",
|
||||
"""{"Host":"10.0.0.5","InspectPassword":"secret:heidenhain/cnc2/inspect","DncPassword":"env:OTOPCUA_HEIDENHAIN_DNC"}""", Ct)).Ok.ShouldBeTrue();
|
||||
// A Modbus driver's config is none of this gate's business.
|
||||
(await svc.CreateDriverAsync(RawTreeTestDb.ClusterId, null, "mb9", DriverTypeNames.Modbus, """{"InspectPassword":"x"}""", Ct)).Ok.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_modal_save_gate_is_the_same_rule()
|
||||
{
|
||||
DriverConfigSaveGate.Validate(DriverTypeNames.Heidenhain, """{"Access":{"InspectPassword":"hunter2"}}""").ShouldNotBeNull();
|
||||
DriverConfigSaveGate.Validate(DriverTypeNames.Heidenhain, """{"Access":{"InspectPassword":"secret:heidenhain/a"}}""").ShouldBeNull();
|
||||
DriverConfigSaveGate.Validate(DriverTypeNames.Modbus, """{"Access":{"InspectPassword":"hunter2"}}""").ShouldBeNull();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ finding 8: tag rows
|
||||
|
||||
private static RawTagInput Row(string name, string dataType, TagAccessLevel access, string config) =>
|
||||
new(name, dataType, access, WriteIdempotent: false, PollGroupId: null, config);
|
||||
|
||||
private const string Exec = """{"address":"Status/ExecutionState"}""";
|
||||
|
||||
[Fact]
|
||||
public async Task CreateTag_refuses_ReadWrite_and_a_mismatched_data_type()
|
||||
{
|
||||
var (svc, _, _, deviceId) = await HeidenhainAsync();
|
||||
(await svc.CreateTagAsync(deviceId, null, Row("a", "Int32", TagAccessLevel.ReadWrite, Exec), Ct)).Ok.ShouldBeFalse();
|
||||
(await svc.CreateTagAsync(deviceId, null, Row("b", "Float", TagAccessLevel.Read, Exec), Ct)).Ok.ShouldBeFalse();
|
||||
(await svc.CreateTagAsync(deviceId, null, Row("c", "Int32", TagAccessLevel.Read, Exec), Ct)).Ok.ShouldBeTrue();
|
||||
(await svc.CreateTagAsync(deviceId, null,
|
||||
Row("d", "Double", TagAccessLevel.Read, """{"address":"Axes/Positions","isArray":true}"""), Ct)).Ok.ShouldBeTrue();
|
||||
(await svc.CreateTagAsync(deviceId, null,
|
||||
Row("e", "Int64", TagAccessLevel.Read, """{"address":"PLC:DWORD:0","dataType":"Int64"}"""), Ct)).Ok.ShouldBeTrue();
|
||||
(await svc.CreateTagAsync(deviceId, null,
|
||||
Row("f", "Int32", TagAccessLevel.Read, """{"address":"PLC:DWORD:0","dataType":"Int64"}"""), Ct)).Ok.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateTag_refuses_ReadWrite()
|
||||
{
|
||||
var (svc, dbName, _, deviceId) = await HeidenhainAsync();
|
||||
var created = await svc.CreateTagAsync(deviceId, null, Row("a", "Int32", TagAccessLevel.Read, Exec), Ct);
|
||||
byte[] rv;
|
||||
using (var db = RawTreeTestDb.CreateNamed(dbName)) rv = db.Tags.Single(t => t.TagId == created.CreatedId).RowVersion;
|
||||
(await svc.UpdateTagAsync(created.CreatedId!, Row("a", "Int32", TagAccessLevel.ReadWrite, Exec), rv, Ct)).Ok.ShouldBeFalse();
|
||||
using var check = RawTreeTestDb.CreateNamed(dbName);
|
||||
check.Tags.Single(t => t.TagId == created.CreatedId).AccessLevel.ShouldBe(TagAccessLevel.Read);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ImportTags_names_the_ReadWrite_and_mismatched_rows_and_inserts_nothing()
|
||||
{
|
||||
var (svc, dbName, _, deviceId) = await HeidenhainAsync();
|
||||
var outcome = await svc.ImportTagsAsync(deviceId,
|
||||
[
|
||||
new RawTagImportRow(null, Row("ok", "Int32", TagAccessLevel.Read, Exec)),
|
||||
new RawTagImportRow(null, Row("rw", "Int32", TagAccessLevel.ReadWrite, Exec)),
|
||||
new RawTagImportRow(null, Row("dt", "String", TagAccessLevel.Read, Exec)),
|
||||
], Ct);
|
||||
outcome.Errors.Count.ShouldBe(2);
|
||||
using var db = RawTreeTestDb.CreateNamed(dbName);
|
||||
db.Tags.ShouldNotContain(t => t.DeviceId == deviceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Row_defaults_force_Read_and_derive_the_data_type()
|
||||
{
|
||||
var access = TagAccessLevel.ReadWrite;
|
||||
var dataType = "Float";
|
||||
RawTagRowDefaults.Apply(DriverTypeNames.Heidenhain, """{"address":"Overrides/Feed"}""", a => access = a, d => dataType = d);
|
||||
access.ShouldBe(TagAccessLevel.Read);
|
||||
dataType.ShouldBe("Double");
|
||||
RawTagRowDefaults.Apply(DriverTypeNames.Modbus, Exec, a => access = TagAccessLevel.ReadWrite, d => dataType = "x");
|
||||
dataType.ShouldBe("Double"); // untouched for other drivers
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ public sealed class TagConfigNonEnumParityTests
|
||||
[DriverTypeNames.MTConnect] = j => MTConnectTagDefinitionFactory.TryFromTagConfig(j, out _, out _),
|
||||
[DriverTypeNames.Calculation] = j => CalculationTagDefinitionFactory.TryReadTagConfig(j, out _),
|
||||
[DriverTypeNames.OpcUaClient] = j => OpcUaClientTagDefinitionFactory.TryReadNodeId(j, out _),
|
||||
[DriverTypeNames.Heidenhain] = j => ZB.MOM.WW.OtOpcUa.Driver.Heidenhain.HeidenhainTagDefinitionFactory.TryFromTagConfig(P, "", j, out _, out _),
|
||||
};
|
||||
|
||||
private static bool RuntimeAccepts(string driverType, string blob) => RuntimeParses[driverType](blob);
|
||||
@@ -91,6 +92,7 @@ public sealed class TagConfigNonEnumParityTests
|
||||
DriverTypeNames.Modbus, DriverTypeNames.S7, DriverTypeNames.AbCip, DriverTypeNames.AbLegacy,
|
||||
DriverTypeNames.TwinCAT, DriverTypeNames.FOCAS, DriverTypeNames.Mqtt, DriverTypeNames.Sql,
|
||||
DriverTypeNames.MTConnect, DriverTypeNames.Calculation, DriverTypeNames.OpcUaClient,
|
||||
DriverTypeNames.Heidenhain,
|
||||
];
|
||||
|
||||
foreach (var driverType in mapped)
|
||||
@@ -425,6 +427,20 @@ public sealed class TagConfigNonEnumParityTests
|
||||
(DriverTypeNames.MTConnect, """{"dataItemId":"Xact"}"""),
|
||||
(DriverTypeNames.MTConnect, """{"fullName":"Xact","driverDataType":"Strng"}"""),
|
||||
|
||||
(DriverTypeNames.Heidenhain, "{}"),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"Status/ExecutionState"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"Status/ExecutionState","dataType":"Int32"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"Status/ExecutionState","dataType":"String"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"Axes/Names","isArray":true}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"Axes/Names"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"PLC:WORD:4","dataType":"Int32"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"PLC:WORD:4","dataType":"8"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"PLC:WORD:4"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"PLC:DWORD:0","dataType":"Int16"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"DATA:/PLC/memory/W/8","dataType":"Int64"}"""),
|
||||
(DriverTypeNames.Heidenhain, """{"address":"Status/ExecutionState","writable":true}"""),
|
||||
(DriverTypeNames.Heidenhain, Pad + """{"address":"Overrides/Feed"}"""),
|
||||
|
||||
(DriverTypeNames.Calculation, "{}"),
|
||||
(DriverTypeNames.Calculation, """{"scriptId":"S1"}"""),
|
||||
(DriverTypeNames.Calculation, """{"scriptId":"S1","changeTriggered":true,"timerIntervalMs":5000}"""),
|
||||
@@ -602,6 +618,9 @@ public sealed class TagConfigNonEnumParityTests
|
||||
new MTConnectTagConfigModel { FullName = "Xact", DataType = DriverDataType.Float64 }.ToJson());
|
||||
data.Add(DriverTypeNames.Mqtt,
|
||||
new MqttTagConfigModel { Mode = MqttMode.Plain, Topic = "otopcua/fixture/a" }.ToJson());
|
||||
data.Add(DriverTypeNames.Heidenhain, new HeidenhainTagConfigModel { Address = "Axes/Positions" }.ToJson());
|
||||
data.Add(DriverTypeNames.Heidenhain,
|
||||
new HeidenhainTagConfigModel { Address = "PLC:INPUT_WORD:3", DataType = DriverDataType.Int32 }.ToJson());
|
||||
data.Add(DriverTypeNames.Mqtt, new MqttTagConfigModel
|
||||
{
|
||||
Mode = MqttMode.SparkplugB,
|
||||
|
||||
@@ -18,6 +18,7 @@ internal static class TagConfigRoundTrip
|
||||
DriverTypeNames.Sql => SqlTagConfigModel.FromJson(json).ToJson(),
|
||||
DriverTypeNames.Mqtt => MqttTagConfigModel.FromJson(json).ToJson(),
|
||||
DriverTypeNames.MTConnect => MTConnectTagConfigModel.FromJson(json).ToJson(),
|
||||
DriverTypeNames.Heidenhain => HeidenhainTagConfigModel.FromJson(json).ToJson(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(driverType)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
using System.Text.Json;
|
||||
using Akka.Actor;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Heidenhain;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Heidenhain.Tests.Simulator;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Drivers;
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#803 end-to-end through the REAL <see cref="DriverInstanceActor"/>: the real Heidenhain driver
|
||||
/// (built by its factory from a merged config) against the in-process LSV2 simulator — subscribe, OPC write
|
||||
/// refusal, controller-side outbound restriction, outage invalidation and recovery.
|
||||
/// </summary>
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class HeidenhainDriverEndToEndTests : RuntimeActorTestBase
|
||||
{
|
||||
private const string Exec = "Plant/H/dev1/Status/ExecutionState";
|
||||
private const string Model = "Plant/H/dev1/Controller/Model";
|
||||
|
||||
private static string Config(int port) => JsonSerializer.Serialize(new
|
||||
{
|
||||
Devices = new[] { new { Host = "127.0.0.1", Port = port, DeviceName = "dev1" } },
|
||||
RawTags = new[]
|
||||
{
|
||||
new { RawPath = Exec, TagConfig = """{"address":"Status/ExecutionState"}""", WriteIdempotent = false, DeviceName = "dev1" },
|
||||
new { RawPath = Model, TagConfig = """{"address":"Controller/Model"}""", WriteIdempotent = false, DeviceName = "dev1" },
|
||||
},
|
||||
TimeoutMs = 500,
|
||||
Polling = new { StatusMs = 100, CustomMs = 100, SlowMs = 200 },
|
||||
Reconnect = new { InitialDelayMs = 100, MaxDelayMs = 200 },
|
||||
});
|
||||
|
||||
private DriverInstanceActor.AttributeValueItem? AwaitItem(Akka.TestKit.TestProbe parent, string reference, Func<DriverInstanceActor.AttributeValueItem, bool> match)
|
||||
{
|
||||
DriverInstanceActor.AttributeValueItem? found = null;
|
||||
parent.FishForMessage<DriverInstanceActor.AttributeValueBatchPublished>(b =>
|
||||
{
|
||||
foreach (var i in b.Items)
|
||||
if (i.FullReference == reference && match(i)) { found = i; return true; }
|
||||
return false;
|
||||
}, TimeSpan.FromSeconds(10), cancellationToken: TestContext.Current.CancellationToken);
|
||||
return found;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Subscribe_write_refusal_outage_and_recovery_through_the_real_actor()
|
||||
{
|
||||
var control = new SimulatedControl();
|
||||
control.Runtime[23] = () => SimulatedControl.U16(4);
|
||||
await using var sim = Lsv2Simulator.WithControl(control);
|
||||
var driver = HeidenhainDriverFactoryExtensions.CreateInstance("hh-e2e", Config(sim.Port));
|
||||
var parent = CreateTestProbe();
|
||||
parent.IgnoreMessages(m => m is not DriverInstanceActor.AttributeValueBatchPublished);
|
||||
var actor = parent.ChildActorOf(
|
||||
DriverInstanceActor.Props(driver, reconnectInterval: TimeSpan.FromMilliseconds(100),
|
||||
healthPollInterval: TimeSpan.FromMilliseconds(100), commsLossTimeout: TimeSpan.FromSeconds(1)),
|
||||
TestContext.Current.CancellationToken);
|
||||
|
||||
actor.Tell(new DriverInstanceActor.SetDesiredSubscriptions([Exec, Model], TimeSpan.FromMilliseconds(100)));
|
||||
actor.Tell(new DriverInstanceActor.InitializeRequested(Config(sim.Port)));
|
||||
|
||||
AwaitItem(parent, Exec, i => i.StatusCode == OpcUaStatus.Good)!.Value.Value.ShouldBe(4);
|
||||
|
||||
// OPC write: refused by the runtime (the driver implements no IWritable) — nothing reaches the control.
|
||||
var write = await actor.Ask<DriverInstanceActor.WriteAttributeResult>(
|
||||
new DriverInstanceActor.WriteAttribute(Exec, 9), TimeSpan.FromSeconds(3), TestContext.Current.CancellationToken);
|
||||
write.Success.ShouldBeFalse();
|
||||
|
||||
// Outage: every remote value goes BadNoCommunication.
|
||||
sim.GoOffline();
|
||||
AwaitItem(parent, Exec, i => i.StatusCode == HeidenhainStatus.BadNoCommunication).ShouldNotBeNull();
|
||||
|
||||
// Recovery: the control comes back holding the SAME value, and it re-publishes Good.
|
||||
sim.GoOnline();
|
||||
AwaitItem(parent, Exec, i => i.StatusCode == OpcUaStatus.Good)!.Value.Value.ShouldBe(4);
|
||||
|
||||
control.Violations.ShouldBeEmpty();
|
||||
sim.Requests.Select(r => r.Command).Distinct().ShouldBeSubsetOf(new[] { "A_LG", "R_VR", "R_RI" });
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,15 @@
|
||||
<!-- Lane S7 review I-1: the real S7 driver (over a scripted IS7Plc), so the comms-loss watchdog test proves an
|
||||
access-denied (PUT/GET disabled) CPU is NOT reconnected every 90 s, against the real actor. -->
|
||||
<ProjectReference Include="..\..\..\src\Drivers\ZB.MOM.WW.OtOpcUa.Driver.S7\ZB.MOM.WW.OtOpcUa.Driver.S7.csproj"/>
|
||||
<!-- lmxopcua#803: the real Heidenhain LSV2 driver over the in-process LSV2 simulator (linked below), so the
|
||||
end-to-end test proves subscribe / write refusal / comms-loss watchdog recovery through the real actor. -->
|
||||
<ProjectReference Include="..\..\..\src\Drivers\ZB.MOM.WW.OtOpcUa.Driver.Heidenhain\ZB.MOM.WW.OtOpcUa.Driver.Heidenhain.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Shared bind-race retry helper for tests that boot a real SDK server on a probed port. -->
|
||||
<Compile Include="..\ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests\OpcUaHostStart.cs" Link="OpcUaHostStart.cs"/>
|
||||
<Compile Include="..\..\Drivers\ZB.MOM.WW.OtOpcUa.Driver.Heidenhain.Tests\Simulator\*.cs" LinkBase="HeidenhainSimulator"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user