-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from eclipse-thingweb/client-factories
feat(servient): improve handling of client factories
- Loading branch information
Showing
12 changed files
with
136 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2023 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 'package:dart_wot/dart_wot.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
const testUriScheme = 'test'; | ||
|
||
class MockedProtocolClientFactory implements ProtocolClientFactory { | ||
@override | ||
ProtocolClient createClient() { | ||
throw UnimplementedError('Instantiating a client is not supported yet.'); | ||
} | ||
|
||
@override | ||
bool destroy() { | ||
return true; | ||
} | ||
|
||
@override | ||
bool init() { | ||
return true; | ||
} | ||
|
||
@override | ||
Set<String> get schemes => {testUriScheme}; | ||
} | ||
|
||
void main() { | ||
group('Servient Tests', () { | ||
test('Should accept a ProtocolClientFactory list as constructor argument', | ||
() { | ||
final servient = Servient( | ||
clientFactories: [ | ||
MockedProtocolClientFactory(), | ||
], | ||
); | ||
|
||
expect(servient.clientSchemes, [testUriScheme]); | ||
expect(servient.hasClientFor(testUriScheme), true); | ||
}); | ||
|
||
test( | ||
'Should allow for adding and removing a ProtocolClientFactory at runtime', | ||
() { | ||
final servient = Servient() | ||
..addClientFactory(MockedProtocolClientFactory()); | ||
|
||
expect(servient.hasClientFor(testUriScheme), true); | ||
|
||
servient.removeClientFactory(testUriScheme); | ||
|
||
expect(servient.hasClientFor(testUriScheme), false); | ||
expect(servient.clientSchemes.length, 0); | ||
}, | ||
); | ||
}); | ||
} |