]> git.basschouten.com Git - openhab-addons.git/blob
30b565454ef61f0f087c2826b59bdb9c0f170e5d
[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.responses;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.fail;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.Test;
20 import org.openhab.binding.vesync.internal.VeSyncConstants;
21 import org.openhab.binding.vesync.internal.dto.responses.VesyncResponse;
22
23 /**
24  * The {@link VesyncResponseTest} class implements unit test case for {@link VesyncResponse}
25  *
26  * @author David Goodyear - Initial contribution
27  */
28 @NonNullByDefault
29 public class VesyncResponseTest {
30
31     @Test
32     public void checkBaseFields() {
33         String baseTestResponse = "{\"traceId\":\"1234569876\",\r\n\"code\": 142,\r\n\"msg\": \"Response Text\"\r\n}";
34         VesyncResponse response = VeSyncConstants.GSON.fromJson(baseTestResponse, VesyncResponse.class);
35         if (response != null) {
36             assertEquals("1234569876", response.getTraceId());
37             assertEquals("142", response.getCode());
38             assertEquals("Response Text", response.msg);
39             assertEquals(false, response.isMsgSuccess());
40         } else {
41             fail("GSON returned null");
42         }
43     }
44
45     @Test
46     public void checkResponseSuccessMsg() {
47         String baseTestResponse = "{\"traceId\":\"1234569876\",\r\n\"code\": 142,\r\n\"msg\": \"request success\"\r\n}";
48         VesyncResponse response = VeSyncConstants.GSON.fromJson(baseTestResponse, VesyncResponse.class);
49         if (response != null) {
50             assertEquals(true, response.isMsgSuccess());
51         } else {
52             fail("GSON returned null");
53         }
54     }
55 }