/*
You may freely copy, distribute, modify and use this class as long
as the original author attribution remains intact. See message
below.
Copyright (C) 2003 Christian Pesch. All Rights Reserved.
*/
package slash.metamusic.lyricsdb;
import junit.framework.TestCase;
import slash.metamusic.util.StringHelper;
import java.io.File;
import java.io.IOException;
public class LyricsDBClientTest extends TestCase {
private LyricsDBClient client = new LyricsDBClient();
private File tempDir;
private static final String PLAIN_TRIMMED = "Oh, how 'bout a round of applause?\r\n" +
"Yeah, standin' ovation\r\n" +
"Oooh, oh yeah, yeah y-yeah yeah\r\n" +
"\r\n" +
"You look so dumb right now\r\n" +
"Standin' outside my house\r\n" +
"Tryin' to apologize\r\n" +
"You're so ugly when you cry\r\n" +
"Please, just cu[...]";
private static final String UMLAUTS_TRIMMED = "Das war ein Super Sommer in jedem Augenblick.\r\n" +
"Wir ließen uns're Träume einfach schweben\r\n" +
"und wenn mich heute einer fragt\r\n" +
"wie definierst du Glück\r\n" +
"\r\n" +
"dann brauch ich gar nicht lang zu überleg[...]";
private static final String HTML = "\n" +
"<!doctype html>\n" +
"<html lang=\"en\" dir=\"ltr\">\n" +
"<head>\n" +
"\t<title>Rihanna:Take A Bow Lyrics - Lyric Wiki - song lyrics, music lyrics</title>\n" +
"\t\t</head>\n" +
"<body class=\"mediawiki ltr ns-0 ns-subject page-Rihanna_Take_A_Bow TOCimprovements skin-oasis\">\n" +
"<div class=\"noprint\" style=\"clear:both; border:solid #BBA34A 1px; margin:0 0 2px 0.5em; padding:2px; font-size:90%; background:#EBDAAC; width:246px; text-align:center; float:right\"><div style=\"float:left; padding:2px\"><img alt=\"Wikipedia\" src=\"http://images1.wikia.nocookie.net/__cb20101130031544/lyricwiki/images/thumb/5/54/Wikipedia_sphere.png/35px-Wikipedia_sphere.png\" width=\"35\" height=\"32\" /></div><div>Wikipedia has an article on<div><i><b><a href=\"http://en.wikipedia.org/wiki/Take_a_Bow_(Rihanna_song)\" class=\"extiw\" title=\"wikipedia:Take a Bow (Rihanna song)\">Take a Bow</a></b></i></div></div></div>\n" +
"<noscript><div class='gracenote-header'>You must enable javascript to view this page. This is a requirement of our licensing agreement with music Gracenote.</div><style type='text/css'>.lyricbox{display:none !important;}</style></noscript>\n" +
"<div class='lyricbox'><div class='rtMatcher'><a href='http://www.ringtonematcher.com/co/ringtonematcher/02/noc.asp?sid=WILWros&artist=Rihanna&song=Take%2BA%2BBow' rel='nofollow' target='_blank'><img src='http://images.wikia.nocookie.net/common/__cb46229/extensions/3rdparty/LyricWiki/phone_left.gif' alt='phone' width='16' height='17'/> Send \"Take A Bow\" Ringtone to your Cell <img src='http://images.wikia.nocookie.net/common/__cb46229/extensions/3rdparty/LyricWiki/phone_right.gif' alt='phone' width='16' height='17'/></a></div>Oh, how 'bout a round of applause?<br />Yeah, standin' ovation<br />Oooh, oh yeah, yeah y-yeah yeah<br /><br />You look so dumb right now<br />Standin' outside my house<br />Tryin' to apologize<br />You're so ugly when you cry<br />Please, just cut it out<br /><br />Don't tell me you're sorry 'cause you're not<br />Baby when I know you're only sorry you got caught<br /><br />But you put on quite a show (ooh)<br />Really had me going<br />But now it's time to go (ooh)<br />Curtains finally closing<br /><br />That was quite a show (ooh)<br />Very entertaining<br />But it's over now<br />(But it's over now)<br />Go on and take a bow<br />Oh oh oh<br /><br />Grab your clothes and get gone (Get gone)<br />Ya better hurry up before the sprinklers come on (Come on)<br />Talkin' 'bout, "Girl I love you, you're the one."<br />This just looks like a rerun<br />Please, what else is on?<br /><br />And don't tell me you're sorry cause you're not (mhmm)<br />Baby when I know you're only sorry you got caught<br /><br />But you put on quite a show (ooh)<br />Really had me going<br />But now it's time to go<br />Curtains finally closing<br /><br />That was quite a show<br />Very entertaining<br />But it's over now<br />(But it's over now)<br />Go on and take a bow<br /><br />Ohh, and the award for the best liar goes to you<br />For making me believe that you could be faithful to me<br />Let's hear your speech out<br /><br />How 'bout a round of applause?<br />A standin' ovation<br /><br />But you put on quite a show<br />Really had me going<br />Now it's time to go<br />Curtains finally closing<br /><br />That was quite a show<br />Very entertaining<br />But it's over now<br />(But it's over now)<br />Go on and take a bow<br /><br />But it's over now...<!-- \n" +
"--><div class='rtMatcher'><a href='http://www.ringtonematcher.com/co/ringtonematcher/02/noc.asp?sid=WILWros&artist=Rihanna&song=Take%2BA%2BBow' rel='nofollow' target='_blank'><img src='http://images.wikia.nocookie.net/common/__cb46229/extensions/3rdparty/LyricWiki/phone_left.gif' alt='phone' width='16' height='17'/> Send \"Take A Bow\" Ringtone to your Cell <img src='http://images.wikia.nocookie.net/common/__cb46229/extensions/3rdparty/LyricWiki/phone_right.gif' alt='phone' width='16' height='17'/></a></div><div class='lyricsbreak'></div>\n" +
"</div>\n" +
"</body>\n" +
"</html>";
private static final String PLAIN = "Oh, how 'bout a round of applause?\r\n" +
"Yeah, standin' ovation\r\n" +
"Oooh, oh yeah, yeah y-yeah yeah\r\n" +
"\r\n" +
"You look so dumb right now\r\n" +
"Standin' outside my house\r\n" +
"Tryin' to apologize\r\n" +
"You're so ugly when you cry\r\n" +
"Please, just cut it out\r\n" +
"\r\n" +
"Don't tell me you're sorry 'cause you're not\r\n" +
"Baby when I know you're only sorry you got caught\r\n" +
"\r\n" +
"But you put on quite a show (ooh)\r\n" +
"Really had me going\r\n" +
"But now it's time to go (ooh)\r\n" +
"Curtains finally closing\r\n" +
"\r\n" +
"That was quite a show (ooh)\r\n" +
"Very entertaining\r\n" +
"But it's over now\r\n" +
"(But it's over now)\r\n" +
"Go on and take a bow\r\n" +
"Oh oh oh\r\n" +
"\r\n" +
"Grab your clothes and get gone (Get gone)\r\n" +
"Ya better hurry up before the sprinklers come on (Come on)\r\n" +
"Talkin' 'bout, \"Girl I love you, you're the one.\"\r\n" +
"This just looks like a rerun\r\n" +
"Please, what else is on?\r\n" +
"\r\n" +
"And don't tell me you're sorry cause you're not (mhmm)\r\n" +
"Baby when I know you're only sorry you got caught\r\n" +
"\r\n" +
"But you put on quite a show (ooh)\r\n" +
"Really had me going\r\n" +
"But now it's time to go\r\n" +
"Curtains finally closing\r\n" +
"\r\n" +
"That was quite a show\r\n" +
"Very entertaining\r\n" +
"But it's over now\r\n" +
"(But it's over now)\r\n" +
"Go on and take a bow\r\n" +
"\r\n" +
"Ohh, and the award for the best liar goes to you\r\n" +
"For making me believe that you could be faithful to me\r\n" +
"Let's hear your speech out\r\n" +
"\r\n" +
"How 'bout a round of applause?\r\n" +
"A standin' ovation\r\n" +
"\r\n" +
"But you put on quite a show\r\n" +
"Really had me going\r\n" +
"Now it's time to go\r\n" +
"Curtains finally closing\r\n" +
"\r\n" +
"That was quite a show\r\n" +
"Very entertaining\r\n" +
"But it's over now\r\n" +
"(But it's over now)\r\n" +
"Go on and take a bow\r\n" +
"\r\n" +
"But it's over now...";
private static final String UMLAUTS = "Das war ein Super Sommer in jedem Augenblick.\r\n" +
"Wir ließen uns're Träume einfach schweben\r\n" +
"und wenn mich heute einer fragt\r\n" +
"wie definierst du Glück\r\n" +
"\r\n" +
"dann brauch ich gar nicht lang zu überlegen:\r\n" +
"\r\n" +
"Die Sonne\r\n" +
"die Sonne und du\r\n" +
"\r\n" +
"uh uh uh uh\r\n" +
"gehör'n dazu\r\n" +
"\r\n" +
"die Sonne\r\n" +
"die Sonne und du\r\n" +
"\r\n" +
"uh uh uh uh\r\n" +
"gehör'n dazu.\r\n" +
"\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la und du.\r\n" +
"\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la und du.\r\n" +
"\r\n" +
"Das wird ein Super Sommer\r\n" +
"wenn wir uns wiedersehn.\r\n" +
"Die Aussicht läßt mich Frost und Streß ertragen\r\n" +
"und wenn mich heute einer fragt\r\n" +
"sie definierst du schön\r\n" +
"\r\n" +
"dann werde ich ihm selbstverständlich sagen:\r\n" +
"\r\n" +
"Die Sonne\r\n" +
"die Sonne und du\r\n" +
"\r\n" +
"uh uh uh uh\r\n" +
"gehör'n dazu\r\n" +
"\r\n" +
"die Sonne\r\n" +
"die Sonne und du\r\n" +
"\r\n" +
"uh uh uh uh\r\n" +
"gehör'n dazu.\r\n" +
"\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la und du.\r\n" +
"\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la und du.\r\n" +
"\r\n" +
"Ibiza\r\n" +
"Saint Tropez\r\n" +
"Sylt und der Wörthersee\r\n" +
"\r\n" +
"Las Palmas\r\n" +
"Rimini und du.\r\n" +
"Cannes und Venezia\r\n" +
"Ascona\r\n" +
"Korsika\r\n" +
"\r\n" +
"Malorca\r\n" +
"Timmendorf und du.\r\n" +
"\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la und du.\r\n" +
"\r\n" +
"Hawaii und Martinique\r\n" +
"Jamaica\r\n" +
"Mozambique\r\n" +
"\r\n" +
"Rio und Malibu und du.\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la la la.\r\n" +
"\r\n" +
"La la la la la la\r\n" +
"la la la la la la\r\n" +
"la la la la la la und du.\r\n" +
"a-ha\r\n" +
"\r\n" +
"doch wir sind gleich wieder zur";
protected void setUp() throws Exception {
super.setUp();
tempDir = File.createTempFile("lyrics", ".cache");
assertTrue(tempDir.delete());
assertTrue(tempDir.mkdir());
}
protected void tearDown() throws Exception {
assertTrue(tempDir.delete());
super.tearDown();
}
public void testDecodeEntities() {
assertEquals("f\u00fchr", StringHelper.decodeEntities("führ"));
}
public void testDownloadLyrics() throws IOException {
client.setLyricsDirectoryName(tempDir.getAbsolutePath());
assertEquals(PLAIN_TRIMMED, client.downloadLyrics("Rihanna", "Take a bow"));
}
public void testDownloadLyricsWithUmlauts() throws IOException {
client.setLyricsDirectoryName(tempDir.getAbsolutePath());
assertEquals(UMLAUTS_TRIMMED, client.downloadLyrics("Udo Jürgens", "Die Sonne und Du"));
}
public void testExtractLyrics() {
assertEquals(PLAIN, client.extractLyrics(HTML));
}
public void testScrapeLyrics() throws IOException {
assertEquals(PLAIN, client.scrapeLyrics("Rihanna", "Take a bow"));
}
public void testScrapeLyricsWithUmlauts() throws IOException {
assertEquals(UMLAUTS, client.scrapeLyrics("Udo Jürgens", "Die Sonne und Du"));
}
}