2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sleepiq.api.model;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.io.FileReader;
18 import java.time.ZoneId;
19 import java.time.ZonedDateTime;
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.Bed;
25 import org.openhab.binding.sleepiq.internal.api.impl.GsonGenerator;
27 import com.google.gson.Gson;
30 * The {@link BedTest} tests deserialization of a bed object.
32 * @author Gregory Moyer - Initial contribution
35 public class BedTest extends AbstractTest {
36 private static Gson gson = GsonGenerator.create(true);
39 public void testSerializeAllFields() throws Exception {
40 Bed bed = new Bed().withAccountId("-8888888888888888888").withBase("MODULAR").withBedId("-9999999999999999999")
41 .withDualSleep(true).withKidsBed(false).withMacAddress("AABBCCDDEEFF").withModel("P5").withName("Bed")
42 .withPurchaseDate(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()))
43 .withReference("55555555555-5")
44 .withRegistrationDate(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()))
45 .withReturnRequestStatus(0L).withSerial("").withSize("QUEEN").withSku("QP5")
46 .withSleeperLeftId("-2222222222222222222").withSleeperRightId("-1111111111111111111").withStatus(1L)
47 .withTimezone("US/Pacific").withVersion("").withZipCode("90210");
48 assertEquals(readJson("bed.json"), gson.toJson(bed));
52 public void testDeserializeAllFields() throws Exception {
53 try (FileReader reader = new FileReader(getTestDataFile("bed.json"))) {
54 Bed bed = gson.fromJson(reader, Bed.class);
55 assertEquals("-8888888888888888888", bed.getAccountId());
56 assertEquals("MODULAR", bed.getBase());
57 assertEquals("-9999999999999999999", bed.getBedId());
58 assertEquals(true, bed.isDualSleep());
59 assertEquals(false, bed.isKidsBed());
60 assertEquals("AABBCCDDEEFF", bed.getMacAddress());
61 assertEquals("P5", bed.getModel());
62 assertEquals("Bed", bed.getName());
63 assertEquals(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()), bed.getPurchaseDate());
64 assertEquals("55555555555-5", bed.getReference());
65 assertEquals(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()),
66 bed.getRegistrationDate());
67 assertEquals(Long.valueOf(0L), bed.getReturnRequestStatus());
68 assertEquals("", bed.getSerial());
69 assertEquals("QUEEN", bed.getSize());
70 assertEquals("QP5", bed.getSku());
71 assertEquals("-2222222222222222222", bed.getSleeperLeftId());
72 assertEquals("-1111111111111111111", bed.getSleeperRightId());
73 assertEquals(Long.valueOf(1L), bed.getStatus());
74 assertEquals("US/Pacific", bed.getTimezone());
75 assertEquals("", bed.getVersion());
76 assertEquals("90210", bed.getZipCode());