diff --git a/example/exposed_thing/http_server.dart b/example/exposed_thing/http_server.dart index 31cec6c6..4f0a6f2f 100644 --- a/example/exposed_thing/http_server.dart +++ b/example/exposed_thing/http_server.dart @@ -3,7 +3,7 @@ import "package:dart_wot/binding_http.dart"; import "package:dart_wot/core.dart"; -var property = "hi :)"; +String property = "hi :)"; void main() async { final servient = diff --git a/lib/src/binding_coap/coap_server.dart b/lib/src/binding_coap/coap_server.dart index ad1d9fc2..2b935817 100644 --- a/lib/src/binding_coap/coap_server.dart +++ b/lib/src/binding_coap/coap_server.dart @@ -26,7 +26,7 @@ final class CoapServer implements ProtocolServer { final int? preferredBlockSize; @override - Future expose(ExposedThing thing) { + Future expose(ExposableThing thing) { // TODO(JKRhb): implement expose throw UnimplementedError(); } diff --git a/lib/src/binding_http/http_server.dart b/lib/src/binding_http/http_server.dart index 846c8322..67ee13e7 100644 --- a/lib/src/binding_http/http_server.dart +++ b/lib/src/binding_http/http_server.dart @@ -14,7 +14,6 @@ import "package:shelf_router/shelf_router.dart"; import "../../core.dart" hide ExposedThing; -import "../core/implementation/exposed_thing.dart"; import "http_config.dart"; const _thingsPath = "things"; @@ -38,7 +37,7 @@ final class HttpServer implements ProtocolServer { io.HttpServer? _server; - final _things = {}; + final _things = {}; late final Servient _servient; @@ -51,7 +50,7 @@ final class HttpServer implements ProtocolServer { } @override - Future expose(ExposedThing thing) async { + Future expose(ExposableThing thing) async { final thingDescription = thing.thingDescription; final key = thingDescription.id; diff --git a/lib/src/core/implementation/exposed_thing.dart b/lib/src/core/implementation/exposed_thing.dart index ce7623f8..ee30150b 100644 --- a/lib/src/core/implementation/exposed_thing.dart +++ b/lib/src/core/implementation/exposed_thing.dart @@ -4,9 +4,8 @@ // // SPDX-License-Identifier: BSD-3-Clause -import "package:meta/meta.dart"; - import "../definitions.dart"; +import "../protocol_interfaces/exposable_thing.dart"; import "../scripting_api.dart" as scripting_api; import "content.dart"; @@ -14,7 +13,7 @@ import "interaction_output.dart"; import "servient.dart"; /// Implementation of the [scripting_api.ExposedThing] interface. -class ExposedThing implements scripting_api.ExposedThing { +class ExposedThing implements scripting_api.ExposedThing, ExposableThing { /// Creates a new [ExposedThing] from a [_servient] and an [exposedThingInit]. ExposedThing(this._servient, scripting_api.ExposedThingInit exposedThingInit) : thingDescription = ThingDescription.fromJson(exposedThingInit); @@ -117,8 +116,7 @@ class ExposedThing implements scripting_api.ExposedThing { // TODO(JKRhb): implement setEventUnsubscribeHandler } - /// Handles a `readproperty` operation triggered by a TD consumer. - @internal + @override Future handleReadProperty( String propertyName, { int? formIndex, @@ -147,8 +145,7 @@ class ExposedThing implements scripting_api.ExposedThing { ); } - /// Handles a `writeproperty` operation triggered by a TD consumer. - @internal + @override Future handleWriteProperty( String propertyName, Content input, { diff --git a/lib/src/core/protocol_interfaces.dart b/lib/src/core/protocol_interfaces.dart index 8866a08b..cac788f4 100644 --- a/lib/src/core/protocol_interfaces.dart +++ b/lib/src/core/protocol_interfaces.dart @@ -4,6 +4,7 @@ // // SPDX-License-Identifier: BSD-3-Clause +export "protocol_interfaces/exposable_thing.dart"; export "protocol_interfaces/protocol_client.dart"; export "protocol_interfaces/protocol_client_factory.dart"; export "protocol_interfaces/protocol_discoverer.dart"; diff --git a/lib/src/core/protocol_interfaces/exposable_thing.dart b/lib/src/core/protocol_interfaces/exposable_thing.dart new file mode 100644 index 00000000..033340d4 --- /dev/null +++ b/lib/src/core/protocol_interfaces/exposable_thing.dart @@ -0,0 +1,32 @@ +// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// +// SPDX-License-Identifier: BSD-3-Clause + +import "../definitions.dart"; +import "../implementation.dart"; + +/// Interface that allows ProtocolServers to interact with ExposedThings. +// TODO: This needs a better name +abstract interface class ExposableThing { + /// The [ThingDescription] that represents this [ExposableThing]. + ThingDescription get thingDescription; + + /// Handles a `readproperty` operation triggered by a TD consumer. + Future handleReadProperty( + String propertyName, { + int? formIndex, + Map? uriVariables, + Object? data, + }); + + /// Handles a `writeproperty` operation triggered by a TD consumer. + Future handleWriteProperty( + String propertyName, + Content input, { + int? formIndex, + Map? uriVariables, + Object? data, + }); +} diff --git a/lib/src/core/protocol_interfaces/protocol_server.dart b/lib/src/core/protocol_interfaces/protocol_server.dart index 437d4a98..876a008d 100644 --- a/lib/src/core/protocol_interfaces/protocol_server.dart +++ b/lib/src/core/protocol_interfaces/protocol_server.dart @@ -6,7 +6,7 @@ import "../implementation/exposed_thing.dart"; import "../implementation/servient.dart"; -// import "../scripting_api/exposed_thing.dart"; +import "exposable_thing.dart"; /// Base class for a Protocol Server. abstract interface class ProtocolServer { @@ -24,5 +24,5 @@ abstract interface class ProtocolServer { Future stop(); /// Exposes a [thing]. - Future expose(ExposedThing thing); + Future expose(ExposableThing thing); } diff --git a/pubspec.yaml b/pubspec.yaml index adeafbcf..9e1a7f1f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,11 +7,9 @@ environment: sdk: '>=3.0.0 <4.0.0' dev_dependencies: - build_runner: ^2.3.0 coverage: ^1.0.4 lint: ^2.0.2 lints: ^4.0.0 - mockito: ^5.0.17 test: ^1.24.3 dependencies: diff --git a/test/binding_coap/binding_coap_test.dart b/test/binding_coap/binding_coap_test.dart index 62702cf0..b202dc4d 100644 --- a/test/binding_coap/binding_coap_test.dart +++ b/test/binding_coap/binding_coap_test.dart @@ -7,11 +7,8 @@ import "package:dart_wot/binding_coap.dart"; import "package:dart_wot/core.dart"; -import "package:mockito/annotations.dart"; import "package:test/test.dart"; -import "binding_coap_test.mocks.dart"; -@GenerateMocks([ExposedThing]) void main() { group("CoAP Binding Tests", () { setUp(() { @@ -37,10 +34,6 @@ void main() { () async => defaultServer.stop(), throwsA(const TypeMatcher()), ); - expect( - () async => defaultServer.expose(MockExposedThing()), - throwsA(const TypeMatcher()), - ); final customServer = CoapServer(const CoapConfig(port: 9001, blocksize: 64)); diff --git a/test/binding_coap/binding_coap_test.mocks.dart b/test/binding_coap/binding_coap_test.mocks.dart deleted file mode 100644 index 44078b5e..00000000 --- a/test/binding_coap/binding_coap_test.mocks.dart +++ /dev/null @@ -1,228 +0,0 @@ -// Mocks generated by Mockito 5.4.3 from annotations -// in dart_wot/test/binding_coap/binding_coap_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; - -import 'package:dart_wot/src/core/definitions.dart' as _i2; -import 'package:dart_wot/src/core/scripting_api/exposed_thing.dart' as _i3; -import 'package:dart_wot/src/core/scripting_api/interaction_input.dart' as _i5; -import 'package:mockito/mockito.dart' as _i1; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -class _FakeThingDescription_0 extends _i1.SmartFake - implements _i2.ThingDescription { - _FakeThingDescription_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [ExposedThing]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockExposedThing extends _i1.Mock implements _i3.ExposedThing { - MockExposedThing() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.ThingDescription get thingDescription => (super.noSuchMethod( - Invocation.getter(#thingDescription), - returnValue: _FakeThingDescription_0( - this, - Invocation.getter(#thingDescription), - ), - ) as _i2.ThingDescription); - - @override - _i4.Future expose() => (super.noSuchMethod( - Invocation.method( - #expose, - [], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - - @override - _i4.Future destroy() => (super.noSuchMethod( - Invocation.method( - #destroy, - [], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - - @override - void setPropertyReadHandler( - String? name, - _i3.PropertyReadHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setPropertyReadHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setPropertyWriteHandler( - String? name, - _i3.PropertyWriteHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setPropertyWriteHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setPropertyObserveHandler( - String? name, - _i3.PropertyReadHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setPropertyObserveHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setPropertyUnobserveHandler( - String? name, - _i3.PropertyReadHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setPropertyUnobserveHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i4.Future emitPropertyChange(String? name) => (super.noSuchMethod( - Invocation.method( - #emitPropertyChange, - [name], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - - @override - void setActionHandler( - String? name, - _i3.ActionHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setActionHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setEventSubscribeHandler( - String? name, - _i3.EventSubscriptionHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setEventSubscribeHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setEventUnsubscribeHandler( - String? name, - _i3.EventSubscriptionHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setEventUnsubscribeHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setEventHandler( - String? name, - _i3.EventListenerHandler? handler, - ) => - super.noSuchMethod( - Invocation.method( - #setEventHandler, - [ - name, - handler, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i4.Future emitEvent( - String? name, - _i5.InteractionInput? data, - ) => - (super.noSuchMethod( - Invocation.method( - #emitEvent, - [ - name, - data, - ], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); -}