File System Renames (No content changes)
Signed-off-by: Andrew DeMaria <lostonamountain@gmail.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package org.libresonic.player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class MissingTranslations {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String[] locales = {"da", "de", "es", "pt", "fi", "fr", "is", "it", "ja_JP", "mk", "nl", "no", "pl", "ru", "sl", "sv", "zh_CN", "zh_TW"};
|
||||
|
||||
for (String locale : locales) {
|
||||
diff(locale, "en");
|
||||
// diff("en", locale);
|
||||
}
|
||||
}
|
||||
|
||||
private static void diff(String locale1, String locale2) throws IOException {
|
||||
Properties en = new Properties();
|
||||
en.load(MissingTranslations.class.getResourceAsStream("/org/libresonic/player/i18n/ResourceBundle_" + locale1 + ".properties"));
|
||||
SortedMap<Object,Object> enSorted = new TreeMap<Object, Object>(en);
|
||||
|
||||
Properties mk = new Properties();
|
||||
mk.load(MissingTranslations.class.getResourceAsStream("/org/libresonic/player/i18n/ResourceBundle_" + locale2 + ".properties"));
|
||||
|
||||
System.out.println("\nMessages present in locale " + locale1 + " and missing in locale " + locale2 + ":");
|
||||
int count = 0;
|
||||
for (Map.Entry<Object, Object> entry : enSorted.entrySet()) {
|
||||
if (!mk.containsKey(entry.getKey())) {
|
||||
System.out.println(entry.getKey() + " = " + entry.getValue());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\nTotal: " + count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package org.libresonic.player;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.libresonic.player.dao.DaoHelper;
|
||||
import org.libresonic.player.service.MediaScannerService;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TestCaseUtils {
|
||||
|
||||
private static File libresonicHomeDirForTest = null;
|
||||
|
||||
/**
|
||||
* Returns the path of the LIBRESONIC_HOME directory to use for tests.
|
||||
* This will create a temporary directory.
|
||||
*
|
||||
* @return LIBRESONIC_HOME directory path.
|
||||
* @throws RuntimeException if it fails to create the temp directory.
|
||||
*/
|
||||
public static String libresonicHomePathForTest() {
|
||||
|
||||
if (libresonicHomeDirForTest == null) {
|
||||
try {
|
||||
libresonicHomeDirForTest = Files.createTempDirectory("libresonic_test_").toFile();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error while creating temporary LIBRESONIC_HOME directory for tests");
|
||||
}
|
||||
System.out.println("LIBRESONIC_HOME directory will be "+libresonicHomeDirForTest.getAbsolutePath());
|
||||
}
|
||||
return libresonicHomeDirForTest.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans the LIBRESONIC_HOME directory used for tests.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void cleanLibresonicHomeForTest() throws IOException {
|
||||
|
||||
File libresonicHomeDir = new File(libresonicHomePathForTest());
|
||||
if (libresonicHomeDir.exists() && libresonicHomeDir.isDirectory()) {
|
||||
System.out.println("Delete libresonic home (ie. "+libresonicHomeDir.getAbsolutePath()+").");
|
||||
try {
|
||||
FileUtils.deleteDirectory(libresonicHomeDir);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error while deleting libresonic home.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a map of records count per table.
|
||||
*
|
||||
* @param daoHelper DaoHelper object
|
||||
* @return Map table name -> records count
|
||||
*/
|
||||
public static Map<String, Integer> recordsInAllTables(DaoHelper daoHelper) {
|
||||
List<String> tableNames = daoHelper.getJdbcTemplate().queryForList("" +
|
||||
"select table_name " +
|
||||
"from information_schema.system_tables " +
|
||||
"where table_name not like 'SYSTEM%'"
|
||||
, String.class);
|
||||
Map<String, Integer> nbRecords =
|
||||
tableNames.stream()
|
||||
.collect(Collectors.toMap(table -> table, table -> recordsInTable(table,daoHelper)));
|
||||
|
||||
return nbRecords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts records in a table.
|
||||
*
|
||||
* @param tableName
|
||||
* @param daoHelper
|
||||
* @return
|
||||
*/
|
||||
public static Integer recordsInTable(String tableName, DaoHelper daoHelper) {
|
||||
return daoHelper.getJdbcTemplate().queryForObject("select count(1) from " + tableName,Integer.class);
|
||||
}
|
||||
|
||||
|
||||
public static ApplicationContext loadSpringApplicationContext(String baseResources) {
|
||||
String applicationContextService = baseResources + "applicationContext-service.xml";
|
||||
String applicationContextCache = baseResources + "applicationContext-cache.xml";
|
||||
|
||||
String[] configLocations = new String[]{
|
||||
TestCaseUtils.class.getClass().getResource(applicationContextCache).toString(),
|
||||
TestCaseUtils.class.getClass().getResource(applicationContextService).toString()
|
||||
};
|
||||
return new ClassPathXmlApplicationContext(configLocations);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans the music library * @param mediaScannerService
|
||||
*/
|
||||
public static void execScan(MediaScannerService mediaScannerService) {
|
||||
mediaScannerService.scanLibrary();
|
||||
|
||||
while (mediaScannerService.isScanning()) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.controller;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.util.Pair;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
* @version $Id: StreamControllerTestCase.java 3307 2013-01-04 13:48:49Z sindre_mehus $
|
||||
*/
|
||||
public class HLSControllerTestCase extends TestCase {
|
||||
|
||||
public void testParseBitRate() {
|
||||
HLSController controller = new HLSController();
|
||||
|
||||
Pair<Integer,Dimension> pair = controller.parseBitRate("1000");
|
||||
assertEquals(1000, pair.getFirst().intValue());
|
||||
assertNull(pair.getSecond());
|
||||
|
||||
pair = controller.parseBitRate("1000@400x300");
|
||||
assertEquals(1000, pair.getFirst().intValue());
|
||||
assertEquals(400, pair.getSecond().width);
|
||||
assertEquals(300, pair.getSecond().height);
|
||||
|
||||
try {
|
||||
controller.parseBitRate("asdfl");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
try {
|
||||
controller.parseBitRate("1000@300");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
try {
|
||||
controller.parseBitRate("1000@300x400ZZ");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.controller;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public class StreamControllerTestCase extends TestCase {
|
||||
|
||||
public void testGetRequestedVideoSize() {
|
||||
StreamController controller = new StreamController();
|
||||
|
||||
// Valid spec.
|
||||
assertEquals("Wrong size.", new Dimension(123, 456), controller.getRequestedVideoSize("123x456"));
|
||||
assertEquals("Wrong size.", new Dimension(456, 123), controller.getRequestedVideoSize("456x123"));
|
||||
assertEquals("Wrong size.", new Dimension(1, 1), controller.getRequestedVideoSize("1x1"));
|
||||
|
||||
// Missing spec.
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize(null));
|
||||
|
||||
// Invalid spec.
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("123"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("123x"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("x123"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("x"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("foo123x456bar"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("foo123x456"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("123x456bar"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("fooxbar"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("-1x1"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("1x-1"));
|
||||
|
||||
// Too large.
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("3000x100"));
|
||||
assertNull("Wrong size.", controller.getRequestedVideoSize("100x3000"));
|
||||
}
|
||||
|
||||
public void testGetSuitableVideoSize() {
|
||||
|
||||
// 4:3 aspect rate
|
||||
doTestGetSuitableVideoSize(1280, 960, 200, 400, 300);
|
||||
doTestGetSuitableVideoSize(1280, 960, 300, 400, 300);
|
||||
doTestGetSuitableVideoSize(1280, 960, 400, 480, 360);
|
||||
doTestGetSuitableVideoSize(1280, 960, 500, 480, 360);
|
||||
doTestGetSuitableVideoSize(1280, 960, 600, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 700, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 800, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 900, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 1000, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 1100, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 1200, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 1500, 640, 480);
|
||||
doTestGetSuitableVideoSize(1280, 960, 1800, 960, 720);
|
||||
doTestGetSuitableVideoSize(1280, 960, 2000, 960, 720);
|
||||
|
||||
// 16:9 aspect rate
|
||||
doTestGetSuitableVideoSize(1280, 720, 200, 400, 226);
|
||||
doTestGetSuitableVideoSize(1280, 720, 300, 400, 226);
|
||||
doTestGetSuitableVideoSize(1280, 720, 400, 480, 270);
|
||||
doTestGetSuitableVideoSize(1280, 720, 500, 480, 270);
|
||||
doTestGetSuitableVideoSize(1280, 720, 600, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 700, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 800, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 900, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 1000, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 1100, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 1200, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 1500, 640, 360);
|
||||
doTestGetSuitableVideoSize(1280, 720, 1800, 960, 540);
|
||||
doTestGetSuitableVideoSize(1280, 720, 2000, 960, 540);
|
||||
|
||||
// Small original size.
|
||||
doTestGetSuitableVideoSize(100, 100, 1000, 100, 100);
|
||||
doTestGetSuitableVideoSize(100, 1000, 1000, 100, 1000);
|
||||
doTestGetSuitableVideoSize(1000, 100, 100, 1000, 100);
|
||||
|
||||
// Unknown original size.
|
||||
doTestGetSuitableVideoSize(720, null, 200, 400, 226);
|
||||
doTestGetSuitableVideoSize(null, 540, 300, 400, 226);
|
||||
doTestGetSuitableVideoSize(null, null, 400, 480, 270);
|
||||
doTestGetSuitableVideoSize(720, null, 500, 480, 270);
|
||||
doTestGetSuitableVideoSize(null, 540, 600, 640, 360);
|
||||
doTestGetSuitableVideoSize(null, null, 700, 640, 360);
|
||||
doTestGetSuitableVideoSize(720, null, 1200, 640, 360);
|
||||
doTestGetSuitableVideoSize(null, 540, 1500, 640, 360);
|
||||
doTestGetSuitableVideoSize(null, null, 2000, 960, 540);
|
||||
|
||||
// Odd original size.
|
||||
doTestGetSuitableVideoSize(203, 101, 1500, 204, 102);
|
||||
doTestGetSuitableVideoSize(464, 853, 1500, 464, 854);
|
||||
}
|
||||
|
||||
private void doTestGetSuitableVideoSize(Integer existingWidth, Integer existingHeight, Integer maxBitRate, int expectedWidth, int expectedHeight) {
|
||||
StreamController controller = new StreamController();
|
||||
Dimension dimension = controller.getSuitableVideoSize(existingWidth, existingHeight, maxBitRate);
|
||||
assertEquals("Wrong width.", expectedWidth, dimension.width);
|
||||
assertEquals("Wrong height.", expectedHeight, dimension.height);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.libresonic.player.util.LibresonicHomeRule;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml"})
|
||||
public class DaoTestCaseBean2 {
|
||||
@ClassRule
|
||||
public static final SpringClassRule classRule = new SpringClassRule() {
|
||||
LibresonicHomeRule libresonicRule = new LibresonicHomeRule();
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
Statement newBase = libresonicRule.apply(base, description);
|
||||
return super.apply(newBase, description);
|
||||
}
|
||||
};
|
||||
|
||||
@Rule
|
||||
public final SpringMethodRule springMethodRule = new SpringMethodRule();
|
||||
|
||||
@Autowired
|
||||
GenericDaoHelper genericDaoHelper;
|
||||
|
||||
|
||||
JdbcTemplate getJdbcTemplate() {
|
||||
return genericDaoHelper.getJdbcTemplate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.libresonic.player.domain.InternetRadio;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test of {@link InternetRadioDao}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class InternetRadioDaoTestCase extends DaoTestCaseBean2 {
|
||||
|
||||
@Autowired
|
||||
InternetRadioDao internetRadioDao;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getJdbcTemplate().execute("delete from internet_radio");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateInternetRadio() {
|
||||
InternetRadio radio = new InternetRadio("name", "streamUrl", "homePageUrl", true, new Date());
|
||||
internetRadioDao.createInternetRadio(radio);
|
||||
|
||||
InternetRadio newRadio = internetRadioDao.getAllInternetRadios().get(0);
|
||||
assertInternetRadioEquals(radio, newRadio);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateInternetRadio() {
|
||||
InternetRadio radio = new InternetRadio("name", "streamUrl", "homePageUrl", true, new Date());
|
||||
internetRadioDao.createInternetRadio(radio);
|
||||
radio = internetRadioDao.getAllInternetRadios().get(0);
|
||||
|
||||
radio.setName("newName");
|
||||
radio.setStreamUrl("newStreamUrl");
|
||||
radio.setHomepageUrl("newHomePageUrl");
|
||||
radio.setEnabled(false);
|
||||
radio.setChanged(new Date(234234L));
|
||||
internetRadioDao.updateInternetRadio(radio);
|
||||
|
||||
InternetRadio newRadio = internetRadioDao.getAllInternetRadios().get(0);
|
||||
assertInternetRadioEquals(radio, newRadio);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteInternetRadio() {
|
||||
assertEquals("Wrong number of radios.", 0, internetRadioDao.getAllInternetRadios().size());
|
||||
|
||||
internetRadioDao.createInternetRadio(new InternetRadio("name", "streamUrl", "homePageUrl", true, new Date()));
|
||||
assertEquals("Wrong number of radios.", 1, internetRadioDao.getAllInternetRadios().size());
|
||||
|
||||
internetRadioDao.createInternetRadio(new InternetRadio("name", "streamUrl", "homePageUrl", true, new Date()));
|
||||
assertEquals("Wrong number of radios.", 2, internetRadioDao.getAllInternetRadios().size());
|
||||
|
||||
internetRadioDao.deleteInternetRadio(internetRadioDao.getAllInternetRadios().get(0).getId());
|
||||
assertEquals("Wrong number of radios.", 1, internetRadioDao.getAllInternetRadios().size());
|
||||
|
||||
internetRadioDao.deleteInternetRadio(internetRadioDao.getAllInternetRadios().get(0).getId());
|
||||
assertEquals("Wrong number of radios.", 0, internetRadioDao.getAllInternetRadios().size());
|
||||
}
|
||||
|
||||
private void assertInternetRadioEquals(InternetRadio expected, InternetRadio actual) {
|
||||
assertEquals("Wrong name.", expected.getName(), actual.getName());
|
||||
assertEquals("Wrong stream url.", expected.getStreamUrl(), actual.getStreamUrl());
|
||||
assertEquals("Wrong home page url.", expected.getHomepageUrl(), actual.getHomepageUrl());
|
||||
assertEquals("Wrong enabled state.", expected.isEnabled(), actual.isEnabled());
|
||||
assertEquals("Wrong changed date.", expected.getChanged(), actual.getChanged());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.libresonic.player.domain.MusicFolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test of {@link MusicFolderDao}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class MusicFolderDaoTestCase extends DaoTestCaseBean2 {
|
||||
|
||||
@Autowired
|
||||
MusicFolderDao musicFolderDao;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getJdbcTemplate().execute("delete from music_folder");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMusicFolder() {
|
||||
MusicFolder musicFolder = new MusicFolder(new File("path"), "name", true, new Date());
|
||||
musicFolderDao.createMusicFolder(musicFolder);
|
||||
|
||||
MusicFolder newMusicFolder = musicFolderDao.getAllMusicFolders().get(0);
|
||||
assertMusicFolderEquals(musicFolder, newMusicFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateMusicFolder() {
|
||||
MusicFolder musicFolder = new MusicFolder(new File("path"), "name", true, new Date());
|
||||
musicFolderDao.createMusicFolder(musicFolder);
|
||||
musicFolder = musicFolderDao.getAllMusicFolders().get(0);
|
||||
|
||||
musicFolder.setPath(new File("newPath"));
|
||||
musicFolder.setName("newName");
|
||||
musicFolder.setEnabled(false);
|
||||
musicFolder.setChanged(new Date(234234L));
|
||||
musicFolderDao.updateMusicFolder(musicFolder);
|
||||
|
||||
MusicFolder newMusicFolder = musicFolderDao.getAllMusicFolders().get(0);
|
||||
assertMusicFolderEquals(musicFolder, newMusicFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteMusicFolder() {
|
||||
assertEquals("Wrong number of music folders.", 0, musicFolderDao.getAllMusicFolders().size());
|
||||
|
||||
musicFolderDao.createMusicFolder(new MusicFolder(new File("path"), "name", true, new Date()));
|
||||
assertEquals("Wrong number of music folders.", 1, musicFolderDao.getAllMusicFolders().size());
|
||||
|
||||
musicFolderDao.createMusicFolder(new MusicFolder(new File("path"), "name", true, new Date()));
|
||||
assertEquals("Wrong number of music folders.", 2, musicFolderDao.getAllMusicFolders().size());
|
||||
|
||||
musicFolderDao.deleteMusicFolder(musicFolderDao.getAllMusicFolders().get(0).getId());
|
||||
assertEquals("Wrong number of music folders.", 1, musicFolderDao.getAllMusicFolders().size());
|
||||
|
||||
musicFolderDao.deleteMusicFolder(musicFolderDao.getAllMusicFolders().get(0).getId());
|
||||
assertEquals("Wrong number of music folders.", 0, musicFolderDao.getAllMusicFolders().size());
|
||||
}
|
||||
|
||||
private void assertMusicFolderEquals(MusicFolder expected, MusicFolder actual) {
|
||||
assertEquals("Wrong name.", expected.getName(), actual.getName());
|
||||
assertEquals("Wrong path.", expected.getPath(), actual.getPath());
|
||||
assertEquals("Wrong enabled state.", expected.isEnabled(), actual.isEnabled());
|
||||
assertEquals("Wrong changed date.", expected.getChanged(), actual.getChanged());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.libresonic.player.domain.MusicFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class MusicFolderTestData {
|
||||
|
||||
private static String baseResources = "/MEDIAS/";
|
||||
|
||||
public static String resolveBaseMediaPath() {
|
||||
String baseDir = MusicFolderTestData.class.getResource(baseResources).toString().replace("file:","");
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public static String resolveMusicFolderPath() {
|
||||
return (MusicFolderTestData.resolveBaseMediaPath() + "Music");
|
||||
}
|
||||
|
||||
public static String resolveMusic2FolderPath() {
|
||||
return (MusicFolderTestData.resolveBaseMediaPath() + "Music2");
|
||||
}
|
||||
|
||||
public static List<MusicFolder> getTestMusicFolders() {
|
||||
List<MusicFolder> liste = new ArrayList<>();
|
||||
File musicDir = new File(MusicFolderTestData.resolveMusicFolderPath());
|
||||
MusicFolder musicFolder = new MusicFolder(1,musicDir,"Music",true,new Date());
|
||||
liste.add(musicFolder);
|
||||
|
||||
File music2Dir = new File(MusicFolderTestData.resolveMusic2FolderPath());
|
||||
MusicFolder musicFolder2 = new MusicFolder(2,music2Dir,"Music2",true,new Date());
|
||||
liste.add(musicFolder2);
|
||||
return liste;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.libresonic.player.domain.PlayQueue;
|
||||
import org.libresonic.player.domain.Player;
|
||||
import org.libresonic.player.domain.PlayerTechnology;
|
||||
import org.libresonic.player.domain.TranscodeScheme;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit test of {@link PlayerDao}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class PlayerDaoTestCase extends DaoTestCaseBean2 {
|
||||
|
||||
@Autowired
|
||||
PlayerDao playerDao;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getJdbcTemplate().execute("delete from player");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreatePlayer() {
|
||||
Player player = new Player();
|
||||
player.setName("name");
|
||||
player.setType("type");
|
||||
player.setUsername("username");
|
||||
player.setIpAddress("ipaddress");
|
||||
player.setDynamicIp(false);
|
||||
player.setAutoControlEnabled(false);
|
||||
player.setTechnology(PlayerTechnology.EXTERNAL_WITH_PLAYLIST);
|
||||
player.setClientId("android");
|
||||
player.setLastSeen(new Date());
|
||||
player.setTranscodeScheme(TranscodeScheme.MAX_160);
|
||||
|
||||
playerDao.createPlayer(player);
|
||||
Player newPlayer = playerDao.getAllPlayers().get(0);
|
||||
assertPlayerEquals(player, newPlayer);
|
||||
|
||||
Player newPlayer2 = playerDao.getPlayerById(newPlayer.getId());
|
||||
assertPlayerEquals(player, newPlayer2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultValues() {
|
||||
playerDao.createPlayer(new Player());
|
||||
Player player = playerDao.getAllPlayers().get(0);
|
||||
|
||||
assertTrue("Player should have dynamic IP by default.", player.isDynamicIp());
|
||||
assertTrue("Player should be auto-controlled by default.", player.isAutoControlEnabled());
|
||||
assertNull("Player client ID should be null by default.", player.getClientId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdentity() {
|
||||
Player player = new Player();
|
||||
|
||||
playerDao.createPlayer(player);
|
||||
assertEquals("Wrong ID", "1", player.getId());
|
||||
assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.createPlayer(player);
|
||||
assertEquals("Wrong ID", "2", player.getId());
|
||||
assertEquals("Wrong number of players.", 2, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.createPlayer(player);
|
||||
assertEquals("Wrong ID", "3", player.getId());
|
||||
assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.deletePlayer("3");
|
||||
playerDao.createPlayer(player);
|
||||
assertEquals("Wrong ID", "3", player.getId());
|
||||
assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.deletePlayer("2");
|
||||
playerDao.createPlayer(player);
|
||||
assertEquals("Wrong ID", "4", player.getId());
|
||||
assertEquals("Wrong number of players.", 3, playerDao.getAllPlayers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaylist() {
|
||||
Player player = new Player();
|
||||
playerDao.createPlayer(player);
|
||||
PlayQueue playQueue = player.getPlayQueue();
|
||||
assertNotNull("Missing playlist.", playQueue);
|
||||
|
||||
playerDao.deletePlayer(player.getId());
|
||||
playerDao.createPlayer(player);
|
||||
assertNotSame("Wrong playlist.", playQueue, player.getPlayQueue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPlayersForUserAndClientId() {
|
||||
Player player = new Player();
|
||||
player.setUsername("sindre");
|
||||
playerDao.createPlayer(player);
|
||||
player = playerDao.getAllPlayers().get(0);
|
||||
|
||||
List<Player> players = playerDao.getPlayersForUserAndClientId("sindre", null);
|
||||
assertFalse("Error in getPlayersForUserAndClientId().", players.isEmpty());
|
||||
assertPlayerEquals(player, players.get(0));
|
||||
assertTrue("Error in getPlayersForUserAndClientId().", playerDao.getPlayersForUserAndClientId("sindre", "foo").isEmpty());
|
||||
|
||||
player.setClientId("foo");
|
||||
playerDao.updatePlayer(player);
|
||||
|
||||
players = playerDao.getPlayersForUserAndClientId("sindre", null);
|
||||
assertTrue("Error in getPlayersForUserAndClientId().", players.isEmpty());
|
||||
players = playerDao.getPlayersForUserAndClientId("sindre", "foo");
|
||||
assertFalse("Error in getPlayersForUserAndClientId().", players.isEmpty());
|
||||
assertPlayerEquals(player, players.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdatePlayer() {
|
||||
Player player = new Player();
|
||||
playerDao.createPlayer(player);
|
||||
assertPlayerEquals(player, playerDao.getAllPlayers().get(0));
|
||||
|
||||
player.setName("name");
|
||||
player.setType("Winamp");
|
||||
player.setTechnology(PlayerTechnology.WEB);
|
||||
player.setClientId("foo");
|
||||
player.setUsername("username");
|
||||
player.setIpAddress("ipaddress");
|
||||
player.setDynamicIp(true);
|
||||
player.setAutoControlEnabled(false);
|
||||
player.setLastSeen(new Date());
|
||||
player.setTranscodeScheme(TranscodeScheme.MAX_160);
|
||||
|
||||
playerDao.updatePlayer(player);
|
||||
Player newPlayer = playerDao.getAllPlayers().get(0);
|
||||
assertPlayerEquals(player, newPlayer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeletePlayer() {
|
||||
assertEquals("Wrong number of players.", 0, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.createPlayer(new Player());
|
||||
assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.createPlayer(new Player());
|
||||
assertEquals("Wrong number of players.", 2, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.deletePlayer("1");
|
||||
assertEquals("Wrong number of players.", 1, playerDao.getAllPlayers().size());
|
||||
|
||||
playerDao.deletePlayer("2");
|
||||
assertEquals("Wrong number of players.", 0, playerDao.getAllPlayers().size());
|
||||
}
|
||||
|
||||
private void assertPlayerEquals(Player expected, Player actual) {
|
||||
assertEquals("Wrong ID.", expected.getId(), actual.getId());
|
||||
assertEquals("Wrong name.", expected.getName(), actual.getName());
|
||||
assertEquals("Wrong technology.", expected.getTechnology(), actual.getTechnology());
|
||||
assertEquals("Wrong client ID.", expected.getClientId(), actual.getClientId());
|
||||
assertEquals("Wrong type.", expected.getType(), actual.getType());
|
||||
assertEquals("Wrong username.", expected.getUsername(), actual.getUsername());
|
||||
assertEquals("Wrong IP address.", expected.getIpAddress(), actual.getIpAddress());
|
||||
assertEquals("Wrong dynamic IP.", expected.isDynamicIp(), actual.isDynamicIp());
|
||||
assertEquals("Wrong auto control enabled.", expected.isAutoControlEnabled(), actual.isAutoControlEnabled());
|
||||
assertEquals("Wrong last seen.", expected.getLastSeen(), actual.getLastSeen());
|
||||
assertEquals("Wrong transcode scheme.", expected.getTranscodeScheme(), actual.getTranscodeScheme());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.libresonic.player.domain.PodcastChannel;
|
||||
import org.libresonic.player.domain.PodcastEpisode;
|
||||
import org.libresonic.player.domain.PodcastStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit test of {@link PodcastDao}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class PodcastDaoTestCase extends DaoTestCaseBean2 {
|
||||
|
||||
@Autowired
|
||||
PodcastDao podcastDao;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getJdbcTemplate().execute("delete from podcast_channel");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateChannel() {
|
||||
PodcastChannel channel = new PodcastChannel("http://foo");
|
||||
podcastDao.createChannel(channel);
|
||||
|
||||
PodcastChannel newChannel = podcastDao.getAllChannels().get(0);
|
||||
assertNotNull("Wrong ID.", newChannel.getId());
|
||||
assertChannelEquals(channel, newChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannelId() {
|
||||
int channelId = podcastDao.createChannel(new PodcastChannel("http://foo"));
|
||||
|
||||
assertEquals("Error in createChannel.", channelId + 1, podcastDao.createChannel(new PodcastChannel("http://foo")));
|
||||
assertEquals("Error in createChannel.", channelId + 2, podcastDao.createChannel(new PodcastChannel("http://foo")));
|
||||
assertEquals("Error in createChannel.", channelId + 3, podcastDao.createChannel(new PodcastChannel("http://foo")));
|
||||
|
||||
podcastDao.deleteChannel(channelId + 1);
|
||||
assertEquals("Error in createChannel.", channelId + 4, podcastDao.createChannel(new PodcastChannel("http://foo")));
|
||||
|
||||
podcastDao.deleteChannel(channelId + 4);
|
||||
assertEquals("Error in createChannel.", channelId + 5, podcastDao.createChannel(new PodcastChannel("http://foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateChannel() {
|
||||
PodcastChannel channel = new PodcastChannel("http://foo");
|
||||
podcastDao.createChannel(channel);
|
||||
channel = podcastDao.getAllChannels().get(0);
|
||||
|
||||
channel.setUrl("http://bar");
|
||||
channel.setTitle("Title");
|
||||
channel.setDescription("Description");
|
||||
channel.setImageUrl("http://foo/bar.jpg");
|
||||
channel.setStatus(PodcastStatus.ERROR);
|
||||
channel.setErrorMessage("Something went terribly wrong.");
|
||||
|
||||
podcastDao.updateChannel(channel);
|
||||
PodcastChannel newChannel = podcastDao.getAllChannels().get(0);
|
||||
|
||||
assertEquals("Wrong ID.", channel.getId(), newChannel.getId());
|
||||
assertChannelEquals(channel, newChannel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteChannel() {
|
||||
assertEquals("Wrong number of channels.", 0, podcastDao.getAllChannels().size());
|
||||
|
||||
PodcastChannel channel = new PodcastChannel("http://foo");
|
||||
podcastDao.createChannel(channel);
|
||||
assertEquals("Wrong number of channels.", 1, podcastDao.getAllChannels().size());
|
||||
|
||||
podcastDao.createChannel(channel);
|
||||
assertEquals("Wrong number of channels.", 2, podcastDao.getAllChannels().size());
|
||||
|
||||
podcastDao.deleteChannel(podcastDao.getAllChannels().get(0).getId());
|
||||
assertEquals("Wrong number of channels.", 1, podcastDao.getAllChannels().size());
|
||||
|
||||
podcastDao.deleteChannel(podcastDao.getAllChannels().get(0).getId());
|
||||
assertEquals("Wrong number of channels.", 0, podcastDao.getAllChannels().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEpisode() {
|
||||
int channelId = createChannel();
|
||||
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", "path", "title", "description",
|
||||
new Date(), "12:34", null, null, PodcastStatus.NEW, null);
|
||||
podcastDao.createEpisode(episode);
|
||||
|
||||
PodcastEpisode newEpisode = podcastDao.getEpisodes(channelId).get(0);
|
||||
assertNotNull("Wrong ID.", newEpisode.getId());
|
||||
assertEpisodeEquals(episode, newEpisode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEpisode() {
|
||||
assertNull("Error in getEpisode()", podcastDao.getEpisode(23));
|
||||
|
||||
int channelId = createChannel();
|
||||
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", "path", "title", "description",
|
||||
new Date(), "12:34", 3276213L, 2341234L, PodcastStatus.NEW, "error");
|
||||
podcastDao.createEpisode(episode);
|
||||
|
||||
int episodeId = podcastDao.getEpisodes(channelId).get(0).getId();
|
||||
PodcastEpisode newEpisode = podcastDao.getEpisode(episodeId);
|
||||
assertEpisodeEquals(episode, newEpisode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEpisodes() {
|
||||
int channelId = createChannel();
|
||||
PodcastEpisode a = new PodcastEpisode(null, channelId, "a", null, null, null,
|
||||
new Date(3000), null, null, null, PodcastStatus.NEW, null);
|
||||
PodcastEpisode b = new PodcastEpisode(null, channelId, "b", null, null, null,
|
||||
new Date(1000), null, null, null, PodcastStatus.NEW, "error");
|
||||
PodcastEpisode c = new PodcastEpisode(null, channelId, "c", null, null, null,
|
||||
new Date(2000), null, null, null, PodcastStatus.NEW, null);
|
||||
PodcastEpisode d = new PodcastEpisode(null, channelId, "c", null, null, null,
|
||||
null, null, null, null, PodcastStatus.NEW, "");
|
||||
podcastDao.createEpisode(a);
|
||||
podcastDao.createEpisode(b);
|
||||
podcastDao.createEpisode(c);
|
||||
podcastDao.createEpisode(d);
|
||||
|
||||
List<PodcastEpisode> episodes = podcastDao.getEpisodes(channelId);
|
||||
assertEquals("Error in getEpisodes().", 4, episodes.size());
|
||||
assertEpisodeEquals(a, episodes.get(0));
|
||||
assertEpisodeEquals(c, episodes.get(1));
|
||||
assertEpisodeEquals(b, episodes.get(2));
|
||||
assertEpisodeEquals(d, episodes.get(3));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdateEpisode() {
|
||||
int channelId = createChannel();
|
||||
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", null, null, null,
|
||||
null, null, null, null, PodcastStatus.NEW, null);
|
||||
podcastDao.createEpisode(episode);
|
||||
episode = podcastDao.getEpisodes(channelId).get(0);
|
||||
|
||||
episode.setUrl("http://bar");
|
||||
episode.setPath("c:/tmp");
|
||||
episode.setTitle("Title");
|
||||
episode.setDescription("Description");
|
||||
episode.setPublishDate(new Date());
|
||||
episode.setDuration("1:20");
|
||||
episode.setBytesTotal(87628374612L);
|
||||
episode.setBytesDownloaded(9086L);
|
||||
episode.setStatus(PodcastStatus.DOWNLOADING);
|
||||
episode.setErrorMessage("Some error");
|
||||
|
||||
podcastDao.updateEpisode(episode);
|
||||
PodcastEpisode newEpisode = podcastDao.getEpisodes(channelId).get(0);
|
||||
assertEquals("Wrong ID.", episode.getId(), newEpisode.getId());
|
||||
assertEpisodeEquals(episode, newEpisode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteEpisode() {
|
||||
int channelId = createChannel();
|
||||
|
||||
assertEquals("Wrong number of episodes.", 0, podcastDao.getEpisodes(channelId).size());
|
||||
|
||||
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", null, null, null,
|
||||
null, null, null, null, PodcastStatus.NEW, null);
|
||||
|
||||
podcastDao.createEpisode(episode);
|
||||
assertEquals("Wrong number of episodes.", 1, podcastDao.getEpisodes(channelId).size());
|
||||
|
||||
podcastDao.createEpisode(episode);
|
||||
assertEquals("Wrong number of episodes.", 2, podcastDao.getEpisodes(channelId).size());
|
||||
|
||||
podcastDao.deleteEpisode(podcastDao.getEpisodes(channelId).get(0).getId());
|
||||
assertEquals("Wrong number of episodes.", 1, podcastDao.getEpisodes(channelId).size());
|
||||
|
||||
podcastDao.deleteEpisode(podcastDao.getEpisodes(channelId).get(0).getId());
|
||||
assertEquals("Wrong number of episodes.", 0, podcastDao.getEpisodes(channelId).size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testCascadingDelete() {
|
||||
int channelId = createChannel();
|
||||
PodcastEpisode episode = new PodcastEpisode(null, channelId, "http://bar", null, null, null,
|
||||
null, null, null, null, PodcastStatus.NEW, null);
|
||||
podcastDao.createEpisode(episode);
|
||||
podcastDao.createEpisode(episode);
|
||||
assertEquals("Wrong number of episodes.", 2, podcastDao.getEpisodes(channelId).size());
|
||||
|
||||
podcastDao.deleteChannel(channelId);
|
||||
assertEquals("Wrong number of episodes.", 0, podcastDao.getEpisodes(channelId).size());
|
||||
}
|
||||
|
||||
private int createChannel() {
|
||||
PodcastChannel channel = new PodcastChannel("http://foo");
|
||||
podcastDao.createChannel(channel);
|
||||
channel = podcastDao.getAllChannels().get(0);
|
||||
return channel.getId();
|
||||
}
|
||||
|
||||
private void assertChannelEquals(PodcastChannel expected, PodcastChannel actual) {
|
||||
assertEquals("Wrong URL.", expected.getUrl(), actual.getUrl());
|
||||
assertEquals("Wrong title.", expected.getTitle(), actual.getTitle());
|
||||
assertEquals("Wrong description.", expected.getDescription(), actual.getDescription());
|
||||
assertEquals("Wrong image URL.", expected.getImageUrl(), actual.getImageUrl());
|
||||
assertSame("Wrong status.", expected.getStatus(), actual.getStatus());
|
||||
assertEquals("Wrong error message.", expected.getErrorMessage(), actual.getErrorMessage());
|
||||
}
|
||||
|
||||
private void assertEpisodeEquals(PodcastEpisode expected, PodcastEpisode actual) {
|
||||
assertEquals("Wrong URL.", expected.getUrl(), actual.getUrl());
|
||||
assertEquals("Wrong path.", expected.getPath(), actual.getPath());
|
||||
assertEquals("Wrong title.", expected.getTitle(), actual.getTitle());
|
||||
assertEquals("Wrong description.", expected.getDescription(), actual.getDescription());
|
||||
assertEquals("Wrong date.", expected.getPublishDate(), actual.getPublishDate());
|
||||
assertEquals("Wrong duration.", expected.getDuration(), actual.getDuration());
|
||||
assertEquals("Wrong bytes total.", expected.getBytesTotal(), actual.getBytesTotal());
|
||||
assertEquals("Wrong bytes downloaded.", expected.getBytesDownloaded(), actual.getBytesDownloaded());
|
||||
assertSame("Wrong status.", expected.getStatus(), actual.getStatus());
|
||||
assertEquals("Wrong error message.", expected.getErrorMessage(), actual.getErrorMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.libresonic.player.domain.Player;
|
||||
import org.libresonic.player.domain.Transcoding;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test of {@link TranscodingDao}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class TranscodingDaoTestCase extends DaoTestCaseBean2 {
|
||||
|
||||
@Autowired
|
||||
TranscodingDao transcodingDao;
|
||||
|
||||
@Autowired
|
||||
PlayerDao playerDao;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getJdbcTemplate().execute("delete from transcoding2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTranscoding() {
|
||||
Transcoding transcoding = new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false);
|
||||
transcodingDao.createTranscoding(transcoding);
|
||||
|
||||
Transcoding newTranscoding = transcodingDao.getAllTranscodings().get(0);
|
||||
assertTranscodingEquals(transcoding, newTranscoding);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTranscoding() {
|
||||
Transcoding transcoding = new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false);
|
||||
transcodingDao.createTranscoding(transcoding);
|
||||
transcoding = transcodingDao.getAllTranscodings().get(0);
|
||||
|
||||
transcoding.setName("newName");
|
||||
transcoding.setSourceFormats("newSourceFormats");
|
||||
transcoding.setTargetFormat("newTargetFormats");
|
||||
transcoding.setStep1("newStep1");
|
||||
transcoding.setStep2("newStep2");
|
||||
transcoding.setStep3("newStep3");
|
||||
transcoding.setDefaultActive(true);
|
||||
transcodingDao.updateTranscoding(transcoding);
|
||||
|
||||
Transcoding newTranscoding = transcodingDao.getAllTranscodings().get(0);
|
||||
assertTranscodingEquals(transcoding, newTranscoding);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTranscoding() {
|
||||
assertEquals("Wrong number of transcodings.", 0, transcodingDao.getAllTranscodings().size());
|
||||
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
|
||||
assertEquals("Wrong number of transcodings.", 1, transcodingDao.getAllTranscodings().size());
|
||||
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
|
||||
assertEquals("Wrong number of transcodings.", 2, transcodingDao.getAllTranscodings().size());
|
||||
|
||||
transcodingDao.deleteTranscoding(transcodingDao.getAllTranscodings().get(0).getId());
|
||||
assertEquals("Wrong number of transcodings.", 1, transcodingDao.getAllTranscodings().size());
|
||||
|
||||
transcodingDao.deleteTranscoding(transcodingDao.getAllTranscodings().get(0).getId());
|
||||
assertEquals("Wrong number of transcodings.", 0, transcodingDao.getAllTranscodings().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerTranscoding() {
|
||||
Player player = new Player();
|
||||
playerDao.createPlayer(player);
|
||||
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", false));
|
||||
Transcoding transcodingA = transcodingDao.getAllTranscodings().get(0);
|
||||
Transcoding transcodingB = transcodingDao.getAllTranscodings().get(1);
|
||||
Transcoding transcodingC = transcodingDao.getAllTranscodings().get(2);
|
||||
|
||||
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
|
||||
|
||||
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcodingA.getId()});
|
||||
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
|
||||
assertTranscodingEquals(transcodingA, activeTranscodings.get(0));
|
||||
|
||||
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcodingB.getId(), transcodingC.getId()});
|
||||
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 2, activeTranscodings.size());
|
||||
assertTranscodingEquals(transcodingB, activeTranscodings.get(0));
|
||||
assertTranscodingEquals(transcodingC, activeTranscodings.get(1));
|
||||
|
||||
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[0]);
|
||||
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadingDeletePlayer() {
|
||||
Player player = new Player();
|
||||
playerDao.createPlayer(player);
|
||||
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
|
||||
Transcoding transcoding = transcodingDao.getAllTranscodings().get(0);
|
||||
|
||||
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcoding.getId()});
|
||||
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
|
||||
|
||||
playerDao.deletePlayer(player.getId());
|
||||
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadingDeleteTranscoding() {
|
||||
Player player = new Player();
|
||||
playerDao.createPlayer(player);
|
||||
|
||||
transcodingDao.createTranscoding(new Transcoding(null, "name", "sourceFormats", "targetFormat", "step1", "step2", "step3", true));
|
||||
Transcoding transcoding = transcodingDao.getAllTranscodings().get(0);
|
||||
|
||||
transcodingDao.setTranscodingsForPlayer(player.getId(), new int[]{transcoding.getId()});
|
||||
List<Transcoding> activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 1, activeTranscodings.size());
|
||||
|
||||
transcodingDao.deleteTranscoding(transcoding.getId());
|
||||
activeTranscodings = transcodingDao.getTranscodingsForPlayer(player.getId());
|
||||
assertEquals("Wrong number of transcodings.", 0, activeTranscodings.size());
|
||||
}
|
||||
|
||||
private void assertTranscodingEquals(Transcoding expected, Transcoding actual) {
|
||||
assertEquals("Wrong name.", expected.getName(), actual.getName());
|
||||
assertEquals("Wrong source formats.", expected.getSourceFormats(), actual.getSourceFormats());
|
||||
assertEquals("Wrong target format.", expected.getTargetFormat(), actual.getTargetFormat());
|
||||
assertEquals("Wrong step 1.", expected.getStep1(), actual.getStep1());
|
||||
assertEquals("Wrong step 2.", expected.getStep2(), actual.getStep2());
|
||||
assertEquals("Wrong step 3.", expected.getStep3(), actual.getStep3());
|
||||
assertEquals("Wrong default active.", expected.isDefaultActive(), actual.isDefaultActive());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
package org.libresonic.player.dao;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.libresonic.player.domain.AvatarScheme;
|
||||
import org.libresonic.player.domain.TranscodeScheme;
|
||||
import org.libresonic.player.domain.User;
|
||||
import org.libresonic.player.domain.UserSettings;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit test of {@link UserDao}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class UserDaoTestCase extends DaoTestCaseBean2 {
|
||||
|
||||
@Autowired
|
||||
UserDao userDao;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
getJdbcTemplate().execute("delete from user_role");
|
||||
getJdbcTemplate().execute("delete from user");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUser() {
|
||||
User user = new User("sindre", "secret", "sindre@activeobjects.no", false, 1000L, 2000L, 3000L);
|
||||
user.setAdminRole(true);
|
||||
user.setCommentRole(true);
|
||||
user.setCoverArtRole(true);
|
||||
user.setDownloadRole(false);
|
||||
user.setPlaylistRole(true);
|
||||
user.setUploadRole(false);
|
||||
user.setPodcastRole(true);
|
||||
user.setStreamRole(true);
|
||||
user.setJukeboxRole(true);
|
||||
user.setSettingsRole(true);
|
||||
userDao.createUser(user);
|
||||
|
||||
User newUser = userDao.getAllUsers().get(0);
|
||||
assertUserEquals(user, newUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUserTransactionalError() {
|
||||
User user = new User ("muff1nman", "secret", "noemail") {
|
||||
@Override
|
||||
public boolean isPlaylistRole() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
};
|
||||
|
||||
user.setAdminRole(true);
|
||||
int beforeSize = userDao.getAllUsers().size();
|
||||
boolean caughtException = false;
|
||||
try {
|
||||
userDao.createUser(user);
|
||||
} catch (RuntimeException e) {
|
||||
caughtException = true;
|
||||
}
|
||||
assertTrue("It was expected for createUser to throw an exception", caughtException);
|
||||
assertEquals(beforeSize, userDao.getAllUsers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUser() {
|
||||
User user = new User("sindre", "secret", null);
|
||||
user.setAdminRole(true);
|
||||
user.setCommentRole(true);
|
||||
user.setCoverArtRole(true);
|
||||
user.setDownloadRole(false);
|
||||
user.setPlaylistRole(true);
|
||||
user.setUploadRole(false);
|
||||
user.setPodcastRole(true);
|
||||
user.setStreamRole(true);
|
||||
user.setJukeboxRole(true);
|
||||
user.setSettingsRole(true);
|
||||
userDao.createUser(user);
|
||||
|
||||
user.setPassword("foo");
|
||||
user.setEmail("sindre@foo.bar");
|
||||
user.setLdapAuthenticated(true);
|
||||
user.setBytesStreamed(1);
|
||||
user.setBytesDownloaded(2);
|
||||
user.setBytesUploaded(3);
|
||||
user.setAdminRole(false);
|
||||
user.setCommentRole(false);
|
||||
user.setCoverArtRole(false);
|
||||
user.setDownloadRole(true);
|
||||
user.setPlaylistRole(false);
|
||||
user.setUploadRole(true);
|
||||
user.setPodcastRole(false);
|
||||
user.setStreamRole(false);
|
||||
user.setJukeboxRole(false);
|
||||
user.setSettingsRole(false);
|
||||
userDao.updateUser(user);
|
||||
|
||||
User newUser = userDao.getAllUsers().get(0);
|
||||
assertUserEquals(user, newUser);
|
||||
assertEquals("Wrong bytes streamed.", 1, newUser.getBytesStreamed());
|
||||
assertEquals("Wrong bytes downloaded.", 2, newUser.getBytesDownloaded());
|
||||
assertEquals("Wrong bytes uploaded.", 3, newUser.getBytesUploaded());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserByName() {
|
||||
User user = new User("sindre", "secret", null);
|
||||
userDao.createUser(user);
|
||||
|
||||
User newUser = userDao.getUserByName("sindre", true);
|
||||
assertNotNull("Error in getUserByName().", newUser);
|
||||
assertUserEquals(user, newUser);
|
||||
|
||||
assertNull("Error in getUserByName().", userDao.getUserByName("sindre2", true));
|
||||
assertNull("Error in getUserByName().", userDao.getUserByName("sindre ", true));
|
||||
assertNull("Error in getUserByName().", userDao.getUserByName("bente", true));
|
||||
assertNull("Error in getUserByName().", userDao.getUserByName("", true));
|
||||
assertNull("Error in getUserByName().", userDao.getUserByName(null, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteUser() {
|
||||
assertEquals("Wrong number of users.", 0, userDao.getAllUsers().size());
|
||||
|
||||
userDao.createUser(new User("sindre", "secret", null));
|
||||
assertEquals("Wrong number of users.", 1, userDao.getAllUsers().size());
|
||||
|
||||
userDao.createUser(new User("bente", "secret", null));
|
||||
assertEquals("Wrong number of users.", 2, userDao.getAllUsers().size());
|
||||
|
||||
userDao.deleteUser("sindre");
|
||||
assertEquals("Wrong number of users.", 1, userDao.getAllUsers().size());
|
||||
|
||||
userDao.deleteUser("bente");
|
||||
assertEquals("Wrong number of users.", 0, userDao.getAllUsers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRolesForUser() {
|
||||
User user = new User("sindre", "secret", null);
|
||||
user.setAdminRole(true);
|
||||
user.setCommentRole(true);
|
||||
user.setPodcastRole(true);
|
||||
user.setStreamRole(true);
|
||||
user.setSettingsRole(true);
|
||||
userDao.createUser(user);
|
||||
|
||||
String[] roles = userDao.getRolesForUser("sindre");
|
||||
assertEquals("Wrong number of roles.", 5, roles.length);
|
||||
assertEquals("Wrong role.", "admin", roles[0]);
|
||||
assertEquals("Wrong role.", "comment", roles[1]);
|
||||
assertEquals("Wrong role.", "podcast", roles[2]);
|
||||
assertEquals("Wrong role.", "stream", roles[3]);
|
||||
assertEquals("Wrong role.", "settings", roles[4]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSettings() {
|
||||
assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
|
||||
|
||||
try {
|
||||
userDao.updateUserSettings(new UserSettings("sindre"));
|
||||
fail("Expected DataIntegrityViolationException.");
|
||||
} catch (DataIntegrityViolationException x) {
|
||||
}
|
||||
|
||||
userDao.createUser(new User("sindre", "secret", null));
|
||||
assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
|
||||
|
||||
userDao.updateUserSettings(new UserSettings("sindre"));
|
||||
UserSettings userSettings = userDao.getUserSettings("sindre");
|
||||
assertNotNull("Error in getUserSettings().", userSettings);
|
||||
assertNull("Error in getUserSettings().", userSettings.getLocale());
|
||||
assertNull("Error in getUserSettings().", userSettings.getThemeId());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isFinalVersionNotificationEnabled());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isBetaVersionNotificationEnabled());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isSongNotificationEnabled());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isShowSideBar());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isLastFmEnabled());
|
||||
assertNull("Error in getUserSettings().", userSettings.getLastFmUsername());
|
||||
assertNull("Error in getUserSettings().", userSettings.getLastFmPassword());
|
||||
assertSame("Error in getUserSettings().", TranscodeScheme.OFF, userSettings.getTranscodeScheme());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
|
||||
assertEquals("Error in getUserSettings().", -1, userSettings.getSelectedMusicFolderId());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isPartyModeEnabled());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
|
||||
assertSame("Error in getUserSettings().", AvatarScheme.NONE, userSettings.getAvatarScheme());
|
||||
assertNull("Error in getUserSettings().", userSettings.getSystemAvatarId());
|
||||
assertEquals("Error in getUserSettings().", 0, userSettings.getListReloadDelay());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
|
||||
assertEquals("Error in getUserSettings().", 0, userSettings.getPaginationSize());
|
||||
|
||||
UserSettings settings = new UserSettings("sindre");
|
||||
settings.setLocale(Locale.SIMPLIFIED_CHINESE);
|
||||
settings.setThemeId("midnight");
|
||||
settings.setBetaVersionNotificationEnabled(true);
|
||||
settings.setSongNotificationEnabled(false);
|
||||
settings.setShowSideBar(true);
|
||||
settings.getMainVisibility().setBitRateVisible(true);
|
||||
settings.getPlaylistVisibility().setYearVisible(true);
|
||||
settings.setLastFmEnabled(true);
|
||||
settings.setLastFmUsername("last_user");
|
||||
settings.setLastFmPassword("last_pass");
|
||||
settings.setTranscodeScheme(TranscodeScheme.MAX_192);
|
||||
settings.setShowNowPlayingEnabled(false);
|
||||
settings.setSelectedMusicFolderId(3);
|
||||
settings.setPartyModeEnabled(true);
|
||||
settings.setNowPlayingAllowed(true);
|
||||
settings.setAvatarScheme(AvatarScheme.SYSTEM);
|
||||
settings.setSystemAvatarId(1);
|
||||
settings.setChanged(new Date(9412L));
|
||||
settings.setListReloadDelay(60);
|
||||
settings.setKeyboardShortcutsEnabled(true);
|
||||
settings.setPaginationSize(120);
|
||||
|
||||
userDao.updateUserSettings(settings);
|
||||
userSettings = userDao.getUserSettings("sindre");
|
||||
assertNotNull("Error in getUserSettings().", userSettings);
|
||||
assertEquals("Error in getUserSettings().", Locale.SIMPLIFIED_CHINESE, userSettings.getLocale());
|
||||
assertEquals("Error in getUserSettings().", false, userSettings.isFinalVersionNotificationEnabled());
|
||||
assertEquals("Error in getUserSettings().", true, userSettings.isBetaVersionNotificationEnabled());
|
||||
assertEquals("Error in getUserSettings().", false, userSettings.isSongNotificationEnabled());
|
||||
assertEquals("Error in getUserSettings().", true, userSettings.isShowSideBar());
|
||||
assertEquals("Error in getUserSettings().", "midnight", userSettings.getThemeId());
|
||||
assertEquals("Error in getUserSettings().", true, userSettings.getMainVisibility().isBitRateVisible());
|
||||
assertEquals("Error in getUserSettings().", true, userSettings.getPlaylistVisibility().isYearVisible());
|
||||
assertEquals("Error in getUserSettings().", true, userSettings.isLastFmEnabled());
|
||||
assertEquals("Error in getUserSettings().", "last_user", userSettings.getLastFmUsername());
|
||||
assertEquals("Error in getUserSettings().", "last_pass", userSettings.getLastFmPassword());
|
||||
assertSame("Error in getUserSettings().", TranscodeScheme.MAX_192, userSettings.getTranscodeScheme());
|
||||
assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
|
||||
assertEquals("Error in getUserSettings().", 3, userSettings.getSelectedMusicFolderId());
|
||||
assertTrue("Error in getUserSettings().", userSettings.isPartyModeEnabled());
|
||||
assertTrue("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
|
||||
assertSame("Error in getUserSettings().", AvatarScheme.SYSTEM, userSettings.getAvatarScheme());
|
||||
assertEquals("Error in getUserSettings().", 1, userSettings.getSystemAvatarId().intValue());
|
||||
assertEquals("Error in getUserSettings().", new Date(9412L), userSettings.getChanged());
|
||||
assertEquals("Error in getUserSettings().", 60, userSettings.getListReloadDelay());
|
||||
assertTrue("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
|
||||
assertEquals("Error in getUserSettings().", 120, userSettings.getPaginationSize());
|
||||
|
||||
userDao.deleteUser("sindre");
|
||||
assertNull("Error in cascading delete.", userDao.getUserSettings("sindre"));
|
||||
}
|
||||
|
||||
private void assertUserEquals(User expected, User actual) {
|
||||
assertEquals("Wrong name.", expected.getUsername(), actual.getUsername());
|
||||
assertEquals("Wrong password.", expected.getPassword(), actual.getPassword());
|
||||
assertEquals("Wrong email.", expected.getEmail(), actual.getEmail());
|
||||
assertEquals("Wrong LDAP auth.", expected.isLdapAuthenticated(), actual.isLdapAuthenticated());
|
||||
assertEquals("Wrong bytes streamed.", expected.getBytesStreamed(), actual.getBytesStreamed());
|
||||
assertEquals("Wrong bytes downloaded.", expected.getBytesDownloaded(), actual.getBytesDownloaded());
|
||||
assertEquals("Wrong bytes uploaded.", expected.getBytesUploaded(), actual.getBytesUploaded());
|
||||
assertEquals("Wrong admin role.", expected.isAdminRole(), actual.isAdminRole());
|
||||
assertEquals("Wrong comment role.", expected.isCommentRole(), actual.isCommentRole());
|
||||
assertEquals("Wrong cover art role.", expected.isCoverArtRole(), actual.isCoverArtRole());
|
||||
assertEquals("Wrong download role.", expected.isDownloadRole(), actual.isDownloadRole());
|
||||
assertEquals("Wrong playlist role.", expected.isPlaylistRole(), actual.isPlaylistRole());
|
||||
assertEquals("Wrong upload role.", expected.isUploadRole(), actual.isUploadRole());
|
||||
assertEquals("Wrong upload role.", expected.isUploadRole(), actual.isUploadRole());
|
||||
assertEquals("Wrong stream role.", expected.isStreamRole(), actual.isStreamRole());
|
||||
assertEquals("Wrong jukebox role.", expected.isJukeboxRole(), actual.isJukeboxRole());
|
||||
assertEquals("Wrong settings role.", expected.isSettingsRole(), actual.isSettingsRole());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.domain;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit test of {@link org.libresonic.player.domain.CacheElement}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class CacheElementTestCase extends TestCase {
|
||||
|
||||
public void testCreateId() {
|
||||
|
||||
assertTrue(CacheElement.createId(1, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home") ==
|
||||
CacheElement.createId(1, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home"));
|
||||
|
||||
assertTrue(CacheElement.createId(1, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home") !=
|
||||
CacheElement.createId(2, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home"));
|
||||
|
||||
assertTrue(CacheElement.createId(237462763, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home") !=
|
||||
CacheElement.createId(28374922, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home"));
|
||||
|
||||
assertTrue(CacheElement.createId(1, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home bla bla") !=
|
||||
CacheElement.createId(1, "/Volumes/WD Passport/music/'Til Tuesday/Welcome Home"));
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.domain;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MediaFileComparatorTestCase extends TestCase {
|
||||
|
||||
private final MediaFileComparator comparator = new MediaFileComparator(true);
|
||||
|
||||
public void testCompareAlbums() throws Exception {
|
||||
|
||||
MediaFile albumA2012 = new MediaFile();
|
||||
albumA2012.setMediaType(MediaFile.MediaType.ALBUM);
|
||||
albumA2012.setPath("a");
|
||||
albumA2012.setYear(2012);
|
||||
|
||||
MediaFile albumB2012 = new MediaFile();
|
||||
albumB2012.setMediaType(MediaFile.MediaType.ALBUM);
|
||||
albumB2012.setPath("b");
|
||||
albumB2012.setYear(2012);
|
||||
|
||||
MediaFile album2013 = new MediaFile();
|
||||
album2013.setMediaType(MediaFile.MediaType.ALBUM);
|
||||
album2013.setPath("c");
|
||||
album2013.setYear(2013);
|
||||
|
||||
MediaFile albumWithoutYear = new MediaFile();
|
||||
albumWithoutYear.setMediaType(MediaFile.MediaType.ALBUM);
|
||||
albumWithoutYear.setPath("c");
|
||||
|
||||
assertEquals(0, comparator.compare(albumWithoutYear, albumWithoutYear));
|
||||
assertEquals(0, comparator.compare(albumA2012, albumA2012));
|
||||
|
||||
assertEquals(-1, comparator.compare(albumA2012, albumWithoutYear));
|
||||
assertEquals(-1, comparator.compare(album2013, albumWithoutYear));
|
||||
assertEquals(1, comparator.compare(album2013, albumA2012));
|
||||
|
||||
assertEquals(1, comparator.compare(albumWithoutYear, albumA2012));
|
||||
assertEquals(1, comparator.compare(albumWithoutYear, album2013));
|
||||
assertEquals(-1, comparator.compare(albumA2012, album2013));
|
||||
|
||||
assertEquals(-1, comparator.compare(albumA2012, albumB2012));
|
||||
assertEquals(1, comparator.compare(albumB2012, albumA2012));
|
||||
}
|
||||
|
||||
public void testCompareDiscNumbers() throws Exception {
|
||||
|
||||
MediaFile discXtrack1 = new MediaFile();
|
||||
discXtrack1.setMediaType(MediaFile.MediaType.MUSIC);
|
||||
discXtrack1.setPath("a");
|
||||
discXtrack1.setTrackNumber(1);
|
||||
|
||||
MediaFile discXtrack2 = new MediaFile();
|
||||
discXtrack2.setMediaType(MediaFile.MediaType.MUSIC);
|
||||
discXtrack2.setPath("a");
|
||||
discXtrack2.setTrackNumber(2);
|
||||
|
||||
MediaFile disc5track1 = new MediaFile();
|
||||
disc5track1.setMediaType(MediaFile.MediaType.MUSIC);
|
||||
disc5track1.setPath("a");
|
||||
disc5track1.setDiscNumber(5);
|
||||
disc5track1.setTrackNumber(1);
|
||||
|
||||
MediaFile disc5track2 = new MediaFile();
|
||||
disc5track2.setMediaType(MediaFile.MediaType.MUSIC);
|
||||
disc5track2.setPath("a");
|
||||
disc5track2.setDiscNumber(5);
|
||||
disc5track2.setTrackNumber(2);
|
||||
|
||||
MediaFile disc6track1 = new MediaFile();
|
||||
disc6track1.setMediaType(MediaFile.MediaType.MUSIC);
|
||||
disc6track1.setPath("a");
|
||||
disc6track1.setDiscNumber(6);
|
||||
disc6track1.setTrackNumber(1);
|
||||
|
||||
MediaFile disc6track2 = new MediaFile();
|
||||
disc6track2.setMediaType(MediaFile.MediaType.MUSIC);
|
||||
disc6track2.setPath("a");
|
||||
disc6track2.setDiscNumber(6);
|
||||
disc6track2.setTrackNumber(2);
|
||||
|
||||
assertEquals(0, comparator.compare(discXtrack1, discXtrack1));
|
||||
assertEquals(0, comparator.compare(disc5track1, disc5track1));
|
||||
|
||||
assertEquals(-1, comparator.compare(discXtrack1, discXtrack2));
|
||||
assertEquals(1, comparator.compare(discXtrack2, discXtrack1));
|
||||
|
||||
assertEquals(-1, comparator.compare(disc5track1, disc5track2));
|
||||
assertEquals(1, comparator.compare(disc6track2, disc5track1));
|
||||
|
||||
assertEquals(-1, comparator.compare(disc5track1, disc6track1));
|
||||
assertEquals(1, comparator.compare(disc6track1, disc5track1));
|
||||
|
||||
assertEquals(-1, comparator.compare(disc5track2, disc6track1));
|
||||
assertEquals(1, comparator.compare(disc6track1, disc5track2));
|
||||
|
||||
assertEquals(-1, comparator.compare(discXtrack1, disc5track1));
|
||||
assertEquals(1, comparator.compare(disc5track1, discXtrack1));
|
||||
|
||||
assertEquals(-1, comparator.compare(discXtrack1, disc5track2));
|
||||
assertEquals(1, comparator.compare(disc5track2, discXtrack1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.domain;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.domain.PlayQueue.SortOrder;
|
||||
import org.libresonic.player.domain.PlayQueue.Status;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Unit test of {@link PlayQueue}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class PlayQueueTestCase extends TestCase {
|
||||
|
||||
public void testEmpty() {
|
||||
PlayQueue playQueue = new PlayQueue();
|
||||
assertEquals(0, playQueue.size());
|
||||
assertTrue(playQueue.isEmpty());
|
||||
assertEquals(0, playQueue.getFiles().size());
|
||||
assertNull(playQueue.getCurrentFile());
|
||||
}
|
||||
|
||||
public void testStatus() throws Exception {
|
||||
PlayQueue playQueue = new PlayQueue();
|
||||
assertEquals(Status.PLAYING, playQueue.getStatus());
|
||||
|
||||
playQueue.setStatus(Status.STOPPED);
|
||||
assertEquals(Status.STOPPED, playQueue.getStatus());
|
||||
|
||||
playQueue.addFiles(true, new TestMediaFile());
|
||||
assertEquals(Status.PLAYING, playQueue.getStatus());
|
||||
|
||||
playQueue.clear();
|
||||
assertEquals(Status.PLAYING, playQueue.getStatus());
|
||||
}
|
||||
|
||||
public void testMoveUp() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(0, "A", "B", "C", "D");
|
||||
playQueue.moveUp(0);
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(0, "A", "B", "C", "D");
|
||||
playQueue.moveUp(9999);
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(1, "A", "B", "C", "D");
|
||||
playQueue.moveUp(1);
|
||||
assertPlaylistEquals(playQueue, 0, "B", "A", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(3, "A", "B", "C", "D");
|
||||
playQueue.moveUp(3);
|
||||
assertPlaylistEquals(playQueue, 2, "A", "B", "D", "C");
|
||||
}
|
||||
|
||||
public void testMoveDown() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(0, "A", "B", "C", "D");
|
||||
playQueue.moveDown(0);
|
||||
assertPlaylistEquals(playQueue, 1, "B", "A", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(0, "A", "B", "C", "D");
|
||||
playQueue.moveDown(9999);
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(1, "A", "B", "C", "D");
|
||||
playQueue.moveDown(1);
|
||||
assertPlaylistEquals(playQueue, 2, "A", "C", "B", "D");
|
||||
|
||||
playQueue = createPlaylist(3, "A", "B", "C", "D");
|
||||
playQueue.moveDown(3);
|
||||
assertPlaylistEquals(playQueue, 3, "A", "B", "C", "D");
|
||||
}
|
||||
|
||||
public void testRemove() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(0, "A", "B", "C", "D");
|
||||
playQueue.removeFileAt(0);
|
||||
assertPlaylistEquals(playQueue, 0, "B", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(1, "A", "B", "C", "D");
|
||||
playQueue.removeFileAt(0);
|
||||
assertPlaylistEquals(playQueue, 0, "B", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(0, "A", "B", "C", "D");
|
||||
playQueue.removeFileAt(3);
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue = createPlaylist(1, "A", "B", "C", "D");
|
||||
playQueue.removeFileAt(1);
|
||||
assertPlaylistEquals(playQueue, 1, "A", "C", "D");
|
||||
|
||||
playQueue = createPlaylist(3, "A", "B", "C", "D");
|
||||
playQueue.removeFileAt(3);
|
||||
assertPlaylistEquals(playQueue, 2, "A", "B", "C");
|
||||
|
||||
playQueue = createPlaylist(0, "A");
|
||||
playQueue.removeFileAt(0);
|
||||
assertPlaylistEquals(playQueue, -1);
|
||||
}
|
||||
|
||||
public void testNext() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(0, "A", "B", "C");
|
||||
assertFalse(playQueue.isRepeatEnabled());
|
||||
playQueue.next();
|
||||
assertPlaylistEquals(playQueue, 1, "A", "B", "C");
|
||||
playQueue.next();
|
||||
assertPlaylistEquals(playQueue, 2, "A", "B", "C");
|
||||
playQueue.next();
|
||||
assertPlaylistEquals(playQueue, -1, "A", "B", "C");
|
||||
|
||||
playQueue = createPlaylist(0, "A", "B", "C");
|
||||
playQueue.setRepeatEnabled(true);
|
||||
assertTrue(playQueue.isRepeatEnabled());
|
||||
playQueue.next();
|
||||
assertPlaylistEquals(playQueue, 1, "A", "B", "C");
|
||||
playQueue.next();
|
||||
assertPlaylistEquals(playQueue, 2, "A", "B", "C");
|
||||
playQueue.next();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
}
|
||||
|
||||
public void testPlayAfterEndReached() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(2, "A", "B", "C");
|
||||
playQueue.setStatus(Status.PLAYING);
|
||||
playQueue.next();
|
||||
assertNull(playQueue.getCurrentFile());
|
||||
assertEquals(Status.STOPPED, playQueue.getStatus());
|
||||
|
||||
playQueue.setStatus(Status.PLAYING);
|
||||
assertEquals(Status.PLAYING, playQueue.getStatus());
|
||||
assertEquals(0, playQueue.getIndex());
|
||||
assertEquals("A", playQueue.getCurrentFile().getName());
|
||||
}
|
||||
|
||||
public void testPlayLast() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(1, "A", "B", "C");
|
||||
|
||||
playQueue.addFiles(true, new TestMediaFile("D"));
|
||||
assertPlaylistEquals(playQueue, 1, "A", "B", "C", "D");
|
||||
|
||||
playQueue.addFiles(false, new TestMediaFile("E"));
|
||||
assertPlaylistEquals(playQueue, 0, "E");
|
||||
}
|
||||
|
||||
public void testAddFilesAt() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(0);
|
||||
|
||||
playQueue.addFilesAt(Arrays.<MediaFile>asList(new TestMediaFile("A"), new TestMediaFile("B"), new TestMediaFile("C")), 0);
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue.addFilesAt(Arrays.<MediaFile>asList(new TestMediaFile("D"), new TestMediaFile("E")), 1);
|
||||
assertPlaylistEquals(playQueue, 0, "A", "D", "E", "B", "C");
|
||||
|
||||
playQueue.addFilesAt(Arrays.<MediaFile>asList(new TestMediaFile("F")), 0);
|
||||
assertPlaylistEquals(playQueue, 0, "F", "A", "D", "E", "B", "C");
|
||||
|
||||
}
|
||||
|
||||
public void testUndo() throws Exception {
|
||||
PlayQueue playQueue = createPlaylist(0, "A", "B", "C");
|
||||
playQueue.setIndex(2);
|
||||
playQueue.undo();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue.removeFileAt(2);
|
||||
playQueue.undo();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue.clear();
|
||||
playQueue.undo();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue.addFiles(true, new TestMediaFile());
|
||||
playQueue.undo();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue.moveDown(1);
|
||||
playQueue.undo();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
|
||||
playQueue.moveUp(1);
|
||||
playQueue.undo();
|
||||
assertPlaylistEquals(playQueue, 0, "A", "B", "C");
|
||||
}
|
||||
|
||||
public void testOrder() throws IOException {
|
||||
PlayQueue playQueue = new PlayQueue();
|
||||
playQueue.addFiles(true, new TestMediaFile(2, "Artist A", "Album B"));
|
||||
playQueue.addFiles(true, new TestMediaFile(1, "Artist C", "Album C"));
|
||||
playQueue.addFiles(true, new TestMediaFile(3, "Artist B", "Album A"));
|
||||
playQueue.addFiles(true, new TestMediaFile(null, "Artist D", "Album D"));
|
||||
playQueue.setIndex(2);
|
||||
assertEquals("Error in sort.", new Integer(3), playQueue.getCurrentFile().getTrackNumber());
|
||||
|
||||
// Order by track.
|
||||
playQueue.sort(SortOrder.TRACK);
|
||||
assertEquals("Error in sort().", null, playQueue.getFile(0).getTrackNumber());
|
||||
assertEquals("Error in sort().", new Integer(1), playQueue.getFile(1).getTrackNumber());
|
||||
assertEquals("Error in sort().", new Integer(2), playQueue.getFile(2).getTrackNumber());
|
||||
assertEquals("Error in sort().", new Integer(3), playQueue.getFile(3).getTrackNumber());
|
||||
assertEquals("Error in sort().", new Integer(3), playQueue.getCurrentFile().getTrackNumber());
|
||||
|
||||
// Order by artist.
|
||||
playQueue.sort(SortOrder.ARTIST);
|
||||
assertEquals("Error in sort().", "Artist A", playQueue.getFile(0).getArtist());
|
||||
assertEquals("Error in sort().", "Artist B", playQueue.getFile(1).getArtist());
|
||||
assertEquals("Error in sort().", "Artist C", playQueue.getFile(2).getArtist());
|
||||
assertEquals("Error in sort().", "Artist D", playQueue.getFile(3).getArtist());
|
||||
assertEquals("Error in sort().", new Integer(3), playQueue.getCurrentFile().getTrackNumber());
|
||||
|
||||
// Order by album.
|
||||
playQueue.sort(SortOrder.ALBUM);
|
||||
assertEquals("Error in sort().", "Album A", playQueue.getFile(0).getAlbumName());
|
||||
assertEquals("Error in sort().", "Album B", playQueue.getFile(1).getAlbumName());
|
||||
assertEquals("Error in sort().", "Album C", playQueue.getFile(2).getAlbumName());
|
||||
assertEquals("Error in sort().", "Album D", playQueue.getFile(3).getAlbumName());
|
||||
assertEquals("Error in sort().", new Integer(3), playQueue.getCurrentFile().getTrackNumber());
|
||||
}
|
||||
|
||||
private void assertPlaylistEquals(PlayQueue playQueue, int index, String... songs) {
|
||||
assertEquals(songs.length, playQueue.size());
|
||||
for (int i = 0; i < songs.length; i++) {
|
||||
assertEquals(songs[i], playQueue.getFiles().get(i).getName());
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
assertNull(playQueue.getCurrentFile());
|
||||
} else {
|
||||
assertEquals(songs[index], playQueue.getCurrentFile().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private PlayQueue createPlaylist(int index, String... songs) throws Exception {
|
||||
PlayQueue playQueue = new PlayQueue();
|
||||
for (String song : songs) {
|
||||
playQueue.addFiles(true, new TestMediaFile(song));
|
||||
}
|
||||
playQueue.setIndex(index);
|
||||
return playQueue;
|
||||
}
|
||||
|
||||
private static class TestMediaFile extends MediaFile {
|
||||
|
||||
private String name;
|
||||
private Integer track;
|
||||
private String album;
|
||||
private String artist;
|
||||
|
||||
TestMediaFile() {
|
||||
}
|
||||
|
||||
TestMediaFile(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
TestMediaFile(Integer track, String artist, String album) {
|
||||
this.track = track;
|
||||
this.album = album;
|
||||
this.artist = artist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFile() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTrackNumber() {
|
||||
return track;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlbumName() {
|
||||
return album;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return new File(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return this == o;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* This file is part of Libresonic.
|
||||
*
|
||||
* Libresonic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Libresonic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2014 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package org.libresonic.player.domain;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SortableArtistTestCase extends TestCase {
|
||||
|
||||
private Collator collator;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
collator = Collator.getInstance(Locale.US);
|
||||
}
|
||||
|
||||
public void testSorting() throws Exception {
|
||||
List<TestSortableArtist> artists = new ArrayList<TestSortableArtist>();
|
||||
|
||||
artists.add(new TestSortableArtist("ABBA"));
|
||||
artists.add(new TestSortableArtist("Abba"));
|
||||
artists.add(new TestSortableArtist("abba"));
|
||||
artists.add(new TestSortableArtist("ACDC"));
|
||||
artists.add(new TestSortableArtist("acdc"));
|
||||
artists.add(new TestSortableArtist("ACDC"));
|
||||
artists.add(new TestSortableArtist("abc"));
|
||||
artists.add(new TestSortableArtist("ABC"));
|
||||
|
||||
Collections.sort(artists);
|
||||
assertEquals("[abba, Abba, ABBA, abc, ABC, acdc, ACDC, ACDC]", artists.toString());
|
||||
}
|
||||
|
||||
public void testSortingWithAccents() throws Exception {
|
||||
List<TestSortableArtist> artists = new ArrayList<TestSortableArtist>();
|
||||
|
||||
TestSortableArtist a1 = new TestSortableArtist("Sea");
|
||||
TestSortableArtist a2 = new TestSortableArtist("SEB");
|
||||
TestSortableArtist a3 = new TestSortableArtist("Seb");
|
||||
TestSortableArtist a4 = new TestSortableArtist("S\u00e9b");
|
||||
TestSortableArtist a5 = new TestSortableArtist("Sed");
|
||||
TestSortableArtist a6 = new TestSortableArtist("See");
|
||||
|
||||
assertTrue(a1.compareTo(a1) == 0);
|
||||
assertTrue(a1.compareTo(a2) < 0);
|
||||
assertTrue(a1.compareTo(a3) < 0);
|
||||
assertTrue(a1.compareTo(a4) < 0);
|
||||
assertTrue(a1.compareTo(a5) < 0);
|
||||
assertTrue(a1.compareTo(a6) < 0);
|
||||
|
||||
assertTrue(a2.compareTo(a1) > 0);
|
||||
assertTrue(a3.compareTo(a1) > 0);
|
||||
assertTrue(a4.compareTo(a1) > 0);
|
||||
assertTrue(a5.compareTo(a1) > 0);
|
||||
assertTrue(a6.compareTo(a1) > 0);
|
||||
|
||||
assertTrue(a4.compareTo(a1) > 0);
|
||||
assertTrue(a4.compareTo(a2) > 0);
|
||||
assertTrue(a4.compareTo(a3) > 0);
|
||||
assertTrue(a4.compareTo(a4) == 0);
|
||||
assertTrue(a4.compareTo(a5) < 0);
|
||||
assertTrue(a4.compareTo(a6) < 0);
|
||||
|
||||
artists.add(a1);
|
||||
artists.add(a2);
|
||||
artists.add(a3);
|
||||
artists.add(a4);
|
||||
artists.add(a5);
|
||||
artists.add(a6);
|
||||
|
||||
Collections.shuffle(artists);
|
||||
Collections.sort(artists);
|
||||
assertEquals("[Sea, Seb, SEB, S\u00e9b, Sed, See]", artists.toString());
|
||||
}
|
||||
|
||||
public void testCollation() throws Exception {
|
||||
List<TestSortableArtist> artists = new ArrayList<TestSortableArtist>();
|
||||
|
||||
artists.add(new TestSortableArtist("p\u00e9ch\u00e9"));
|
||||
artists.add(new TestSortableArtist("peach"));
|
||||
artists.add(new TestSortableArtist("p\u00eache"));
|
||||
|
||||
Collections.sort(artists);
|
||||
assertEquals("[peach, p\u00e9ch\u00e9, p\u00eache]", artists.toString());
|
||||
}
|
||||
|
||||
private class TestSortableArtist extends MusicIndex.SortableArtist {
|
||||
|
||||
public TestSortableArtist(String sortableName) {
|
||||
super(sortableName, sortableName, collator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSortableName();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.domain;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import static org.libresonic.player.domain.TranscodeScheme.*;
|
||||
|
||||
/**
|
||||
* Unit test of {@link TranscodeScheme}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class TranscodeSchemeTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests {@link TranscodeScheme#strictest}.
|
||||
*/
|
||||
public void testStrictest() {
|
||||
assertSame("Error in strictest().", OFF, OFF.strictest(null));
|
||||
assertSame("Error in strictest().", OFF, OFF.strictest(OFF));
|
||||
assertSame("Error in strictest().", MAX_32, OFF.strictest(MAX_32));
|
||||
assertSame("Error in strictest().", MAX_32, MAX_32.strictest(null));
|
||||
assertSame("Error in strictest().", MAX_32, MAX_32.strictest(OFF));
|
||||
assertSame("Error in strictest().", MAX_32, MAX_32.strictest(MAX_64));
|
||||
assertSame("Error in strictest().", MAX_32, MAX_64.strictest(MAX_32));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.domain;
|
||||
|
||||
/**
|
||||
* Unit test of {@link Version}.
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class VersionTestCase extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests that equals(), hashCode(), toString() and compareTo() works.
|
||||
*/
|
||||
public void testVersion() {
|
||||
doTestVersion("0.0", "0.1");
|
||||
doTestVersion("1.5", "2.3");
|
||||
doTestVersion("2.3", "2.34");
|
||||
|
||||
doTestVersion("1.5", "1.5.1");
|
||||
doTestVersion("1.5.1", "1.5.2");
|
||||
doTestVersion("1.5.2", "1.5.11");
|
||||
|
||||
doTestVersion("1.4", "1.5.beta1");
|
||||
doTestVersion("1.4.1", "1.5.beta1");
|
||||
doTestVersion("1.5.beta1", "1.5");
|
||||
doTestVersion("1.5.beta1", "1.5.1");
|
||||
doTestVersion("1.5.beta1", "1.6");
|
||||
doTestVersion("1.5.beta1", "1.5.beta2");
|
||||
doTestVersion("1.5.beta2", "1.5.beta11");
|
||||
|
||||
doTestVersion("6.2-SNAPSHOT", "6.11-SNAPSHOT");
|
||||
}
|
||||
|
||||
public void testIsPreview() {
|
||||
Version version = new Version("1.6.0-SNAPSHOT");
|
||||
assertTrue("Version should be snapshot", version.isPreview());
|
||||
|
||||
version = new Version("1.6.0-beta2");
|
||||
assertTrue("Version should be snapshot", version.isPreview());
|
||||
|
||||
version = new Version("1.6.0");
|
||||
assertFalse("Version should not be snapshot", version.isPreview());
|
||||
|
||||
version = new Version("1.6.0-RELEASE");
|
||||
assertFalse("Version should not be snapshot", version.isPreview());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that equals(), hashCode(), toString() and compareTo() works.
|
||||
* @param v1 A lower version.
|
||||
* @param v2 A higher version.
|
||||
*/
|
||||
private void doTestVersion(String v1, String v2) {
|
||||
Version ver1 = new Version(v1);
|
||||
Version ver2 = new Version(v2);
|
||||
|
||||
assertEquals("Error in toString().", v1, ver1.toString());
|
||||
assertEquals("Error in toString().", v2, ver2.toString());
|
||||
|
||||
assertEquals("Error in equals().", ver1, ver1);
|
||||
|
||||
assertEquals("Error in compareTo().", 0, ver1.compareTo(ver1));
|
||||
assertEquals("Error in compareTo().", 0, ver2.compareTo(ver2));
|
||||
assertTrue("Error in compareTo().", ver1.compareTo(ver2) < 0);
|
||||
assertTrue("Error in compareTo().", ver2.compareTo(ver1) > 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2014 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.io;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.util.HttpRange;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RangeOutputStreamTestCase extends TestCase {
|
||||
|
||||
public void testWrap() throws Exception {
|
||||
doTestWrap(0, 99, 100, 1);
|
||||
doTestWrap(0, 99, 100, 10);
|
||||
doTestWrap(0, 99, 100, 13);
|
||||
doTestWrap(0, 99, 100, 70);
|
||||
doTestWrap(0, 99, 100, 100);
|
||||
|
||||
doTestWrap(10, 99, 100, 1);
|
||||
doTestWrap(10, 99, 100, 10);
|
||||
doTestWrap(10, 99, 100, 13);
|
||||
doTestWrap(10, 99, 100, 70);
|
||||
doTestWrap(10, 99, 100, 100);
|
||||
|
||||
doTestWrap(66, 66, 100, 1);
|
||||
doTestWrap(66, 66, 100, 2);
|
||||
|
||||
doTestWrap(10, 20, 100, 1);
|
||||
doTestWrap(10, 20, 100, 10);
|
||||
doTestWrap(10, 20, 100, 13);
|
||||
doTestWrap(10, 20, 100, 70);
|
||||
doTestWrap(10, 20, 100, 100);
|
||||
|
||||
for (int start = 0; start < 10; start++) {
|
||||
for (int end = start; end < 10; end++) {
|
||||
for (int bufferSize = 1; bufferSize < 10; bufferSize++) {
|
||||
doTestWrap(start, end, 10, bufferSize);
|
||||
doTestWrap(start, null, 10, bufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestWrap(int first, Integer last, int sourceSize, int bufferSize) throws Exception {
|
||||
byte[] source = createSource(sourceSize);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
OutputStream rangeOut = RangeOutputStream.wrap(out, new HttpRange((long) first, last == null ? null : last.longValue()));
|
||||
copy(source, rangeOut, bufferSize);
|
||||
verify(out.toByteArray(), first, last, sourceSize);
|
||||
}
|
||||
|
||||
private void verify(byte[] bytes, int first, Integer last, int sourceSize) {
|
||||
if (last == null) {
|
||||
assertEquals(sourceSize - first, bytes.length);
|
||||
} else {
|
||||
assertEquals(last - first + 1, bytes.length);
|
||||
}
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
assertEquals(first + i, bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void copy(byte[] source, OutputStream out, int bufsz) throws IOException {
|
||||
InputStream in = new ByteArrayInputStream(source);
|
||||
byte[] buffer = new byte[bufsz];
|
||||
int n;
|
||||
while (-1 != (n = in.read(buffer))) {
|
||||
int split = n / 2;
|
||||
out.write(buffer, 0, split);
|
||||
out.write(buffer, split, n - split);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] createSource(int size) {
|
||||
byte[] result = new byte[size];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = (byte) i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.Claim;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class JWTSecurityServiceTest {
|
||||
|
||||
private final String key = "someKey";
|
||||
private final JWTSecurityService service = new JWTSecurityService(settingsWithKey(key));
|
||||
private final String uriString;
|
||||
private final Algorithm algorithm = JWTSecurityService.getAlgorithm(key);
|
||||
private final JWTVerifier verifier = JWT.require(algorithm).build();
|
||||
private final String expectedClaimString;
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ "http://localhost:8080/libresonic/stream?id=4", "/libresonic/stream?id=4" },
|
||||
{ "/libresonic/stream?id=4", "/libresonic/stream?id=4" },
|
||||
});
|
||||
}
|
||||
|
||||
public JWTSecurityServiceTest(String uriString, String expectedClaimString) {
|
||||
this.uriString = uriString;
|
||||
this.expectedClaimString = expectedClaimString;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void addJWTToken() throws Exception {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriString);
|
||||
String actualUri = service.addJWTToken(builder).build().toUriString();
|
||||
String jwtToken = UriComponentsBuilder.fromUriString(actualUri).build().getQueryParams().getFirst(
|
||||
JWTSecurityService.JWT_PARAM_NAME);
|
||||
DecodedJWT verify = verifier.verify(jwtToken);
|
||||
Claim claim = verify.getClaim(JWTSecurityService.CLAIM_PATH);
|
||||
assertEquals(expectedClaimString, claim.asString());
|
||||
}
|
||||
|
||||
private SettingsService settingsWithKey(String jwtKey) {
|
||||
return new SettingsService() {
|
||||
@Override
|
||||
public String getJWTKey() {
|
||||
return jwtKey;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.libresonic.player.TestCaseUtils;
|
||||
import org.libresonic.player.util.LibresonicHomeRule;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml"})
|
||||
public class LegacyDatabaseStartupTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static final SpringClassRule classRule = new SpringClassRule() {
|
||||
LibresonicHomeRule libresonicRule = new LibresonicHomeRule() {
|
||||
@Override
|
||||
protected void before() throws Throwable {
|
||||
super.before();
|
||||
String homeParent = TestCaseUtils.libresonicHomePathForTest();
|
||||
System.setProperty("libresonic.home", TestCaseUtils.libresonicHomePathForTest());
|
||||
TestCaseUtils.cleanLibresonicHomeForTest();
|
||||
File dbDirectory = new File(homeParent, "/db");
|
||||
FileUtils.forceMkdir(dbDirectory);
|
||||
org.libresonic.player.util.FileUtils.copyResourcesRecursively(getClass().getResource("/db/pre-liquibase/db"), new File(homeParent));
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
Statement spring = super.apply(base, description);
|
||||
return libresonicRule.apply(spring, description);
|
||||
}
|
||||
};
|
||||
|
||||
@Rule
|
||||
public final SpringMethodRule springMethodRule = new SpringMethodRule();
|
||||
|
||||
@Test
|
||||
public void testStartup() throws Exception {
|
||||
System.out.println("Successful startup");
|
||||
}
|
||||
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import com.codahale.metrics.ConsoleReporter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.Timer;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.libresonic.player.TestCaseUtils;
|
||||
import org.libresonic.player.dao.*;
|
||||
import org.libresonic.player.domain.Album;
|
||||
import org.libresonic.player.domain.Artist;
|
||||
import org.libresonic.player.domain.MediaFile;
|
||||
import org.libresonic.player.domain.MusicFolder;
|
||||
import org.libresonic.player.util.LibresonicHomeRule;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* A unit test class to test the MediaScannerService.
|
||||
* <p>
|
||||
* This class uses the Spring application context configuration present in the
|
||||
* /org/libresonic/player/service/mediaScannerServiceTestCase/ directory.
|
||||
* <p>
|
||||
* The media library is found in the /MEDIAS directory.
|
||||
* It is composed of 2 musicFolders (Music and Music2) and several little weight audio files.
|
||||
* <p>
|
||||
* At runtime, the subsonic_home dir is set to target/test-classes/org/libresonic/player/service/mediaScannerServiceTestCase.
|
||||
* An empty database is created on the fly.
|
||||
*/
|
||||
@ContextConfiguration(locations = {
|
||||
"/applicationContext-service.xml",
|
||||
"/applicationContext-cache.xml",
|
||||
"/applicationContext-testdb.xml",
|
||||
"/applicationContext-mockSonos.xml"})
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class MediaScannerServiceTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static final SpringClassRule classRule = new SpringClassRule() {
|
||||
LibresonicHomeRule libresonicRule = new LibresonicHomeRule();
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
Statement spring = super.apply(base, description);
|
||||
return libresonicRule.apply(spring, description);
|
||||
}
|
||||
};
|
||||
|
||||
@Rule
|
||||
public final SpringMethodRule springMethodRule = new SpringMethodRule();
|
||||
|
||||
private final MetricRegistry metrics = new MetricRegistry();
|
||||
|
||||
@Autowired
|
||||
private MediaScannerService mediaScannerService;
|
||||
|
||||
@Autowired
|
||||
private MediaFileDao mediaFileDao;
|
||||
|
||||
@Autowired
|
||||
private MusicFolderDao musicFolderDao;
|
||||
|
||||
@Autowired
|
||||
private DaoHelper daoHelper;
|
||||
|
||||
@Autowired
|
||||
private MediaFileService mediaFileService;
|
||||
|
||||
@Autowired
|
||||
private ArtistDao artistDao;
|
||||
|
||||
@Autowired
|
||||
private AlbumDao albumDao;
|
||||
|
||||
@Autowired
|
||||
private SettingsService settingsService;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Autowired
|
||||
ResourceLoader resourceLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the MediaScannerService by scanning the test media library into an empty database.
|
||||
*/
|
||||
@Test
|
||||
public void testScanLibrary() {
|
||||
MusicFolderTestData.getTestMusicFolders().forEach(musicFolderDao::createMusicFolder);
|
||||
settingsService.clearMusicFolderCache();
|
||||
|
||||
Timer globalTimer = metrics.timer(MetricRegistry.name(MediaScannerServiceTestCase.class, "Timer.global"));
|
||||
|
||||
Timer.Context globalTimerContext = globalTimer.time();
|
||||
TestCaseUtils.execScan(mediaScannerService);
|
||||
globalTimerContext.stop();
|
||||
|
||||
System.out.println("--- Report of records count per table ---");
|
||||
Map<String, Integer> records = TestCaseUtils.recordsInAllTables(daoHelper);
|
||||
records.keySet().forEach(tableName -> System.out.println(tableName + " : " + records.get(tableName).toString()));
|
||||
System.out.println("--- *********************** ---");
|
||||
|
||||
|
||||
// Music Folder Music must have 3 children
|
||||
List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath());
|
||||
Assert.assertEquals(3, listeMusicChildren.size());
|
||||
// Music Folder Music2 must have 1 children
|
||||
List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath());
|
||||
Assert.assertEquals(1, listeMusic2Children.size());
|
||||
|
||||
System.out.println("--- List of all artists ---");
|
||||
System.out.println("artistName#albumCount");
|
||||
List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, musicFolderDao.getAllMusicFolders());
|
||||
allArtists.forEach(artist -> System.out.println(artist.getName() + "#" + artist.getAlbumCount()));
|
||||
System.out.println("--- *********************** ---");
|
||||
|
||||
System.out.println("--- List of all albums ---");
|
||||
System.out.println("name#artist");
|
||||
List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders());
|
||||
allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist()));
|
||||
Assert.assertEquals(5, allAlbums.size());
|
||||
System.out.println("--- *********************** ---");
|
||||
|
||||
List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental", 0, 0, musicFolderDao.getAllMusicFolders());
|
||||
Assert.assertEquals(2, listeSongs.size());
|
||||
|
||||
// display out metrics report
|
||||
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
|
||||
.convertRatesTo(TimeUnit.SECONDS.SECONDS)
|
||||
.convertDurationsTo(TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
reporter.report();
|
||||
|
||||
System.out.print("End");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecialCharactersInFilename() throws Exception {
|
||||
Resource resource = resourceLoader.getResource("MEDIAS/piano.mp3");
|
||||
String directoryName = "Muff1nman\u2019s \uFF0FMusic";
|
||||
String fileName = "Muff1nman\u2019s\uFF0FPiano.mp3";
|
||||
File artistDir = temporaryFolder.newFolder(directoryName);
|
||||
File musicFile = artistDir.toPath().resolve(fileName).toFile();
|
||||
IOUtils.copy(resource.getInputStream(), new FileOutputStream(musicFile));
|
||||
|
||||
MusicFolder musicFolder = new MusicFolder(1, temporaryFolder.getRoot(), "Music", true, new Date());
|
||||
musicFolderDao.createMusicFolder(musicFolder);
|
||||
settingsService.clearMusicFolderCache();
|
||||
TestCaseUtils.execScan(mediaScannerService);
|
||||
MediaFile mediaFile = mediaFileService.getMediaFile(musicFile);
|
||||
assertEquals(mediaFile.getFile().toString(), musicFile.toString());
|
||||
System.out.println(mediaFile.getFile().getPath());
|
||||
assertNotNull(mediaFile);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.domain.MusicIndex;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Unit test of {@link MusicIndex}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class MusicIndexServiceTestCase extends TestCase {
|
||||
|
||||
private final MusicIndexService musicIndexService = new MusicIndexService();
|
||||
|
||||
public void testCreateIndexFromExpression() throws Exception {
|
||||
MusicIndex index = musicIndexService.createIndexFromExpression("A");
|
||||
assertEquals("A", index.getIndex());
|
||||
assertEquals(1, index.getPrefixes().size());
|
||||
assertEquals("A", index.getPrefixes().get(0));
|
||||
|
||||
index = musicIndexService.createIndexFromExpression("The");
|
||||
assertEquals("The", index.getIndex());
|
||||
assertEquals(1, index.getPrefixes().size());
|
||||
assertEquals("The", index.getPrefixes().get(0));
|
||||
|
||||
index = musicIndexService.createIndexFromExpression("X-Z(XYZ)");
|
||||
assertEquals("X-Z", index.getIndex());
|
||||
assertEquals(3, index.getPrefixes().size());
|
||||
assertEquals("X", index.getPrefixes().get(0));
|
||||
assertEquals("Y", index.getPrefixes().get(1));
|
||||
assertEquals("Z", index.getPrefixes().get(2));
|
||||
}
|
||||
|
||||
public void testCreateIndexesFromExpression() throws Exception {
|
||||
List<MusicIndex> indexes = musicIndexService.createIndexesFromExpression("A B The X-Z(XYZ)");
|
||||
assertEquals(4, indexes.size());
|
||||
|
||||
assertEquals("A", indexes.get(0).getIndex());
|
||||
assertEquals(1, indexes.get(0).getPrefixes().size());
|
||||
assertEquals("A", indexes.get(0).getPrefixes().get(0));
|
||||
|
||||
assertEquals("B", indexes.get(1).getIndex());
|
||||
assertEquals(1, indexes.get(1).getPrefixes().size());
|
||||
assertEquals("B", indexes.get(1).getPrefixes().get(0));
|
||||
|
||||
assertEquals("The", indexes.get(2).getIndex());
|
||||
assertEquals(1, indexes.get(2).getPrefixes().size());
|
||||
assertEquals("The", indexes.get(2).getPrefixes().get(0));
|
||||
|
||||
assertEquals("X-Z", indexes.get(3).getIndex());
|
||||
assertEquals(3, indexes.get(3).getPrefixes().size());
|
||||
assertEquals("X", indexes.get(3).getPrefixes().get(0));
|
||||
assertEquals("Y", indexes.get(3).getPrefixes().get(1));
|
||||
assertEquals("Z", indexes.get(3).getPrefixes().get(2));
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.libresonic.player.dao.MediaFileDao;
|
||||
import org.libresonic.player.dao.PlaylistDao;
|
||||
import org.libresonic.player.domain.MediaFile;
|
||||
import org.libresonic.player.domain.Playlist;
|
||||
import org.libresonic.player.service.playlist.DefaultPlaylistExportHandler;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PlaylistServiceTestExport {
|
||||
|
||||
PlaylistService playlistService;
|
||||
|
||||
@InjectMocks
|
||||
DefaultPlaylistExportHandler defaultPlaylistExportHandler;
|
||||
|
||||
@Mock
|
||||
MediaFileDao mediaFileDao;
|
||||
|
||||
@Mock
|
||||
PlaylistDao playlistDao;
|
||||
|
||||
@Mock
|
||||
MediaFileService mediaFileService;
|
||||
|
||||
@Mock
|
||||
SettingsService settingsService;
|
||||
|
||||
@Mock
|
||||
SecurityService securityService;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<Playlist> actual;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<List<MediaFile>> medias;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
playlistService = new PlaylistService(mediaFileDao,
|
||||
playlistDao,
|
||||
securityService,
|
||||
settingsService,
|
||||
Lists.newArrayList(
|
||||
defaultPlaylistExportHandler),
|
||||
Collections.emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExportToM3U() throws Exception {
|
||||
|
||||
when(mediaFileDao.getFilesInPlaylist(eq(23))).thenReturn(getPlaylistFiles());
|
||||
when(settingsService.getPlaylistExportFormat()).thenReturn("m3u");
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
playlistService.exportPlaylist(23, outputStream);
|
||||
String actual = outputStream.toString();
|
||||
Assert.assertEquals(IOUtils.toString(getClass().getResourceAsStream("/PLAYLISTS/23.m3u")), actual);
|
||||
}
|
||||
|
||||
private List<MediaFile> getPlaylistFiles() {
|
||||
List<MediaFile> mediaFiles = new ArrayList<>();
|
||||
|
||||
MediaFile mf1 = new MediaFile();
|
||||
mf1.setId(142);
|
||||
mf1.setPath("/some/path/to_album/to_artist/name - of - song.mp3");
|
||||
mf1.setPresent(true);
|
||||
mediaFiles.add(mf1);
|
||||
|
||||
MediaFile mf2 = new MediaFile();
|
||||
mf2.setId(1235);
|
||||
mf2.setPath("/some/path/to_album2/to_artist/another song.mp3");
|
||||
mf2.setPresent(true);
|
||||
mediaFiles.add(mf2);
|
||||
|
||||
MediaFile mf3 = new MediaFile();
|
||||
mf3.setId(198403);
|
||||
mf3.setPath("/some/path/to_album2/to_artist/another song2.mp3");
|
||||
mf3.setPresent(false);
|
||||
mediaFiles.add(mf3);
|
||||
|
||||
return mediaFiles;
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.libresonic.player.dao.MediaFileDao;
|
||||
import org.libresonic.player.dao.PlaylistDao;
|
||||
import org.libresonic.player.domain.MediaFile;
|
||||
import org.libresonic.player.domain.Playlist;
|
||||
import org.libresonic.player.service.playlist.DefaultPlaylistExportHandler;
|
||||
import org.libresonic.player.service.playlist.DefaultPlaylistImportHandler;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PlaylistServiceTestImport {
|
||||
|
||||
PlaylistService playlistService;
|
||||
|
||||
@InjectMocks
|
||||
DefaultPlaylistImportHandler defaultPlaylistImportHandler;
|
||||
|
||||
@Mock
|
||||
MediaFileDao mediaFileDao;
|
||||
|
||||
@Mock
|
||||
PlaylistDao playlistDao;
|
||||
|
||||
@Mock
|
||||
MediaFileService mediaFileService;
|
||||
|
||||
@Mock
|
||||
SettingsService settingsService;
|
||||
|
||||
@Mock
|
||||
SecurityService securityService;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<Playlist> actual;
|
||||
|
||||
@Captor
|
||||
ArgumentCaptor<List<MediaFile>> medias;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
playlistService = new PlaylistService(
|
||||
mediaFileDao,
|
||||
playlistDao,
|
||||
securityService,
|
||||
settingsService,
|
||||
Collections.emptyList(),
|
||||
Lists.newArrayList(defaultPlaylistImportHandler));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportFromM3U() throws Exception {
|
||||
String username = "testUser";
|
||||
String playlistName = "test-playlist";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("#EXTM3U\n");
|
||||
File mf1 = folder.newFile();
|
||||
FileUtils.touch(mf1);
|
||||
File mf2 = folder.newFile();
|
||||
FileUtils.touch(mf2);
|
||||
File mf3 = folder.newFile();
|
||||
FileUtils.touch(mf3);
|
||||
builder.append(mf1.getAbsolutePath() + "\n");
|
||||
builder.append(mf2.getAbsolutePath() + "\n");
|
||||
builder.append(mf3.getAbsolutePath() + "\n");
|
||||
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
||||
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
||||
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
|
||||
String path = "/path/to/"+playlistName+".m3u";
|
||||
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
||||
verify(playlistDao).createPlaylist(actual.capture());
|
||||
verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());
|
||||
Playlist expected = new Playlist();
|
||||
expected.setUsername(username);
|
||||
expected.setName(playlistName);
|
||||
expected.setComment("Auto-imported from " + path);
|
||||
expected.setImportedFrom(path);
|
||||
expected.setShared(true);
|
||||
expected.setId(23);
|
||||
assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));
|
||||
List<MediaFile> mediaFiles = medias.getValue();
|
||||
assertEquals(3, mediaFiles.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportFromPLS() throws Exception {
|
||||
String username = "testUser";
|
||||
String playlistName = "test-playlist";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("[playlist]\n");
|
||||
File mf1 = folder.newFile();
|
||||
FileUtils.touch(mf1);
|
||||
File mf2 = folder.newFile();
|
||||
FileUtils.touch(mf2);
|
||||
File mf3 = folder.newFile();
|
||||
FileUtils.touch(mf3);
|
||||
builder.append("File1=" + mf1.getAbsolutePath() + "\n");
|
||||
builder.append("File2=" + mf2.getAbsolutePath() + "\n");
|
||||
builder.append("File3=" + mf3.getAbsolutePath() + "\n");
|
||||
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
||||
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
||||
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
|
||||
String path = "/path/to/"+playlistName+".pls";
|
||||
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
||||
verify(playlistDao).createPlaylist(actual.capture());
|
||||
verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());
|
||||
Playlist expected = new Playlist();
|
||||
expected.setUsername(username);
|
||||
expected.setName(playlistName);
|
||||
expected.setComment("Auto-imported from " + path);
|
||||
expected.setImportedFrom(path);
|
||||
expected.setShared(true);
|
||||
expected.setId(23);
|
||||
assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));
|
||||
List<MediaFile> mediaFiles = medias.getValue();
|
||||
assertEquals(3, mediaFiles.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportFromXSPF() throws Exception {
|
||||
String username = "testUser";
|
||||
String playlistName = "test-playlist";
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n"
|
||||
+ " <trackList>\n");
|
||||
File mf1 = folder.newFile();
|
||||
FileUtils.touch(mf1);
|
||||
File mf2 = folder.newFile();
|
||||
FileUtils.touch(mf2);
|
||||
File mf3 = folder.newFile();
|
||||
FileUtils.touch(mf3);
|
||||
builder.append("<track><location>file://" + mf1.getAbsolutePath() + "</location></track>\n");
|
||||
builder.append("<track><location>file://" + mf2.getAbsolutePath() + "</location></track>\n");
|
||||
builder.append("<track><location>file://" + mf3.getAbsolutePath() + "</location></track>\n");
|
||||
builder.append(" </trackList>\n" + "</playlist>\n");
|
||||
doAnswer(new PersistPlayList(23)).when(playlistDao).createPlaylist(any());
|
||||
doAnswer(new MediaFileHasEverything()).when(mediaFileService).getMediaFile(any(File.class));
|
||||
InputStream inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
|
||||
String path = "/path/to/"+playlistName+".xspf";
|
||||
playlistService.importPlaylist(username, playlistName, path, inputStream, null);
|
||||
verify(playlistDao).createPlaylist(actual.capture());
|
||||
verify(playlistDao).setFilesInPlaylist(eq(23), medias.capture());
|
||||
Playlist expected = new Playlist();
|
||||
expected.setUsername(username);
|
||||
expected.setName(playlistName);
|
||||
expected.setComment("Auto-imported from " + path);
|
||||
expected.setImportedFrom(path);
|
||||
expected.setShared(true);
|
||||
expected.setId(23);
|
||||
assertTrue("\n" + ToStringBuilder.reflectionToString(actual.getValue()) + "\n\n did not equal \n\n" + ToStringBuilder.reflectionToString(expected), EqualsBuilder.reflectionEquals(actual.getValue(), expected, "created", "changed"));
|
||||
List<MediaFile> mediaFiles = medias.getValue();
|
||||
assertEquals(3, mediaFiles.size());
|
||||
}
|
||||
|
||||
private class PersistPlayList implements Answer {
|
||||
private final int id;
|
||||
public PersistPlayList(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
Playlist playlist = invocationOnMock.getArgument(0);
|
||||
playlist.setId(id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class MediaFileHasEverything implements Answer {
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
File file = invocationOnMock.getArgument(0);
|
||||
MediaFile mediaFile = new MediaFile();
|
||||
mediaFile.setPath(file.getPath());
|
||||
return mediaFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
/**
|
||||
* Unit test of {@link SecurityService}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class SecurityServiceTestCase extends TestCase {
|
||||
|
||||
public void testIsFileInFolder() {
|
||||
SecurityService service = new SecurityService();
|
||||
|
||||
assertTrue(service.isFileInFolder("/music/foo.mp3", "\\"));
|
||||
assertTrue(service.isFileInFolder("/music/foo.mp3", "/"));
|
||||
|
||||
assertTrue(service.isFileInFolder("/music/foo.mp3", "/music"));
|
||||
assertTrue(service.isFileInFolder("\\music\\foo.mp3", "/music"));
|
||||
assertTrue(service.isFileInFolder("/music/foo.mp3", "\\music"));
|
||||
assertTrue(service.isFileInFolder("/music/foo.mp3", "\\music\\"));
|
||||
|
||||
assertFalse(service.isFileInFolder("", "/tmp"));
|
||||
assertFalse(service.isFileInFolder("foo.mp3", "/tmp"));
|
||||
assertFalse(service.isFileInFolder("/music/foo.mp3", "/tmp"));
|
||||
assertFalse(service.isFileInFolder("/music/foo.mp3", "/tmp/music"));
|
||||
|
||||
// Test that references to the parent directory (..) is not allowed.
|
||||
assertTrue(service.isFileInFolder("/music/foo..mp3", "/music"));
|
||||
assertTrue(service.isFileInFolder("/music/foo..", "/music"));
|
||||
assertTrue(service.isFileInFolder("/music/foo.../", "/music"));
|
||||
assertFalse(service.isFileInFolder("/music/foo/..", "/music"));
|
||||
assertFalse(service.isFileInFolder("../music/foo", "/music"));
|
||||
assertFalse(service.isFileInFolder("/music/../foo", "/music"));
|
||||
assertFalse(service.isFileInFolder("/music/../bar/../foo", "/music"));
|
||||
assertFalse(service.isFileInFolder("/music\\foo\\..", "/music"));
|
||||
assertFalse(service.isFileInFolder("..\\music/foo", "/music"));
|
||||
assertFalse(service.isFileInFolder("/music\\../foo", "/music"));
|
||||
assertFalse(service.isFileInFolder("/music/..\\bar/../foo", "/music"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.TestCaseUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Unit test of {@link SettingsService}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class SettingsServiceTestCase extends TestCase {
|
||||
|
||||
private SettingsService settingsService;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
String libresonicHome = TestCaseUtils.libresonicHomePathForTest();
|
||||
System.setProperty("libresonic.home", libresonicHome);
|
||||
new File(libresonicHome, "libresonic.properties").delete();
|
||||
settingsService = newSettingsService();
|
||||
}
|
||||
|
||||
private SettingsService newSettingsService() {
|
||||
SettingsService settingsService = new SettingsService();
|
||||
settingsService.setConfigurationService(new ApacheCommonsConfigurationService());
|
||||
return settingsService;
|
||||
}
|
||||
|
||||
public void testLibresonicHome() {
|
||||
assertEquals("Wrong Libresonic home.", TestCaseUtils.libresonicHomePathForTest(), SettingsService.getLibresonicHome().getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testDefaultValues() {
|
||||
assertEquals("Wrong default language.", "en", settingsService.getLocale().getLanguage());
|
||||
assertEquals("Wrong default index creation interval.", 1, settingsService.getIndexCreationInterval());
|
||||
assertEquals("Wrong default index creation hour.", 3, settingsService.getIndexCreationHour());
|
||||
assertTrue("Wrong default playlist folder.", settingsService.getPlaylistFolder().endsWith("playlists"));
|
||||
assertEquals("Wrong default theme.", "default", settingsService.getThemeId());
|
||||
assertEquals("Wrong default Podcast episode retention count.", 10, settingsService.getPodcastEpisodeRetentionCount());
|
||||
assertEquals("Wrong default Podcast episode download count.", 1, settingsService.getPodcastEpisodeDownloadCount());
|
||||
assertTrue("Wrong default Podcast folder.", settingsService.getPodcastFolder().endsWith("Podcast"));
|
||||
assertEquals("Wrong default Podcast update interval.", 24, settingsService.getPodcastUpdateInterval());
|
||||
assertEquals("Wrong default LDAP enabled.", false, settingsService.isLdapEnabled());
|
||||
assertEquals("Wrong default LDAP URL.", "ldap://host.domain.com:389/cn=Users,dc=domain,dc=com", settingsService.getLdapUrl());
|
||||
assertNull("Wrong default LDAP manager DN.", settingsService.getLdapManagerDn());
|
||||
assertNull("Wrong default LDAP manager password.", settingsService.getLdapManagerPassword());
|
||||
assertEquals("Wrong default LDAP search filter.", "(sAMAccountName={0})", settingsService.getLdapSearchFilter());
|
||||
assertEquals("Wrong default LDAP auto-shadowing.", false, settingsService.isLdapAutoShadowing());
|
||||
}
|
||||
|
||||
public void testChangeSettings() {
|
||||
settingsService.setIndexString("indexString");
|
||||
settingsService.setIgnoredArticles("a the foo bar");
|
||||
settingsService.setShortcuts("new incoming \"rock 'n' roll\"");
|
||||
settingsService.setPlaylistFolder("playlistFolder");
|
||||
settingsService.setMusicFileTypes("mp3 ogg aac");
|
||||
settingsService.setCoverArtFileTypes("jpeg gif png");
|
||||
settingsService.setWelcomeMessage("welcomeMessage");
|
||||
settingsService.setLoginMessage("loginMessage");
|
||||
settingsService.setLocale(Locale.CANADA_FRENCH);
|
||||
settingsService.setThemeId("dark");
|
||||
settingsService.setIndexCreationInterval(4);
|
||||
settingsService.setIndexCreationHour(9);
|
||||
settingsService.setPodcastEpisodeRetentionCount(5);
|
||||
settingsService.setPodcastEpisodeDownloadCount(-1);
|
||||
settingsService.setPodcastFolder("d:/podcasts");
|
||||
settingsService.setPodcastUpdateInterval(-1);
|
||||
settingsService.setLdapEnabled(true);
|
||||
settingsService.setLdapUrl("newLdapUrl");
|
||||
settingsService.setLdapManagerDn("admin");
|
||||
settingsService.setLdapManagerPassword("secret");
|
||||
settingsService.setLdapSearchFilter("newLdapSearchFilter");
|
||||
settingsService.setLdapAutoShadowing(true);
|
||||
|
||||
verifySettings(settingsService);
|
||||
|
||||
settingsService.save();
|
||||
verifySettings(settingsService);
|
||||
|
||||
verifySettings(newSettingsService());
|
||||
}
|
||||
|
||||
private void verifySettings(SettingsService ss) {
|
||||
assertEquals("Wrong index string.", "indexString", ss.getIndexString());
|
||||
assertEquals("Wrong ignored articles.", "a the foo bar", ss.getIgnoredArticles());
|
||||
assertEquals("Wrong shortcuts.", "new incoming \"rock 'n' roll\"", ss.getShortcuts());
|
||||
assertTrue("Wrong ignored articles array.", Arrays.equals(new String[] {"a", "the", "foo", "bar"}, ss.getIgnoredArticlesAsArray()));
|
||||
assertTrue("Wrong shortcut array.", Arrays.equals(new String[] {"new", "incoming", "rock 'n' roll"}, ss.getShortcutsAsArray()));
|
||||
assertEquals("Wrong playlist folder.", "playlistFolder", ss.getPlaylistFolder());
|
||||
assertEquals("Wrong music mask.", "mp3 ogg aac", ss.getMusicFileTypes());
|
||||
assertTrue("Wrong music mask array.", Arrays.equals(new String[] {"mp3", "ogg", "aac"}, ss.getMusicFileTypesAsArray()));
|
||||
assertEquals("Wrong cover art mask.", "jpeg gif png", ss.getCoverArtFileTypes());
|
||||
assertTrue("Wrong cover art mask array.", Arrays.equals(new String[] {"jpeg", "gif", "png"}, ss.getCoverArtFileTypesAsArray()));
|
||||
assertEquals("Wrong welcome message.", "welcomeMessage", ss.getWelcomeMessage());
|
||||
assertEquals("Wrong login message.", "loginMessage", ss.getLoginMessage());
|
||||
assertEquals("Wrong locale.", Locale.CANADA_FRENCH, ss.getLocale());
|
||||
assertEquals("Wrong theme.", "dark", ss.getThemeId());
|
||||
assertEquals("Wrong index creation interval.", 4, ss.getIndexCreationInterval());
|
||||
assertEquals("Wrong index creation hour.", 9, ss.getIndexCreationHour());
|
||||
assertEquals("Wrong Podcast episode retention count.", 5, settingsService.getPodcastEpisodeRetentionCount());
|
||||
assertEquals("Wrong Podcast episode download count.", -1, settingsService.getPodcastEpisodeDownloadCount());
|
||||
assertEquals("Wrong Podcast folder.", "d:/podcasts", settingsService.getPodcastFolder());
|
||||
assertEquals("Wrong Podcast update interval.", -1, settingsService.getPodcastUpdateInterval());
|
||||
assertTrue("Wrong LDAP enabled.", settingsService.isLdapEnabled());
|
||||
assertEquals("Wrong LDAP URL.", "newLdapUrl", settingsService.getLdapUrl());
|
||||
assertEquals("Wrong LDAP manager DN.", "admin", settingsService.getLdapManagerDn());
|
||||
assertEquals("Wrong LDAP manager password.", "secret", settingsService.getLdapManagerPassword());
|
||||
assertEquals("Wrong LDAP search filter.", "newLdapSearchFilter", settingsService.getLdapSearchFilter());
|
||||
assertTrue("Wrong LDAP auto-shadowing.", settingsService.isLdapAutoShadowing());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of Libresonic.
|
||||
*
|
||||
* Libresonic is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Libresonic is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Copyright 2015 (C) Sindre Mehus
|
||||
*/
|
||||
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SonosServiceTest extends TestCase {
|
||||
|
||||
public void testParsePlaylistIndices() {
|
||||
SonosService sonosService = new SonosService();
|
||||
assertEquals("[]", sonosService.parsePlaylistIndices("").toString());
|
||||
assertEquals("[999]", sonosService.parsePlaylistIndices("999").toString());
|
||||
assertEquals("[1, 2, 3]", sonosService.parsePlaylistIndices("1,2,3").toString());
|
||||
assertEquals("[1, 2, 3]", sonosService.parsePlaylistIndices("2,1,3").toString());
|
||||
assertEquals("[1, 2, 4, 5, 6, 7]", sonosService.parsePlaylistIndices("1,2,4-7").toString());
|
||||
assertEquals("[11, 12, 15, 20, 21, 22]", sonosService.parsePlaylistIndices("11-12,15,20-22").toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.service;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.domain.Player;
|
||||
import org.libresonic.player.domain.TransferStatus;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Unit test of {@link StatusService}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class StatusServiceTestCase extends TestCase {
|
||||
|
||||
private StatusService service;
|
||||
private Player player1;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
service = new StatusService();
|
||||
player1 = new Player();
|
||||
player1.setId("1");
|
||||
}
|
||||
|
||||
public void testSimpleAddRemove() {
|
||||
TransferStatus status = service.createStreamStatus(player1);
|
||||
assertTrue("Wrong status.", status.isActive());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getAllStreamStatuses());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getStreamStatusesForPlayer(player1));
|
||||
|
||||
service.removeStreamStatus(status);
|
||||
assertFalse("Wrong status.", status.isActive());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getAllStreamStatuses());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getStreamStatusesForPlayer(player1));
|
||||
}
|
||||
|
||||
public void testMultipleStreamsSamePlayer() {
|
||||
TransferStatus statusA = service.createStreamStatus(player1);
|
||||
TransferStatus statusB = service.createStreamStatus(player1);
|
||||
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusA, statusB), service.getAllStreamStatuses());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusA, statusB), service.getStreamStatusesForPlayer(player1));
|
||||
|
||||
// Stop stream A.
|
||||
service.removeStreamStatus(statusA);
|
||||
assertFalse("Wrong status.", statusA.isActive());
|
||||
assertTrue("Wrong status.", statusB.isActive());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getAllStreamStatuses());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getStreamStatusesForPlayer(player1));
|
||||
|
||||
// Stop stream B.
|
||||
service.removeStreamStatus(statusB);
|
||||
assertFalse("Wrong status.", statusB.isActive());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getAllStreamStatuses());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getStreamStatusesForPlayer(player1));
|
||||
|
||||
// Start stream C.
|
||||
TransferStatus statusC = service.createStreamStatus(player1);
|
||||
assertTrue("Wrong status.", statusC.isActive());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusC), service.getAllStreamStatuses());
|
||||
assertEquals("Wrong list of statuses.", Arrays.asList(statusC), service.getStreamStatusesForPlayer(player1));
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.service.metadata;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.domain.MediaFile;
|
||||
|
||||
/**
|
||||
* Unit test of {@link MediaFile}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class MediaFileTestCase extends TestCase {
|
||||
|
||||
public void testGetDurationAsString() throws Exception {
|
||||
doTestGetDurationAsString(0, "0:00");
|
||||
doTestGetDurationAsString(1, "0:01");
|
||||
doTestGetDurationAsString(10, "0:10");
|
||||
doTestGetDurationAsString(33, "0:33");
|
||||
doTestGetDurationAsString(59, "0:59");
|
||||
doTestGetDurationAsString(60, "1:00");
|
||||
doTestGetDurationAsString(61, "1:01");
|
||||
doTestGetDurationAsString(70, "1:10");
|
||||
doTestGetDurationAsString(119, "1:59");
|
||||
doTestGetDurationAsString(120, "2:00");
|
||||
doTestGetDurationAsString(1200, "20:00");
|
||||
doTestGetDurationAsString(1201, "20:01");
|
||||
doTestGetDurationAsString(3599, "59:59");
|
||||
doTestGetDurationAsString(3600, "1:00:00");
|
||||
doTestGetDurationAsString(3601, "1:00:01");
|
||||
doTestGetDurationAsString(3661, "1:01:01");
|
||||
doTestGetDurationAsString(4200, "1:10:00");
|
||||
doTestGetDurationAsString(4201, "1:10:01");
|
||||
doTestGetDurationAsString(4210, "1:10:10");
|
||||
doTestGetDurationAsString(36000, "10:00:00");
|
||||
doTestGetDurationAsString(360000, "100:00:00");
|
||||
}
|
||||
|
||||
private void doTestGetDurationAsString(int seconds, String expected) {
|
||||
MediaFile mediaFile = new MediaFile();
|
||||
mediaFile.setDurationSeconds(seconds);
|
||||
assertEquals("Error in getDurationString().", expected, mediaFile.getDurationString());
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.service.metadata;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.libresonic.player.domain.MediaFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Unit test of {@link MetaDataParser}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class MetaDataParserTestCase extends TestCase {
|
||||
|
||||
public void testRemoveTrackNumberFromTitle() throws Exception {
|
||||
|
||||
MetaDataParser parser = new MetaDataParser() {
|
||||
public MetaData getRawMetaData(File file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setMetaData(MediaFile file, MetaData metaData) {
|
||||
}
|
||||
|
||||
public boolean isEditingSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isApplicable(File file) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
assertEquals("", parser.removeTrackNumberFromTitle("", null));
|
||||
assertEquals("kokos", parser.removeTrackNumberFromTitle("kokos", null));
|
||||
assertEquals("01 kokos", parser.removeTrackNumberFromTitle("01 kokos", null));
|
||||
assertEquals("01 - kokos", parser.removeTrackNumberFromTitle("01 - kokos", null));
|
||||
assertEquals("01-kokos", parser.removeTrackNumberFromTitle("01-kokos", null));
|
||||
assertEquals("01 - kokos", parser.removeTrackNumberFromTitle("01 - kokos", null));
|
||||
assertEquals("99 - kokos", parser.removeTrackNumberFromTitle("99 - kokos", null));
|
||||
assertEquals("99.- kokos", parser.removeTrackNumberFromTitle("99.- kokos", null));
|
||||
assertEquals("01 kokos", parser.removeTrackNumberFromTitle(" 01 kokos", null));
|
||||
assertEquals("400 years", parser.removeTrackNumberFromTitle("400 years", null));
|
||||
assertEquals("49ers", parser.removeTrackNumberFromTitle("49ers", null));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle("01", null));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle("01 ", null));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle(" 01 ", null));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle(" 01", null));
|
||||
|
||||
assertEquals("", parser.removeTrackNumberFromTitle("", 1));
|
||||
assertEquals("kokos", parser.removeTrackNumberFromTitle("01 kokos", 1));
|
||||
assertEquals("kokos", parser.removeTrackNumberFromTitle("01 - kokos", 1));
|
||||
assertEquals("kokos", parser.removeTrackNumberFromTitle("01-kokos", 1));
|
||||
assertEquals("kokos", parser.removeTrackNumberFromTitle("99 - kokos", 99));
|
||||
assertEquals("kokos", parser.removeTrackNumberFromTitle("99.- kokos", 99));
|
||||
assertEquals("01 kokos", parser.removeTrackNumberFromTitle("01 kokos", 2));
|
||||
assertEquals("1 kokos", parser.removeTrackNumberFromTitle("1 kokos", 2));
|
||||
assertEquals("50 years", parser.removeTrackNumberFromTitle("50 years", 1));
|
||||
assertEquals("years", parser.removeTrackNumberFromTitle("50 years", 50));
|
||||
assertEquals("15 Step", parser.removeTrackNumberFromTitle("15 Step", 1));
|
||||
assertEquals("Step", parser.removeTrackNumberFromTitle("15 Step", 15));
|
||||
|
||||
assertEquals("49ers", parser.removeTrackNumberFromTitle("49ers", 1));
|
||||
assertEquals("49ers", parser.removeTrackNumberFromTitle("49ers", 49));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle("01", 1));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle("01 ", 1));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle(" 01 ", 1));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle(" 01", 1));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle("01", 2));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle("01 ", 2));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle(" 01 ", 2));
|
||||
assertEquals("01", parser.removeTrackNumberFromTitle(" 01", 2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.libresonic.player.util;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
public class FileUtils {
|
||||
public static boolean copyFile(final File toCopy, final File destFile) {
|
||||
try {
|
||||
return FileUtils.copyStream(new FileInputStream(toCopy), new FileOutputStream(destFile));
|
||||
} catch (final FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean copyFilesRecusively(
|
||||
final File toCopy, final File destDir
|
||||
) {
|
||||
assert destDir.isDirectory();
|
||||
|
||||
if (!toCopy.isDirectory()) {
|
||||
return FileUtils.copyFile(toCopy, new File(destDir, toCopy.getName()));
|
||||
} else {
|
||||
final File newDestDir = new File(destDir, toCopy.getName());
|
||||
if (!newDestDir.exists() && !newDestDir.mkdir()) {
|
||||
return false;
|
||||
}
|
||||
for (final File child : toCopy.listFiles()) {
|
||||
if (!FileUtils.copyFilesRecusively(child, newDestDir)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean copyJarResourcesRecursively(
|
||||
final File destDir, final JarURLConnection jarConnection
|
||||
) throws IOException {
|
||||
|
||||
final JarFile jarFile = jarConnection.getJarFile();
|
||||
|
||||
for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
|
||||
final JarEntry entry = e.nextElement();
|
||||
if (entry.getName().startsWith(jarConnection.getEntryName())) {
|
||||
final String filename = StringUtils.removeStart(
|
||||
entry.getName(), //
|
||||
jarConnection.getEntryName());
|
||||
|
||||
final File f = new File(destDir, filename);
|
||||
if (!entry.isDirectory()) {
|
||||
final InputStream entryInputStream = jarFile.getInputStream(entry);
|
||||
if (!FileUtils.copyStream(entryInputStream, f)) {
|
||||
return false;
|
||||
}
|
||||
entryInputStream.close();
|
||||
} else {
|
||||
if (!FileUtils.ensureDirectoryExists(f)) {
|
||||
throw new IOException("Could not create directory: " + f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean copyResourcesRecursively(final URL originUrl, final File destination) {
|
||||
try {
|
||||
final URLConnection urlConnection = originUrl.openConnection();
|
||||
if (urlConnection instanceof JarURLConnection) {
|
||||
return FileUtils.copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
|
||||
} else {
|
||||
return FileUtils.copyFilesRecusively(new File(originUrl.getPath()), destination);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean copyStream(final InputStream is, final File f) {
|
||||
try {
|
||||
return FileUtils.copyStream(is, new FileOutputStream(f));
|
||||
} catch (final FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean copyStream(final InputStream is, final OutputStream os) {
|
||||
try {
|
||||
final byte[] buf = new byte[1024];
|
||||
|
||||
int len = 0;
|
||||
while ((len = is.read(buf)) > 0) {
|
||||
os.write(buf, 0, len);
|
||||
}
|
||||
is.close();
|
||||
os.close();
|
||||
return true;
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean ensureDirectoryExists(final File f) {
|
||||
return f.exists() || f.mkdir();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.libresonic.player.util;
|
||||
|
||||
import org.junit.rules.ExternalResource;
|
||||
import org.libresonic.player.TestCaseUtils;
|
||||
|
||||
public class LibresonicHomeRule extends ExternalResource {
|
||||
@Override
|
||||
protected void before() throws Throwable {
|
||||
super.before();
|
||||
System.setProperty("libresonic.home", TestCaseUtils.libresonicHomePathForTest());
|
||||
|
||||
TestCaseUtils.cleanLibresonicHomeForTest();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Unit test of {@link HttpRange}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class HttpRangeTestCase extends TestCase {
|
||||
|
||||
public void testSize() {
|
||||
assertEquals(1, new HttpRange(0L, 0L).size());
|
||||
assertEquals(2, new HttpRange(0L, 1L).size());
|
||||
assertEquals(1, new HttpRange(66L, 66L).size());
|
||||
assertEquals(2, new HttpRange(66L, 67L).size());
|
||||
assertEquals(10, new HttpRange(66L, 75L).size());
|
||||
assertEquals(-1, new HttpRange(66L, null).size());
|
||||
}
|
||||
|
||||
public void testContains() {
|
||||
assertFalse(new HttpRange(0L, 0L).contains(-1));
|
||||
assertTrue(new HttpRange(0L, 0L).contains(0));
|
||||
assertFalse(new HttpRange(0L, 0L).contains(1));
|
||||
|
||||
assertFalse(new HttpRange(5L, 10L).contains(-1));
|
||||
assertFalse(new HttpRange(5L, 10L).contains(4));
|
||||
assertTrue(new HttpRange(5L, 10L).contains(5));
|
||||
assertTrue(new HttpRange(5L, 10L).contains(9));
|
||||
assertTrue(new HttpRange(5L, 10L).contains(10));
|
||||
assertFalse(new HttpRange(5L, 10L).contains(11));
|
||||
assertFalse(new HttpRange(5L, 10L).contains(66));
|
||||
|
||||
assertFalse(new HttpRange(5L, null).contains(-1));
|
||||
assertFalse(new HttpRange(5L, null).contains(4));
|
||||
assertTrue(new HttpRange(5L, null).contains(5));
|
||||
assertTrue(new HttpRange(5L, null).contains(6));
|
||||
assertTrue(new HttpRange(5L, null).contains(66));
|
||||
}
|
||||
|
||||
public void testParseRange() {
|
||||
doTestParseRange(0L, 0L, "bytes=0-0");
|
||||
doTestParseRange(0L, 1L, "bytes=0-1");
|
||||
doTestParseRange(100L, 100L, "bytes=100-100");
|
||||
doTestParseRange(0L, 499L, "bytes=0-499");
|
||||
doTestParseRange(500L, 999L, "bytes=500-999");
|
||||
doTestParseRange(9500L, null, "bytes=9500-");
|
||||
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf(null));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf(""));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf("bytes"));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf("bytes=a-b"));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf("bytes=-100-500"));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf("bytes=-500"));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf("bytes=500-600,601-999"));
|
||||
assertNull("Error in parseRange().", HttpRange.valueOf("bytes=200-100"));
|
||||
}
|
||||
|
||||
private void doTestParseRange(Long expectedFrom, Long expectedTo, String range) {
|
||||
HttpRange actual = HttpRange.valueOf(range);
|
||||
assertEquals("Error in parseRange().", expectedFrom, actual.getFirstBytePos());
|
||||
assertEquals("Error in parseRange().", expectedTo, actual.getLastBytePos());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
This file is part of Libresonic.
|
||||
|
||||
Libresonic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Libresonic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Libresonic. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2016 (C) Libresonic Authors
|
||||
Based upon Subsonic, Copyright 2009 (C) Sindre Mehus
|
||||
*/
|
||||
package org.libresonic.player.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Unit test of {@link StringUtil}.
|
||||
*
|
||||
* @author Sindre Mehus
|
||||
*/
|
||||
public class StringUtilTestCase extends TestCase {
|
||||
|
||||
public void testToHtml() throws Exception {
|
||||
assertEquals(null, StringUtil.toHtml(null));
|
||||
assertEquals("", StringUtil.toHtml(""));
|
||||
assertEquals(" ", StringUtil.toHtml(" "));
|
||||
assertEquals("q & a", StringUtil.toHtml("q & a"));
|
||||
assertEquals("q & a <> b", StringUtil.toHtml("q & a <> b"));
|
||||
}
|
||||
|
||||
public void testRemoveSuffix() {
|
||||
assertEquals("Error in removeSuffix().", "foo", StringUtil.removeSuffix("foo.mp3"));
|
||||
assertEquals("Error in removeSuffix().", "", StringUtil.removeSuffix(".mp3"));
|
||||
assertEquals("Error in removeSuffix().", "foo.bar", StringUtil.removeSuffix("foo.bar.mp3"));
|
||||
assertEquals("Error in removeSuffix().", "foo.", StringUtil.removeSuffix("foo..mp3"));
|
||||
assertEquals("Error in removeSuffix().", "foo", StringUtil.removeSuffix("foo"));
|
||||
assertEquals("Error in removeSuffix().", "", StringUtil.removeSuffix(""));
|
||||
}
|
||||
|
||||
public void testGetMimeType() {
|
||||
assertEquals("Error in getMimeType().", "audio/mpeg", StringUtil.getMimeType("mp3"));
|
||||
assertEquals("Error in getMimeType().", "audio/mpeg", StringUtil.getMimeType(".mp3"));
|
||||
assertEquals("Error in getMimeType().", "audio/mpeg", StringUtil.getMimeType(".MP3"));
|
||||
assertEquals("Error in getMimeType().", "application/octet-stream", StringUtil.getMimeType("koko"));
|
||||
assertEquals("Error in getMimeType().", "application/octet-stream", StringUtil.getMimeType(""));
|
||||
assertEquals("Error in getMimeType().", "application/octet-stream", StringUtil.getMimeType(null));
|
||||
}
|
||||
|
||||
public void testFormatBytes() throws Exception {
|
||||
Locale locale = Locale.ENGLISH;
|
||||
assertEquals("Error in formatBytes().", "918 B", StringUtil.formatBytes(918, locale));
|
||||
assertEquals("Error in formatBytes().", "1023 B", StringUtil.formatBytes(1023, locale));
|
||||
assertEquals("Error in formatBytes().", "1 KB", StringUtil.formatBytes(1024, locale));
|
||||
assertEquals("Error in formatBytes().", "96 KB", StringUtil.formatBytes(98765, locale));
|
||||
assertEquals("Error in formatBytes().", "1024 KB", StringUtil.formatBytes(1048575, locale));
|
||||
assertEquals("Error in formatBytes().", "1.2 MB", StringUtil.formatBytes(1238476, locale));
|
||||
assertEquals("Error in formatBytes().", "3.50 GB", StringUtil.formatBytes(3758096384L, locale));
|
||||
assertEquals("Error in formatBytes().", "410.00 TB", StringUtil.formatBytes(450799767388160L, locale));
|
||||
assertEquals("Error in formatBytes().", "4413.43 TB", StringUtil.formatBytes(4852617603375432L, locale));
|
||||
|
||||
locale = new Locale("no", "", "");
|
||||
assertEquals("Error in formatBytes().", "918 B", StringUtil.formatBytes(918, locale));
|
||||
assertEquals("Error in formatBytes().", "1023 B", StringUtil.formatBytes(1023, locale));
|
||||
assertEquals("Error in formatBytes().", "1 KB", StringUtil.formatBytes(1024, locale));
|
||||
assertEquals("Error in formatBytes().", "96 KB", StringUtil.formatBytes(98765, locale));
|
||||
assertEquals("Error in formatBytes().", "1024 KB", StringUtil.formatBytes(1048575, locale));
|
||||
assertEquals("Error in formatBytes().", "1,2 MB", StringUtil.formatBytes(1238476, locale));
|
||||
assertEquals("Error in formatBytes().", "3,50 GB", StringUtil.formatBytes(3758096384L, locale));
|
||||
assertEquals("Error in formatBytes().", "410,00 TB", StringUtil.formatBytes(450799767388160L, locale));
|
||||
assertEquals("Error in formatBytes().", "4413,43 TB", StringUtil.formatBytes(4852617603375432L, locale));
|
||||
}
|
||||
|
||||
public void testFormatDuration() {
|
||||
assertEquals("Error in formatDuration().", "0:00", StringUtil.formatDuration(0));
|
||||
assertEquals("Error in formatDuration().", "0:05", StringUtil.formatDuration(5));
|
||||
assertEquals("Error in formatDuration().", "0:10", StringUtil.formatDuration(10));
|
||||
assertEquals("Error in formatDuration().", "0:59", StringUtil.formatDuration(59));
|
||||
assertEquals("Error in formatDuration().", "1:00", StringUtil.formatDuration(60));
|
||||
assertEquals("Error in formatDuration().", "1:01", StringUtil.formatDuration(61));
|
||||
assertEquals("Error in formatDuration().", "1:10", StringUtil.formatDuration(70));
|
||||
assertEquals("Error in formatDuration().", "10:00", StringUtil.formatDuration(600));
|
||||
assertEquals("Error in formatDuration().", "45:50", StringUtil.formatDuration(2750));
|
||||
assertEquals("Error in formatDuration().", "83:45", StringUtil.formatDuration(5025));
|
||||
}
|
||||
|
||||
public void testSplit() {
|
||||
doTestSplit("u2 rem \"greatest hits\"", "u2", "rem", "greatest hits");
|
||||
doTestSplit("u2", "u2");
|
||||
doTestSplit("u2 rem", "u2", "rem");
|
||||
doTestSplit(" u2 \t rem ", "u2", "rem");
|
||||
doTestSplit("u2 \"rem\"", "u2", "rem");
|
||||
doTestSplit("u2 \"rem", "u2", "\"rem");
|
||||
doTestSplit("\"", "\"");
|
||||
|
||||
assertEquals(0, StringUtil.split("").length);
|
||||
assertEquals(0, StringUtil.split(" ").length);
|
||||
assertEquals(0, StringUtil.split(null).length);
|
||||
}
|
||||
|
||||
private void doTestSplit(String input, String... expected) {
|
||||
String[] actual = StringUtil.split(input);
|
||||
assertEquals("Wrong number of elements.", expected.length, actual.length);
|
||||
|
||||
for (int i = 0; i < expected.length; i++) {
|
||||
assertEquals("Wrong criteria.", expected[i], actual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testParseInts() {
|
||||
doTestParseInts("123", 123);
|
||||
doTestParseInts("1 2 3", 1, 2, 3);
|
||||
doTestParseInts("10 20 \t\n 30", 10, 20, 30);
|
||||
|
||||
assertTrue("Error in parseInts().", StringUtil.parseInts(null).length == 0);
|
||||
assertTrue("Error in parseInts().", StringUtil.parseInts("").length == 0);
|
||||
assertTrue("Error in parseInts().", StringUtil.parseInts(" ").length == 0);
|
||||
assertTrue("Error in parseInts().", StringUtil.parseInts(" ").length == 0);
|
||||
}
|
||||
|
||||
private void doTestParseInts(String s, int... expected) {
|
||||
assertEquals("Error in parseInts().", Arrays.toString(expected), Arrays.toString(StringUtil.parseInts(s)));
|
||||
}
|
||||
|
||||
public void testParseLocale() {
|
||||
assertEquals("Error in parseLocale().", null, null);
|
||||
assertEquals("Error in parseLocale().", new Locale("en"), StringUtil.parseLocale("en"));
|
||||
assertEquals("Error in parseLocale().", new Locale("en"), StringUtil.parseLocale("en_"));
|
||||
assertEquals("Error in parseLocale().", new Locale("en"), StringUtil.parseLocale("en__"));
|
||||
assertEquals("Error in parseLocale().", new Locale("en", "US"), StringUtil.parseLocale("en_US"));
|
||||
assertEquals("Error in parseLocale().", new Locale("en", "US", "WIN"), StringUtil.parseLocale("en_US_WIN"));
|
||||
assertEquals("Error in parseLocale().", new Locale("en", "", "WIN"), StringUtil.parseLocale("en__WIN"));
|
||||
}
|
||||
|
||||
public void testUtf8Hex() throws Exception {
|
||||
doTestUtf8Hex(null);
|
||||
doTestUtf8Hex("");
|
||||
doTestUtf8Hex("a");
|
||||
doTestUtf8Hex("abcdefg");
|
||||
doTestUtf8Hex("abc������");
|
||||
doTestUtf8Hex("NRK P3 � FK Fotball");
|
||||
}
|
||||
|
||||
private void doTestUtf8Hex(String s) throws Exception {
|
||||
assertEquals("Error in utf8hex.", s, StringUtil.utf8HexDecode(StringUtil.utf8HexEncode(s)));
|
||||
}
|
||||
|
||||
public void testMd5Hex() {
|
||||
assertNull("Error in md5Hex().", StringUtil.md5Hex(null));
|
||||
assertEquals("Error in md5Hex().", "d41d8cd98f00b204e9800998ecf8427e", StringUtil.md5Hex(""));
|
||||
assertEquals("Error in md5Hex().", "308ed0af23d48f6d2fd4717e77a23e0c", StringUtil.md5Hex("sindre@activeobjects.no"));
|
||||
}
|
||||
|
||||
public void testGetUrlFile() {
|
||||
assertEquals("Error in getUrlFile().", "foo.mp3", StringUtil.getUrlFile("http://www.asdf.com/foo.mp3"));
|
||||
assertEquals("Error in getUrlFile().", "foo.mp3", StringUtil.getUrlFile("http://www.asdf.com/bar/foo.mp3"));
|
||||
assertEquals("Error in getUrlFile().", "foo", StringUtil.getUrlFile("http://www.asdf.com/bar/foo"));
|
||||
assertEquals("Error in getUrlFile().", "foo.mp3", StringUtil.getUrlFile("http://www.asdf.com/bar/foo.mp3?a=1&b=2"));
|
||||
assertNull("Error in getUrlFile().", StringUtil.getUrlFile("not a url"));
|
||||
assertNull("Error in getUrlFile().", StringUtil.getUrlFile("http://www.asdf.com"));
|
||||
assertNull("Error in getUrlFile().", StringUtil.getUrlFile("http://www.asdf.com/"));
|
||||
assertNull("Error in getUrlFile().", StringUtil.getUrlFile("http://www.asdf.com/foo/"));
|
||||
}
|
||||
|
||||
public void testFileSystemSafe() {
|
||||
assertEquals("Error in fileSystemSafe().", "foo", StringUtil.fileSystemSafe("foo"));
|
||||
assertEquals("Error in fileSystemSafe().", "foo.mp3", StringUtil.fileSystemSafe("foo.mp3"));
|
||||
assertEquals("Error in fileSystemSafe().", "foo-bar", StringUtil.fileSystemSafe("foo/bar"));
|
||||
assertEquals("Error in fileSystemSafe().", "foo-bar", StringUtil.fileSystemSafe("foo\\bar"));
|
||||
assertEquals("Error in fileSystemSafe().", "foo-bar", StringUtil.fileSystemSafe("foo:bar"));
|
||||
}
|
||||
|
||||
public void testRemoveMarkup() {
|
||||
assertEquals("Error in removeMarkup()", "foo", StringUtil.removeMarkup("<b>foo</b>"));
|
||||
assertEquals("Error in removeMarkup()", "foobar", StringUtil.removeMarkup("<b>foo</b>bar"));
|
||||
assertEquals("Error in removeMarkup()", "foo", StringUtil.removeMarkup("foo"));
|
||||
assertEquals("Error in removeMarkup()", "foo", StringUtil.removeMarkup("<b>foo"));
|
||||
assertEquals("Error in removeMarkup()", null, StringUtil.removeMarkup(null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
This file should not be scanned
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
|
After Width: | Height: | Size: 51 KiB |
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
/some/path/to_album/to_artist/name - of - song.mp3
|
||||
/some/path/to_album2/to_artist/another song.mp3
|
||||
/some/path/to_album2/to_artist/another song2.mp3
|
||||
@@ -0,0 +1,6 @@
|
||||
[playlist]
|
||||
File1=/some/path/to_album/to_artist/name - of - song.mp3
|
||||
File2=/some/path/to_album2/to_artist/another song.mp3
|
||||
File3=/some/path/to_album2/to_artist/another song2.mp3
|
||||
NumberOfEntries=3
|
||||
Version=2
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<playlist version="1" xmlns="http://xspf.org/ns/0/">
|
||||
<trackList>
|
||||
<track><location>file:///some/path/to_album/to_artist/name - of - song.mp3</location></track>
|
||||
<track><location>file:///some/path/to_album2/to_artist/another song.mp3</location></track>
|
||||
<track><location>file:///some/path/to_album2/to_artist/another song2.mp3</location></track>
|
||||
</trackList>
|
||||
</playlist>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jaxws="http://cxf.apache.org/jaxws"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
|
||||
|
||||
<bean id="sonosHelper" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.libresonic.player.service.sonos.SonosHelper" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
|
||||
<property name="url" value="jdbc:hsqldb:file:#{systemProperties['libresonic.home']}/db/libresonic" />
|
||||
<property name="username" value="sa" />
|
||||
<property name="password" value="" />
|
||||
</bean>
|
||||
</beans>
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,17 @@
|
||||
#HSQL Database Engine 1.8.0.5
|
||||
#Sun Dec 18 21:11:59 MST 2016
|
||||
hsqldb.script_format=0
|
||||
runtime.gc_interval=0
|
||||
sql.enforce_strict_size=false
|
||||
hsqldb.cache_size_scale=8
|
||||
readonly=false
|
||||
hsqldb.nio_data_file=true
|
||||
hsqldb.cache_scale=14
|
||||
version=1.8.0
|
||||
hsqldb.default_table_type=memory
|
||||
hsqldb.cache_file_scale=1
|
||||
hsqldb.log_size=200
|
||||
modified=yes
|
||||
hsqldb.cache_version=1.7.0
|
||||
hsqldb.original_version=1.8.0
|
||||
hsqldb.compatible_version=1.8.0
|
||||
@@ -0,0 +1,314 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<jmeterTestPlan version="1.2" properties="3.1" jmeter="3.1 r1770033">
|
||||
<hashTree>
|
||||
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Plan de test" enabled="true">
|
||||
<stringProp name="TestPlan.comments"></stringProp>
|
||||
<boolProp name="TestPlan.functional_mode">false</boolProp>
|
||||
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
|
||||
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="Variables pré-définies" enabled="true">
|
||||
<collectionProp name="Arguments.arguments"/>
|
||||
</elementProp>
|
||||
<stringProp name="TestPlan.user_define_classpath"></stringProp>
|
||||
</TestPlan>
|
||||
<hashTree>
|
||||
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="Libresonic Server configuration" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="SERVER_NAME" elementType="Argument">
|
||||
<stringProp name="Argument.name">SERVER_NAME</stringProp>
|
||||
<stringProp name="Argument.value">localhost</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="SERVER_PORT" elementType="Argument">
|
||||
<stringProp name="Argument.name">SERVER_PORT</stringProp>
|
||||
<stringProp name="Argument.value">8080</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</Arguments>
|
||||
<hashTree/>
|
||||
<CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="HTTP Cookie Manager" enabled="true">
|
||||
<collectionProp name="CookieManager.cookies"/>
|
||||
<boolProp name="CookieManager.clearEachIteration">false</boolProp>
|
||||
<stringProp name="CookieManager.policy">standard</stringProp>
|
||||
<stringProp name="CookieManager.implementation">org.apache.jmeter.protocol.http.control.HC4CookieHandler</stringProp>
|
||||
</CookieManager>
|
||||
<hashTree/>
|
||||
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
|
||||
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
|
||||
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
|
||||
<boolProp name="LoopController.continue_forever">false</boolProp>
|
||||
<stringProp name="LoopController.loops">1</stringProp>
|
||||
</elementProp>
|
||||
<stringProp name="ThreadGroup.num_threads">1</stringProp>
|
||||
<stringProp name="ThreadGroup.ramp_time"></stringProp>
|
||||
<longProp name="ThreadGroup.start_time">1459196515000</longProp>
|
||||
<longProp name="ThreadGroup.end_time">1459196515000</longProp>
|
||||
<boolProp name="ThreadGroup.scheduler">false</boolProp>
|
||||
<stringProp name="ThreadGroup.duration"></stringProp>
|
||||
<stringProp name="ThreadGroup.delay"></stringProp>
|
||||
</ThreadGroup>
|
||||
<hashTree>
|
||||
<OnceOnlyController guiclass="OnceOnlyControllerGui" testclass="OnceOnlyController" testname="login Controller" enabled="true"/>
|
||||
<hashTree>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="login" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
|
||||
<collectionProp name="Arguments.arguments"/>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.domain">${SERVER_NAME}</stringProp>
|
||||
<stringProp name="HTTPSampler.port">${SERVER_PORT}</stringProp>
|
||||
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.response_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.protocol"></stringProp>
|
||||
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
|
||||
<stringProp name="HTTPSampler.path">/login</stringProp>
|
||||
<stringProp name="HTTPSampler.method">GET</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
|
||||
<boolProp name="HTTPSampler.monitor">false</boolProp>
|
||||
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree>
|
||||
<HtmlExtractor guiclass="HtmlExtractorGui" testclass="HtmlExtractor" testname="Extract csrf token" enabled="true">
|
||||
<stringProp name="HtmlExtractor.refname">LOGIN_CSRF_TOKEN</stringProp>
|
||||
<stringProp name="HtmlExtractor.expr">input[name=_csrf]</stringProp>
|
||||
<stringProp name="HtmlExtractor.attribute">value</stringProp>
|
||||
<stringProp name="HtmlExtractor.default"></stringProp>
|
||||
<boolProp name="HtmlExtractor.default_empty_value">false</boolProp>
|
||||
<stringProp name="HtmlExtractor.match_number"></stringProp>
|
||||
<stringProp name="HtmlExtractor.extractor_impl">JSOUP</stringProp>
|
||||
<stringProp name="Scope.variable">${LOGIN_CSRF_TOKEN}</stringProp>
|
||||
</HtmlExtractor>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="submit login form" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="_csrf" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">${LOGIN_CSRF_TOKEN}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">_csrf</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="j_username" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">admin</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">j_username</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="j_password" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">admin</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">j_password</stringProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.domain">${SERVER_NAME}</stringProp>
|
||||
<stringProp name="HTTPSampler.port">${SERVER_PORT}</stringProp>
|
||||
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.response_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.protocol"></stringProp>
|
||||
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
|
||||
<stringProp name="HTTPSampler.path">/login</stringProp>
|
||||
<stringProp name="HTTPSampler.method">POST</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
|
||||
<boolProp name="HTTPSampler.monitor">false</boolProp>
|
||||
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
<LoopController guiclass="LoopControlPanel" testclass="LoopController" testname="Loop view random album Controller" enabled="true">
|
||||
<boolProp name="LoopController.continue_forever">true</boolProp>
|
||||
<intProp name="LoopController.loops">-1</intProp>
|
||||
</LoopController>
|
||||
<hashTree>
|
||||
<ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Wait next request Timer" enabled="true">
|
||||
<stringProp name="ConstantTimer.delay">5000</stringProp>
|
||||
</ConstantTimer>
|
||||
<hashTree/>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="pick random album id" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="u" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">admin</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">u</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="p" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">admin</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">p</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="v" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">1.13.0</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">v</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="c" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">jmeter</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">c</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="type" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">random</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">type</stringProp>
|
||||
</elementProp>
|
||||
<elementProp name="size" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">1</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">size</stringProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.domain">${SERVER_NAME}</stringProp>
|
||||
<stringProp name="HTTPSampler.port">${SERVER_PORT}</stringProp>
|
||||
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.response_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.protocol"></stringProp>
|
||||
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
|
||||
<stringProp name="HTTPSampler.path">/rest/getAlbumList.view</stringProp>
|
||||
<stringProp name="HTTPSampler.method">GET</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
|
||||
<boolProp name="HTTPSampler.monitor">false</boolProp>
|
||||
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree>
|
||||
<XPathExtractor guiclass="XPathExtractorGui" testclass="XPathExtractor" testname="Extracteur XPath" enabled="true">
|
||||
<stringProp name="XPathExtractor.default"></stringProp>
|
||||
<stringProp name="XPathExtractor.refname">ALBUM_ID</stringProp>
|
||||
<stringProp name="XPathExtractor.xpathQuery">/subsonic-response/albumList/album/@id</stringProp>
|
||||
<boolProp name="XPathExtractor.validate">false</boolProp>
|
||||
<boolProp name="XPathExtractor.tolerant">false</boolProp>
|
||||
<boolProp name="XPathExtractor.namespace">false</boolProp>
|
||||
</XPathExtractor>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="main.view" enabled="true">
|
||||
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
|
||||
<collectionProp name="Arguments.arguments">
|
||||
<elementProp name="id" elementType="HTTPArgument">
|
||||
<boolProp name="HTTPArgument.always_encode">false</boolProp>
|
||||
<stringProp name="Argument.value">${ALBUM_ID}</stringProp>
|
||||
<stringProp name="Argument.metadata">=</stringProp>
|
||||
<boolProp name="HTTPArgument.use_equals">true</boolProp>
|
||||
<stringProp name="Argument.name">id</stringProp>
|
||||
</elementProp>
|
||||
</collectionProp>
|
||||
</elementProp>
|
||||
<stringProp name="HTTPSampler.domain">${SERVER_NAME}</stringProp>
|
||||
<stringProp name="HTTPSampler.port">${SERVER_PORT}</stringProp>
|
||||
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.response_timeout"></stringProp>
|
||||
<stringProp name="HTTPSampler.protocol"></stringProp>
|
||||
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
|
||||
<stringProp name="HTTPSampler.path">/main.view</stringProp>
|
||||
<stringProp name="HTTPSampler.method">GET</stringProp>
|
||||
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
|
||||
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
|
||||
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
|
||||
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
|
||||
<boolProp name="HTTPSampler.monitor">false</boolProp>
|
||||
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
|
||||
</HTTPSamplerProxy>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
</hashTree>
|
||||
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
|
||||
<boolProp name="ResultCollector.error_logging">false</boolProp>
|
||||
<objProp>
|
||||
<name>saveConfig</name>
|
||||
<value class="SampleSaveConfiguration">
|
||||
<time>true</time>
|
||||
<latency>true</latency>
|
||||
<timestamp>true</timestamp>
|
||||
<success>true</success>
|
||||
<label>true</label>
|
||||
<code>true</code>
|
||||
<message>true</message>
|
||||
<threadName>true</threadName>
|
||||
<dataType>true</dataType>
|
||||
<encoding>false</encoding>
|
||||
<assertions>true</assertions>
|
||||
<subresults>true</subresults>
|
||||
<responseData>false</responseData>
|
||||
<samplerData>false</samplerData>
|
||||
<xml>false</xml>
|
||||
<fieldNames>true</fieldNames>
|
||||
<responseHeaders>false</responseHeaders>
|
||||
<requestHeaders>false</requestHeaders>
|
||||
<responseDataOnError>false</responseDataOnError>
|
||||
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
|
||||
<assertionsResultsToSave>0</assertionsResultsToSave>
|
||||
<bytes>true</bytes>
|
||||
<sentBytes>true</sentBytes>
|
||||
<threadCounts>true</threadCounts>
|
||||
<idleTime>true</idleTime>
|
||||
<connectTime>true</connectTime>
|
||||
</value>
|
||||
</objProp>
|
||||
<stringProp name="filename"></stringProp>
|
||||
</ResultCollector>
|
||||
<hashTree/>
|
||||
<ResultCollector guiclass="RespTimeGraphVisualizer" testclass="ResultCollector" testname="Response Time Graph" enabled="true">
|
||||
<boolProp name="ResultCollector.error_logging">false</boolProp>
|
||||
<objProp>
|
||||
<name>saveConfig</name>
|
||||
<value class="SampleSaveConfiguration">
|
||||
<time>true</time>
|
||||
<latency>true</latency>
|
||||
<timestamp>true</timestamp>
|
||||
<success>true</success>
|
||||
<label>true</label>
|
||||
<code>true</code>
|
||||
<message>true</message>
|
||||
<threadName>true</threadName>
|
||||
<dataType>true</dataType>
|
||||
<encoding>false</encoding>
|
||||
<assertions>true</assertions>
|
||||
<subresults>true</subresults>
|
||||
<responseData>false</responseData>
|
||||
<samplerData>false</samplerData>
|
||||
<xml>false</xml>
|
||||
<fieldNames>true</fieldNames>
|
||||
<responseHeaders>false</responseHeaders>
|
||||
<requestHeaders>false</requestHeaders>
|
||||
<responseDataOnError>false</responseDataOnError>
|
||||
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
|
||||
<assertionsResultsToSave>0</assertionsResultsToSave>
|
||||
<bytes>true</bytes>
|
||||
<sentBytes>true</sentBytes>
|
||||
<threadCounts>true</threadCounts>
|
||||
<idleTime>true</idleTime>
|
||||
<connectTime>true</connectTime>
|
||||
</value>
|
||||
</objProp>
|
||||
<stringProp name="filename"></stringProp>
|
||||
</ResultCollector>
|
||||
<hashTree/>
|
||||
</hashTree>
|
||||
</hashTree>
|
||||
</jmeterTestPlan>
|
||||
@@ -0,0 +1,8 @@
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml" />
|
||||
<root level="WARN">
|
||||
<appender-ref ref="CONSOLE" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
<logger name="liquibase" level="ERROR" />
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user