2 * Copyright (c) 2010-2020 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.yamahareceiver.internal.protocol.xml;
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.mockito.ArgumentMatchers.eq;
18 import static org.mockito.Mockito.verify;
19 import static org.openhab.binding.yamahareceiver.internal.TestModels.*;
20 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Zone.Main_Zone;
22 import org.junit.Test;
23 import org.mockito.ArgumentCaptor;
24 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlState;
27 * Unit test for {@link ZoneControlXML}.
29 * @author Tomasz Maruszak - Initial contribution
31 public class ZoneControlXMLTest extends AbstractZoneControlXMLTest {
33 private ZoneControlXML subject;
35 private void given(String model) throws Exception {
36 ctx.prepareForModel(model);
38 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
39 deviceInformation.update();
41 subject = new ZoneControlXML(con, Main_Zone, zoneConfig, zoneControlStateListener, deviceInformationState,
42 () -> inputConverter);
46 public void given_RX_S601D_when_power_then_sendsProperCommand() throws Exception {
47 when_power_then_sendsProperCommand(RX_S601D);
51 public void given_RX_V3900_when_power_then_sendsProperCommand() throws Exception {
52 when_power_then_sendsProperCommand(RX_V3900);
55 private void when_power_then_sendsProperCommand(String model) throws Exception {
59 subject.setPower(true);
60 subject.setPower(false);
63 verify(con).send(eq("<Main_Zone><Power_Control><Power>On</Power></Power_Control></Main_Zone>"));
64 verify(con).send(eq("<Main_Zone><Power_Control><Power>Standby</Power></Power_Control></Main_Zone>"));
68 public void given_RX_S601D_when_mute_then_sendsProperCommand() throws Exception {
72 subject.setMute(true);
73 subject.setMute(false);
76 verify(con).send(eq("<Main_Zone><Volume><Mute>On</Mute></Volume></Main_Zone>"));
77 verify(con).send(eq("<Main_Zone><Volume><Mute>Off</Mute></Volume></Main_Zone>"));
81 public void given_RX_V3900_when_mute_then_sendsProperCommand() throws Exception {
85 subject.setMute(true);
86 subject.setMute(false);
89 verify(con).send(eq("<Main_Zone><Vol><Mute>On</Mute></Vol></Main_Zone>"));
90 verify(con).send(eq("<Main_Zone><Vol><Mute>Off</Mute></Vol></Main_Zone>"));
94 public void given_RX_S601D_when_volume_then_sendsProperCommand() throws Exception {
98 subject.setVolumeDB(-2);
102 eq("<Main_Zone><Volume><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone>"));
106 public void given_RX_V3900_when_volume_then_sendsProperCommand() throws Exception {
110 subject.setVolumeDB(-2);
113 verify(con).send(eq("<Main_Zone><Vol><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Vol></Main_Zone>"));
117 public void given_RX_S601D_when_input_then_sendsProperCommand() throws Exception {
118 when_input_then_sendsProperCommand(RX_S601D);
122 public void given_RX_V3900_when_input_then_sendsProperCommand() throws Exception {
123 when_input_then_sendsProperCommand(RX_V3900);
126 private void when_input_then_sendsProperCommand(String model) throws Exception {
130 subject.setInput("HDMI1");
133 verify(con).send(eq("<Main_Zone><Input><Input_Sel>HDMI1</Input_Sel></Input></Main_Zone>"));
137 public void given_RX_S601D_when_surroundProgram_then_sendsProperCommand() throws Exception {
141 subject.setSurroundProgram("Adventure");
145 "<Main_Zone><Surround><Program_Sel><Current><Sound_Program>Adventure</Sound_Program></Current></Program_Sel></Surround></Main_Zone>"));
149 public void given_RX_V3900_when_surroundProgram_then_sendsProperCommand() throws Exception {
153 subject.setSurroundProgram("Adventure");
157 "<Main_Zone><Surr><Pgm_Sel><Straight>Off</Straight><Pgm>Adventure</Pgm></Pgm_Sel></Surr></Main_Zone>"));
161 public void given_RX_S601D_when_surroundProgramStraight_then_sendsProperCommand() throws Exception {
165 subject.setSurroundProgram("Straight");
169 "<Main_Zone><Surround><Program_Sel><Current><Straight>On</Straight></Current></Program_Sel></Surround></Main_Zone>"));
173 public void given_RX_V3900_when_surroundProgramStraight_then_sendsProperCommand() throws Exception {
177 subject.setSurroundProgram("Straight");
180 verify(con).send(eq("<Main_Zone><Surr><Pgm_Sel><Straight>On</Straight></Pgm_Sel></Surr></Main_Zone>"));
184 public void given_HTR_4069_when_dialogueLevel_then_sendsProperCommand() throws Exception {
188 subject.setDialogueLevel(10);
192 "<Main_Zone><Sound_Video><Dialogue_Adjust><Dialogue_Lvl>10</Dialogue_Lvl></Dialogue_Adjust></Sound_Video></Main_Zone>"));
196 public void given_RX_S601D_when_update_then_readsStateProperly() throws Exception {
203 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
204 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
206 ZoneControlState state = stateArg.getValue();
207 assertNotNull(state);
209 assertEquals(false, state.power);
210 assertEquals(false, state.mute);
211 assertEquals(-43, state.volumeDB, 0);
212 assertEquals("Spotify", state.inputID);
213 assertEquals("5ch Stereo", state.surroundProgram);
214 // this model does not support dialogue level
215 assertEquals(0, state.dialogueLevel);
219 public void given_RX_V3900_when_update_then_readsStateProperly() throws Exception {
226 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
227 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
229 ZoneControlState state = stateArg.getValue();
230 assertNotNull(state);
232 assertEquals(true, state.power);
233 assertEquals(false, state.mute);
234 assertEquals(-46, state.volumeDB, 0);
235 assertEquals("TV", state.inputID);
236 assertEquals("2ch Stereo", state.surroundProgram);
237 // this model does not support dialogue level
238 assertEquals(0, state.dialogueLevel);
242 public void given_HTR_4069_when_update_then_readsStateProperly() throws Exception {
249 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
250 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
252 ZoneControlState state = stateArg.getValue();
253 assertNotNull(state);
255 assertEquals(false, state.power);
256 assertEquals(false, state.mute);
257 assertEquals(-46, state.volumeDB, 0);
258 assertEquals("TUNER", state.inputID);
259 assertEquals("5ch Stereo", state.surroundProgram);
260 assertEquals(1, state.dialogueLevel);