# SPDX-FileCopyrightText: 2026 Contributors to the Eclipse Foundation
# SPDX-License-Identifier: Apache-2.0
#
# E2E test spec. Rendered to docs/specs/sldt-digital-twin-registry.md by
# specs/build_specs.py. Edit this file, not the page.

$schema: ./spec.schema.json
product: sldt-digital-twin-registry
specVersion: "1.0"
status: proven
statusNote: >
  The worked example is built from tests 1 to 3 of this spec and passes in GitHub
  Actions. Test 4 is new and has not been run yet.

inOneSentence: >
  A partner finds a twin by its part number and reads it through the owner's
  connector, and a twin that does not exist is not found.

whatItDoes: >
  A company lists its parts in the registry as "digital twins": one shell descriptor
  per part, with the part numbers it is known by and a pointer to where its data is.
  A partner who knows a part number asks the registry, through the owner's connector,
  which twin belongs to it. Without the registry, a partner cannot find any data.

journey:
  yourSide: The owner's connector and its Digital Twin Registry
  partnerSide: The partner's connector, where the tests run from
  moves:
    - The owner offers its registry in its connector, under an access and a usage policy.
    - The owner registers a twin with a part number the partner may see.
    - The partner negotiates access to the registry and gets a token.
    - The partner looks the part number up and gets the twin's id.
    - The partner reads the twin. Its answer matches the AAS shell descriptor schema.
    - The owner removes the twin and the offer again.

tck:
  id: digital-twin-registry-e2e
  folder: tck/e2e
  standards:
    - id: CX-0002
      version: v2.3.0
  infrastructure:
    engine: [connector]
    sut: [connector, dtr]
  runsInWorkshop: true
  workflow:
    runInToolbox: true
  variables:
    - id: engine_bpnl
      kind: input
      scope: engine
      what: BPN of the partner. The twin is made visible to this BPN.
      example: BPNL000000000002
      inWorkflow: Filled from engine_bpnl.
    - id: sut_bpnl
      kind: input
      scope: sut
      what: BPN of the owner. Only test 4 needs it, for a part number the partner may not see.
      example: BPNL000000000001
      inWorkflow: Filled from sut_bpnl.
    - id: dtr_internal_url
      kind: input
      scope: sut
      what: The registry API as the owner's connector reaches it. It is the asset's base URL.
      example: http://provider-dtr.umbrella.svc.cluster.local:8080/api/v3
      inWorkflow: Filled from dtr_internal_url.
    - id: access_policy
      kind: policy
      what: "Who may see the registry offer: active members."
    - id: usage_policy
      kind: policy
      what: >
        What the registry may be used for: active membership, the framework agreement
        DataExchangeGovernance:1.0 and the usage purpose cx.core.digitalTwinRegistry:1.
  schemas:
    - id: shell_descriptor
      file: shell_descriptor.json
      what: The AAS shell descriptor. Every answer that returns a twin is held to it.
      copyFrom: examples/digital-twin-registry/tck/e2e/schemas/shell_descriptor.json

