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.homematic.internal.communicator.client;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.hamcrest.MatcherAssert.assertThat;
17 import static org.openhab.binding.homematic.internal.HomematicBindingConstants.*;
18 import static org.openhab.binding.homematic.test.util.DimmerHelper.*;
19 import static org.openhab.binding.homematic.test.util.RpcClientMockImpl.*;
21 import java.io.IOException;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.binding.homematic.internal.communicator.message.RpcRequest;
26 import org.openhab.binding.homematic.internal.communicator.message.XmlRpcRequest;
27 import org.openhab.binding.homematic.internal.model.HmChannel;
28 import org.openhab.binding.homematic.internal.model.HmParamsetType;
29 import org.openhab.binding.homematic.test.util.RpcClientMockImpl;
30 import org.openhab.core.test.java.JavaTest;
33 * @author Florian Stolte - Initial contribution
35 public class RpcClientTest extends JavaTest {
37 private RpcClientMockImpl rpcClient;
40 public void setup() throws IOException {
41 this.rpcClient = new RpcClientMockImpl();
45 public void valuesParamsetDescriptionIsLoadedForChannel() throws IOException {
46 HmChannel channel = createDimmerHmChannel();
48 rpcClient.addChannelDatapoints(channel, HmParamsetType.VALUES);
50 assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_DESCRIPTION_NAME), is(1));
54 public void masterParamsetDescriptionIsLoadedForDummyChannel() throws IOException {
55 HmChannel channel = createDimmerDummyChannel();
57 rpcClient.addChannelDatapoints(channel, HmParamsetType.MASTER);
59 assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_DESCRIPTION_NAME), is(1));
63 public void valuesParamsetDescriptionIsNotLoadedForDummyChannel() throws IOException {
64 HmChannel channel = createDimmerDummyChannel();
66 rpcClient.addChannelDatapoints(channel, HmParamsetType.VALUES);
68 assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_DESCRIPTION_NAME), is(0));
72 public void valuesParamsetIsLoadedForChannel() throws IOException {
73 HmChannel channel = createDimmerHmChannel();
75 rpcClient.setChannelDatapointValues(channel, HmParamsetType.VALUES);
77 assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_NAME), is(1));
81 public void masterParamsetIsLoadedForDummyChannel() throws IOException {
82 HmChannel channel = createDimmerDummyChannel();
84 rpcClient.setChannelDatapointValues(channel, HmParamsetType.MASTER);
86 assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_NAME), is(1));
90 public void valuesParamsetIsNotLoadedForDummyChannel() throws IOException {
91 HmChannel channel = createDimmerDummyChannel();
93 rpcClient.setChannelDatapointValues(channel, HmParamsetType.VALUES);
95 assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_NAME), is(0));
99 public void burstRxModeIsConfiguredAsParameterOnRequest() throws IOException {
100 RpcRequest<String> request = new XmlRpcRequest("setValue");
102 rpcClient.configureRxMode(request, RX_BURST_MODE);
104 assertThat(request.createMessage(), containsString(String.format("<value>%s</value>", RX_BURST_MODE)));
108 public void wakeupRxModeIsConfiguredAsParameterOnRequest() throws IOException {
109 RpcRequest<String> request = new XmlRpcRequest("setValue");
111 rpcClient.configureRxMode(request, RX_WAKEUP_MODE);
113 assertThat(request.createMessage(), containsString(String.format("<value>%s</value>", RX_WAKEUP_MODE)));
117 public void rxModeIsNotConfiguredAsParameterOnRequestForNull() throws IOException {
118 RpcRequest<String> request = new XmlRpcRequest("setValue");
120 rpcClient.configureRxMode(request, null);
122 assertThat(request.createMessage(), not(containsString("<value>")));
126 public void rxModeIsNotConfiguredAsParameterOnRequestForInvalidString() throws IOException {
127 RpcRequest<String> request = new XmlRpcRequest("setValue");
129 rpcClient.configureRxMode(request, "SUPER_RX_MODE");
131 assertThat(request.createMessage(), not(containsString("<value>")));