]> git.basschouten.com Git - openhab-addons.git/blob
a333543396d11ecee4a5b9f8e3feb7242cf6cdd1
[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.surepetcare.internal.data;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.surepetcare.internal.SurePetcareConstants;
20 import org.openhab.binding.surepetcare.internal.dto.SurePetcareTopology;
21
22 /**
23  * The {@link SurePetcareTopologyTest} class implements unit test case for {@link SurePetcareTopology}
24  *
25  * @author Rene Scherer - Initial contribution
26  */
27 @NonNullByDefault
28 public class SurePetcareTopologyTest {
29
30     @Test
31     public void testTopologyPopulated() {
32         String testResponse = "{\"devices\":[{\"id\":23912},{\"id\":23481}],\"households\":[{\"id\":83271}],\"pets\":[{\"id\":12345}],\"photos\":[{\"id\":64257,\"version\":\"MA==\",\"created_at\":\"2019-10-04T16:03:20+00:00\",\"updated_at\":\"2019-10-04T16:03:20+00:00\"}],\"user\":{\"id\":33421,\"version\":\"MA==\",\"created_at\":\"2019-09-18T16:09:30+00:00\",\"updated_at\":\"2019-09-18T16:09:30+00:00\"}}";
33         SurePetcareTopology response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareTopology.class);
34
35         if (response != null) {
36             assertNotNull(response.devices);
37             assertEquals(2, response.devices.size());
38             assertNotNull(response.households);
39             assertEquals(1, response.households.size());
40             assertNotNull(response.pets);
41             assertEquals(1, response.pets.size());
42             assertNotNull(response.photos);
43             assertEquals(1, response.photos.size());
44             assertNotNull(response.user);
45         } else {
46             fail("GSON returned null");
47         }
48     }
49
50     @Test
51     public void testTopologyEmpty() {
52         String testResponse = "{}";
53         SurePetcareTopology response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareTopology.class);
54
55         if (response != null) {
56             assertNotNull(response.tags);
57             assertEquals(0, response.tags.size());
58             assertNotNull(response.households);
59             assertEquals(0, response.households.size());
60             assertNotNull(response.pets);
61             assertEquals(0, response.pets.size());
62             assertNotNull(response.devices);
63             assertEquals(0, response.devices.size());
64             assertNull(response.user);
65         } else {
66             fail("GSON returned null");
67         }
68     }
69
70     @Test
71     public void testGetUserNull() {
72         String testResponse = "{\"devices\":[{\"id\":23912},{\"id\":23481}],\"households\":[{\"id\":83271}],\"pets\":[{\"id\":12345}],\"photos\":[{\"id\":64257,\"version\":\"MA==\",\"created_at\":\"2019-10-04T16:03:20+00:00\",\"updated_at\":\"2019-10-04T16:03:20+00:00\"}]}";
73         SurePetcareTopology response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareTopology.class);
74
75         if (response != null) {
76             assertNull(response.user);
77         } else {
78             fail("GSON returned null");
79         }
80     }
81 }