]> git.basschouten.com Git - openhab-addons.git/blob
3d624dd71e2e594424ca3d771d1e91360eff75b1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.homematic.internal.communicator.client;
14
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.*;
20
21 import java.io.IOException;
22
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;
31
32 /**
33  * @author Florian Stolte - Initial contribution
34  */
35 public class RpcClientTest extends JavaTest {
36
37     private RpcClientMockImpl rpcClient;
38
39     @BeforeEach
40     public void setup() throws IOException {
41         this.rpcClient = new RpcClientMockImpl();
42     }
43
44     @Test
45     public void valuesParamsetDescriptionIsLoadedForChannel() throws IOException {
46         HmChannel channel = createDimmerHmChannel();
47
48         rpcClient.addChannelDatapoints(channel, HmParamsetType.VALUES);
49
50         assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_DESCRIPTION_NAME), is(1));
51     }
52
53     @Test
54     public void masterParamsetDescriptionIsLoadedForDummyChannel() throws IOException {
55         HmChannel channel = createDimmerDummyChannel();
56
57         rpcClient.addChannelDatapoints(channel, HmParamsetType.MASTER);
58
59         assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_DESCRIPTION_NAME), is(1));
60     }
61
62     @Test
63     public void valuesParamsetDescriptionIsNotLoadedForDummyChannel() throws IOException {
64         HmChannel channel = createDimmerDummyChannel();
65
66         rpcClient.addChannelDatapoints(channel, HmParamsetType.VALUES);
67
68         assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_DESCRIPTION_NAME), is(0));
69     }
70
71     @Test
72     public void valuesParamsetIsLoadedForChannel() throws IOException {
73         HmChannel channel = createDimmerHmChannel();
74
75         rpcClient.setChannelDatapointValues(channel, HmParamsetType.VALUES);
76
77         assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_NAME), is(1));
78     }
79
80     @Test
81     public void masterParamsetIsLoadedForDummyChannel() throws IOException {
82         HmChannel channel = createDimmerDummyChannel();
83
84         rpcClient.setChannelDatapointValues(channel, HmParamsetType.MASTER);
85
86         assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_NAME), is(1));
87     }
88
89     @Test
90     public void valuesParamsetIsNotLoadedForDummyChannel() throws IOException {
91         HmChannel channel = createDimmerDummyChannel();
92
93         rpcClient.setChannelDatapointValues(channel, HmParamsetType.VALUES);
94
95         assertThat(rpcClient.numberOfCalls.get(GET_PARAMSET_NAME), is(0));
96     }
97
98     @Test
99     public void burstRxModeIsConfiguredAsParameterOnRequest() throws IOException {
100         RpcRequest<String> request = new XmlRpcRequest("setValue");
101
102         rpcClient.configureRxMode(request, RX_BURST_MODE);
103
104         assertThat(request.createMessage(), containsString(String.format("<value>%s</value>", RX_BURST_MODE)));
105     }
106
107     @Test
108     public void wakeupRxModeIsConfiguredAsParameterOnRequest() throws IOException {
109         RpcRequest<String> request = new XmlRpcRequest("setValue");
110
111         rpcClient.configureRxMode(request, RX_WAKEUP_MODE);
112
113         assertThat(request.createMessage(), containsString(String.format("<value>%s</value>", RX_WAKEUP_MODE)));
114     }
115
116     @Test
117     public void rxModeIsNotConfiguredAsParameterOnRequestForNull() throws IOException {
118         RpcRequest<String> request = new XmlRpcRequest("setValue");
119
120         rpcClient.configureRxMode(request, null);
121
122         assertThat(request.createMessage(), not(containsString("<value>")));
123     }
124
125     @Test
126     public void rxModeIsNotConfiguredAsParameterOnRequestForInvalidString() throws IOException {
127         RpcRequest<String> request = new XmlRpcRequest("setValue");
128
129         rpcClient.configureRxMode(request, "SUPER_RX_MODE");
130
131         assertThat(request.createMessage(), not(containsString("<value>")));
132     }
133 }