]> git.basschouten.com Git - openhab-addons.git/blob
adbe511ab27480f73c67de06d346a3da942862a5
[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
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.sleepiq.api.test.AbstractTest;
22 import org.openhab.binding.sleepiq.internal.api.dto.FoundationStatusResponse;
23 import org.openhab.binding.sleepiq.internal.api.enums.FoundationPreset;
24 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
25
26 import com.google.gson.Gson;
27
28 /**
29  * The {@link FoundationStatusResponseTest} tests deserialization of a foundation status
30  * response object.
31  *
32  * @author Mark Hilbush - Initial contribution
33  */
34 @NonNullByDefault
35 public class FoundationStatusResponseTest extends AbstractTest {
36     private static Gson gson = GsonGenerator.create(true);
37
38     @Test
39     public void testDeserializeAllFields() throws Exception {
40         try (FileReader reader = new FileReader(getTestDataFile("foundation-status-response.json"))) {
41             FoundationStatusResponse status = gson.fromJson(reader, FoundationStatusResponse.class);
42
43             assertNotNull(status);
44             assertEquals(0x0f, status.getLeftHeadPosition());
45             assertEquals(0x21, status.getLeftFootPosition());
46             assertEquals(0x0d, status.getRightHeadPosition());
47             assertEquals(0x04, status.getRightFootPosition());
48             assertEquals(FoundationPreset.SNORE, status.getCurrentPositionPresetLeft());
49             assertEquals(FoundationPreset.READ, status.getCurrentPositionPresetRight());
50         }
51     }
52 }