]> git.basschouten.com Git - openhab-addons.git/blob
535376a11534ca95b8d805eba7a3ac989d4304b5
[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.ihc.internal.ws;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.Mockito.*;
17
18 import java.net.SocketTimeoutException;
19 import java.nio.charset.StandardCharsets;
20
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;
27
28 /**
29  * Test for IHC / ELKO binding
30  *
31  * @author Pauli Anttila - Initial contribution
32  */
33 public class IhcClientTest {
34
35     private IhcClient ihcClient;
36
37     @BeforeEach
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);
43
44         doReturn(projectInfo).when(ihcClient).getProjectInfo();
45         doReturn(2).when(ihcClient).getProjectNumberOfSegments();
46         doReturn(100).when(ihcClient).getProjectSegmentationSize();
47
48         final String segment0 = ResourceFileUtils.getFileContent("Segment0.base64");
49         final String segment1 = ResourceFileUtils.getFileContent("Segment1.base64");
50
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));
57     }
58
59     @Test
60     public void loadProjectFileFromControllerTest() throws IhcExecption {
61         final String expectedFileContent = ResourceFileUtils.getFileContent("ProjectFileContent.txt");
62
63         final byte[] result = ihcClient.getProjectFileFromController();
64         assertEquals(expectedFileContent, new String(result, StandardCharsets.UTF_8));
65     }
66 }