]> git.basschouten.com Git - openhab-addons.git/blob
da1ed506bba0ae220aac244a4376a110082546f9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.xml;
14
15 import static org.junit.jupiter.api.Assertions.*;
16 import static org.openhab.binding.yamahareceiver.internal.YamahaReceiverBindingConstants.Inputs.*;
17 import static org.openhab.binding.yamahareceiver.internal.protocol.xml.XMLConstants.Commands.ZONE_INPUT_QUERY;
18
19 import org.junit.jupiter.api.Test;
20
21 /**
22  * Unit test for {@link InputConverterXML}.
23  *
24  * @author Tomasz Maruszak - Initial contribution
25  */
26 public class InputConverterXMLTest extends AbstractXMLProtocolTest {
27
28     private InputConverterXML subject;
29
30     @Override
31     protected void onSetUp() throws Exception {
32         super.onSetUp();
33
34         ctx.prepareForModel("HTR-4069");
35         ctx.respondWith(String.format("<Main_Zone>%s</Main_Zone>", ZONE_INPUT_QUERY),
36                 "Main_Zone_Input_Input_Sel_Item.xml");
37     }
38
39     @Test
40     public void when_noMapping_fromStateName_returnsCanonicalNames() {
41         // arrange
42         subject = new InputConverterXML(con, "");
43
44         // act
45         String hdmi1 = subject.fromStateName("HDMI1");
46         String hdmi2 = subject.fromStateName("HDMI2");
47         String av1 = subject.fromStateName("AV1");
48         String av2 = subject.fromStateName("AV2");
49         String audio1 = subject.fromStateName("AUDIO1");
50         String audio2 = subject.fromStateName("AUDIO2");
51         String bluetooth = subject.fromStateName(INPUT_BLUETOOTH);
52         String usb = subject.fromStateName(INPUT_USB);
53         String tuner = subject.fromStateName(INPUT_TUNER);
54         String netRadio = subject.fromStateName(INPUT_NET_RADIO);
55         String server = subject.fromStateName(INPUT_SERVER);
56         String multiCastLink = subject.fromStateName(INPUT_MUSIC_CAST_LINK);
57         String spotify = subject.fromStateName(INPUT_SPOTIFY);
58
59         // assert
60         assertEquals("HDMI1", hdmi1);
61         assertEquals("HDMI2", hdmi2);
62         assertEquals("AV1", av1);
63         assertEquals("AV2", av2);
64         assertEquals("AUDIO1", audio1);
65         assertEquals("AUDIO2", audio2);
66         assertEquals("Bluetooth", bluetooth);
67         assertEquals("USB", usb);
68         assertEquals("TUNER", tuner);
69         assertEquals("NET RADIO", netRadio);
70         assertEquals("SERVER", server);
71         assertEquals("MusicCast Link", multiCastLink);
72         assertEquals("Spotify", spotify);
73     }
74
75     @Test
76     public void when_mapping_fromStateName_takesUserMappingAboveAll() {
77         // arrange
78         subject = new InputConverterXML(con, "HDMI1=HDMI 1,Bluetooth=BLUETOOTH");
79
80         // act
81         String hdmi1 = subject.fromStateName("HDMI1");
82         String bluetooth = subject.fromStateName(INPUT_BLUETOOTH);
83
84         // assert
85         assertEquals("HDMI 1", hdmi1);
86         assertEquals("BLUETOOTH", bluetooth);
87     }
88 }