2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.mielecloud.internal.discovery;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
18 import java.util.Optional;
19 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.params.ParameterizedTest;
23 import org.junit.jupiter.params.provider.Arguments;
24 import org.junit.jupiter.params.provider.CsvSource;
25 import org.junit.jupiter.params.provider.MethodSource;
26 import org.openhab.binding.mielecloud.internal.MieleCloudBindingConstants;
27 import org.openhab.binding.mielecloud.internal.webservice.api.DeviceState;
28 import org.openhab.binding.mielecloud.internal.webservice.api.json.DeviceType;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
33 * @author Björn Lange - Initial contribution
36 public class ThingInformationExtractorTest {
37 private static Stream<Arguments> extractedPropertiesContainSerialNumberAndModelIdParameterSource() {
39 Arguments.of(MieleCloudBindingConstants.THING_TYPE_HOOD, DeviceType.HOOD, "000124430018",
40 Optional.of("000124430017"), Optional.of("Ventilation Hood"), Optional.of("DA-6996"),
41 "000124430017", "Ventilation Hood DA-6996", "000124430018"),
42 Arguments.of(MieleCloudBindingConstants.THING_TYPE_COFFEE_SYSTEM, DeviceType.COFFEE_SYSTEM,
43 "000124431235", Optional.of("000124431234"), Optional.of("Coffee Machine"),
44 Optional.of("CM-1234"), "000124431234", "Coffee Machine CM-1234", "000124431235"),
45 Arguments.of(MieleCloudBindingConstants.THING_TYPE_HOOD, DeviceType.HOOD, "000124430018",
46 Optional.empty(), Optional.of("Ventilation Hood"), Optional.of("DA-6996"), "000124430018",
47 "Ventilation Hood DA-6996", "000124430018"),
48 Arguments.of(MieleCloudBindingConstants.THING_TYPE_HOOD, DeviceType.HOOD, "000124430018",
49 Optional.empty(), Optional.empty(), Optional.of("DA-6996"), "000124430018", "DA-6996",
51 Arguments.of(MieleCloudBindingConstants.THING_TYPE_HOOD, DeviceType.HOOD, "000124430018",
52 Optional.empty(), Optional.of("Ventilation Hood"), Optional.empty(), "000124430018",
53 "Ventilation Hood", "000124430018"),
54 Arguments.of(MieleCloudBindingConstants.THING_TYPE_HOOD, DeviceType.HOOD, "000124430018",
55 Optional.empty(), Optional.empty(), Optional.empty(), "000124430018", "Unknown",
60 @MethodSource("extractedPropertiesContainSerialNumberAndModelIdParameterSource")
61 void extractedPropertiesContainSerialNumberAndModelId(ThingTypeUID thingTypeUid, DeviceType deviceType,
62 String deviceIdentifier, Optional<String> fabNumber, Optional<String> type, Optional<String> techType,
63 String expectedSerialNumber, String expectedModelId, String expectedDeviceIdentifier) {
65 var deviceState = mock(DeviceState.class);
66 when(deviceState.getRawType()).thenReturn(deviceType);
67 when(deviceState.getDeviceIdentifier()).thenReturn(deviceIdentifier);
68 when(deviceState.getFabNumber()).thenReturn(fabNumber);
69 when(deviceState.getType()).thenReturn(type);
70 when(deviceState.getTechType()).thenReturn(techType);
73 var properties = ThingInformationExtractor.extractProperties(thingTypeUid, deviceState);
76 assertEquals(3, properties.size());
77 assertEquals(expectedSerialNumber, properties.get(Thing.PROPERTY_SERIAL_NUMBER));
78 assertEquals(expectedModelId, properties.get(Thing.PROPERTY_MODEL_ID));
79 assertEquals(expectedDeviceIdentifier,
80 properties.get(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER));
84 @CsvSource({ "2,2", "4,4" })
85 void propertiesForHobContainPlateCount(int plateCount, String expectedPlateCountPropertyValue) {
87 var deviceState = mock(DeviceState.class);
88 when(deviceState.getRawType()).thenReturn(DeviceType.HOB_INDUCTION);
89 when(deviceState.getDeviceIdentifier()).thenReturn("000124430019");
90 when(deviceState.getFabNumber()).thenReturn(Optional.of("000124430019"));
91 when(deviceState.getType()).thenReturn(Optional.of("Induction Hob"));
92 when(deviceState.getTechType()).thenReturn(Optional.of("IH-7890"));
93 when(deviceState.getPlateStepCount()).thenReturn(Optional.of(plateCount));
96 var properties = ThingInformationExtractor.extractProperties(MieleCloudBindingConstants.THING_TYPE_HOB,
100 assertEquals(4, properties.size());
101 assertEquals("000124430019", properties.get(Thing.PROPERTY_SERIAL_NUMBER));
102 assertEquals("Induction Hob IH-7890", properties.get(Thing.PROPERTY_MODEL_ID));
103 assertEquals("000124430019", properties.get(MieleCloudBindingConstants.CONFIG_PARAM_DEVICE_IDENTIFIER));
104 assertEquals(expectedPlateCountPropertyValue, properties.get(MieleCloudBindingConstants.PROPERTY_PLATE_COUNT));