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.tplinksmarthome.internal;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.io.IOException;
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;
26 * Test class for {@link PropertiesCollector} class.
28 * @author Hilbrand Bouwkamp - Initial contribution
31 public class PropertiesCollectorTest {
34 * Tests if properties for a bulb device are correctly parsed.
36 * @throws IOException exception in case device not reachable
39 public void testBulbProperties() throws IOException {
40 assertProperties("bulb_get_sysinfo_response_on", TPLinkSmartHomeThingType.LB130, 11);
44 * Tests if properties for a switch device are correctly parsed.
46 * @throws IOException exception in case device not reachable
49 public void testSwitchProperties() throws IOException {
50 assertProperties("plug_get_sysinfo_response", TPLinkSmartHomeThingType.HS100, 12);
54 * Tests if properties for a range extender device are correctly parsed.
56 * @throws IOException exception in case device not reachable
59 public void testRangeExtenderProperties() throws IOException {
60 assertProperties("rangeextender_get_sysinfo_response", TPLinkSmartHomeThingType.RE270K, 11);
63 private void assertProperties(String responseFile, TPLinkSmartHomeThingType thingType, int expectedSize)
65 final Map<String, Object> props = PropertiesCollector.collectProperties(thingType, "localhost",
66 ModelTestUtil.jsonFromFile(responseFile, GetSysinfo.class).getSysinfo());
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"));