]> git.basschouten.com Git - openhab-addons.git/blob
4f3683c87644a36c54c69cc08ec3fb995df1fbb8
[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.yamahareceiver.internal.protocol;
14
15 import static org.junit.jupiter.api.Assertions.assertTrue;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.when;
18 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Zone.Zone_2;
19
20 import java.io.IOException;
21
22 import org.junit.jupiter.api.Test;
23 import org.mockito.Mock;
24 import org.openhab.binding.yamahareceiver.internal.config.YamahaZoneConfig;
25 import org.openhab.binding.yamahareceiver.internal.protocol.xml.AbstractXMLProtocolTest;
26 import org.openhab.binding.yamahareceiver.internal.protocol.xml.DeviceInformationXML;
27 import org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLProtocolFactory;
28 import org.openhab.binding.yamahareceiver.internal.protocol.xml.ZoneBControlXML;
29 import org.openhab.binding.yamahareceiver.internal.protocol.xml.ZoneControlXML;
30 import org.openhab.binding.yamahareceiver.internal.state.DeviceInformationState;
31 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlStateListener;
32
33 /**
34  * Unit test for {@link ProtocolFactory}.
35  *
36  * @author Tomasz Maruszak - Initial contribution
37  */
38 public class XMLProtocolFactoryTest extends AbstractXMLProtocolTest {
39
40     private @Mock YamahaZoneConfig zoneConfig;
41     private @Mock ZoneControlStateListener zoneControlStateListener;
42
43     private DeviceInformationState state = new DeviceInformationState();
44
45     private XMLProtocolFactory subject;
46
47     @Override
48     protected void onSetUp() throws Exception {
49         super.onSetUp();
50
51         when(zoneConfig.getZone()).thenReturn(Zone_2);
52         when(con.sendReceive(eq("<Zone_2><Basic_Status>GetParam</Basic_Status></Zone_2>"))).thenReturn("<xml></xml>");
53
54         subject = new XMLProtocolFactory();
55     }
56
57     @Test
58     public void given_HTR4069_with_ZONEB_then_Zone2_control_is_ZoneBControlXML()
59             throws IOException, ReceivedMessageParseException {
60         // arrange
61         ctx.prepareForModel("HTR-4069");
62
63         DeviceInformationXML deviceInformation = new DeviceInformationXML(con, state);
64         deviceInformation.update();
65
66         // act
67         ZoneControl zoneControl = subject.ZoneControl(con, zoneConfig, zoneControlStateListener, () -> null, state);
68
69         // assert
70         assertTrue(zoneControl instanceof ZoneBControlXML, "Created ZoneB control");
71     }
72
73     @Test
74     public void given_RXS601D_without_ZONEB_then_Zone2_control_is_ZoneControlXML()
75             throws IOException, ReceivedMessageParseException {
76         // arrange
77         ctx.prepareForModel("RX-S601D");
78
79         DeviceInformationXML deviceInformation = new DeviceInformationXML(con, state);
80         deviceInformation.update();
81
82         // act
83         ZoneControl zoneControl = subject.ZoneControl(con, zoneConfig, zoneControlStateListener, () -> null, state);
84
85         // assert
86         assertTrue(zoneControl instanceof ZoneControlXML, "Created Zone control");
87     }
88 }