]> git.basschouten.com Git - openhab-addons.git/blob
6ed1d2699cdeb92569a580cc64ff2c85019a44d6
[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.vesync.internal.handler.responses.v1;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.junit.jupiter.api.Test;
17 import org.openhab.binding.vesync.internal.VeSyncConstants;
18 import org.openhab.binding.vesync.internal.dto.responses.VesyncLoginResponse;
19 import org.openhab.binding.vesync.internal.dto.responses.v1.VesyncV1AirPurifierDeviceDetailsResponse;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.fail;
23
24 /**
25  * The {@link VesyncV1AirPurifierDeviceDetailsTest} class implements unit test case for {@link VesyncLoginResponse}
26  *
27  * @author David Goodyear - Initial contribution
28  */
29 @NonNullByDefault
30 public class VesyncV1AirPurifierDeviceDetailsTest {
31
32     public final static String testAirPurifierResponseBasedOnCore400S = "{\n" +
33             "    \"code\": 0,\n" +
34             "    \"msg\": \"request success\",\n" +
35             "    \"traceId\": \"1634255391\",\n" +
36             "    \"screenStatus\": \"on1\",\n" +
37             "    \"airQuality\": 1,\n" +
38             "    \"level\": 2,\n" +
39             "    \"mode\": \"manual\",\n" +
40             "    \"deviceName\": \"Lounge Air Purifier\",\n" +
41             "    \"currentFirmVersion\": \"1.0.17\",\n" +
42             "    \"childLock\": \"off1\",\n" +
43             "    \"deviceStatus\": \"on2\",\n" +
44             "    \"deviceImg\": \"https://image.vesync.com/defaultImages/Core_400S_Series/icon_core400s_purifier_160.png\",\n" +
45             "    \"connectionStatus\": \"online\"\n" +
46             "}";
47
48     @Test
49     public void testParseV1AirPurifierDeviceDetailsResponse() {
50         VesyncV1AirPurifierDeviceDetailsResponse response = VeSyncConstants.GSON.fromJson(testAirPurifierResponseBasedOnCore400S,
51                 VesyncV1AirPurifierDeviceDetailsResponse.class);
52
53         if (response != null) {
54             assertEquals("on1", response.getScreenStatus());
55             assertEquals(1, response.getAirQuality());
56             assertEquals(2, response.getLevel());
57             assertEquals("manual", response.getMode());
58             assertEquals("Lounge Air Purifier", response.getDeviceName());
59             assertEquals("1.0.17", response.getCurrentFirmVersion());
60             assertEquals("off1", response.getChildLock());
61             assertEquals("on2", response.getDeviceStatus());
62             assertEquals("https://image.vesync.com/defaultImages/Core_400S_Series/icon_core400s_purifier_160.png", response.getDeviceImgUrl());
63             assertEquals("online", response.getConnectionStatus());
64         } else {
65             fail("GSON returned null");
66         }
67     }
68 }