2 * Copyright (c) 2010-2022 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.test.util;
15 import java.io.IOException;
16 import java.util.Arrays;
17 import java.util.HashMap;
20 import org.openhab.binding.homematic.internal.common.HomematicConfig;
21 import org.openhab.binding.homematic.internal.communicator.client.RpcClient;
22 import org.openhab.binding.homematic.internal.communicator.message.RpcRequest;
25 * @author Florian Stolte - Initial contribution
27 public class RpcClientMockImpl extends RpcClient<String> {
29 public static final String GET_PARAMSET_DESCRIPTION_NAME = "getParamsetDescription";
30 public static final String GET_PARAMSET_NAME = "getParamset";
32 public Map<String, Integer> numberOfCalls = new HashMap<>();
34 public RpcClientMockImpl() throws IOException {
35 this(new HomematicConfig());
38 public RpcClientMockImpl(HomematicConfig config) throws IOException {
41 Arrays.asList(GET_PARAMSET_DESCRIPTION_NAME, GET_PARAMSET_NAME).forEach(method -> numberOfCalls.put(method, 0));
45 protected Object[] sendMessage(int port, RpcRequest<String> request) throws IOException {
46 String methodName = request.getMethodName();
48 increaseNumberOfCalls(methodName);
50 return mockResponse();
53 private void increaseNumberOfCalls(String methodName) {
54 Integer currentNumber = numberOfCalls.get(methodName);
55 if (currentNumber == null) {
56 numberOfCalls.put(methodName, 1);
58 numberOfCalls.put(methodName, currentNumber + 1);
62 private Object[] mockResponse() {
63 Object[] response = new Object[1];
64 response[0] = new HashMap<>();
69 protected RpcRequest<String> createRpcRequest(String methodName) {
70 return new RpcRequest<String>() {
73 public void addArg(Object arg) {
77 public String createMessage() {
82 public String getMethodName() {
89 public void dispose() {
93 protected String getRpcCallbackUrl() {