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