]> git.basschouten.com Git - openhab-addons.git/blob
51c42d6b657627d7bfa3f8517d98ecb4c5407fb7
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.mielecloud.internal.discovery;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
17
18 import java.util.Optional;
19 import java.util.stream.Stream;
20
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;
31
32 /**
33  * @author Björn Lange - Initial contribution
34  */
35 @NonNullByDefault
36 public class ThingInformationExtractorTest {
37     private static Stream<Arguments> extractedPropertiesContainSerialNumberAndModelIdParameterSource() {
38         return Stream.of(
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",
50                         "000124430018"),
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",
56                         "000124430018"));
57     }
58
59     @ParameterizedTest
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) {
64         // given:
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);
71
72         // when:
73         var properties = ThingInformationExtractor.extractProperties(thingTypeUid, deviceState);
74
75         // then:
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));
81     }
82
83     @ParameterizedTest
84     @CsvSource({ "2,2", "4,4" })
85     void propertiesForHobContainPlateCount(int plateCount, String expectedPlateCountPropertyValue) {
86         // given:
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));
94
95         // when:
96         var properties = ThingInformationExtractor.extractProperties(MieleCloudBindingConstants.THING_TYPE_HOB,
97                 deviceState);
98
99         // then:
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));
105     }
106 }