Skip to content

Commit

Permalink
test: add tests for supportsOperation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Jan 12, 2024
1 parent 2781723 commit 6f3ffa7
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/binding_coap/coap_client_factory_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 "package:dart_wot/binding_coap.dart";
import "package:dart_wot/core.dart";
import "package:test/test.dart";

void main() {
group("CoapClientFactory should", () {
test("indicate correctly whether an operation is supported", () {
final coapClientFactory = CoapClientFactory();

const observeOperations = [
OperationType.observeproperty,
OperationType.unobserveproperty,
OperationType.subscribeevent,
OperationType.unsubscribeevent,
];
final otherOperations = OperationType.values
.where((operationType) => !observeOperations.contains(operationType));

final testVector = [
(
expectedResult: true,
operationTypes: observeOperations,
subprotocol: "cov:observe",
),
(
expectedResult: false,
operationTypes: observeOperations,
subprotocol: null,
),
(
expectedResult: true,
operationTypes: otherOperations,
subprotocol: null,
),
(
expectedResult: false,
operationTypes: otherOperations,
subprotocol: "cov:observe",
),
(
expectedResult: false,
operationTypes: OperationType.values,
subprotocol: "foobar",
),
];

for (final testCase in testVector) {
for (final operationType in testCase.operationTypes) {
expect(
coapClientFactory.supportsOperation(
operationType,
testCase.subprotocol,
),
testCase.expectedResult,
);
}
}
});
});
}
61 changes: 61 additions & 0 deletions test/binding_http/http_client_factory_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 "package:dart_wot/binding_http.dart";
import "package:dart_wot/core.dart";
import "package:test/test.dart";

void main() {
group("HttpClientFactory should", () {
test("indicate correctly whether an operation is supported", () {
final httpClientFactory = HttpClientFactory();

const observeOperations = [
OperationType.observeproperty,
OperationType.unobserveproperty,
OperationType.subscribeevent,
OperationType.unsubscribeevent,
];
final otherOperations = OperationType.values
.where((operationType) => !observeOperations.contains(operationType));

final testVector = [
(
expectedResult: false,
operationTypes: observeOperations,
subprotocol: null,
),
(
expectedResult: false,
operationTypes: observeOperations,
subprotocol: "foobar",
),
(
expectedResult: true,
operationTypes: otherOperations,
subprotocol: null,
),
(
expectedResult: false,
operationTypes: otherOperations,
subprotocol: "foobar",
),
];

for (final testCase in testVector) {
for (final operationType in testCase.operationTypes) {
expect(
httpClientFactory.supportsOperation(
operationType,
testCase.subprotocol,
),
testCase.expectedResult,
);
}
}
});
});
}
42 changes: 42 additions & 0 deletions test/binding_mqtt/mqtt_client_factory_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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 "package:dart_wot/binding_mqtt.dart";
import "package:dart_wot/core.dart";
import "package:test/test.dart";

void main() {
group("MqttClientFactory should", () {
test("indicate correctly whether an operation is supported", () {
final coapClientFactory = MqttClientFactory();

final testVector = [
(
expectedResult: false,
operationTypes: OperationType.values,
subprotocol: "foobar",
),
(
expectedResult: true,
operationTypes: OperationType.values,
subprotocol: null,
),
];

for (final testCase in testVector) {
for (final operationType in testCase.operationTypes) {
expect(
coapClientFactory.supportsOperation(
operationType,
testCase.subprotocol,
),
testCase.expectedResult,
);
}
}
});
});
}

0 comments on commit 6f3ffa7

Please sign in to comment.