Files
UA-.NETStandard/tests/Opc.Ua.WotCon.Samples.Tests/AggregationClientDocumentTests.cs
Marc Schier e8bec27d5d Complete WoT binding preservation and two-pump aggregation (#4431)
# Description

Complete WoT Binding preservation and the two-pump aggregation workflow
without implicit overlays or multi-source action fan-out.

- Add verified linked-document export and bounded partition merging.
Preserve complete source facts, reject contradictory archival content,
and retain usable readable content when a future native grammar is
unsupported.
- Wire local Methods and Condition events through the existing
injectable binding/runtime infrastructure. Keep local and upstream
identities distinct, translate namespace-bearing values, and bound
occurrence routes by source and generation.
- Wait for asynchronous event-producer readiness before completing
subscription creation, so the first alarm is not lost. Preserve
cancellation, teardown, and startup-failure reporting.
- Import runtime types in inheritance order and attach typed Method
argument Properties. Keep generated Double spelling deterministic across
supported frameworks and remove an AOT-unsafe registry validation
conversion.
- Generate both pumps and their asset/group projections. Expose fifteen
typed readings per pump, separate source-owned controls, and
acknowledge/confirm/reset workflows. Extend the demo script for managed
and NativeAOT execution, bounded failures, and exact-process cleanup.
- Synchronize current-state documentation and specification fixtures.
Compose fixture paths from platform-independent components and emit/pin
LF pump XML so byte-exact regeneration holds on Windows, Linux, and
macOS.
- Keep sample JSON readable with sorted members, two-space indentation,
and LF line endings. Normalize generated filenames to single hyphens
without changing registry resource IDs, document values, logical links,
or dependency ordering; the manifest maps resource IDs to their physical
filenames.

Most changed files are deterministic regenerations of checked-in sample
documents. The demo manifest contains 533 linked resources; the
aggregation server remains generic and has no Pump-specific compiled
model dependency.

No new alarm vocabulary, shelving/suppression/dialog/ConditionRefresh
transport mapping, Azure SDK changes, or complete Pump/OpenUSD parity is
introduced.

## Related Issues

Fixes #4430, which records the approved implementation scope, design
decisions, and acceptance criteria.

Follow-up to #4411. Specification fixtures are pinned to
[OPCF-Members/spec-drafts commit
82620d9](https://github.com/OPCF-Members/spec-drafts/commit/82620d9e313f35386dfc7477f7875cd47d2fd268),
associated with OPCF-Members/spec-drafts#35.

## Validation

- .NET 10 and .NET 8: complete affected converter/schema, WoT
Connectivity, and binding suites passed.
- .NET Framework 4.8: affected libraries, converter/generator, projected
runtime, readiness, and NodeSet-import compatibility runs passed. The
existing filesystem test exceeding the host's legacy path limit passed
through a temporary short-path alias, without changing its assertions.
- All 29 aggregation sample tests passed, including the independent
companion-model oracle.
- Managed/default-port and NativeAOT/alternate-port demo runs completed
with 533 documents, two pumps, thirty Good readings, and all four
pump/source control and alarm workflows.
- Timeout and duplicate-port failure paths were exercised; owned
processes and ports were released.
- Specification artifact/rule checks, byte-identical example mirroring,
statement-digest verification, and changed-file whitespace checks
passed.
- The [Build and Test .NET 10.0 workflow for
278b092](https://github.com/OPCFoundation/UA-.NETStandard/actions/runs/34095520510)
passed, including the previously failing Linux/macOS Types and WoT
Connectivity jobs. Portability fixes preserve the existing assertions
and add an explicit LF-output regression.
- After the readability changes in `dc61d032`, all 131 targeted
sample/projected-runtime cases passed on both .NET 10 and .NET Framework
4.8, and all 29 aggregation sample tests passed after rebuilding. All
539 JSON assets meet the formatting and filename rules; the 538 document
JSON values are unchanged, with only physical paths changing in the
manifest. Byte-exact regeneration assertions remain in place.

Local validation was scoped to affected projects rather than the entire
UA.slnx solution. Numeric coverage percentages and remaining CI gates
remain for CI; coverage thresholds were not changed. Existing unrelated
analyzer warnings were left unchanged.

## Checklist

- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [x] I have addressed **all** PR feedback received.

Regression and integration tests are included and passed as described
above; the combined tests/coverage checkbox remains open because numeric
coverage was not measured locally.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a9f41b1-72f0-4c74-bd7f-26fa531e5738
2026-09-07 12:24:14 +00:00

114 lines
5.5 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System.Text;
using System.Text.Json;
using NUnit.Framework;
using AggregationClient;
namespace Opc.Ua.WotCon.Samples.Tests
{
[TestFixture]
public sealed class AggregationClientDocumentTests
{
[Test]
public void SubstitutionTargetsOnlyRootAndAffordanceForms()
{
const string input =
"""
{
"forms": [{ "href": "${SOURCE_A_ENDPOINT}" }],
"properties": {
"value": {
"forms": [{ "href": "${SOURCE_A_ENDPOINT}" }],
"default": { "href": "${SOURCE_B_ENDPOINT}" }
}
},
"actions": { "start": { "forms": [{ "href": "${SOURCE_B_ENDPOINT}" }] } },
"events": { "alarm": { "forms": [{ "href": "${SOURCE_A_ENDPOINT}" }] } },
"links": [{ "href": "${SOURCE_A_ENDPOINT}" }],
"x-vendor": { "href": "${SOURCE_B_ENDPOINT}" }
}
""";
var options = new AggregationClientOptions();
byte[] output = AggregationClientRunner.SubstituteEndpoints(input, options);
using JsonDocument document = JsonDocument.Parse(output);
JsonElement root = document.RootElement;
Assert.That(root.GetProperty("forms")[0].GetProperty("href").GetString(),
Is.EqualTo(options.SourceAEndpoint));
Assert.That(root.GetProperty("properties").GetProperty("value")
.GetProperty("forms")[0].GetProperty("href").GetString(), Is.EqualTo(options.SourceAEndpoint));
Assert.That(root.GetProperty("actions").GetProperty("start")
.GetProperty("forms")[0].GetProperty("href").GetString(), Is.EqualTo(options.SourceBEndpoint));
Assert.That(root.GetProperty("events").GetProperty("alarm")
.GetProperty("forms")[0].GetProperty("href").GetString(), Is.EqualTo(options.SourceAEndpoint));
Assert.That(root.GetProperty("properties").GetProperty("value")
.GetProperty("default").GetProperty("href").GetString(), Is.EqualTo("${SOURCE_B_ENDPOINT}"));
Assert.That(root.GetProperty("links")[0].GetProperty("href").GetString(),
Is.EqualTo("${SOURCE_A_ENDPOINT}"));
Assert.That(root.GetProperty("x-vendor").GetProperty("href").GetString(),
Is.EqualTo("${SOURCE_B_ENDPOINT}"));
}
[TestCase("uav:nodes")]
[TestCase("uav:nodeSet")]
[TestCase("uav:metadata")]
[TestCase("uav:propertyConfiguration")]
[TestCase("uav:actionConfiguration")]
[TestCase("uav:eventConfiguration")]
[TestCase("x-vendor")]
public void SubstitutionDoesNotInterpretFormsInOpaqueContent(string name)
{
string input = $$"""
{
"forms": [{ "href": "${SOURCE_A_ENDPOINT}" }],
"{{name}}": { "forms": [{ "href": "${SOURCE_B_ENDPOINT}" }] }
}
""";
var options = new AggregationClientOptions();
byte[] output = AggregationClientRunner.SubstituteEndpoints(input, options);
using JsonDocument document = JsonDocument.Parse(output);
Assert.That(document.RootElement.GetProperty("forms")[0].GetProperty("href").GetString(),
Is.EqualTo(options.SourceAEndpoint));
Assert.That(document.RootElement.GetProperty(name)
.GetProperty("forms")[0].GetProperty("href").GetString(), Is.EqualTo("${SOURCE_B_ENDPOINT}"));
}
[TestCase("{ \"x-vendor\": { \"href\": \"${SOURCE_A_ENDPOINT}\" } }\r\n")]
[TestCase("{ \"forms\": [{ \"href\": \"${SOURCE_A_ENDPOINT}/suffix\" }] }\r\n")]
[TestCase("{ \"title\": \"No placeholders\", \"value\": 1.00 }\r\n")]
public void DocumentsWithoutSubstitutableFormsKeepTheirOriginalBytes(string input)
{
byte[] output = AggregationClientRunner.SubstituteEndpoints(input, new AggregationClientOptions());
Assert.That(output, Is.EqualTo(Encoding.UTF8.GetBytes(input)));
}
}
}