]> git.basschouten.com Git - openhab-addons.git/blob
4cc58a4594463ab9a43e53a621631f1a27d26fa1
[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.sonos.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.nio.charset.StandardCharsets;
20 import java.util.List;
21
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.junit.jupiter.api.Test;
24
25 /**
26  *
27  * @author Laurent Garnier - Initial contribution
28  */
29 @NonNullByDefault
30 public class SonosXMLParserTest {
31
32     @Test
33     public void buildThingTypeIdFromModelWithoutSpace() {
34         assertEquals("Move", SonosXMLParser.buildThingTypeIdFromModelName("Sonos Move"));
35     }
36
37     @Test
38     public void buildThingTypeIdFromModelWithSpace() {
39         assertEquals("RoamSL", SonosXMLParser.buildThingTypeIdFromModelName("Sonos Roam SL"));
40     }
41
42     @Test
43     public void buildThingTypeIdFromModelWithColon() {
44         assertEquals("PLAY5", SonosXMLParser.buildThingTypeIdFromModelName("Sonos PLAY:5"));
45     }
46
47     @Test
48     public void buildThingTypeIdFromSymfoniskModel() {
49         assertEquals("SYMFONISK", SonosXMLParser.buildThingTypeIdFromModelName("SYMFONISK Table lamp"));
50         assertEquals("SYMFONISK", SonosXMLParser.buildThingTypeIdFromModelName("Symfonisk Table lamp"));
51         assertEquals("SYMFONISK", SonosXMLParser.buildThingTypeIdFromModelName("Sonos Symfonisk"));
52     }
53
54     @Test
55     public void buildThingTypeIdFromZP80Model() {
56         assertEquals("CONNECT", SonosXMLParser.buildThingTypeIdFromModelName("Sonos ZP80"));
57     }
58
59     @Test
60     public void buildThingTypeIdFromZP100Model() {
61         assertEquals("CONNECTAMP", SonosXMLParser.buildThingTypeIdFromModelName("Sonos ZP100"));
62     }
63
64     @Test
65     public void buildThingTypeIdFromModelWithAdditionalTextInParenthesis() {
66         assertEquals("OneSL", SonosXMLParser.buildThingTypeIdFromModelName("Sonos One SL (OpenHome)"));
67     }
68
69     @Test
70     public void getRadioTimeFromXML() throws IOException {
71         InputStream resourceStream = getClass().getResourceAsStream("/OPML.xml");
72         assertNotNull(resourceStream);
73         final String opmlResult = new String(resourceStream.readAllBytes(), StandardCharsets.UTF_8);
74         List<String> result = SonosXMLParser.getRadioTimeFromXML(opmlResult);
75         assertEquals(3, result.size());
76         if (result.size() == 3) {
77             assertEquals("RTL2 105.9", result.get(0));
78             assertEquals("Le Son Pop-Rock", result.get(1));
79             assertEquals("Paris, France", result.get(2));
80         }
81     }
82 }