]> git.basschouten.com Git - openhab-addons.git/blob
ff94d7d5ba5ff2166d86805a8878e70e17445bf9
[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 static final String testAirPurifierResponseBasedOnCore400S = """
33             {
34                 "code": 0,
35                 "msg": "request success",
36                 "traceId": "1634255391",
37                 "screenStatus": "on1",
38                 "airQuality": 1,
39                 "level": 2,
40                 "mode": "manual",
41                 "deviceName": "Lounge Air Purifier",
42                 "currentFirmVersion": "1.0.17",
43                 "childLock": "off1",
44                 "deviceStatus": "on2",
45                 "deviceImg": "https://image.vesync.com/defaultImages/Core_400S_Series/icon_core400s_purifier_160.png",
46                 "connectionStatus": "online"
47             }\
48             """;
49
50     @Test
51     public void testParseV1AirPurifierDeviceDetailsResponse() {
52         VesyncV1AirPurifierDeviceDetailsResponse response = VeSyncConstants.GSON.fromJson(testAirPurifierResponseBasedOnCore400S,
53                 VesyncV1AirPurifierDeviceDetailsResponse.class);
54
55         if (response != null) {
56             assertEquals("on1", response.getScreenStatus());
57             assertEquals(1, response.getAirQuality());
58             assertEquals(2, response.getLevel());
59             assertEquals("manual", response.getMode());
60             assertEquals("Lounge Air Purifier", response.getDeviceName());
61             assertEquals("1.0.17", response.getCurrentFirmVersion());
62             assertEquals("off1", response.getChildLock());
63             assertEquals("on2", response.getDeviceStatus());
64             assertEquals("https://image.vesync.com/defaultImages/Core_400S_Series/icon_core400s_purifier_160.png", response.getDeviceImgUrl());
65             assertEquals("online", response.getConnectionStatus());
66         } else {
67             fail("GSON returned null");
68         }
69     }
70 }