]> git.basschouten.com Git - openhab-addons.git/blob
6dd01daeb0de8a3a4b25ffc15265bf47060290f9
[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.sleepiq.api.model;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.FileReader;
18 import java.util.Arrays;
19 import java.util.List;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.sleepiq.api.test.AbstractTest;
24 import org.openhab.binding.sleepiq.internal.api.dto.BedStatus;
25 import org.openhab.binding.sleepiq.internal.api.dto.FamilyStatusResponse;
26 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
27
28 import com.google.gson.Gson;
29
30 /**
31  * The {@link FamilyStatusText} tests deserialization of a family status object.
32  *
33  * @author Gregory Moyer - Initial contribution
34  */
35 @NonNullByDefault
36 public class FamilyStatusTest extends AbstractTest {
37     private static Gson gson = GsonGenerator.create(true);
38
39     @Test
40     public void testSerializeAllFields() throws Exception {
41         FamilyStatusResponse familyStatus = new FamilyStatusResponse()
42                 .withBeds(Arrays.asList(new BedStatus().withStatus(1L)));
43         assertEquals(readJson("family-status.json"), gson.toJson(familyStatus));
44     }
45
46     @Test
47     public void testDeserializeAllFields() throws Exception {
48         try (FileReader reader = new FileReader(getTestDataFile("family-status.json"))) {
49             FamilyStatusResponse familyStatus = gson.fromJson(reader, FamilyStatusResponse.class);
50
51             List<BedStatus> beds = familyStatus.getBeds();
52             assertNotNull(beds);
53             assertEquals(1, beds.size());
54             assertEquals(Long.valueOf(1L), beds.get(0).getStatus());
55         }
56     }
57 }