]> git.basschouten.com Git - openhab-addons.git/blob
31b53b1db4e50b4d191a4a5fb06009844d2f9c03
[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;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.vesync.internal.VeSyncConstants;
20 import org.openhab.binding.vesync.internal.dto.responses.VesyncLoginResponse;
21
22 /**
23  * The {@link VesyncLoginResponseTest} class implements unit test case for {@link VesyncLoginResponse}
24  *
25  * @author David Goodyear - Initial contribution
26  */
27 @NonNullByDefault
28 public class VesyncLoginResponseTest {
29
30     public final static String testGoodLoginResponseBody = "{\r\n" + "    \"traceId\": \"1634253816\",\r\n"
31             + "    \"code\": 0,\r\n" + "    \"msg\": \"request success\",\r\n" + "    \"result\": {\r\n"
32             + "        \"isRequiredVerify\": true,\r\n" + "        \"accountID\": \"5328043\",\r\n"
33             + "        \"avatarIcon\": \"https://image.vesync.com/defaultImages/user/avatar_nor.png\",\r\n"
34             + "        \"birthday\": \"\",\r\n" + "        \"gender\": \"\",\r\n"
35             + "        \"acceptLanguage\": \"en\",\r\n" + "        \"userType\": \"1\",\r\n"
36             + "        \"nickName\": \"david.goodyear\",\r\n" + "        \"mailConfirmation\": true,\r\n"
37             + "        \"termsStatus\": true,\r\n" + "        \"gdprStatus\": true,\r\n"
38             + "        \"countryCode\": \"GB\",\r\n" + "        \"registerAppVersion\": \"VeSync 3.1.37 build3\",\r\n"
39             + "        \"registerTime\": \"2021-10-14 17:35:50\",\r\n"
40             + "        \"verifyEmail\": \"david.goodyear@gmail.com\",\r\n" + "        \"heightCm\": 0.0,\r\n"
41             + "        \"weightTargetSt\": 0.0,\r\n" + "        \"heightUnit\": \"FT\",\r\n"
42             + "        \"heightFt\": 0.0,\r\n" + "        \"weightTargetKg\": 0.0,\r\n"
43             + "        \"weightTargetLb\": 0.0,\r\n" + "        \"weightUnit\": \"LB\",\r\n"
44             + "        \"targetBfr\": 0.0,\r\n" + "        \"displayFlag\": [],\r\n"
45             + "        \"real_weight_kg\": 0.0,\r\n" + "        \"real_weight_lb\": 0.0,\r\n"
46             + "        \"real_weight_unit\": \"lb\",\r\n" + "        \"heart_rate_zones\": 0.0,\r\n"
47             + "        \"run_step_long_cm\": 0.0,\r\n" + "        \"walk_step_long_cm\": 0.0,\r\n"
48             + "        \"step_target\": 0.0,\r\n" + "        \"sleep_target_mins\": 0.0,\r\n"
49             + "        \"token\": \"AccessTokenString=\"\r\n" + "    }\r\n" + "}";
50
51     @Test
52     public void testParseLoginGoodResponse() {
53         VesyncLoginResponse response = VeSyncConstants.GSON.fromJson(testGoodLoginResponseBody,
54                 VesyncLoginResponse.class);
55         if (response != null) {
56             assertEquals("1634253816", response.getTraceId());
57             assertEquals("AccessTokenString=", response.result.token);
58             assertEquals("request success", response.msg);
59             assertEquals("5328043", response.result.accountId);
60             assertEquals("VeSync 3.1.37 build3", response.result.registerAppVersion);
61             assertEquals("GB", response.result.countryCode);
62             assertTrue(response.isMsgSuccess());
63         } else {
64             fail("GSON returned null");
65         }
66     }
67
68     @Test
69     public void testParseLoginFailResponse() {
70         String testReponse = "{\r\n" + "    \"traceId\": \"1634253816\",\r\n" + "    \"code\": -11201022,\r\n"
71                 + "    \"msg\": \"password incorrect\",\r\n" + "    \"result\": null\r\n" + "}";
72         VesyncLoginResponse response = VeSyncConstants.GSON.fromJson(testReponse,
73                 VesyncLoginResponse.class);
74         if (response != null) {
75             assertEquals("password incorrect", response.msg);
76             assertFalse(response.isMsgSuccess());
77         } else {
78             fail("GSON returned null");
79         }
80     }
81 }