2 * Copyright (c) 2010-2024 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.*;
17 import java.io.FileReader;
18 import java.util.Iterator;
19 import java.util.SortedMap;
20 import java.util.TreeMap;
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;
27 import com.google.gson.Gson;
32 * @author Gregory Moyer - Initial contribution
34 public class ActionTest extends AbstractTest {
35 private static Gson gson;
38 public static void setUpBeforeClass() {
39 gson = GsonGenerator.create(true);
43 @SuppressWarnings("serial")
44 public void testSerialize() throws Exception {
46 Action action = new Action().withParameters(new TreeMap<String, Parameter>(){{put("enabled", new BooleanParameter());
47 put("time", new StringParameter());}});
49 assertEquals(readJson("action.json"), gson.toJson(action));
53 public void testDeserialize() throws Exception {
54 try (FileReader reader = new FileReader(getTestDataFile("action.json"))) {
55 Action action = gson.fromJson(reader, Action.class);
56 SortedMap<String, Parameter> parameters = action.getParameters();
57 assertNotNull(parameters);
58 assertEquals(2, parameters.size());
60 Iterator<String> parametersIter = parameters.keySet().iterator();
61 assertEquals("enabled", parametersIter.next());
62 assertEquals("time", parametersIter.next());