feat(heidenhain): AdminUI driver/device forms, typed tag editor, CSV + browse-commit (#803)
- HeidenhainDriverForm over HeidenhainDriverFormModel (JsonObject bag preserves Devices and unknown keys; no enum fields; Validate asks HeidenhainOptionsParser) + DriverConfigFormMap. - HeidenhainDeviceForm/Model (Host, Port 19000, optional per-device password references) + DeviceFormMap. Literal passwords are refused in both forms. - RawDriverTypeDialog entry; HeidenhainTagConfigEditor over HeidenhainTagConfigModel, whose Validate is the driver's own TryFromTagConfig; catalog leaves derive dataType + isArray; registered in TagConfigEditorMap + TagConfigValidator. - CsvColumnMap (HhAddress/HhDataType/HhIsArray) and RawBrowseCommitMapper branch. - Guards: DriverPageJsonConverterTests external-serializer entry, TagConfigNonEnumParityTests runtime map + corpus + freshly-authored rows, TagConfigRoundTrip, HeidenhainAuthoringTests.
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:lsv2/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:lsv2/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:LSV2_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:LSV2_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);
|
||||
}
|
||||
}
|
||||
@@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user