2 * Copyright (c) 2010-2023 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.jupiter.api.Assertions.*;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.verify;
18 import static org.openhab.binding.yamahareceiver.internal.TestModels.*;
19 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Zone.Main_Zone;
21 import org.junit.jupiter.api.Test;
22 import org.mockito.ArgumentCaptor;
23 import org.openhab.binding.yamahareceiver.internal.state.ZoneControlState;
26 * Unit test for {@link ZoneControlXML}.
28 * @author Tomasz Maruszak - Initial contribution
30 public class ZoneControlXMLTest extends AbstractZoneControlXMLTest {
32 private ZoneControlXML subject;
34 private void given(String model) throws Exception {
35 ctx.prepareForModel(model);
37 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
38 deviceInformation.update();
40 subject = new ZoneControlXML(con, Main_Zone, zoneConfig, zoneControlStateListener, deviceInformationState,
41 () -> inputConverter);
45 public void given_RX_S601D_when_power_then_sendsProperCommand() throws Exception {
46 when_power_then_sendsProperCommand(RX_S601D);
50 public void given_RX_V3900_when_power_then_sendsProperCommand() throws Exception {
51 when_power_then_sendsProperCommand(RX_V3900);
54 private void when_power_then_sendsProperCommand(String model) throws Exception {
58 subject.setPower(true);
59 subject.setPower(false);
62 verify(con).send(eq("<Main_Zone><Power_Control><Power>On</Power></Power_Control></Main_Zone>"));
63 verify(con).send(eq("<Main_Zone><Power_Control><Power>Standby</Power></Power_Control></Main_Zone>"));
67 public void given_RX_S601D_when_mute_then_sendsProperCommand() throws Exception {
71 subject.setMute(true);
72 subject.setMute(false);
75 verify(con).send(eq("<Main_Zone><Volume><Mute>On</Mute></Volume></Main_Zone>"));
76 verify(con).send(eq("<Main_Zone><Volume><Mute>Off</Mute></Volume></Main_Zone>"));
80 public void given_RX_V3900_when_mute_then_sendsProperCommand() throws Exception {
84 subject.setMute(true);
85 subject.setMute(false);
88 verify(con).send(eq("<Main_Zone><Vol><Mute>On</Mute></Vol></Main_Zone>"));
89 verify(con).send(eq("<Main_Zone><Vol><Mute>Off</Mute></Vol></Main_Zone>"));
93 public void given_RX_S601D_when_volume_then_sendsProperCommand() throws Exception {
97 subject.setVolumeDB(-2);
101 eq("<Main_Zone><Volume><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone>"));
105 public void given_RX_V3900_when_volume_then_sendsProperCommand() throws Exception {
109 subject.setVolumeDB(-2);
112 verify(con).send(eq("<Main_Zone><Vol><Lvl><Val>-20</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Vol></Main_Zone>"));
116 public void given_RX_S601D_when_input_then_sendsProperCommand() throws Exception {
117 when_input_then_sendsProperCommand(RX_S601D);
121 public void given_RX_V3900_when_input_then_sendsProperCommand() throws Exception {
122 when_input_then_sendsProperCommand(RX_V3900);
125 private void when_input_then_sendsProperCommand(String model) throws Exception {
129 subject.setInput("HDMI1");
132 verify(con).send(eq("<Main_Zone><Input><Input_Sel>HDMI1</Input_Sel></Input></Main_Zone>"));
136 public void given_RX_S601D_when_surroundProgram_then_sendsProperCommand() throws Exception {
140 subject.setSurroundProgram("Adventure");
144 "<Main_Zone><Surround><Program_Sel><Current><Sound_Program>Adventure</Sound_Program></Current></Program_Sel></Surround></Main_Zone>"));
148 public void given_RX_V3900_when_surroundProgram_then_sendsProperCommand() throws Exception {
152 subject.setSurroundProgram("Adventure");
156 "<Main_Zone><Surr><Pgm_Sel><Straight>Off</Straight><Pgm>Adventure</Pgm></Pgm_Sel></Surr></Main_Zone>"));
160 public void given_RX_S601D_when_surroundProgramStraight_then_sendsProperCommand() throws Exception {
164 subject.setSurroundProgram("Straight");
168 "<Main_Zone><Surround><Program_Sel><Current><Straight>On</Straight></Current></Program_Sel></Surround></Main_Zone>"));
172 public void given_RX_V3900_when_surroundProgramStraight_then_sendsProperCommand() throws Exception {
176 subject.setSurroundProgram("Straight");
179 verify(con).send(eq("<Main_Zone><Surr><Pgm_Sel><Straight>On</Straight></Pgm_Sel></Surr></Main_Zone>"));
183 public void given_HTR_4069_when_dialogueLevel_then_sendsProperCommand() throws Exception {
187 subject.setDialogueLevel(10);
191 "<Main_Zone><Sound_Video><Dialogue_Adjust><Dialogue_Lvl>10</Dialogue_Lvl></Dialogue_Adjust></Sound_Video></Main_Zone>"));
195 public void given_RX_S601D_when_update_then_readsStateProperly() throws Exception {
202 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
203 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
205 ZoneControlState state = stateArg.getValue();
206 assertNotNull(state);
208 assertEquals(false, state.power);
209 assertEquals(false, state.mute);
210 assertEquals(-43, state.volumeDB, 0);
211 assertEquals("Spotify", state.inputID);
212 assertEquals("5ch Stereo", state.surroundProgram);
213 // this model does not support dialogue level
214 assertEquals(0, state.dialogueLevel);
218 public void given_RX_V3900_when_update_then_readsStateProperly() throws Exception {
225 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
226 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
228 ZoneControlState state = stateArg.getValue();
229 assertNotNull(state);
231 assertEquals(true, state.power);
232 assertEquals(false, state.mute);
233 assertEquals(-46, state.volumeDB, 0);
234 assertEquals("TV", state.inputID);
235 assertEquals("2ch Stereo", state.surroundProgram);
236 // this model does not support dialogue level
237 assertEquals(0, state.dialogueLevel);
241 public void given_HTR_4069_when_update_then_readsStateProperly() throws Exception {
248 ArgumentCaptor<ZoneControlState> stateArg = ArgumentCaptor.forClass(ZoneControlState.class);
249 verify(zoneControlStateListener).zoneStateChanged(stateArg.capture());
251 ZoneControlState state = stateArg.getValue();
252 assertNotNull(state);
254 assertEquals(false, state.power);
255 assertEquals(false, state.mute);
256 assertEquals(-46, state.volumeDB, 0);
257 assertEquals("TUNER", state.inputID);
258 assertEquals("5ch Stereo", state.surroundProgram);
259 assertEquals(1, state.dialogueLevel);