[sonos] Unit tests added for OPML request parsing (#13245)
Fix a typo in previous unit tests Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
4eb74c45f1
commit
f795f87f5d
|
@ -12,7 +12,6 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.sonos.internal.handler;
|
package org.openhab.binding.sonos.internal.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,9 +19,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.sonos.internal.SonosMetaData;
|
import org.openhab.binding.sonos.internal.SonosMetaData;
|
||||||
import org.openhab.binding.sonos.internal.SonosXMLParser;
|
import org.openhab.binding.sonos.internal.SonosXMLParser;
|
||||||
import org.openhab.core.io.net.http.HttpUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link SonosMediaInformation} is responsible for extracting media information from XML metadata
|
* The {@link SonosMediaInformation} is responsible for extracting media information from XML metadata
|
||||||
|
@ -32,10 +28,6 @@ import org.slf4j.LoggerFactory;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class SonosMediaInformation {
|
public class SonosMediaInformation {
|
||||||
|
|
||||||
private static final int HTTP_TIMEOUT = 5000;
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SonosMediaInformation.class);
|
|
||||||
|
|
||||||
private @Nullable String artist;
|
private @Nullable String artist;
|
||||||
private @Nullable String album;
|
private @Nullable String album;
|
||||||
private @Nullable String title;
|
private @Nullable String title;
|
||||||
|
@ -79,36 +71,18 @@ public class SonosMediaInformation {
|
||||||
return needsUpdate;
|
return needsUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SonosMediaInformation parseTuneInMediaInfo(@Nullable String opmlUrl, @Nullable String radioTitle,
|
public static SonosMediaInformation parseTuneInMediaInfo(@Nullable String opmlData, @Nullable String radioTitle,
|
||||||
@Nullable SonosMetaData trackMetaData) {
|
@Nullable SonosMetaData trackMetaData) {
|
||||||
String title = null;
|
String title = null;
|
||||||
String combinedInfo = null;
|
String combinedInfo = null;
|
||||||
if (opmlUrl != null) {
|
if (opmlData != null) {
|
||||||
String response = null;
|
List<String> fields = SonosXMLParser.getRadioTimeFromXML(opmlData);
|
||||||
try {
|
|
||||||
response = HttpUtil.executeUrl("GET", opmlUrl, HTTP_TIMEOUT);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.debug("Request to device failed", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response != null) {
|
|
||||||
List<String> fields = SonosXMLParser.getRadioTimeFromXML(response);
|
|
||||||
|
|
||||||
if (!fields.isEmpty()) {
|
if (!fields.isEmpty()) {
|
||||||
combinedInfo = "";
|
title = fields.get(0);
|
||||||
for (String field : fields) {
|
combinedInfo = String.join(" - ", fields);
|
||||||
if (combinedInfo.isEmpty()) {
|
|
||||||
// radio name should be first field
|
|
||||||
title = field;
|
|
||||||
} else {
|
|
||||||
combinedInfo += " - ";
|
|
||||||
}
|
|
||||||
combinedInfo += field;
|
|
||||||
}
|
|
||||||
return new SonosMediaInformation(null, null, title, combinedInfo, true);
|
return new SonosMediaInformation(null, null, title, combinedInfo, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (radioTitle != null && !radioTitle.isEmpty()) {
|
if (radioTitle != null && !radioTitle.isEmpty()) {
|
||||||
title = radioTitle;
|
title = radioTitle;
|
||||||
combinedInfo = title;
|
combinedInfo = title;
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.openhab.binding.sonos.internal.handler;
|
||||||
|
|
||||||
import static org.openhab.binding.sonos.internal.SonosBindingConstants.*;
|
import static org.openhab.binding.sonos.internal.SonosBindingConstants.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
@ -164,6 +165,8 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
|
||||||
private static final int MIN_HEIGHT_LEVEL = -10;
|
private static final int MIN_HEIGHT_LEVEL = -10;
|
||||||
private static final int MAX_HEIGHT_LEVEL = 10;
|
private static final int MAX_HEIGHT_LEVEL = 10;
|
||||||
|
|
||||||
|
private static final int HTTP_TIMEOUT = 5000;
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(ZonePlayerHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(ZonePlayerHandler.class);
|
||||||
|
|
||||||
private final ThingRegistry localThingRegistry;
|
private final ThingRegistry localThingRegistry;
|
||||||
|
@ -1249,7 +1252,7 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
|
||||||
else if (isPlayingStream(currentURI) || isPlayingRadioStartedByAmazonEcho(currentURI)) {
|
else if (isPlayingStream(currentURI) || isPlayingRadioStartedByAmazonEcho(currentURI)) {
|
||||||
// Radio stream (tune-in)
|
// Radio stream (tune-in)
|
||||||
stationID = extractStationId(currentURI);
|
stationID = extractStationId(currentURI);
|
||||||
mediaInfo = SonosMediaInformation.parseTuneInMediaInfo(buildOpmlUrl(stationID),
|
mediaInfo = SonosMediaInformation.parseTuneInMediaInfo(getOpmlData(stationID),
|
||||||
currentUriMetaData != null ? currentUriMetaData.getTitle() : null, currentTrack);
|
currentUriMetaData != null ? currentUriMetaData.getTitle() : null, currentTrack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1308,14 +1311,21 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable String buildOpmlUrl(@Nullable String stationId) {
|
private @Nullable String getOpmlData(@Nullable String stationId) {
|
||||||
String url = opmlUrl;
|
String url = opmlUrl;
|
||||||
if (url != null && stationId != null && !stationId.isEmpty()) {
|
if (url != null && stationId != null && !stationId.isEmpty()) {
|
||||||
String mac = getMACAddress();
|
String mac = getMACAddress();
|
||||||
if (mac != null && !mac.isEmpty()) {
|
if (mac != null && !mac.isEmpty()) {
|
||||||
url = url.replace("%id", stationId);
|
url = url.replace("%id", stationId);
|
||||||
url = url.replace("%serial", mac);
|
url = url.replace("%serial", mac);
|
||||||
return url;
|
String response = null;
|
||||||
|
try {
|
||||||
|
response = HttpUtil.executeUrl("GET", url, HTTP_TIMEOUT);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.debug("OPML request failed ({})", url, e);
|
||||||
|
}
|
||||||
|
logger.trace("OPML response = {}", response);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -14,6 +14,10 @@ package org.openhab.binding.sonos.internal;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.openhab.binding.sonos.internal.handler.SonosMediaInformation;
|
import org.openhab.binding.sonos.internal.handler.SonosMediaInformation;
|
||||||
|
@ -26,23 +30,47 @@ import org.openhab.binding.sonos.internal.handler.SonosMediaInformation;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class SonosMediaInformationTest {
|
public class SonosMediaInformationTest {
|
||||||
|
|
||||||
|
private static final SonosMetaData METADATA_STREAM_CONTENT = new SonosMetaData("yyy", "yyy", "yyy", "Morning Live",
|
||||||
|
"yyy", "yyy", "yyy", "yyy", "yyy", "yyy");
|
||||||
|
private static final SonosMetaData METADATA_EMPTY_STREAM_CONTENT = new SonosMetaData("yyy", "yyy", "yyy", "", "yyy",
|
||||||
|
"yyy", "yyy", "yyy", "yyy", "yyy");
|
||||||
|
|
||||||
|
private static final SonosMetaData METADATA_RADIOAPP_1 = new SonosMetaData("yyy", "yyy", "yyy",
|
||||||
|
"TYPE=SNG|TITLE Green Day - Time Of Your Life (Good Riddance)|ARTIST |ALBUM ", "yyy", "yyy", "yyy", "yyy",
|
||||||
|
"yyy", "yyy");
|
||||||
|
private static final SonosMetaData METADATA_RADIOAPP_2 = new SonosMetaData("yyy", "yyy", "yyy",
|
||||||
|
"TYPE=SNG|TITLE Time Of Your Life (Good Riddance)|ARTIST Green Day|ALBUM Nimrod", "yyy", "yyy", "yyy",
|
||||||
|
"yyy", "yyy", "yyy");
|
||||||
|
private static final SonosMetaData METADATA_RADIOAPP_ADVERTISEMENT = new SonosMetaData("yyy", "yyy", "yyy",
|
||||||
|
"TYPE=SNG|TITLE Advertisement_Stop|ARTIST |ALBUM ", "yyy", "yyy", "yyy", "yyy", "yyy", "yyy");
|
||||||
|
|
||||||
|
private static final SonosMetaData METADATA_ARTIST_ALBUM_TITLE = new SonosMetaData("xxx", "xxx", "xxx", "xxx",
|
||||||
|
"xxx", "Time Of Your Life (Good Riddance)", "xxx", "xxx", "Nimrod", "Green Day");
|
||||||
|
private static final SonosMetaData METADATA_EMPTY_CREATOR_ARTIST = new SonosMetaData("xxx", "xxx", "xxx", "xxx",
|
||||||
|
"xxx", "Time Of Your Life (Good Riddance)", "xxx", "", "Nimrod", "");
|
||||||
|
private static final SonosMetaData METADATA_EMPTY_ALBUM = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx",
|
||||||
|
"Time Of Your Life (Good Riddance)", "xxx", "Green Day", "", "");
|
||||||
|
private static final SonosMetaData METADATA_EMPTY_TITLE = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx", "",
|
||||||
|
"xxx", "xxx", "Nimrod", "Green Day");
|
||||||
|
private static final SonosMetaData METADATA_ONLY_TITLE = new SonosMetaData("", "", "", "", "",
|
||||||
|
"Time Of Your Life (Good Riddance)", "", "", "", "");
|
||||||
|
private static final SonosMetaData METADATA_EMPTY = new SonosMetaData("", "", "", "", "", "", "", "", "", "");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTuneInMediaInfoWithStreamContent() {
|
public void parseTuneInMediaInfoWithStreamContent() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy", "Mroning Live", "yyy", "yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(null, "Radio One",
|
||||||
"yyy", "yyy");
|
METADATA_STREAM_CONTENT);
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(null, "Radio One", trackMetaData);
|
|
||||||
assertNull(result.getArtist());
|
assertNull(result.getArtist());
|
||||||
assertNull(result.getAlbum());
|
assertNull(result.getAlbum());
|
||||||
assertEquals("Radio One", result.getTitle());
|
assertEquals("Radio One", result.getTitle());
|
||||||
assertEquals("Radio One - Mroning Live", result.getCombinedInfo());
|
assertEquals("Radio One - Morning Live", result.getCombinedInfo());
|
||||||
assertEquals(true, result.needsUpdate());
|
assertEquals(true, result.needsUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTuneInMediaInfoWithoutStreamContent() {
|
public void parseTuneInMediaInfoWithoutStreamContent() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy", "", "yyy", "yyy", "yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(null, "Radio One",
|
||||||
"yyy");
|
METADATA_EMPTY_STREAM_CONTENT);
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(null, "Radio One", trackMetaData);
|
|
||||||
assertNull(result.getArtist());
|
assertNull(result.getArtist());
|
||||||
assertNull(result.getAlbum());
|
assertNull(result.getAlbum());
|
||||||
assertEquals("Radio One", result.getTitle());
|
assertEquals("Radio One", result.getTitle());
|
||||||
|
@ -52,9 +80,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTuneInMediaInfoWithoutTitle() {
|
public void parseTuneInMediaInfoWithoutTitle() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy", "Mroning Live", "yyy", "yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(null, "", METADATA_STREAM_CONTENT);
|
||||||
"yyy", "yyy");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(null, "", trackMetaData);
|
|
||||||
assertNull(result.getArtist());
|
assertNull(result.getArtist());
|
||||||
assertNull(result.getAlbum());
|
assertNull(result.getAlbum());
|
||||||
assertNull(result.getTitle());
|
assertNull(result.getTitle());
|
||||||
|
@ -72,12 +98,23 @@ public class SonosMediaInformationTest {
|
||||||
assertEquals(false, result.needsUpdate());
|
assertEquals(false, result.needsUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseTuneInMediaInfoWithOPMLRequest() throws IOException {
|
||||||
|
InputStream resourceStream = getClass().getResourceAsStream("/OPML.xml");
|
||||||
|
assertNotNull(resourceStream);
|
||||||
|
final String opmlResult = new String(resourceStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
SonosMediaInformation result = SonosMediaInformation.parseTuneInMediaInfo(opmlResult, "Radio One",
|
||||||
|
METADATA_STREAM_CONTENT);
|
||||||
|
assertNull(result.getArtist());
|
||||||
|
assertNull(result.getAlbum());
|
||||||
|
assertEquals("RTL2 105.9", result.getTitle());
|
||||||
|
assertEquals("RTL2 105.9 - Le Son Pop-Rock - Paris, France", result.getCombinedInfo());
|
||||||
|
assertEquals(true, result.needsUpdate());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRadioAppMediaInfoWithSongTitle() {
|
public void parseRadioAppMediaInfoWithSongTitle() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two", METADATA_RADIOAPP_1);
|
||||||
"TYPE=SNG|TITLE Green Day - Time Of Your Life (Good Riddance)|ARTIST |ALBUM ", "yyy", "yyy", "yyy",
|
|
||||||
"yyy", "yyy", "yyy");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two", trackMetaData);
|
|
||||||
assertEquals("Green Day", result.getArtist());
|
assertEquals("Green Day", result.getArtist());
|
||||||
assertEquals("", result.getAlbum());
|
assertEquals("", result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
@ -87,10 +124,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRadioAppMediaInfoWithSongTitleArtistAlbum() {
|
public void parseRadioAppMediaInfoWithSongTitleArtistAlbum() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two", METADATA_RADIOAPP_2);
|
||||||
"TYPE=SNG|TITLE Time Of Your Life (Good Riddance)|ARTIST Green Day|ALBUM Nimrod", "yyy", "yyy", "yyy",
|
|
||||||
"yyy", "yyy", "yyy");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two", trackMetaData);
|
|
||||||
assertEquals("Green Day", result.getArtist());
|
assertEquals("Green Day", result.getArtist());
|
||||||
assertEquals("Nimrod", result.getAlbum());
|
assertEquals("Nimrod", result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
@ -100,9 +134,8 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRadioAppMediaInfoWithdvertisement() {
|
public void parseRadioAppMediaInfoWithdvertisement() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two",
|
||||||
"TYPE=SNG|TITLE Advertisement_Stop|ARTIST |ALBUM ", "yyy", "yyy", "yyy", "yyy", "yyy", "yyy");
|
METADATA_RADIOAPP_ADVERTISEMENT);
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two", trackMetaData);
|
|
||||||
assertEquals("", result.getArtist());
|
assertEquals("", result.getArtist());
|
||||||
assertEquals("", result.getAlbum());
|
assertEquals("", result.getAlbum());
|
||||||
assertEquals("Radio Two", result.getTitle());
|
assertEquals("Radio Two", result.getTitle());
|
||||||
|
@ -112,9 +145,8 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRadioAppMediaInfoWithoutStreamContent() {
|
public void parseRadioAppMediaInfoWithoutStreamContent() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy", "", "yyy", "yyy", "yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two",
|
||||||
"yyy");
|
METADATA_EMPTY_STREAM_CONTENT);
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("Radio Two", trackMetaData);
|
|
||||||
assertNull(result.getArtist());
|
assertNull(result.getArtist());
|
||||||
assertNull(result.getAlbum());
|
assertNull(result.getAlbum());
|
||||||
assertEquals("Radio Two", result.getTitle());
|
assertEquals("Radio Two", result.getTitle());
|
||||||
|
@ -124,10 +156,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRadioAppMediaInfoWithoutTitle() {
|
public void parseRadioAppMediaInfoWithoutTitle() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("yyy", "yyy", "yyy",
|
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("", METADATA_RADIOAPP_1);
|
||||||
"TYPE=SNG|TITLE Green Day - Time Of Your Life (Good Riddance)|ARTIST |ALBUM ", "yyy", "yyy", "yyy",
|
|
||||||
"yyy", "yyy", "yyy");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseRadioAppMediaInfo("", trackMetaData);
|
|
||||||
assertNull(result.getArtist());
|
assertNull(result.getArtist());
|
||||||
assertNull(result.getAlbum());
|
assertNull(result.getAlbum());
|
||||||
assertNull(result.getTitle());
|
assertNull(result.getTitle());
|
||||||
|
@ -147,9 +176,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrack() {
|
public void parseTrack() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx",
|
SonosMediaInformation result = SonosMediaInformation.parseTrack(METADATA_ARTIST_ALBUM_TITLE);
|
||||||
"Time Of Your Life (Good Riddance)", "xxx", "xxx", "Nimrod", "Green Day");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrack(trackMetaData);
|
|
||||||
assertEquals("Green Day", result.getArtist());
|
assertEquals("Green Day", result.getArtist());
|
||||||
assertEquals("Nimrod", result.getAlbum());
|
assertEquals("Nimrod", result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
@ -159,9 +186,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrackWithoutArtist() {
|
public void parseTrackWithoutArtist() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx",
|
SonosMediaInformation result = SonosMediaInformation.parseTrack(METADATA_EMPTY_CREATOR_ARTIST);
|
||||||
"Time Of Your Life (Good Riddance)", "xxx", "", "Nimrod", "");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrack(trackMetaData);
|
|
||||||
assertEquals("", result.getArtist());
|
assertEquals("", result.getArtist());
|
||||||
assertEquals("Nimrod", result.getAlbum());
|
assertEquals("Nimrod", result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
@ -171,9 +196,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrackWithoutAlbum() {
|
public void parseTrackWithoutAlbum() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx",
|
SonosMediaInformation result = SonosMediaInformation.parseTrack(METADATA_EMPTY_ALBUM);
|
||||||
"Time Of Your Life (Good Riddance)", "xxx", "Green Day", "", "");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrack(trackMetaData);
|
|
||||||
assertEquals("Green Day", result.getArtist());
|
assertEquals("Green Day", result.getArtist());
|
||||||
assertEquals("", result.getAlbum());
|
assertEquals("", result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
@ -183,9 +206,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrackWithoutTitle() {
|
public void parseTrackWithoutTitle() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx", "", "xxx", "xxx", "Nimrod",
|
SonosMediaInformation result = SonosMediaInformation.parseTrack(METADATA_EMPTY_TITLE);
|
||||||
"Green Day");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrack(trackMetaData);
|
|
||||||
assertEquals("Green Day", result.getArtist());
|
assertEquals("Green Day", result.getArtist());
|
||||||
assertEquals("Nimrod", result.getAlbum());
|
assertEquals("Nimrod", result.getAlbum());
|
||||||
assertEquals("", result.getTitle());
|
assertEquals("", result.getTitle());
|
||||||
|
@ -195,9 +216,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrackWithOnlyTitle() {
|
public void parseTrackWithOnlyTitle() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("", "", "", "", "", "Time Of Your Life (Good Riddance)", "", "",
|
SonosMediaInformation result = SonosMediaInformation.parseTrack(METADATA_ONLY_TITLE);
|
||||||
"", "");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrack(trackMetaData);
|
|
||||||
assertEquals("", result.getArtist());
|
assertEquals("", result.getArtist());
|
||||||
assertEquals("", result.getAlbum());
|
assertEquals("", result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
@ -207,8 +226,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrackWithEmptyMetaData() {
|
public void parseTrackWithEmptyMetaData() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("", "", "", "", "", "", "", "", "", "");
|
SonosMediaInformation result = SonosMediaInformation.parseTrack(METADATA_EMPTY);
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrack(trackMetaData);
|
|
||||||
assertEquals("", result.getArtist());
|
assertEquals("", result.getArtist());
|
||||||
assertEquals("", result.getAlbum());
|
assertEquals("", result.getAlbum());
|
||||||
assertEquals("", result.getTitle());
|
assertEquals("", result.getTitle());
|
||||||
|
@ -228,9 +246,7 @@ public class SonosMediaInformationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseTrackTitle() {
|
public void parseTrackTitle() {
|
||||||
SonosMetaData trackMetaData = new SonosMetaData("xxx", "xxx", "xxx", "xxx", "xxx",
|
SonosMediaInformation result = SonosMediaInformation.parseTrackTitle(METADATA_ARTIST_ALBUM_TITLE);
|
||||||
"Time Of Your Life (Good Riddance)", "xxx", "xxx", "Nimrod", "Green Day");
|
|
||||||
SonosMediaInformation result = SonosMediaInformation.parseTrackTitle(trackMetaData);
|
|
||||||
assertNull(result.getArtist());
|
assertNull(result.getArtist());
|
||||||
assertNull(result.getAlbum());
|
assertNull(result.getAlbum());
|
||||||
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
assertEquals("Time Of Your Life (Good Riddance)", result.getTitle());
|
||||||
|
|
|
@ -12,7 +12,12 @@
|
||||||
*/
|
*/
|
||||||
package org.openhab.binding.sonos.internal;
|
package org.openhab.binding.sonos.internal;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -60,4 +65,18 @@ public class SonosXMLParserTest {
|
||||||
public void buildThingTypeIdFromModelWithAdditionalTextInParenthesis() {
|
public void buildThingTypeIdFromModelWithAdditionalTextInParenthesis() {
|
||||||
assertEquals("OneSL", SonosXMLParser.buildThingTypeIdFromModelName("Sonos One SL (OpenHome)"));
|
assertEquals("OneSL", SonosXMLParser.buildThingTypeIdFromModelName("Sonos One SL (OpenHome)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getRadioTimeFromXML() throws IOException {
|
||||||
|
InputStream resourceStream = getClass().getResourceAsStream("/OPML.xml");
|
||||||
|
assertNotNull(resourceStream);
|
||||||
|
final String opmlResult = new String(resourceStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
List<String> result = SonosXMLParser.getRadioTimeFromXML(opmlResult);
|
||||||
|
assertEquals(3, result.size());
|
||||||
|
if (result.size() == 3) {
|
||||||
|
assertEquals("RTL2 105.9", result.get(0));
|
||||||
|
assertEquals("Le Son Pop-Rock", result.get(1));
|
||||||
|
assertEquals("Paris, France", result.get(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<opml version="1">
|
||||||
|
<head>
|
||||||
|
<status>200</status>
|
||||||
|
<ttl>43200</ttl>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<outline type="text" text="RTL2 105.9" guide_id="s50486" key="station" image="http://cdn-radiotime-logos.tunein.com/_0q.png?t=1" preset_id="s50486"/>
|
||||||
|
<outline type="text" text="Le Son Pop-Rock"/>
|
||||||
|
<outline type="text" text="Paris, France"/>
|
||||||
|
<outline type="object" text="NowPlaying">
|
||||||
|
<nowplaying>
|
||||||
|
<logo>http://cdn-radiotime-logos.tunein.com/_0.png?t=1</logo>
|
||||||
|
<twitter_id>RTL2officiel</twitter_id>
|
||||||
|
</nowplaying>
|
||||||
|
</outline>
|
||||||
|
</body>
|
||||||
|
</opml>
|
Loading…
Reference in New Issue