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.bsblan.internal.api;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterDTO;
20 import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterQueryResponseDTO;
21 import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterSetRequestDTO;
22 import org.openhab.binding.bsblan.internal.api.dto.BsbLanApiParameterSetRequestDTO.Type;
24 import com.google.gson.JsonObject;
25 import com.google.gson.JsonParser;
28 * The {@link BsbLanApiContentConverterTests} class implements tests
29 * for {@link BsbLanApiContentConverter}.
31 * @author Peter Schraffl - Initial contribution
34 public class BsbLanApiContentConverterTests {
37 public void parseBsbLanApiParameterQueryResponse() {
41 "name": "Betriebsart",
44 "desc": "Schutzbetrieb",
50 BsbLanApiParameterQueryResponseDTO r = BsbLanApiContentConverter.fromJson(content,
51 BsbLanApiParameterQueryResponseDTO.class);
53 assertTrue(r.containsKey(700));
55 BsbLanApiParameterDTO p = r.get(700);
56 assertEquals("Betriebsart", p.name);
57 assertEquals("0", p.value);
58 assertEquals("", p.unit);
59 assertEquals("Schutzbetrieb", p.description);
60 assertEquals(BsbLanApiParameterDTO.DataType.DT_ENUM, p.dataType);
64 public void serializeBsbLanApiParameterSetRequest() {
65 BsbLanApiParameterSetRequestDTO request = new BsbLanApiParameterSetRequestDTO();
66 request.parameter = "1234";
67 request.value = "Hello World";
68 request.type = Type.SET;
70 String serializedRequest = BsbLanApiContentConverter.toJson(request);
72 // verify serialized content
73 JsonObject json = JsonParser.parseString(serializedRequest).getAsJsonObject();
75 // Although specifying the parameter as int (which would be nicer) also seems to work,
76 // we use a String here as this is the way it is noted in the documentation.
77 // So ensure there is a 'Parameter' and it is serialized as string.
78 assertEquals("1234", json.get("Parameter").getAsString());
80 // ensure there is a 'Value' and it is serialized as string
81 assertEquals("Hello World", json.get("Value").getAsString());
83 // ensure there is a 'Type' and it is serialized as number
84 assertEquals(1, json.get("Type").getAsInt());