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.requests;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.Test;
22 import org.openhab.binding.vesync.internal.exceptions.AuthenticationException;
23 import org.openhab.binding.vesync.internal.VeSyncConstants;
24 import org.openhab.binding.vesync.internal.dto.requests.VesyncAuthenticatedRequest;
25 import org.openhab.binding.vesync.internal.dto.requests.VesyncLoginCredentials;
26 import org.openhab.binding.vesync.internal.dto.responses.VesyncLoginResponse;
29 * The {@link VesyncLoginCredentials} class implements unit test case for {@link VesyncLoginResponse}
31 * @author David Goodyear - Initial contribution
34 public class VesyncAuthenticatedRequestTest {
36 public static final VesyncLoginResponse.VesyncUserSession testUser = VeSyncConstants.GSON.fromJson(
37 org.openhab.binding.vesync.internal.handler.responses.VesyncLoginResponseTest.testGoodLoginResponseBody,
38 VesyncLoginResponse.class).result;
41 public void checkBaseFieldsExist() {
42 String content = VeSyncConstants.GSON.toJson(new VesyncLoginCredentials("username", "passmd5"));
44 assertEquals(true, content.contains("\"timeZone\": \"America/New_York\""));
45 assertEquals(true, content.contains("\"acceptLanguage\": \"en\""));
47 assertEquals(true, content.contains("\"appVersion\": \"2.5.1\""));
48 assertEquals(true, content.contains("\"phoneBrand\": \"SM N9005\""));
49 assertEquals(true, content.contains("\"phoneOS\": \"Android\""));
51 Pattern p = Pattern.compile("\"traceId\": \"\\d+\"");
52 Matcher m = p.matcher(content);
53 assertEquals(true, m.find());
57 public void checkAuthenicationData() {
59 // Simulate as the code flow should run - parse data and then use it
60 VesyncLoginResponse response = VeSyncConstants.GSON
61 .fromJson(org.openhab.binding.vesync.internal.handler.responses.VesyncLoginResponseTest.testGoodLoginResponseBody, VesyncLoginResponse.class);
66 content = VeSyncConstants.GSON.toJson(new VesyncAuthenticatedRequest(response.result));
67 } catch (AuthenticationException ae) {
71 assertEquals(true, content.contains("\"token\": \"AccessTokenString=\""));
72 assertEquals(true, content.contains("\"accountID\": \"5328043\""));