tests:
  - file: register_and_read.yaml
    id: register-and-read
    name: A registered twin can be read back and matches the AAS schema
    kinds: [positive, contract]
    proves: The owner's registry stores a twin as it was given and returns it in the shape the standard prescribes.
    execution:
      - do: Mint a twin id that is new in every run.
        step: util/generate_uuid
      - do: Register a twin with that id, one manufacturerPartId and one submodel descriptor.
        step: digital-twin-registry/provider/create_shell_descriptor
        check:
          - The id returned is the id that was sent.
          - The answer matches the shell_descriptor schema.
      - do: Read the twin back as the owner.
        step: digital-twin-registry/provider/get_shell_descriptor
        check:
          - id and idShort are the ones that were sent.
          - The manufacturerPartId has the value that was sent.
          - The answer matches the shell_descriptor schema.
    teardown:
      - do: Delete the twin.
        step: digital-twin-registry/provider/delete_shell_descriptor
        check:
          - The registry answers 204.

  - file: partner_reads_through_connector.yaml
    id: partner-reads-through-connector
    name: A partner finds and reads the twin through the owner's connector
    kinds: [journey, positive, contract]
    proves: A partner who knows nothing but a part number reaches the right twin through the dataspace.
    setup:
      - do: Create the access policy.
        step: connector/provider/create_policy
      - do: Create the usage policy.
        step: connector/provider/create_policy
      - do: Offer the registry as an asset of type https://w3id.org/catenax/taxonomy#DigitalTwinRegistry, with base URL dtr_internal_url.
        step: connector/provider/create_asset
      - do: Publish the offer under both policies.
        step: connector/provider/create_contract_definition
      - do: Register a twin whose customerPartId is visible to the partner's BPN and whose manufacturerPartId is PUBLIC_READABLE.
        step: digital-twin-registry/provider/wizard/create_shell_descriptor
      - do: Attach a submodel descriptor that points at the owner's connector.
        step: digital-twin-registry/provider/create_submodel_descriptor
    execution:
      - do: As the partner, negotiate access to the registry.
        step: connector/discover/digital-twin-registry/auth
        check:
          - A data plane URL is returned.
          - An EDR token is returned.
      - do: Look the twin up by its manufacturerPartId.
        step: digital-twin-registry/consumer/dataplane/lookup_shell
        check:
          - The list of shell ids contains the twin registered in setup.
      - do: Read the twin through the data plane.
        step: digital-twin-registry/consumer/dataplane/get_shell_descriptor
        check:
          - The id is the twin registered in setup.
          - The answer matches the shell_descriptor schema.
    teardown:
      - do: Delete the twin.
        step: digital-twin-registry/provider/delete_shell_descriptor
      - do: Delete the contract definition.
        step: connector/provider/delete_contract_definition
      - do: Delete the asset.
        step: connector/provider/delete_asset
      - do: Delete the usage policy.
        step: connector/provider/delete_policy
      - do: Delete the access policy.
        step: connector/provider/delete_policy

  - file: unknown_twin_is_not_found.yaml
    id: unknown-twin-is-not-found
    name: A twin that does not exist is answered with 404
    kinds: [negative]
    proves: The registry does not invent data for an id it has never held.
    execution:
      - do: Ask the registry for a twin id it has never held, base64url-encoded in the path as the AAS API expects.
        step: connector/dataplane/http_request
        check:
          - The registry answers 404.

  - file: hidden_twin_stays_hidden.yaml
    id: hidden-twin-stays-hidden
    name: A twin the partner may not see is not in its lookup
    kinds: [negative]
    optional: true
    proves: The registry only shows a partner the part numbers that were shared with its BPN.
    setup:
      - do: Create both policies, the asset and the contract definition, as in test 2.
        step: connector/provider/create_policy
      - do: Register a twin whose only part number is visible to the owner's own BPN, not to the partner.
        step: digital-twin-registry/provider/wizard/create_shell_descriptor
    execution:
      - do: As the partner, negotiate access to the registry.
        step: connector/discover/digital-twin-registry/auth
      - do: Look the hidden twin up by its part number.
        step: digital-twin-registry/consumer/dataplane/lookup_shell
        check:
          - The list of shell ids does not contain the hidden twin.
    teardown:
      - do: Delete the twin, the offer and both policies, in that order.
        step: digital-twin-registry/provider/delete_shell_descriptor

breakItOnPurpose:
  - test: register_and_read.yaml
    change: Expect idShort "e2eTwinX" instead of "e2eTwin".
    expect: The read-back check fails and names idShort.
  - test: partner_reads_through_connector.yaml
    change: Remove the submodel descriptor from setup.
    expect: The schema check on the partner's read fails. This is the red run of the worked example.
  - test: unknown_twin_is_not_found.yaml
    change: Expect 200 instead of 404.
    expect: The check fails with the real answer, 404.

notInScope:
  - Submodel data itself. The registry only points at it; reading it is a test for the submodel server.
  - Paging through many twins.

pitfalls:
  - A twin without a submodel descriptor fails the schema check. That is correct, not a bug in the test.
  - Use a new twin id in every run (util/generate_uuid), or the second run fails with a conflict.
  - The not-found test needs the id base64url-encoded in the path, without padding.

sources:
  - label: The worked example
    url: https://eclipse-tractusx.github.io/tutorial-resources/e2e-testing/reference/worked-example/
  - label: Digital Twin Registry repository
    url: https://github.com/eclipse-tractusx/sldt-digital-twin-registry
