]> git.basschouten.com Git - openhab-addons.git/blob
fd3ef99d8e91cd81748f8a72de4c667328f5e099
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.Assert.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.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     @Mock
41     private YamahaZoneConfig zoneConfig;
42
43     @Mock
44     private ZoneControlStateListener zoneControlStateListener;
45
46     private DeviceInformationState state = new DeviceInformationState();
47
48     private XMLProtocolFactory subject;
49
50     @Override
51     protected void onSetUp() throws Exception {
52         super.onSetUp();
53
54         when(zoneConfig.getZone()).thenReturn(Zone_2);
55         when(con.sendReceive(eq("<Zone_2><Basic_Status>GetParam</Basic_Status></Zone_2>"))).thenReturn("<xml></xml>");
56
57         subject = new XMLProtocolFactory();
58     }
59
60     @Test
61     public void given_HTR4069_with_ZONEB_then_Zone2_control_is_ZoneBControlXML()
62             throws IOException, ReceivedMessageParseException {
63         // arrange
64         ctx.prepareForModel("HTR-4069");
65
66         DeviceInformationXML deviceInformation = new DeviceInformationXML(con, state);
67         deviceInformation.update();
68
69         // act
70         ZoneControl zoneControl = subject.ZoneControl(con, zoneConfig, zoneControlStateListener, () -> null, state);
71
72         // assert
73         assertTrue("Created ZoneB control", zoneControl instanceof ZoneBControlXML);
74     }
75
76     @Test
77     public void given_RXS601D_without_ZONEB_then_Zone2_control_is_ZoneControlXML()
78             throws IOException, ReceivedMessageParseException {
79         // arrange
80         ctx.prepareForModel("RX-S601D");
81
82         DeviceInformationXML deviceInformation = new DeviceInformationXML(con, state);
83         deviceInformation.update();
84
85         // act
86         ZoneControl zoneControl = subject.ZoneControl(con, zoneConfig, zoneControlStateListener, () -> null, state);
87
88         // assert
89         assertTrue("Created Zone control", zoneControl instanceof ZoneControlXML);
90     }
91 }