]> git.basschouten.com Git - openhab-addons.git/blob
f797add6cc9eeb64cf9c4ca043694b9c53ebcb29
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lametrictime.internal.api.local.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.io.FileInputStream;
18 import java.io.InputStreamReader;
19 import java.nio.charset.StandardCharsets;
20 import java.util.Arrays;
21
22 import org.junit.jupiter.api.BeforeAll;
23 import org.junit.jupiter.api.Test;
24 import org.openhab.binding.lametrictime.internal.api.common.impl.GsonGenerator;
25 import org.openhab.binding.lametrictime.internal.api.test.AbstractTest;
26
27 import com.google.gson.Gson;
28
29 /**
30  * widget updates test.
31  *
32  * @author Gregory Moyer - Initial contribution
33  */
34 public class WidgetUpdatesTest extends AbstractTest {
35     private static Gson gson;
36
37     @BeforeAll
38     public static void setUpBeforeClass() {
39         gson = GsonGenerator.create(true);
40     }
41
42     @Test
43     public void testSerialize() throws Exception {
44         WidgetUpdates widgetUpdates = new WidgetUpdates()
45                 .withFrames(Arrays.asList(new Frame().withIcon("i120").withText("12°").withIndex(0)));
46
47         assertEquals(readJson("widget-updates.json"), gson.toJson(widgetUpdates));
48     }
49
50     @Test
51     public void testDeserialize() throws Exception {
52         try (InputStreamReader reader = new InputStreamReader(
53                 new FileInputStream(getTestDataFile("widget-updates.json")), StandardCharsets.UTF_8)) {
54             WidgetUpdates widgetUpdates = gson.fromJson(reader, WidgetUpdates.class);
55             assertEquals("i120", widgetUpdates.getFrames().get(0).getIcon());
56             assertEquals("12°", widgetUpdates.getFrames().get(0).getText());
57             assertEquals(null, widgetUpdates.getFrames().get(0).getGoalData());
58             assertEquals(null, widgetUpdates.getFrames().get(0).getChartData());
59         }
60     }
61 }