]> git.basschouten.com Git - openhab-addons.git/blob
9f375209345002724e5f6532dbfdd3e54cf98db2
[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 static final String testGoodLoginResponseBody = """
31             {
32                 "traceId": "1634253816",
33                 "code": 0,
34                 "msg": "request success",
35                 "result": {
36                     "isRequiredVerify": true,
37                     "accountID": "5328043",
38                     "avatarIcon": "https://image.vesync.com/defaultImages/user/avatar_nor.png",
39                     "birthday": "",
40                     "gender": "",
41                     "acceptLanguage": "en",
42                     "userType": "1",
43                     "nickName": "david.goodyear",
44                     "mailConfirmation": true,
45                     "termsStatus": true,
46                     "gdprStatus": true,
47                     "countryCode": "GB",
48                     "registerAppVersion": "VeSync 3.1.37 build3",
49                     "registerTime": "2021-10-14 17:35:50",
50                     "verifyEmail": "david.goodyear@gmail.com",
51                     "heightCm": 0.0,
52                     "weightTargetSt": 0.0,
53                     "heightUnit": "FT",
54                     "heightFt": 0.0,
55                     "weightTargetKg": 0.0,
56                     "weightTargetLb": 0.0,
57                     "weightUnit": "LB",
58                     "targetBfr": 0.0,
59                     "displayFlag": [],
60                     "real_weight_kg": 0.0,
61                     "real_weight_lb": 0.0,
62                     "real_weight_unit": "lb",
63                     "heart_rate_zones": 0.0,
64                     "run_step_long_cm": 0.0,
65                     "walk_step_long_cm": 0.0,
66                     "step_target": 0.0,
67                     "sleep_target_mins": 0.0,
68                     "token": "AccessTokenString="
69                 }
70             }\
71             """;
72
73     @Test
74     public void testParseLoginGoodResponse() {
75         VesyncLoginResponse response = VeSyncConstants.GSON.fromJson(testGoodLoginResponseBody,
76                 VesyncLoginResponse.class);
77         if (response != null) {
78             assertEquals("1634253816", response.getTraceId());
79             assertEquals("AccessTokenString=", response.result.token);
80             assertEquals("request success", response.msg);
81             assertEquals("5328043", response.result.accountId);
82             assertEquals("VeSync 3.1.37 build3", response.result.registerAppVersion);
83             assertEquals("GB", response.result.countryCode);
84             assertTrue(response.isMsgSuccess());
85         } else {
86             fail("GSON returned null");
87         }
88     }
89
90     @Test
91     public void testParseLoginFailResponse() {
92         String testReponse = """
93                 {
94                     "traceId": "1634253816",
95                     "code": -11201022,
96                     "msg": "password incorrect",
97                     "result": null
98                 }\
99                 """;
100         VesyncLoginResponse response = VeSyncConstants.GSON.fromJson(testReponse,
101                 VesyncLoginResponse.class);
102         if (response != null) {
103             assertEquals("password incorrect", response.msg);
104             assertFalse(response.isMsgSuccess());
105         } else {
106             fail("GSON returned null");
107         }
108     }
109 }