]> git.basschouten.com Git - openhab-addons.git/blob
10d0c5434829ecfb775f2783ff6eec5438b79791
[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 org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.Test;
19 import org.openhab.binding.vesync.internal.exceptions.AuthenticationException;
20 import org.openhab.binding.vesync.internal.VeSyncConstants;
21 import org.openhab.binding.vesync.internal.dto.requests.VesyncLoginCredentials;
22 import org.openhab.binding.vesync.internal.dto.requests.VesyncRequestManagedDevicesPage;
23
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26
27 /**
28  * The {@link VesyncRequestManagedDevicesPageTest} class implements unit test case for
29  * {@link VesyncRequestManagedDevicesPage}
30  *
31  * @author David Goodyear - Initial contribution
32  */
33 @NonNullByDefault
34 public class VesyncRequestManagedDevicesPageTest {
35
36     @Test
37     public void checkBaseFieldsExist() {
38         String content = VeSyncConstants.GSON.toJson(new VesyncLoginCredentials("username", "passmd5"));
39
40         assertEquals(true, content.contains("\"timeZone\": \"America/New_York\""));
41         assertEquals(true, content.contains("\"acceptLanguage\": \"en\""));
42
43         assertEquals(true, content.contains("\"appVersion\": \"2.5.1\""));
44         assertEquals(true, content.contains("\"phoneBrand\": \"SM N9005\""));
45         assertEquals(true, content.contains("\"phoneOS\": \"Android\""));
46
47         Pattern p = Pattern.compile("\"traceId\": \"\\d+\"");
48         Matcher m = p.matcher(content);
49         assertEquals(true, m.find());
50     }
51
52     @Test
53     public void checkRequestDevicesFields() {
54
55         String content = "";
56         try {
57             content = VeSyncConstants.GSON
58                     .toJson(new VesyncRequestManagedDevicesPage(org.openhab.binding.vesync.internal.handler.requests.VesyncAuthenticatedRequestTest.testUser, 1, 100));
59         } catch (AuthenticationException ae) {
60
61         }
62
63
64         assertEquals(true, content.contains("\"method\": \"devices\""));
65         assertEquals(true, content.contains("\"pageNo\": \"1\""));
66         assertEquals(true, content.contains("\"pageSize\": \"100\""));
67         assertEquals(true, content.contains("\"token\": \"AccessTokenString=\""));
68         assertEquals(true, content.contains("\"accountID\": \"5328043\""));
69     }
70 }