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.surepetcare.internal.data;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.text.ParseException;
18 import java.time.LocalTime;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.surepetcare.internal.SurePetcareConstants;
23 import org.openhab.binding.surepetcare.internal.dto.SurePetcareDeviceControl;
24 import org.openhab.binding.surepetcare.internal.dto.SurePetcareDeviceCurfew;
25 import org.openhab.binding.surepetcare.internal.dto.SurePetcareDeviceCurfewList;
28 * The {@link SurePetcareDeviceControlTest} class implements unit test case for {@link SurePetcareDeviceControl}
30 * @author Rene Scherer - Initial contribution
33 public class SurePetcareDeviceControlTest {
36 public void testJsonDeserializeCurfewArray() throws ParseException {
37 String testResponse = "{\"curfew\":[{\"enabled\":true,\"lock_time\":\"19:30\",\"unlock_time\":\"07:00\"}],\"locking\":0,\"fast_polling\":false}";
38 SurePetcareDeviceControl response = SurePetcareConstants.GSON.fromJson(testResponse,
39 SurePetcareDeviceControl.class);
40 if (response != null) {
41 assertEquals(1, response.curfewList.size());
42 assertEquals(Integer.valueOf(0), response.lockingModeId);
44 fail("GSON returned null");
49 public void testJsonDeserializeSingleCurfew() throws ParseException {
50 String testResponse = "{\"curfew\":{\"enabled\":true,\"lock_time\":\"19:00\",\"unlock_time\":\"08:00\"},\"fast_polling\":true}";
52 SurePetcareDeviceControl response = SurePetcareConstants.GSON.fromJson(testResponse,
53 SurePetcareDeviceControl.class);
54 if (response != null) {
55 assertEquals(1, response.curfewList.size());
56 assertEquals(true, response.fastPolling);
58 fail("GSON returned null");
63 public void testJsonSerializeLockingMode() throws ParseException {
64 SurePetcareDeviceControl control = new SurePetcareDeviceControl();
65 control.lockingModeId = Integer.valueOf(4);
67 String json = SurePetcareConstants.GSON.toJson(control);
68 assertEquals("{\"locking\":4}", json);
72 public void testJsonSerializeCurfew() throws ParseException {
73 SurePetcareDeviceControl control = new SurePetcareDeviceControl();
74 SurePetcareDeviceCurfewList curfews = new SurePetcareDeviceCurfewList();
75 curfews.add(new SurePetcareDeviceCurfew(true, LocalTime.of(19, 30, 00), LocalTime.of(07, 00, 00)));
76 control.curfewList = curfews;
78 String json = SurePetcareConstants.GSON.toJson(control);
79 assertEquals("{\"curfew\":[{\"enabled\":true,\"lock_time\":\"19:30\",\"unlock_time\":\"07:00\"}]}", json);