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.Assert.assertEquals;
20 import java.io.FileReader;
21 import java.time.ZoneId;
22 import java.time.ZonedDateTime;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.openhab.binding.sleepiq.api.impl.GsonGenerator;
27 import org.openhab.binding.sleepiq.api.model.Bed;
28 import org.openhab.binding.sleepiq.api.test.AbstractTest;
30 import com.google.gson.Gson;
32 public class BedTest extends AbstractTest
34 private static Gson gson;
37 public static void setUpBeforeClass()
39 gson = GsonGenerator.create(true);
43 public void testSerializeAllFields() throws Exception
45 Bed bed = new Bed().withAccountId("-8888888888888888888")
47 .withBedId("-9999999999999999999")
50 .withMacAddress("AABBCCDDEEFF")
53 .withPurchaseDate(ZonedDateTime.of(2017,
60 ZoneId.of("Z").normalized()))
61 .withReference("55555555555-5")
62 .withRegistrationDate(ZonedDateTime.of(2017,
69 ZoneId.of("Z").normalized()))
70 .withReturnRequestStatus(0L)
74 .withSleeperLeftId("-2222222222222222222")
75 .withSleeperRightId("-1111111111111111111")
77 .withTimezone("US/Pacific")
79 .withZipCode("90210");
80 assertEquals(readJson("bed.json"), gson.toJson(bed));
84 public void testDeserializeAllFields() throws Exception
86 try (FileReader reader = new FileReader(getTestDataFile("bed.json")))
88 Bed bed = gson.fromJson(reader, Bed.class);
89 assertEquals("-8888888888888888888", bed.getAccountId());
90 assertEquals("MODULAR", bed.getBase());
91 assertEquals("-9999999999999999999", bed.getBedId());
92 assertEquals(true, bed.isDualSleep());
93 assertEquals(false, bed.isKidsBed());
94 assertEquals("AABBCCDDEEFF", bed.getMacAddress());
95 assertEquals("P5", bed.getModel());
96 assertEquals("Bed", bed.getName());
97 assertEquals(ZonedDateTime.of(2017, 2, 2, 0, 0, 1, 0, ZoneId.of("Z").normalized()),
98 bed.getPurchaseDate());
99 assertEquals("55555555555-5", bed.getReference());
100 assertEquals(ZonedDateTime.of(2017, 2, 17, 2, 14, 10, 0, ZoneId.of("Z").normalized()),
101 bed.getRegistrationDate());
102 assertEquals(Long.valueOf(0L), bed.getReturnRequestStatus());
103 assertEquals("", bed.getSerial());
104 assertEquals("QUEEN", bed.getSize());
105 assertEquals("QP5", bed.getSku());
106 assertEquals("-2222222222222222222", bed.getSleeperLeftId());
107 assertEquals("-1111111111111111111", bed.getSleeperRightId());
108 assertEquals(Long.valueOf(1L), bed.getStatus());
109 assertEquals("US/Pacific", bed.getTimezone());
110 assertEquals("", bed.getVersion());
111 assertEquals("90210", bed.getZipCode());