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.ihc.internal.ws;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
18 import java.net.SocketTimeoutException;
19 import java.nio.charset.StandardCharsets;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.mockito.ArgumentMatchers;
24 import org.openhab.binding.ihc.internal.ws.datatypes.WSFile;
25 import org.openhab.binding.ihc.internal.ws.datatypes.WSProjectInfo;
26 import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
29 * Test for IHC / ELKO binding
31 * @author Pauli Anttila - Initial contribution
33 public class IhcClientTest {
35 private IhcClient ihcClient;
38 public void setUp() throws IhcExecption, SocketTimeoutException {
39 ihcClient = spy(new IhcClient("test1", "test2", "test3"));
40 WSProjectInfo projectInfo = new WSProjectInfo();
41 projectInfo.setProjectMajorRevision(111);
42 projectInfo.setProjectMinorRevision(222);
44 doReturn(projectInfo).when(ihcClient).getProjectInfo();
45 doReturn(2).when(ihcClient).getProjectNumberOfSegments();
46 doReturn(100).when(ihcClient).getProjectSegmentationSize();
48 final String segment0 = ResourceFileUtils.getFileContent("Segment0.base64");
49 final String segment1 = ResourceFileUtils.getFileContent("Segment1.base64");
51 WSFile file0 = new WSFile(segment0.getBytes(), "");
52 doReturn(file0).when(ihcClient).getProjectSegment(ArgumentMatchers.eq(0), ArgumentMatchers.eq(111),
53 ArgumentMatchers.eq(222));
54 WSFile file1 = new WSFile(segment1.getBytes(), "");
55 doReturn(file1).when(ihcClient).getProjectSegment(ArgumentMatchers.eq(1), ArgumentMatchers.eq(111),
56 ArgumentMatchers.eq(222));
60 public void loadProjectFileFromControllerTest() throws IhcExecption {
61 final String expectedFileContent = ResourceFileUtils.getFileContent("ProjectFileContent.txt");
63 final byte[] result = ihcClient.getProjectFileFromController();
64 assertEquals(expectedFileContent, new String(result, StandardCharsets.UTF_8));