]> git.basschouten.com Git - openhab-addons.git/blob
afcb27ec713a71717e32bfc0b1eda861ea4df78f
[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.tplinksmarthome.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.IOException;
18 import java.util.Map;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.tplinksmarthome.internal.model.GetSysinfo;
23 import org.openhab.binding.tplinksmarthome.internal.model.ModelTestUtil;
24
25 /**
26  * Test class for {@link PropertiesCollector} class.
27  *
28  * @author Hilbrand Bouwkamp - Initial contribution
29  */
30 @NonNullByDefault
31 public class PropertiesCollectorTest {
32
33     /**
34      * Tests if properties for a bulb device are correctly parsed.
35      *
36      * @throws IOException exception in case device not reachable
37      */
38     @Test
39     public void testBulbProperties() throws IOException {
40         assertProperties("bulb_get_sysinfo_response_on", TPLinkSmartHomeThingType.LB130, 11);
41     }
42
43     /**
44      * Tests if properties for a switch device are correctly parsed.
45      *
46      * @throws IOException exception in case device not reachable
47      */
48     @Test
49     public void testSwitchProperties() throws IOException {
50         assertProperties("plug_get_sysinfo_response", TPLinkSmartHomeThingType.HS100, 12);
51     }
52
53     /**
54      * Tests if properties for a range extender device are correctly parsed.
55      *
56      * @throws IOException exception in case device not reachable
57      */
58     @Test
59     public void testRangeExtenderProperties() throws IOException {
60         assertProperties("rangeextender_get_sysinfo_response", TPLinkSmartHomeThingType.RE270K, 11);
61     }
62
63     private void assertProperties(String responseFile, TPLinkSmartHomeThingType thingType, int expectedSize)
64             throws IOException {
65         final Map<String, Object> props = PropertiesCollector.collectProperties(thingType, "localhost",
66                 ModelTestUtil.jsonFromFile(responseFile, GetSysinfo.class).getSysinfo());
67
68         assertEquals(expectedSize, props.size(), "Number of properties not as expected for properties: " + props);
69         props.entrySet().stream().forEach(
70                 entry -> assertNotNull(entry.getValue(), "Property '" + entry.getKey() + "' should not be null"));
71     }
72 }