]> git.basschouten.com Git - openhab-addons.git/blob
a1656c6d3e8eb2fc9a56b15de99b26edbe1a44e8
[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.max.internal.command;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.util.ArrayList;
18 import java.util.List;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.junit.jupiter.api.Test;
22 import org.openhab.binding.max.internal.device.Device;
23 import org.openhab.binding.max.internal.device.DeviceConfiguration;
24 import org.openhab.binding.max.internal.device.RoomInformation;
25 import org.openhab.binding.max.internal.message.CMessage;
26
27 /**
28  * Tests cases for {@link MCommand}.
29  *
30  * @author Marcel Verpaalen - Initial contribution
31  */
32 @NonNullByDefault
33 public class MCommandTest {
34
35     private List<DeviceConfiguration> configurations = new ArrayList<>();
36     private List<Device> devices = new ArrayList<>();
37     private List<RoomInformation> rooms = new ArrayList<>();
38
39     String deviceCMsg[] = {
40             "C:0b0da3,0gsNowIBEABLRVEwNTQ0MjQyLCQ9CQcYAzAM/wBIYViRSP1ZFE0gTSBNIEUgRSBFIEUgRSBFIEhhWJFQ/VkVUSBRIFEgRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIEhQWFpI/lkUTSBNIE0gRSBFIEUgRSBFIEUgSFBYWkj+WRRNIE0gTSBFIEUgRSBFIEUgRSBIUFhaSP5ZFE0gTSBNIEUgRSBFIEUgRSBFIA==",
41             "C:08c1d6,0gjB1gEFGP9LRVEwNjQ5MzEyKyE9CQcYAzAM/wBEeFUgVSBVIFUgVSBVIEUgRSBFIEUgRSBFIER4VRZFIEUgRSBFIEUgRSBFIEUgRSBFIEUgRFFEYkTkTQ9FIEUgRSBFIEUgRSBFIEUgRSBEUURiRORND0UgRSBFIEUgRSBFIEUgRSBFIERRRGJE5E0PRSBFIEUgRSBFIEUgRSBFIEUgRFFEYkTkTQ9FIEUgRSBFIEUgRSBFIEUgRSBEUURiRORRGEUgRSBFIEUgRSBFIEUgRSBFIA==",
42             "C:0e75f6,EQ519gQCEABLRVExMTA0Mzgw",
43             "C:0f1d54,0g8dVAEAEKBMRVEwMTU1NTc4KiI9CQcYAzAM/wBESFUIRSBFIEUgRSBFIEUgRSBFIEUgRSBFIERIVQhFIEUgRSBFIEUgRSBFIEUgRSBFIEUgREhUbETMVRRFIEUgRSBFIEUgRSBFIEUgRSBESFRsRMxVFEUgRSBFIEUgRSBFIEUgRSBFIERIVGxEzFUURSBFIEUgRSBFIEUgRSBFIEUgREhUbETMVRRFIEUgRSBFIEUgRSBFIEUgRSBESFRsRMxVFEUgRSBFIEUgRSBFIEUgRSBFIA==" };
44
45     private void prepareDevices() {
46         // create a devices array
47         for (String cMsg : deviceCMsg) {
48             CMessage msg = new CMessage(cMsg);
49             // DeviceConfiguration c = null;
50             configurations.add(DeviceConfiguration.create(msg));
51             Device di = Device.create(msg.getRFAddress(), configurations);
52             devices.add(di);
53         }
54     }
55
56     @Test
57     public void prefixTest() {
58         prepareDevices();
59         MCommand mcmd = new MCommand(devices);
60         String commandStr = mcmd.getCommandString();
61
62         String prefix = commandStr.substring(0, 2);
63         assertEquals("m:", prefix);
64     }
65
66     @Test
67     public void baseCommandTest() {
68         prepareDevices();
69
70         MCommand mCmd = new MCommand(devices);
71         rooms = new ArrayList<>(mCmd.getRooms());
72         String commandStr = mCmd.getCommandString();
73         assertEquals(
74                 "m:00,VgIDAQALDaMCAA519gUACMHWBAILDaNLRVEwNTQ0MjQyAAEBCMHWS0VRMDY0OTMxMgAFBA519ktFUTExMDQzODAAAgEPHVRMRVEwMTU1NTc4AAAB\r\n",
75                 commandStr);
76     }
77
78     @Test
79     public void addRoomsTest() {
80         prepareDevices();
81
82         MCommand mCmd = new MCommand(devices);
83         rooms = new ArrayList<>(mCmd.getRooms());
84
85         RoomInformation room = new RoomInformation(3, "testroom", "0f1d54");
86         rooms.add(room);
87         mCmd = new MCommand(devices, rooms);
88         String commandStr = mCmd.getCommandString();
89         assertEquals(
90                 "m:00,VgIEAQALDaMCAA519gMIdGVzdHJvb20PHVQFAAjB1gQCCw2jS0VRMDU0NDI0MgABAQjB1ktFUTA2NDkzMTIABQQOdfZLRVExMTA0MzgwAAIBDx1UTEVRMDE1NTU3OAAAAQ==\r\n",
91                 commandStr);
92         devices.get(3).setRoomId(3);
93         devices.get(3).setName("Testroom");
94
95         mCmd = new MCommand(devices, rooms);
96         commandStr = mCmd.getCommandString();
97
98         assertEquals(
99                 "m:00,VgIEAQALDaMCAA519gMIdGVzdHJvb20PHVQFAAjB1gQCCw2jS0VRMDU0NDI0MgABAQjB1ktFUTA2NDkzMTIABQQOdfZLRVExMTA0MzgwAAIBDx1UTEVRMDE1NTU3OAhUZXN0cm9vbQMB\r\n",
100                 commandStr);
101     }
102 }