]> git.basschouten.com Git - openhab-addons.git/blob
fe148be14bba8d4f36a058339655369a03814578
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.*;
16
17 import java.io.FileReader;
18 import java.util.TreeMap;
19
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;
24
25 import com.google.gson.Gson;
26
27 /**
28  * update action test.
29  *
30  * @author Gregory Moyer - Initial contribution
31  */
32 public class UpdateActionTest extends AbstractTest {
33     private static Gson gson;
34
35     @BeforeAll
36     public static void setUpBeforeClass() {
37         gson = GsonGenerator.create(true);
38     }
39
40     @Test
41     @SuppressWarnings("serial")
42     public void testSerialize() throws Exception {
43         UpdateAction action = new UpdateAction().withId("countdown.configure")
44         // @formatter:off
45                                                 .withParameters(new TreeMap<String, Parameter>(){{put("duration", new IntegerParameter().withValue(30));}});
46                                                 // @formatter:on
47         assertEquals(readJson("update-action.json"), gson.toJson(action));
48     }
49
50     @Test
51     public void testDeserialize() throws Exception {
52         try (FileReader reader = new FileReader(getTestDataFile("update-action.json"))) {
53             assertThrows(UnsupportedOperationException.class, () -> gson.fromJson(reader, UpdateAction.class));
54         }
55     }
56 }