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.vesync.internal.handler.responses;
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.VesyncManagedDevicesPage;
21 import static org.junit.jupiter.api.Assertions.*;
24 * The {@link VesyncManagedDevicesPageTest} class implements unit test case for {@link VesyncLoginResponse}
26 * @author David Goodyear - Initial contribution
29 public class VesyncManagedDevicesPageTest {
31 public static final String testGoodSearchResponsePageBody = """
33 "traceId": "1634387642",
35 "msg": "request success",
45 "deviceName": "Air Filter",
46 "deviceImg": "https://image.vesync.com/defaultImages/Core_400S_Series/icon_core400s_purifier_160.png",
49 "connectionStatus": "online",
50 "connectionType": "WiFi+BTOnboarding+BTNotify",
51 "deviceType": "Core400S",
53 "uuid": "abcdefab-1234-1234-abcd-123498761234",
54 "configModule": "WiFiBTOnboardingNotify_AirPurifier_Core400S_EU",
55 "macID": "ab:cd:ef:12:34:56",
56 "mode": "simModeData",
64 "currentFirmVersion": null,
65 "subDeviceNo": "simSubDevice",
66 "subDeviceType": "simSubDeviceType",
67 "deviceFirstSetupTime": "Oct 15, 2021 3:43:02 PM"
75 public void testParseManagedDevicesSearchGoodResponse() {
76 VesyncManagedDevicesPage response = VeSyncConstants.GSON.fromJson(testGoodSearchResponsePageBody,
77 VesyncManagedDevicesPage.class);
78 if (response != null) {
79 assertEquals("1634387642", response.getTraceId());
80 assertEquals("1", response.result.getPageNo());
81 assertEquals("100", response.result.getPageSize());
82 assertEquals("2", response.result.getTotal());
83 assertEquals("1", String.valueOf(response.result.list.length));
85 assertEquals("EU", response.result.list[0].getDeviceRegion());
86 assertEquals("Air Filter", response.result.list[0].getDeviceName());
87 assertEquals("https://image.vesync.com/defaultImages/Core_400S_Series/icon_core400s_purifier_160.png", response.result.list[0].getDeviceImg());
88 assertEquals("on", response.result.list[0].getDeviceStatus());
89 assertEquals("online", response.result.list[0].getConnectionStatus());
90 assertEquals("WiFi+BTOnboarding+BTNotify", response.result.list[0].getConnectionType());
91 assertEquals("Core400S", response.result.list[0].getDeviceType());
92 assertEquals("wifi-air", response.result.list[0].getType());
93 assertEquals("abcdefab-1234-1234-abcd-123498761234", response.result.list[0].getUuid());
94 assertEquals("WiFiBTOnboardingNotify_AirPurifier_Core400S_EU", response.result.list[0].getConfigModule());
95 assertEquals("simModeData",response.result.list[0].getMode());
96 assertEquals("simSubDevice", response.result.list[0].getSubDeviceNo());
97 assertEquals("simSubDeviceType", response.result.list[0].getSubDeviceType());
98 assertEquals( "4", response.result.list[0].getSpeed());
99 assertEquals("cidValue1",response.result.list[0].getCid());
100 assertEquals("ab:cd:ef:12:34:56", response.result.list[0].getMacId());
102 fail("GSON returned null");