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.mockito.ArgumentMatchers.eq;
17 import static org.mockito.Mockito.verify;
18 import static org.mockito.Mockito.when;
19 import static org.openhab.binding.yamahareceiver.internal.TestModels.*;
20 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Inputs.*;
22 import java.util.function.Consumer;
24 import org.junit.Test;
25 import org.mockito.ArgumentCaptor;
26 import org.mockito.Captor;
27 import org.mockito.Mock;
28 import org.openhab.binding.yamahareceiver.internal.config.YamahaBridgeConfig;
29 import org.openhab.binding.yamahareceiver.internal.state.PlayInfoState;
30 import org.openhab.binding.yamahareceiver.internal.state.PlayInfoStateListener;
33 * Unit test for {@link InputWithPlayControlXML}.
35 * @author Tomasz Maruszak - Initial contribution
37 public class InputWithPlayControlXMLTest extends AbstractZoneControlXMLTest {
39 private InputWithPlayControlXML subject;
42 private PlayInfoStateListener playInfoStateListener;
45 private ArgumentCaptor<PlayInfoState> playInfoStateArg;
48 private YamahaBridgeConfig bridgeConfig;
50 private String albumUrl;
52 private void given(String model, String input, Consumer<ModelContext> setup) throws Exception {
53 ctx.prepareForModel(model);
55 DeviceInformationXML deviceInformation = new DeviceInformationXML(con, deviceInformationState);
56 deviceInformation.update();
60 albumUrl = "http://some/url.jpg";
61 when(bridgeConfig.getAlbumUrl()).thenReturn(albumUrl);
63 subject = new InputWithPlayControlXML(input, con, playInfoStateListener, bridgeConfig, deviceInformationState);
67 public void given_RX_S601D_and_Spotify_when_playStopPause_then_sendsProperCommand() throws Exception {
68 given(RX_S601D, INPUT_SPOTIFY, ctx -> {
69 ctx.respondWith("<Spotify><Play_Info>GetParam</Play_Info></Spotify>", "Spotify_Play_Info.xml");
78 verify(con).send(eq("<Spotify><Play_Control><Playback>Play</Playback></Play_Control></Spotify>"));
79 verify(con).send(eq("<Spotify><Play_Control><Playback>Stop</Playback></Play_Control></Spotify>"));
80 verify(con).send(eq("<Spotify><Play_Control><Playback>Pause</Playback></Play_Control></Spotify>"));
84 public void given_RX_S601D_and_Spotify_when_nextPrevious_then_sendsProperCommand() throws Exception {
85 given(RX_S601D, INPUT_SPOTIFY, ctx -> {
86 ctx.respondWith("<Spotify><Play_Info>GetParam</Play_Info></Spotify>", "Spotify_Play_Info.xml");
91 subject.previousTrack();
94 verify(con).send(eq("<Spotify><Play_Control><Playback>Skip Fwd</Playback></Play_Control></Spotify>"));
95 verify(con).send(eq("<Spotify><Play_Control><Playback>Skip Rev</Playback></Play_Control></Spotify>"));
99 public void given_RX_S601D_and_Bluetooth_when_playStopPause_then_sendsProperCommand() throws Exception {
100 given(RX_S601D, INPUT_BLUETOOTH, ctx -> {
101 ctx.respondWith("<Bluetooth><Play_Info>GetParam</Play_Info></Bluetooth>", "Bluetooth_Play_Info.xml");
110 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Play</Playback></Play_Control></Bluetooth>"));
111 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Stop</Playback></Play_Control></Bluetooth>"));
112 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Pause</Playback></Play_Control></Bluetooth>"));
116 public void given_RX_S601D_and_Bluetooth_when_nextPrevious_then_sendsProperCommand() throws Exception {
117 given(RX_S601D, INPUT_BLUETOOTH, ctx -> {
118 ctx.respondWith("<Bluetooth><Play_Info>GetParam</Play_Info></Bluetooth>", "Bluetooth_Play_Info.xml");
123 subject.previousTrack();
126 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Skip Fwd</Playback></Play_Control></Bluetooth>"));
127 verify(con).send(eq("<Bluetooth><Play_Control><Playback>Skip Rev</Playback></Play_Control></Bluetooth>"));
131 public void given_RX_S601D_and_NET_RADIO_when_nextPrevious_then_sendsProperCommand() throws Exception {
132 given(RX_S601D, INPUT_NET_RADIO, ctx -> {
133 ctx.respondWith("<NET_RADIO><Play_Info>GetParam</Play_Info></NET_RADIO>", "NET_RADIO_Play_Info.xml");
138 subject.previousTrack();
141 verify(con).send(eq("<NET_RADIO><Play_Control><Playback>Skip Fwd</Playback></Play_Control></NET_RADIO>"));
142 verify(con).send(eq("<NET_RADIO><Play_Control><Playback>Skip Rev</Playback></Play_Control></NET_RADIO>"));
146 public void given_RX_S601D_and_Spotify_when_update_then_stateIsProperlyRead() throws Exception {
147 given(RX_S601D, INPUT_SPOTIFY, ctx -> {
148 ctx.respondWith("<Spotify><Play_Info>GetParam</Play_Info></Spotify>", "Spotify_Play_Info.xml");
151 ArgumentCaptor<PlayInfoState> playInfoStateArg = ArgumentCaptor.forClass(PlayInfoState.class);
157 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
158 PlayInfoState state = playInfoStateArg.getValue();
160 assertEquals("Play", state.playbackMode);
161 assertEquals("Above & Beyond", state.artist);
162 assertEquals("Acoustic - Live At The Hollywood Bowl", state.album);
163 assertEquals("No One On Earth - Live At The Hollywood Bowl", state.song);
164 assertEquals("N/A", state.station);
165 assertEquals("http://localhost/YamahaRemoteControl/AlbumART/AlbumART6585.jpg", state.songImageUrl);
169 public void given_RX_S601D_and_NET_RADIO_when_update_then_stateIsProperlyRead() throws Exception {
170 given(RX_S601D, INPUT_NET_RADIO, ctx -> {
171 ctx.respondWith("<NET_RADIO><Play_Info>GetParam</Play_Info></NET_RADIO>", "NET_RADIO_Play_Info.xml");
178 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
179 PlayInfoState state = playInfoStateArg.getValue();
181 assertEquals("Play", state.playbackMode);
182 assertEquals("N/A", state.artist);
183 assertEquals("Chilli ZET PL", state.station);
184 assertEquals("", state.album);
185 assertEquals("LESZEK MOZDZER - ZDROWY KOLATAJ", state.song);
186 assertEquals("http://localhost/YamahaRemoteControl/AlbumART/AlbumART4626.jpg", state.songImageUrl);
190 public void given_RX_S601D_and_Bluetooth_when_update_then_stateIsProperlyRead() throws Exception {
191 given(RX_S601D, INPUT_BLUETOOTH, ctx -> {
192 ctx.respondWith("<Bluetooth><Play_Info>GetParam</Play_Info></Bluetooth>", "Bluetooth_Play_Info.xml");
195 ArgumentCaptor<PlayInfoState> playInfoStateArg = ArgumentCaptor.forClass(PlayInfoState.class);
201 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
202 PlayInfoState state = playInfoStateArg.getValue();
204 assertEquals("Play", state.playbackMode);
205 assertEquals("M.I.K.E.", state.artist);
206 assertEquals("A State Of Trance Classics, Vol. 12 (The Full Unmixed Versions)", state.album);
207 assertEquals("Voices From The Inside", state.song);
208 assertEquals("N/A", state.station);
209 assertEquals(albumUrl, state.songImageUrl);
213 public void given_RX_V3900_and_NET_RADIO_when_playStopPause_then_sendsProperCommand() throws Exception {
214 given(RX_V3900, INPUT_NET_RADIO, ctx -> {
215 ctx.respondWith("<NET_USB><Play_Info>GetParam</Play_Info></NET_USB>", "NET_USB_Play_Info.xml");
224 verify(con).send(eq("<NET_USB><Play_Control><Play>Play</Play></Play_Control></NET_USB>"));
225 verify(con).send(eq("<NET_USB><Play_Control><Play>Stop</Play></Play_Control></NET_USB>"));
226 verify(con).send(eq("<NET_USB><Play_Control><Play>Pause</Play></Play_Control></NET_USB>"));
230 public void given_RX_V3900_and_NET_RADIO_when_nextPrevious_then_sendsProperCommand() throws Exception {
231 given(RX_V3900, INPUT_NET_RADIO, ctx -> {
232 ctx.respondWith("<NET_USB><Play_Info>GetParam</Play_Info></NET_USB>", "NET_USB_Play_Info.xml");
237 subject.previousTrack();
240 verify(con).send(eq("<NET_USB><Play_Control><Skip>Fwd</Skip></Play_Control></NET_USB>"));
241 verify(con).send(eq("<NET_USB><Play_Control><Skip>Rev</Skip></Play_Control></NET_USB>"));
245 public void given_RX_V3900_and_NET_RADIO_when_update_then_stateIsProperlyRead() throws Exception {
246 given(RX_V3900, INPUT_NET_RADIO, ctx -> {
247 ctx.respondWith("<NET_USB><Play_Info>GetParam</Play_Info></NET_USB>", "NET_USB_Play_Info.xml");
254 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
255 PlayInfoState state = playInfoStateArg.getValue();
257 assertEquals("Play", state.playbackMode);
258 assertEquals("Some Artist", state.artist);
259 assertEquals("Some Album", state.album);
260 assertEquals("SuomiPOP 98.1", state.song);
261 assertEquals("N/A", state.station);
262 assertEquals(albumUrl, state.songImageUrl);
266 public void given_RX_V3900_and_TUNER_when_update_then_stateIsProperlyRead() throws Exception {
267 given(RX_V3900, INPUT_TUNER, ctx -> {
268 ctx.respondWith("<Tuner><Play_Info>GetParam</Play_Info></Tuner>", "Tuner_Play_Info.xml");
275 verify(playInfoStateListener).playInfoUpdated(playInfoStateArg.capture());
276 PlayInfoState state = playInfoStateArg.getValue();
278 assertEquals("Stop", state.playbackMode);
279 assertEquals("", state.artist);
280 assertEquals("POP_M", state.album);
281 assertEquals("", state.song);
282 assertEquals("SUOMIPOP", state.station);
283 assertEquals(albumUrl, state.songImageUrl);