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.assertEquals;
16 import static org.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.*;
18 import static org.openhab.binding.yamahareceiver.internal.TestModels.*;
19 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Inputs.*;
21 import java.util.function.Consumer;
23 import org.junit.jupiter.api.Test;
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Captor;
26 import org.mockito.Mock;
27 import org.openhab.binding.yamahareceiver.internal.config.YamahaBridgeConfig;
28 import org.openhab.binding.yamahareceiver.internal.state.PlayInfoState;
29 import org.openhab.binding.yamahareceiver.internal.state.PlayInfoStateListener;
32 * Unit test for {@link InputWithPlayControlXML}.
34 * @author Tomasz Maruszak - Initial contribution
36 public class InputWithPlayControlXMLTest extends AbstractZoneControlXMLTest {
38 private InputWithPlayControlXML subject;
40 private @Mock PlayInfoStateListener playInfoStateListener;
41 private @Captor ArgumentCaptor<PlayInfoState> playInfoStateArg;
42 private @Mock YamahaBridgeConfig bridgeConfig;
44 private String albumUrl;
46 private void given(String model, String input, Consumer<ModelContext> setup) throws Exception {
47 ctx.prepareForModel(model);
49 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
50 deviceInformation.update();
54 albumUrl = "http://some/url.jpg";
55 when(bridgeConfig.getAlbumUrl()).thenReturn(albumUrl);
57 subject = new InputWithPlayControlXML(input, con, playInfoStateListener, bridgeConfig, deviceInformationState);
61 public void given_RX_S601D_and_Spotify_when_playStopPause_then_sendsProperCommand() throws Exception {
62 given(RX_S601D, INPUT_SPOTIFY, ctx -> {
63 ctx.respondWith("<Spotify><Play_Info>GetParam</Play_Info></Spotify>", "Spotify_Play_Info.xml");
72 verify(con).send(eq("<Spotify><Play_Control><Playback>Play</Playback></Play_Control></Spotify>"));
73 verify(con).send(eq("<Spotify><Play_Control><Playback>Stop</Playback></Play_Control></Spotify>"));
74 verify(con).send(eq("<Spotify><Play_Control><Playback>Pause</Playback></Play_Control></Spotify>"));
78 public void given_RX_S601D_and_Spotify_when_nextPrevious_then_sendsProperCommand() throws Exception {
79 given(RX_S601D, INPUT_SPOTIFY, ctx -> {
80 ctx.respondWith("<Spotify><Play_Info>GetParam</Play_Info></Spotify>", "Spotify_Play_Info.xml");
85 subject.previousTrack();
88 verify(con).send(eq("<Spotify><Play_Control><Playback>Skip Fwd</Playback></Play_Control></Spotify>"));
89 verify(con).send(eq("<Spotify><Play_Control><Playback>Skip Rev</Playback></Play_Control></Spotify>"));
93 public void given_RX_S601D_and_Bluetooth_when_playStopPause_then_sendsProperCommand() throws Exception {
94 given(RX_S601D, INPUT_BLUETOOTH, ctx -> {
95 ctx.respondWith("<Bluetooth><Play_Info>GetParam</Play_Info></Bluetooth>", "Bluetooth_Play_Info.xml");
104 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Play</Playback></Play_Control></Bluetooth>"));
105 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Stop</Playback></Play_Control></Bluetooth>"));
106 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Pause</Playback></Play_Control></Bluetooth>"));
110 public void given_RX_S601D_and_Bluetooth_when_nextPrevious_then_sendsProperCommand() throws Exception {
111 given(RX_S601D, INPUT_BLUETOOTH, ctx -> {
112 ctx.respondWith("<Bluetooth><Play_Info>GetParam</Play_Info></Bluetooth>", "Bluetooth_Play_Info.xml");
117 subject.previousTrack();
120 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Skip Fwd</Playback></Play_Control></Bluetooth>"));
121 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Skip Rev</Playback></Play_Control></Bluetooth>"));
125 public void given_RX_S601D_and_NET_RADIO_when_nextPrevious_then_sendsProperCommand() throws Exception {
126 given(RX_S601D, INPUT_NET_RADIO, ctx -> {
127 ctx.respondWith("<NET_RADIO><Play_Info>GetParam</Play_Info></NET_RADIO>", "NET_RADIO_Play_Info.xml");
132 subject.previousTrack();
135 verify(con).send(eq("<NET_RADIO><Play_Control><Playback>Skip Fwd</Playback></Play_Control></NET_RADIO>"));
136 verify(con).send(eq("<NET_RADIO><Play_Control><Playback>Skip Rev</Playback></Play_Control></NET_RADIO>"));
140 public void given_RX_S601D_and_Spotify_when_update_then_stateIsProperlyRead() throws Exception {
141 given(RX_S601D, INPUT_SPOTIFY, ctx -> {
142 ctx.respondWith("<Spotify><Play_Info>GetParam</Play_Info></Spotify>", "Spotify_Play_Info.xml");
145 ArgumentCaptor<PlayInfoState> playInfoStateArg = ArgumentCaptor.forClass(PlayInfoState.class);
151 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
152 PlayInfoState state = playInfoStateArg.getValue();
154 assertEquals("Play", state.playbackMode);
155 assertEquals("Above & Beyond", state.artist);
156 assertEquals("Acoustic - Live At The Hollywood Bowl", state.album);
157 assertEquals("No One On Earth - Live At The Hollywood Bowl", state.song);
158 assertEquals("N/A", state.station);
159 assertEquals("http://localhost/YamahaRemoteControl/AlbumART/AlbumART6585.jpg", state.songImageUrl);
163 public void given_RX_S601D_and_NET_RADIO_when_update_then_stateIsProperlyRead() throws Exception {
164 given(RX_S601D, INPUT_NET_RADIO, ctx -> {
165 ctx.respondWith("<NET_RADIO><Play_Info>GetParam</Play_Info></NET_RADIO>", "NET_RADIO_Play_Info.xml");
172 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
173 PlayInfoState state = playInfoStateArg.getValue();
175 assertEquals("Play", state.playbackMode);
176 assertEquals("N/A", state.artist);
177 assertEquals("Chilli ZET PL", state.station);
178 assertEquals("", state.album);
179 assertEquals("LESZEK MOZDZER - ZDROWY KOLATAJ", state.song);
180 assertEquals("http://localhost/YamahaRemoteControl/AlbumART/AlbumART4626.jpg", state.songImageUrl);
184 public void given_RX_S601D_and_Bluetooth_when_update_then_stateIsProperlyRead() throws Exception {
185 given(RX_S601D, INPUT_BLUETOOTH, ctx -> {
186 ctx.respondWith("<Bluetooth><Play_Info>GetParam</Play_Info></Bluetooth>", "Bluetooth_Play_Info.xml");
189 ArgumentCaptor<PlayInfoState> playInfoStateArg = ArgumentCaptor.forClass(PlayInfoState.class);
195 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
196 PlayInfoState state = playInfoStateArg.getValue();
198 assertEquals("Play", state.playbackMode);
199 assertEquals("M.I.K.E.", state.artist);
200 assertEquals("A State Of Trance Classics, Vol. 12 (The Full Unmixed Versions)", state.album);
201 assertEquals("Voices From The Inside", state.song);
202 assertEquals("N/A", state.station);
203 assertEquals(albumUrl, state.songImageUrl);
207 public void given_RX_V3900_and_NET_RADIO_when_playStopPause_then_sendsProperCommand() throws Exception {
208 given(RX_V3900, INPUT_NET_RADIO, ctx -> {
209 ctx.respondWith("<NET_USB><Play_Info>GetParam</Play_Info></NET_USB>", "NET_USB_Play_Info.xml");
218 verify(con).send(eq("<NET_USB><Play_Control><Play>Play</Play></Play_Control></NET_USB>"));
219 verify(con).send(eq("<NET_USB><Play_Control><Play>Stop</Play></Play_Control></NET_USB>"));
220 verify(con).send(eq("<NET_USB><Play_Control><Play>Pause</Play></Play_Control></NET_USB>"));
224 public void given_RX_V3900_and_NET_RADIO_when_nextPrevious_then_sendsProperCommand() throws Exception {
225 given(RX_V3900, INPUT_NET_RADIO, ctx -> {
226 ctx.respondWith("<NET_USB><Play_Info>GetParam</Play_Info></NET_USB>", "NET_USB_Play_Info.xml");
231 subject.previousTrack();
234 verify(con).send(eq("<NET_USB><Play_Control><Skip>Fwd</Skip></Play_Control></NET_USB>"));
235 verify(con).send(eq("<NET_USB><Play_Control><Skip>Rev</Skip></Play_Control></NET_USB>"));
239 public void given_RX_V3900_and_NET_RADIO_when_update_then_stateIsProperlyRead() throws Exception {
240 given(RX_V3900, INPUT_NET_RADIO, ctx -> {
241 ctx.respondWith("<NET_USB><Play_Info>GetParam</Play_Info></NET_USB>", "NET_USB_Play_Info.xml");
248 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
249 PlayInfoState state = playInfoStateArg.getValue();
251 assertEquals("Play", state.playbackMode);
252 assertEquals("Some Artist", state.artist);
253 assertEquals("Some Album", state.album);
254 assertEquals("SuomiPOP 98.1", state.song);
255 assertEquals("N/A", state.station);
256 assertEquals(albumUrl, state.songImageUrl);
260 public void given_RX_V3900_and_TUNER_when_update_then_stateIsProperlyRead() throws Exception {
261 given(RX_V3900, INPUT_TUNER, ctx -> {
262 ctx.respondWith("<Tuner><Play_Info>GetParam</Play_Info></Tuner>", "Tuner_Play_Info.xml");
269 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
270 PlayInfoState state = playInfoStateArg.getValue();
272 assertEquals("Stop", state.playbackMode);
273 assertEquals("", state.artist);
274 assertEquals("POP_M", state.album);
275 assertEquals("", state.song);
276 assertEquals("SUOMIPOP", state.station);
277 assertEquals(albumUrl, state.songImageUrl);