2 * Copyright 2017-2018 Gregory Moyer and contributors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openhab.binding.lametrictime.api.local.model;
18 import static org.junit.jupiter.api.Assertions.*;
20 import java.io.FileReader;
21 import java.util.Iterator;
22 import java.util.SortedMap;
23 import java.util.TreeMap;
25 import org.junit.jupiter.api.BeforeAll;
26 import org.junit.jupiter.api.Test;
27 import org.openhab.binding.lametrictime.api.common.impl.GsonGenerator;
28 import org.openhab.binding.lametrictime.api.test.AbstractTest;
30 import com.google.gson.Gson;
32 public class ActionTest extends AbstractTest
34 private static Gson gson;
37 public static void setUpBeforeClass()
39 gson = GsonGenerator.create(true);
43 @SuppressWarnings("serial")
44 public void testSerialize() throws Exception
47 Action action = new Action().withParameters(new TreeMap<String, Parameter>(){{put("enabled", new BooleanParameter());
48 put("time", new StringParameter());}});
50 assertEquals(readJson("action.json"), gson.toJson(action));
54 public void testDeserialize() throws Exception
56 try (FileReader reader = new FileReader(getTestDataFile("action.json")))
58 Action action = gson.fromJson(reader, Action.class);
59 SortedMap<String, Parameter> parameters = action.getParameters();
60 assertNotNull(parameters);
61 assertEquals(2, parameters.size());
63 Iterator<String> parametersIter = parameters.keySet().iterator();
64 assertEquals("enabled", parametersIter.next());
65 assertEquals("time", parametersIter.next());