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 static org.junit.jupiter.api.Assertions.*;
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;
23 * The {@link VesyncLoginResponseTest} class implements unit test case for {@link VesyncLoginResponse}
25 * @author David Goodyear - Initial contribution
28 public class VesyncLoginResponseTest {
30 public static final String testGoodLoginResponseBody = """
32 "traceId": "1634253816",
34 "msg": "request success",
36 "isRequiredVerify": true,
37 "accountID": "5328043",
38 "avatarIcon": "https://image.vesync.com/defaultImages/user/avatar_nor.png",
41 "acceptLanguage": "en",
43 "nickName": "david.goodyear",
44 "mailConfirmation": true,
48 "registerAppVersion": "VeSync 3.1.37 build3",
49 "registerTime": "2021-10-14 17:35:50",
50 "verifyEmail": "david.goodyear@gmail.com",
52 "weightTargetSt": 0.0,
55 "weightTargetKg": 0.0,
56 "weightTargetLb": 0.0,
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,
67 "sleep_target_mins": 0.0,
68 "token": "AccessTokenString="
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());
86 fail("GSON returned null");
91 public void testParseLoginFailResponse() {
92 String testReponse = """
94 "traceId": "1634253816",
96 "msg": "password incorrect",
100 VesyncLoginResponse response = VeSyncConstants.GSON.fromJson(testReponse,
101 VesyncLoginResponse.class);
102 if (response != null) {
103 assertEquals("password incorrect", response.msg);
104 assertFalse(response.isMsgSuccess());
106 fail("GSON returned null");