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.VeSyncConstants;
23 import org.openhab.binding.vesync.internal.api.VesyncV2ApiHelper;
24 import org.openhab.binding.vesync.internal.dto.requests.VesyncLoginCredentials;
27 * The {@link VesyncLoginCredentials} class implements unit test case for {@link VesyncLoginResponse}
29 * @author David Goodyear - Initial contribution
32 public class VesyncLoginCredentialsTest {
35 public void checkMd5Calculation() {
36 assertEquals("577441848f056cd02d4c500b25fdd76a",VesyncV2ApiHelper.calculateMd5("TestHashInPythonLib=+"));
40 public void checkBaseFieldsExist() {
41 String content = VeSyncConstants.GSON.toJson(new VesyncLoginCredentials("username", "passmd5"));
43 assertEquals(true, content.contains("\"timeZone\": \"America/New_York\""));
44 assertEquals(true, content.contains("\"acceptLanguage\": \"en\""));
46 assertEquals(true, content.contains("\"appVersion\": \"2.5.1\""));
47 assertEquals(true, content.contains("\"phoneBrand\": \"SM N9005\""));
48 assertEquals(true, content.contains("\"phoneOS\": \"Android\""));
50 Pattern p = Pattern.compile("\"traceId\": \"\\d+\"");
51 Matcher m = p.matcher(content);
52 assertEquals(true, m.find());
56 public void checkLoginMethodJson() {
58 String content = VeSyncConstants.GSON.toJson(new VesyncLoginCredentials("username", "passmd5"));
60 assertEquals(true, content.contains("\"method\": \"login\""));
61 assertEquals(true, content.contains("\"email\": \"username\""));
62 assertEquals(true, content.contains("\"password\": \"passmd5\""));
63 assertEquals(true, content.contains("\"userType\": \"1\""));
64 assertEquals(true, content.contains("\"devToken\": \"\""));