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.lametrictime.internal.api.local.dto;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.io.FileReader;
18 import java.util.Arrays;
20 import org.junit.jupiter.api.BeforeAll;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.lametrictime.internal.api.common.impl.GsonGenerator;
23 import org.openhab.binding.lametrictime.internal.api.test.AbstractTest;
25 import com.google.gson.Gson;
30 * @author Gregory Moyer - Initial contribution
32 public class FrameTest extends AbstractTest {
33 private static Gson gson;
36 public static void setUpBeforeClass() {
37 gson = GsonGenerator.create(true);
41 public void testSerializeSimple() throws Exception {
42 Frame frame = new Frame().withIcon("i87").withText("Hello world!");
43 assertEquals(readJson("frame-simple.json"), gson.toJson(frame));
47 public void testSerializeGoal() throws Exception {
48 Frame frame = new Frame().withIcon("i120").withGoalData(new GoalData());
49 assertEquals(readJson("frame-goal.json"), gson.toJson(frame));
53 public void testSerializeChart() throws Exception {
54 Frame frame = new Frame().withChartData(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
55 assertEquals(readJson("frame-chart.json"), gson.toJson(frame));
59 public void testDeserializeSimple() throws Exception {
60 try (FileReader reader = new FileReader(getTestDataFile("frame-simple.json"))) {
61 Frame frame = gson.fromJson(reader, Frame.class);
62 assertEquals("i87", frame.getIcon());
63 assertEquals("Hello world!", frame.getText());
64 assertEquals(null, frame.getGoalData());
65 assertEquals(null, frame.getChartData());
70 public void testDeserializeGoal() throws Exception {
71 try (FileReader reader = new FileReader(getTestDataFile("frame-goal.json"))) {
72 Frame frame = gson.fromJson(reader, Frame.class);
73 assertEquals("i120", frame.getIcon());
74 assertEquals(new GoalData(), frame.getGoalData());
79 public void testDeserializeChart() throws Exception {
80 try (FileReader reader = new FileReader(getTestDataFile("frame-chart.json"))) {
81 Frame frame = gson.fromJson(reader, Frame.class);
82 assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7), frame.getChartData());