From 830b9649aacec031ff7910d65cda69c51f3ac492 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sun, 19 May 2024 19:52:34 +0200 Subject: [PATCH] feat!: rework Servient API --- example/coap_discovery.dart | 4 +- example/coap_dns_sd_discovery.dart | 4 +- example/coaps_readproperty.dart | 2 +- example/complex_example.dart | 2 +- example/core_link_format_discovery.dart | 4 +- example/directory_discovery.dart | 2 +- example/example.dart | 2 +- example/http_basic_authentication.dart | 2 +- example/mqtt_example.dart | 2 +- lib/src/core/implementation.dart | 2 +- .../core/implementation/consumed_thing.dart | 4 +- lib/src/core/implementation/servient.dart | 215 ++++++++++++++++-- .../core/implementation/thing_discovery.dart | 4 +- lib/src/core/implementation/wot.dart | 112 ++------- test/binding_http/http_test.dart | 3 +- test/core/consumed_thing_test.dart | 4 +- test/core/dart_wot_test.dart | 2 +- test/core/discovery_test.dart | 18 +- test/core/servient_test.dart | 7 +- test/core/wot_test.dart | 5 +- 20 files changed, 245 insertions(+), 155 deletions(-) diff --git a/example/coap_discovery.dart b/example/coap_discovery.dart index fe84a61d..c72c7e72 100644 --- a/example/coap_discovery.dart +++ b/example/coap_discovery.dart @@ -37,9 +37,9 @@ Future handleThingDescription( } Future main(List args) async { - final servient = Servient( + final servient = Servient.create( clientFactories: [CoapClientFactory()], - discoveryConfiguration: [ + discoveryConfigurations: [ DirectConfiguration( Uri.parse("coap://plugfest.thingweb.io:5683/testthing"), ), diff --git a/example/coap_dns_sd_discovery.dart b/example/coap_dns_sd_discovery.dart index 53a4f0b9..ab365e98 100644 --- a/example/coap_dns_sd_discovery.dart +++ b/example/coap_dns_sd_discovery.dart @@ -14,12 +14,12 @@ void handleThingDescription(ThingDescription thingDescription) => print('Discovered TD with title "${thingDescription.title}".'); Future main(List args) async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ CoapClientFactory(), HttpClientFactory(), ], - discoveryConfiguration: [ + discoveryConfigurations: [ DnsSdDConfiguration(protocolType: ProtocolType.udp), ], ); diff --git a/example/coaps_readproperty.dart b/example/coaps_readproperty.dart index 807fb816..cda980ae 100644 --- a/example/coaps_readproperty.dart +++ b/example/coaps_readproperty.dart @@ -37,7 +37,7 @@ Future main(List args) async { pskCredentialsCallback: _pskCredentialsCallback, ); - final servient = Servient( + final servient = Servient.create( clientFactories: [ coapClientFactory, ], diff --git a/example/complex_example.dart b/example/complex_example.dart index ad9eb06f..22f08e81 100644 --- a/example/complex_example.dart +++ b/example/complex_example.dart @@ -98,7 +98,7 @@ Future main() async { final httpClientFactory = HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback); - final servient = Servient( + final servient = Servient.create( clientFactories: [ coapClientFactory, httpClientFactory, diff --git a/example/core_link_format_discovery.dart b/example/core_link_format_discovery.dart index 9a08e242..93a6bc43 100644 --- a/example/core_link_format_discovery.dart +++ b/example/core_link_format_discovery.dart @@ -10,9 +10,9 @@ import "package:dart_wot/binding_coap.dart"; import "package:dart_wot/core.dart"; Future main(List args) async { - final servient = Servient( + final servient = Servient.create( clientFactories: [CoapClientFactory()], - discoveryConfiguration: [ + discoveryConfigurations: [ CoreLinkFormatConfiguration( Uri.parse("coap://plugfest.thingweb.io"), ), diff --git a/example/directory_discovery.dart b/example/directory_discovery.dart index 0ae35aa0..a8e59b17 100644 --- a/example/directory_discovery.dart +++ b/example/directory_discovery.dart @@ -10,7 +10,7 @@ import "package:dart_wot/binding_http.dart"; import "package:dart_wot/core.dart"; Future main(List args) async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ HttpClientFactory(), ], diff --git a/example/example.dart b/example/example.dart index edf73ef8..3aabbf3e 100644 --- a/example/example.dart +++ b/example/example.dart @@ -11,7 +11,7 @@ import "package:dart_wot/binding_http.dart"; import "package:dart_wot/core.dart"; Future main(List args) async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ CoapClientFactory(), HttpClientFactory(), diff --git a/example/http_basic_authentication.dart b/example/http_basic_authentication.dart index 3731f0f8..6e722659 100644 --- a/example/http_basic_authentication.dart +++ b/example/http_basic_authentication.dart @@ -61,7 +61,7 @@ Future main(List args) async { final httpClientFactory = HttpClientFactory( basicCredentialsCallback: basicCredentialsCallback, ); - final servient = Servient( + final servient = Servient.create( clientFactories: [ httpClientFactory, ], diff --git a/example/mqtt_example.dart b/example/mqtt_example.dart index 238335ac..2c72c272 100644 --- a/example/mqtt_example.dart +++ b/example/mqtt_example.dart @@ -60,7 +60,7 @@ Future basicCredentialsCallback( } Future main(List args) async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ MqttClientFactory(basicCredentialsCallback: basicCredentialsCallback), ], diff --git a/lib/src/core/implementation.dart b/lib/src/core/implementation.dart index 6f72c841..8c066481 100644 --- a/lib/src/core/implementation.dart +++ b/lib/src/core/implementation.dart @@ -15,4 +15,4 @@ export "implementation/discovery/discovery_configuration.dart"; export "implementation/protocol_interfaces/protocol_client.dart"; export "implementation/protocol_interfaces/protocol_client_factory.dart"; export "implementation/protocol_interfaces/protocol_server.dart"; -export "implementation/servient.dart"; +export "implementation/servient.dart" show Servient; diff --git a/lib/src/core/implementation/consumed_thing.dart b/lib/src/core/implementation/consumed_thing.dart index bf4fda7c..ed45e513 100644 --- a/lib/src/core/implementation/consumed_thing.dart +++ b/lib/src/core/implementation/consumed_thing.dart @@ -20,7 +20,7 @@ class ConsumedThing implements scripting_api.ConsumedThing { : title = thingDescription.title; /// The [Servient] corresponding with this [ConsumedThing]. - final Servient servient; + final InternalServient servient; @override final ThingDescription thingDescription; @@ -428,7 +428,7 @@ class ConsumedThing implements scripting_api.ConsumedThing { _subscribedEvents.clear(); if (external) { - return servient.deregisterConsumedthing(this); + return servient.deregisterConsumedThing(this); } return false; diff --git a/lib/src/core/implementation/servient.dart b/lib/src/core/implementation/servient.dart index 20a80b2a..0b7fc7a8 100644 --- a/lib/src/core/implementation/servient.dart +++ b/lib/src/core/implementation/servient.dart @@ -5,8 +5,10 @@ // SPDX-License-Identifier: BSD-3-Clause import "package:meta/meta.dart"; +import "package:uuid/uuid.dart"; import "../definitions.dart"; +import "../definitions/context.dart"; import "../exceptions.dart"; import "../scripting_api.dart" as scripting_api; import "consumed_thing.dart"; @@ -16,32 +18,77 @@ import "exposed_thing.dart"; import "protocol_interfaces/protocol_client.dart"; import "protocol_interfaces/protocol_client_factory.dart"; import "protocol_interfaces/protocol_server.dart"; +import "thing_discovery.dart"; import "wot.dart"; -// TODO(JKRhb): Documentation should be improved. /// A software stack that implements the WoT building blocks. /// /// A [Servient] can host and expose Things and/or host Consumers that consume /// Things. Servients can support multiple Protocol Bindings to enable /// interaction with different IoT platforms. -class Servient { +abstract class Servient { /// Creates a new [Servient]. /// - /// The [Servient] can be preconfigured with a [List] of - /// [ProtocolClientFactory]s. + /// The [Servient] can be pre-configured with [List]s of + /// [clientFactories] and [discoveryConfigurations]. /// However, it is also possible to dynamically [addClientFactory]s and /// [removeClientFactory]s at runtime. /// /// If you want to support a custom media type not already included in the /// [ContentSerdes] class, a custom [contentSerdes] object can be passed as an /// argument. - Servient({ + factory Servient.create({ List? clientFactories, ServerSecurityCallback? serverSecurityCallback, ContentSerdes? contentSerdes, - List? discoveryConfiguration, + List? discoveryConfigurations, + }) { + return InternalServient( + clientFactories: clientFactories, + serverSecurityCallback: serverSecurityCallback, + contentSerdes: contentSerdes, + discoveryConfigurations: discoveryConfigurations, + ); + } + + /// [List] of [DiscoveryConfiguration]s that are used when calling the + /// [scripting_api.WoT.discover] method. + List get discoveryConfigurations; + + set discoveryConfigurations( + List discoveryConfigurations, + ); + + /// Starts this [Servient] and returns a [WoT] runtime object. + /// + /// The [scripting_api.WoT] runtime can be used for consuming, producing, and + /// discovering Things. + Future start(); + + /// Adds a new [clientFactory] to this [Servient]. + void addClientFactory(ProtocolClientFactory clientFactory); + + /// Removes a [ProtocolClientFactory] matching the given [scheme] from this + /// [Servient], if present. + /// + /// If a [ProtocolClientFactory] was removed, the method returns it, otherwise + /// the return value is `null`. + ProtocolClientFactory? removeClientFactory(String scheme); + + /// Closes this [Servient] and cleans up all resources. + Future shutdown(); +} + +/// Provides the internal implementation details of the [Servient] class. +class InternalServient implements Servient { + /// Creates a new [InternalServient]. + InternalServient({ + List? clientFactories, + ServerSecurityCallback? serverSecurityCallback, + ContentSerdes? contentSerdes, + List? discoveryConfigurations, }) : contentSerdes = contentSerdes ?? ContentSerdes(), - discoveryConfiguration = discoveryConfiguration ?? [], + discoveryConfigurations = discoveryConfigurations ?? [], _serverSecurityCallback = serverSecurityCallback { for (final clientFactory in clientFactories ?? []) { addClientFactory(clientFactory); @@ -55,18 +102,14 @@ class Servient { final ServerSecurityCallback? _serverSecurityCallback; - /// [List] of [DiscoveryConfiguration]s that are used when calling the - /// [scripting_api.WoT.discover] method. - List discoveryConfiguration; + @override + List discoveryConfigurations; /// The [ContentSerdes] object that is used for serializing/deserializing. final ContentSerdes contentSerdes; - /// Starts this [Servient] and returns a [WoT] runtime object. - /// - /// The [scripting_api.WoT] runtime can be used for consuming, producing, and - /// discovering Things. - Future start() async { + @override + Future start() async { final serverStatuses = _servers .map((server) => server.start(_serverSecurityCallback)) .toList(growable: false); @@ -79,7 +122,7 @@ class Servient { return WoT(this); } - /// Closes the client. + @override Future shutdown() async { for (final clientFactory in _clientFactories.values) { clientFactory.destroy(); @@ -143,11 +186,11 @@ class Servient { return consumedThing.destroy(external: false); } - /// Deregisters the given [consumedThing]. + /// De-registers the given [consumedThing]. /// /// If the [ConsumedThing] has not been registered before, `false` is /// returned, otherwise `true`. - bool deregisterConsumedthing(ConsumedThing consumedThing) { + bool deregisterConsumedThing(ConsumedThing consumedThing) { return _consumedThings.remove(consumedThing); } @@ -181,18 +224,14 @@ class Servient { List get clientSchemes => _clientFactories.keys.toList(growable: false); - /// Adds a new [clientFactory] to this [Servient]. + @override void addClientFactory(ProtocolClientFactory clientFactory) { for (final scheme in clientFactory.schemes) { _clientFactories[scheme] = clientFactory; } } - /// Removes a [ProtocolClientFactory] matching the given [scheme] from this - /// [Servient], if present. - /// - /// If a [ProtocolClientFactory] was removed, the method returns it, otherwise - /// the return value is `null`. + @override ProtocolClientFactory? removeClientFactory(String scheme) => _clientFactories.remove(scheme); @@ -229,6 +268,49 @@ class Servient { return protocolClient.supportsOperation(operationType, subprotocol); } + /// Consumes a [ThingDescription] and returns a [scripting_api.ConsumedThing]. + Future consume( + ThingDescription thingDescription, + ) async { + final newThing = ConsumedThing(this, thingDescription); + addConsumedThing(newThing); + + return newThing; + } + + /// Exposes a Thing based on an [scripting_api.ExposedThingInit]. + Future produce( + scripting_api.ExposedThingInit init, + ) async { + const uuid = Uuid(); + + final exposedThingInit = { + "id": "urn:uuid:${uuid.v4()}", + ...init, + }; + + final newThing = ExposedThing(this, exposedThingInit); + if (addThing(newThing)) { + return newThing; + } else { + final id = newThing.thingDescription.identifier; + throw DartWotException( + "A ConsumedThing with identifier $id already exists.", + ); + } + } + + /// Perform automatic discovery using this [InternalServient]'s + /// [discoveryConfigurations]. + /// + /// A [thingFilter] can be provided to filter the discovered Thing + /// Descriptions; however, doing so currently does not have any effect yet. + ThingDiscovery discover({ + scripting_api.ThingFilter? thingFilter, + }) { + return ThingDiscovery(thingFilter, this); + } + /// Requests a [ThingDescription] from a [url]. Future requestThingDescription(Uri url) async { final client = clientFor(url.scheme); @@ -245,4 +327,89 @@ class Servient { return ThingDescription.fromJson(dataSchemaValue.value); } + + /// Retrieves [ThingDescription] from a Thing Description Directory (TDD). + /// + /// This method expects the TDD's Thing Description to be located under the + /// provided [url] (e.g., https://example.org/.well-known/wot). + /// Optionally, a [thingFilter] can be provided that is supposed to be used + /// as part of the query issues to the TDD; however, providing the filter + /// has no effect at the moment. + /// + /// Corresponding with the [API] specified in the + /// [WoT Discovery Recommendation], it possible to specify an [offset] and + /// a limit for the Thing Descriptions that are supposed to be returned from + /// the TDD. + /// The [format] is also configurable, however, only + /// [scripting_api.DirectoryPayloadFormat.array] is supported at the moment. + /// + /// [API]: https://www.w3.org/TR/wot-discovery/#exploration-directory-api + /// [WoT Discovery Recommendation]: https://www.w3.org/TR/wot-discovery + Future exploreDirectory( + Uri url, { + scripting_api.ThingFilter? thingFilter, + int? offset, + int? limit, + scripting_api.DirectoryPayloadFormat? format, + }) async { + // TODO(JKRhb): Add support for the collection format. + if (format == scripting_api.DirectoryPayloadFormat.collection) { + throw ArgumentError('Format "$format" is currently not supported.'); + } + + final thingDescription = await requestThingDescription(url); + + if (!thingDescription.isValidDirectoryThingDescription) { + throw const DiscoveryException( + "Encountered an invalid Directory Thing Description", + ); + } + + final consumedDirectoryThing = await consume(thingDescription); + + final interactionOutput = await consumedDirectoryThing.readProperty( + "things", + uriVariables: { + if (offset != null) "offset": offset, + if (limit != null) "limit": limit, + if (format != null) "format": format.toString(), + }, + ); + final rawThingDescriptions = await interactionOutput.value(); + + if (rawThingDescriptions is! List) { + throw const DiscoveryException( + "Expected an array of Thing Descriptions but received an " + "invalid output instead.", + ); + } + + final thingDescriptionStream = Stream.fromIterable( + rawThingDescriptions.whereType>(), + ).map((rawThingDescription) => rawThingDescription.toThingDescription()); + + return ThingDiscoveryProcess(thingDescriptionStream, thingFilter); + } +} + +extension _DirectoryValidationExtension on ThingDescription { + bool get isValidDirectoryThingDescription { + final atTypes = atType; + + if (atTypes == null) { + return false; + } + + const discoveryContextUri = "https://www.w3.org/2022/wot/discovery"; + const type = "ThingDirectory"; + const fullIri = "$discoveryContextUri#$type"; + + if (atTypes.contains(fullIri)) { + return true; + } + + return context.contextEntries + .contains(SingleContextEntry.fromString(discoveryContextUri)) && + atTypes.contains(type); + } } diff --git a/lib/src/core/implementation/thing_discovery.dart b/lib/src/core/implementation/thing_discovery.dart index 9cae9f9c..805be98b 100644 --- a/lib/src/core/implementation/thing_discovery.dart +++ b/lib/src/core/implementation/thing_discovery.dart @@ -26,7 +26,7 @@ class ThingDiscovery extends Stream _stream = _start(); } - final Servient _servient; + final InternalServient _servient; final Map _clients = {}; @@ -43,7 +43,7 @@ class ThingDiscovery extends Stream late final Stream _stream; Stream _start() async* { - for (final discoveryParameter in _servient.discoveryConfiguration) { + for (final discoveryParameter in _servient.discoveryConfigurations) { switch (discoveryParameter) { case DnsSdDConfiguration( :final discoveryType, diff --git a/lib/src/core/implementation/wot.dart b/lib/src/core/implementation/wot.dart index 35a0da0a..f906810d 100644 --- a/lib/src/core/implementation/wot.dart +++ b/lib/src/core/implementation/wot.dart @@ -6,14 +6,9 @@ import "dart:async"; -import "package:uuid/uuid.dart"; - import "../definitions.dart"; -import "../definitions/context.dart"; -import "../exceptions.dart"; import "../scripting_api.dart" as scripting_api; import "consumed_thing.dart"; -import "exposed_thing.dart"; import "servient.dart"; import "thing_discovery.dart"; @@ -22,7 +17,7 @@ class WoT implements scripting_api.WoT { /// Creates a new [WoT] runtime based on a [Servient]. WoT(this._servient); - final Servient _servient; + final InternalServient _servient; /// Consumes a [ThingDescription] and returns a [scripting_api.ConsumedThing]. /// @@ -33,47 +28,25 @@ class WoT implements scripting_api.WoT { @override Future consume( ThingDescription thingDescription, - ) async { - final newThing = ConsumedThing(_servient, thingDescription); - _servient.addConsumedThing(newThing); - - return newThing; - } + ) => + _servient.consume(thingDescription); /// Exposes a Thing based on a (partial) TD. @override Future produce( Map init, - ) async { - const uuid = Uuid(); - - final exposedThingInit = { - "id": "urn:uuid:${uuid.v4()}", - ...init, - }; - - final newThing = ExposedThing(_servient, exposedThingInit); - if (_servient.addThing(newThing)) { - return newThing; - } else { - final id = newThing.thingDescription.identifier; - throw DartWotException( - "A ConsumedThing with identifier $id already exists.", - ); - } - } + ) => + _servient.produce(init); @override ThingDiscovery discover({ scripting_api.ThingFilter? thingFilter, - }) { - return ThingDiscovery(thingFilter, _servient); - } + }) => + _servient.discover(thingFilter: thingFilter); @override - Future requestThingDescription(Uri url) { - return _servient.requestThingDescription(url); - } + Future requestThingDescription(Uri url) => + _servient.requestThingDescription(url); @override Future exploreDirectory( @@ -82,65 +55,12 @@ class WoT implements scripting_api.WoT { int? offset, int? limit, scripting_api.DirectoryPayloadFormat? format, - }) async { - // TODO(JKRhb): Add support for the collection format. - if (format == scripting_api.DirectoryPayloadFormat.collection) { - throw ArgumentError('Format "$format" is currently not supported.'); - } - - final thingDescription = await requestThingDescription(url); - - if (!thingDescription.isValidDirectoryThingDescription) { - throw const DiscoveryException( - "Encountered an invalid Directory Thing Description", + }) => + _servient.exploreDirectory( + url, + thingFilter: filter, + offset: offset, + limit: limit, + format: format, ); - } - - final consumedDirectoryThing = await consume(thingDescription); - - final interactionOutput = await consumedDirectoryThing.readProperty( - "things", - uriVariables: { - if (offset != null) "offset": offset, - if (limit != null) "limit": limit, - if (format != null) "format": format.toString(), - }, - ); - final rawThingDescriptions = await interactionOutput.value(); - - if (rawThingDescriptions is! List) { - throw const DiscoveryException( - "Expected an array of Thing Descriptions but received an " - "invalid output instead.", - ); - } - - final thingDescriptionStream = Stream.fromIterable( - rawThingDescriptions.whereType>(), - ).map((rawThingDescription) => rawThingDescription.toThingDescription()); - - return ThingDiscoveryProcess(thingDescriptionStream, filter); - } -} - -extension _DirectoryValidationExtension on ThingDescription { - bool get isValidDirectoryThingDescription { - final atTypes = atType; - - if (atTypes == null) { - return false; - } - - const discoveryContextUri = "https://www.w3.org/2022/wot/discovery"; - const type = "ThingDirectory"; - const fullIri = "$discoveryContextUri#$type"; - - if (atTypes.contains(fullIri)) { - return true; - } - - return context.contextEntries - .contains(SingleContextEntry.fromString(discoveryContextUri)) && - atTypes.contains(type); - } } diff --git a/test/binding_http/http_test.dart b/test/binding_http/http_test.dart index 85bb05d6..997ed1c9 100644 --- a/test/binding_http/http_test.dart +++ b/test/binding_http/http_test.dart @@ -6,6 +6,7 @@ import "package:dart_wot/binding_http.dart"; import "package:dart_wot/core.dart"; +import "package:dart_wot/src/core/implementation/servient.dart"; import "package:mockito/annotations.dart"; import "package:test/test.dart"; import "http_test.mocks.dart"; @@ -116,7 +117,7 @@ void main() { ]) async => bearerCredentialsStore[uri.host]; - final servient = Servient( + final servient = InternalServient( clientFactories: [ HttpClientFactory( basicCredentialsCallback: basicCredentialsCallback, diff --git a/test/core/consumed_thing_test.dart b/test/core/consumed_thing_test.dart index 075f7412..5e00de3d 100644 --- a/test/core/consumed_thing_test.dart +++ b/test/core/consumed_thing_test.dart @@ -238,7 +238,7 @@ void main() { final parsedTd = ThingDescription.fromJson(thingDescriptionJson); - final servient = Servient(clientFactories: [HttpClientFactory()]); + final servient = Servient.create(clientFactories: [HttpClientFactory()]); final wot = await servient.start(); final uriVariables = {"value": "SFRUUEJJTiBpcyBhd2Vzb21l"}; @@ -278,7 +278,7 @@ void main() { final parsedTd = ThingDescription.fromJson(thingDescriptionJson); - final servient = Servient(); + final servient = Servient.create(); final wot = await servient.start(); final consumedThing = await wot.consume(parsedTd); diff --git a/test/core/dart_wot_test.dart b/test/core/dart_wot_test.dart index aa8bfa81..dfaedd0d 100644 --- a/test/core/dart_wot_test.dart +++ b/test/core/dart_wot_test.dart @@ -18,7 +18,7 @@ void main() { test( "Parse incomplete Thing Description", () async { - final servient = Servient(); + final servient = Servient.create(); final wot = await servient.start(); final Map exposedThingInit = { "@context": "https://www.w3.org/2022/wot/td/v1.1", diff --git a/test/core/discovery_test.dart b/test/core/discovery_test.dart index ba7e851f..56918c71 100644 --- a/test/core/discovery_test.dart +++ b/test/core/discovery_test.dart @@ -279,7 +279,7 @@ extension _DiscoveryContentCreationExtension on String { void main() { group("requestThingDescription()", () { test("should be able to retrieve a valid TD", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -295,7 +295,7 @@ void main() { test( "should throw an exception when an invalid TD is retrieved", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -313,7 +313,7 @@ void main() { group("exploreDirectory()", () { test("should be able to discover valid TDs from a TD directory", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -333,7 +333,7 @@ void main() { }); test("should reject invalid TDD Thing Descriptions", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -349,7 +349,7 @@ void main() { test("should be able to handle an array of invalid TDs during discovery", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -382,7 +382,7 @@ void main() { test( "should be able to handle an invalid non-array output during discovery", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -397,7 +397,7 @@ void main() { }); test("should be able to handle premature cancellation", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -416,7 +416,7 @@ void main() { }); test("should support the experimental query parameters API", () async { - final servient = Servient( + final servient = Servient.create( clientFactories: [ _MockedProtocolClientFactory(), ], @@ -442,7 +442,7 @@ void main() { test( 'should currently not support the "collection" format when using the ' "experimental query parameters API", () async { - final servient = Servient(); + final servient = Servient.create(); final wot = await servient.start(); expect( diff --git a/test/core/servient_test.dart b/test/core/servient_test.dart index e0e672f6..9c588b96 100644 --- a/test/core/servient_test.dart +++ b/test/core/servient_test.dart @@ -5,6 +5,7 @@ // SPDX-License-Identifier: BSD-3-Clause import "package:dart_wot/core.dart"; +import "package:dart_wot/src/core/implementation/servient.dart"; import "package:test/test.dart"; const testUriScheme = "test"; @@ -37,7 +38,7 @@ void main() { group("Servient", () { test("should accept a ProtocolClientFactory list as constructor argument", () { - final servient = Servient( + final servient = InternalServient( clientFactories: [ MockedProtocolClientFactory(), ], @@ -49,7 +50,7 @@ void main() { test( "should allow for adding and removing a ProtocolClientFactory at runtime", () { - final servient = Servient() + final servient = InternalServient() ..addClientFactory(MockedProtocolClientFactory()); expect(servient.clientSchemes.contains(testUriScheme), true); @@ -66,7 +67,7 @@ void main() { "should throw a DartWotException when a " "ProtocolClientFactory is not registered", () { - final servient = Servient(); + final servient = InternalServient(); expect( () => servient.clientFor(testUriScheme), diff --git a/test/core/wot_test.dart b/test/core/wot_test.dart index 33eb1621..f8400b43 100644 --- a/test/core/wot_test.dart +++ b/test/core/wot_test.dart @@ -5,6 +5,7 @@ // SPDX-License-Identifier: BSD-3-Clause import "package:dart_wot/core.dart"; +import "package:dart_wot/src/core/implementation/servient.dart"; import "package:test/test.dart"; void main() { @@ -20,7 +21,7 @@ void main() { }; final thingDescription = thingDescriptionJson.toThingDescription(); - final wot = await Servient().start(); + final wot = await InternalServient().start(); final firstConsumedThing = await wot.consume(thingDescription); final secondConsumedThing = await wot.consume(thingDescription); @@ -40,7 +41,7 @@ void main() { "id": "urn:test", }; - final wot = await Servient().start(); + final wot = await InternalServient().start(); await wot.produce(exposedThingInit); final result = wot.produce(exposedThingInit);