2 * Copyright 2017 Gregory Moyer
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openhab.binding.sleepiq.api.model;
18 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import java.io.FileReader;
21 import java.time.ZoneId;
22 import java.time.ZonedDateTime;
24 import org.junit.jupiter.api.BeforeAll;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
27 import org.openhab.binding.sleepiq.api.test.AbstractTest;
29 import com.google.gson.Gson;
31 public class BedTest extends AbstractTest {
32 private static Gson gson;
35 public static void setUpBeforeClass() {
36 gson = GsonGenerator.create(true);
40 public void testSerializeAllFields() throws Exception {
41 Bed bed = new Bed().withAccountId("-8888888888888888888").withBase("MODULAR").withBedId("-9999999999999999999")
42 .withDualSleep(true).withKidsBed(false).withMacAddress("AABBCCDDEEFF").withModel("P5").withName("Bed")
43 .withPurchaseDate(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()))
44 .withReference("55555555555-5")
45 .withRegistrationDate(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()))
46 .withReturnRequestStatus(0L).withSerial("").withSize("QUEEN").withSku("QP5")
47 .withSleeperLeftId("-2222222222222222222").withSleeperRightId("-1111111111111111111").withStatus(1L)
48 .withTimezone("US/Pacific").withVersion("").withZipCode("90210");
49 assertEquals(readJson("bed.json"), gson.toJson(bed));
53 public void testDeserializeAllFields() throws Exception {
54 try (FileReader reader = new FileReader(getTestDataFile("bed.json"))) {
55 Bed bed = gson.fromJson(reader, Bed.class);
56 assertEquals("-8888888888888888888", bed.getAccountId());
57 assertEquals("MODULAR", bed.getBase());
58 assertEquals("-9999999999999999999", bed.getBedId());
59 assertEquals(true, bed.isDualSleep());
60 assertEquals(false, bed.isKidsBed());
61 assertEquals("AABBCCDDEEFF", bed.getMacAddress());
62 assertEquals("P5", bed.getModel());
63 assertEquals("Bed", bed.getName());
64 assertEquals(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()), bed.getPurchaseDate());
65 assertEquals("55555555555-5", bed.getReference());
66 assertEquals(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()),
67 bed.getRegistrationDate());
68 assertEquals(Long.valueOf(0L), bed.getReturnRequestStatus());
69 assertEquals("", bed.getSerial());
70 assertEquals("QUEEN", bed.getSize());
71 assertEquals("QP5", bed.getSku());
72 assertEquals("-2222222222222222222", bed.getSleeperLeftId());
73 assertEquals("-1111111111111111111", bed.getSleeperRightId());
74 assertEquals(Long.valueOf(1L), bed.getStatus());
75 assertEquals("US/Pacific", bed.getTimezone());
76 assertEquals("", bed.getVersion());
77 assertEquals("90210", bed.getZipCode());