]> git.basschouten.com Git - openhab-addons.git/blob
0d7e830f61b5659c157ada1df90e539525f38290
[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.requests;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
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;
25
26 /**
27  * The {@link VesyncLoginCredentials} class implements unit test case for {@link VesyncLoginResponse}
28  *
29  * @author David Goodyear - Initial contribution
30  */
31 @NonNullByDefault
32 public class VesyncLoginCredentialsTest {
33
34     @Test
35     public void checkMd5Calculation() {
36         assertEquals("577441848f056cd02d4c500b25fdd76a",VesyncV2ApiHelper.calculateMd5("TestHashInPythonLib=+"));
37     }
38
39     @Test
40     public void checkBaseFieldsExist() {
41         String content = VeSyncConstants.GSON.toJson(new VesyncLoginCredentials("username", "passmd5"));
42
43         assertEquals(true, content.contains("\"timeZone\": \"America/New_York\""));
44         assertEquals(true, content.contains("\"acceptLanguage\": \"en\""));
45
46         assertEquals(true, content.contains("\"appVersion\": \"2.5.1\""));
47         assertEquals(true, content.contains("\"phoneBrand\": \"SM N9005\""));
48         assertEquals(true, content.contains("\"phoneOS\": \"Android\""));
49
50         Pattern p = Pattern.compile("\"traceId\": \"\\d+\"");
51         Matcher m = p.matcher(content);
52         assertEquals(true, m.find());
53     }
54
55     @Test
56     public void checkLoginMethodJson() {
57
58         String content = VeSyncConstants.GSON.toJson(new VesyncLoginCredentials("username", "passmd5"));
59
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\": \"\""));
65     }
66 }