Skip to content

Commit 6f3ffa7

Browse files
committed
test: add tests for supportsOperation methods
1 parent 2781723 commit 6f3ffa7

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
import "package:dart_wot/binding_coap.dart";
8+
import "package:dart_wot/core.dart";
9+
import "package:test/test.dart";
10+
11+
void main() {
12+
group("CoapClientFactory should", () {
13+
test("indicate correctly whether an operation is supported", () {
14+
final coapClientFactory = CoapClientFactory();
15+
16+
const observeOperations = [
17+
OperationType.observeproperty,
18+
OperationType.unobserveproperty,
19+
OperationType.subscribeevent,
20+
OperationType.unsubscribeevent,
21+
];
22+
final otherOperations = OperationType.values
23+
.where((operationType) => !observeOperations.contains(operationType));
24+
25+
final testVector = [
26+
(
27+
expectedResult: true,
28+
operationTypes: observeOperations,
29+
subprotocol: "cov:observe",
30+
),
31+
(
32+
expectedResult: false,
33+
operationTypes: observeOperations,
34+
subprotocol: null,
35+
),
36+
(
37+
expectedResult: true,
38+
operationTypes: otherOperations,
39+
subprotocol: null,
40+
),
41+
(
42+
expectedResult: false,
43+
operationTypes: otherOperations,
44+
subprotocol: "cov:observe",
45+
),
46+
(
47+
expectedResult: false,
48+
operationTypes: OperationType.values,
49+
subprotocol: "foobar",
50+
),
51+
];
52+
53+
for (final testCase in testVector) {
54+
for (final operationType in testCase.operationTypes) {
55+
expect(
56+
coapClientFactory.supportsOperation(
57+
operationType,
58+
testCase.subprotocol,
59+
),
60+
testCase.expectedResult,
61+
);
62+
}
63+
}
64+
});
65+
});
66+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
import "package:dart_wot/binding_http.dart";
8+
import "package:dart_wot/core.dart";
9+
import "package:test/test.dart";
10+
11+
void main() {
12+
group("HttpClientFactory should", () {
13+
test("indicate correctly whether an operation is supported", () {
14+
final httpClientFactory = HttpClientFactory();
15+
16+
const observeOperations = [
17+
OperationType.observeproperty,
18+
OperationType.unobserveproperty,
19+
OperationType.subscribeevent,
20+
OperationType.unsubscribeevent,
21+
];
22+
final otherOperations = OperationType.values
23+
.where((operationType) => !observeOperations.contains(operationType));
24+
25+
final testVector = [
26+
(
27+
expectedResult: false,
28+
operationTypes: observeOperations,
29+
subprotocol: null,
30+
),
31+
(
32+
expectedResult: false,
33+
operationTypes: observeOperations,
34+
subprotocol: "foobar",
35+
),
36+
(
37+
expectedResult: true,
38+
operationTypes: otherOperations,
39+
subprotocol: null,
40+
),
41+
(
42+
expectedResult: false,
43+
operationTypes: otherOperations,
44+
subprotocol: "foobar",
45+
),
46+
];
47+
48+
for (final testCase in testVector) {
49+
for (final operationType in testCase.operationTypes) {
50+
expect(
51+
httpClientFactory.supportsOperation(
52+
operationType,
53+
testCase.subprotocol,
54+
),
55+
testCase.expectedResult,
56+
);
57+
}
58+
}
59+
});
60+
});
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2024 Contributors to the Eclipse Foundation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
//
5+
// SPDX-License-Identifier: BSD-3-Clause
6+
7+
import "package:dart_wot/binding_mqtt.dart";
8+
import "package:dart_wot/core.dart";
9+
import "package:test/test.dart";
10+
11+
void main() {
12+
group("MqttClientFactory should", () {
13+
test("indicate correctly whether an operation is supported", () {
14+
final coapClientFactory = MqttClientFactory();
15+
16+
final testVector = [
17+
(
18+
expectedResult: false,
19+
operationTypes: OperationType.values,
20+
subprotocol: "foobar",
21+
),
22+
(
23+
expectedResult: true,
24+
operationTypes: OperationType.values,
25+
subprotocol: null,
26+
),
27+
];
28+
29+
for (final testCase in testVector) {
30+
for (final operationType in testCase.operationTypes) {
31+
expect(
32+
coapClientFactory.supportsOperation(
33+
operationType,
34+
testCase.subprotocol,
35+
),
36+
testCase.expectedResult,
37+
);
38+
}
39+
}
40+
});
41+
});
42+
}

0 commit comments

Comments
 (0)