|
|
@ -38,16 +38,15 @@ import static org.junit.Assert.assertNotNull; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A unit test class to test the MediaScannerService. |
|
|
|
* A unit test class to test the MediaScannerService. |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* This class uses the Spring application context configuration present in the |
|
|
|
* This class uses the Spring application context configuration present in the |
|
|
|
* /org/libresonic/player/service/mediaScannerServiceTestCase/ directory. |
|
|
|
* /org/libresonic/player/service/mediaScannerServiceTestCase/ directory. |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* The media library is found in the /MEDIAS directory. |
|
|
|
* The media library is found in the /MEDIAS directory. |
|
|
|
* It is composed of 2 musicFolders (Music and Music2) and several little weight audio files. |
|
|
|
* 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. |
|
|
|
* 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. |
|
|
|
* An empty database is created on the fly. |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ContextConfiguration(locations = { |
|
|
|
@ContextConfiguration(locations = { |
|
|
|
"/applicationContext-service.xml", |
|
|
|
"/applicationContext-service.xml", |
|
|
@ -60,6 +59,7 @@ public class MediaScannerServiceTestCase { |
|
|
|
@ClassRule |
|
|
|
@ClassRule |
|
|
|
public static final SpringClassRule classRule = new SpringClassRule() { |
|
|
|
public static final SpringClassRule classRule = new SpringClassRule() { |
|
|
|
LibresonicHomeRule libresonicRule = new LibresonicHomeRule(); |
|
|
|
LibresonicHomeRule libresonicRule = new LibresonicHomeRule(); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Statement apply(Statement base, Description description) { |
|
|
|
public Statement apply(Statement base, Description description) { |
|
|
|
Statement spring = super.apply(base, description); |
|
|
|
Statement spring = super.apply(base, description); |
|
|
@ -118,33 +118,33 @@ public class MediaScannerServiceTestCase { |
|
|
|
globalTimerContext.stop(); |
|
|
|
globalTimerContext.stop(); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("--- Report of records count per table ---"); |
|
|
|
System.out.println("--- Report of records count per table ---"); |
|
|
|
Map<String,Integer> records = TestCaseUtils.recordsInAllTables(daoHelper); |
|
|
|
Map<String, Integer> records = TestCaseUtils.recordsInAllTables(daoHelper); |
|
|
|
records.keySet().forEach(tableName -> System.out.println(tableName+" : "+records.get(tableName).toString() )); |
|
|
|
records.keySet().forEach(tableName -> System.out.println(tableName + " : " + records.get(tableName).toString())); |
|
|
|
System.out.println("--- *********************** ---"); |
|
|
|
System.out.println("--- *********************** ---"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Music Folder Music must have 3 children
|
|
|
|
// Music Folder Music must have 3 children
|
|
|
|
List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath()); |
|
|
|
List<MediaFile> listeMusicChildren = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusicFolderPath()); |
|
|
|
Assert.assertEquals(3,listeMusicChildren.size()); |
|
|
|
Assert.assertEquals(3, listeMusicChildren.size()); |
|
|
|
// Music Folder Music2 must have 1 children
|
|
|
|
// Music Folder Music2 must have 1 children
|
|
|
|
List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath()); |
|
|
|
List<MediaFile> listeMusic2Children = mediaFileDao.getChildrenOf(MusicFolderTestData.resolveMusic2FolderPath()); |
|
|
|
Assert.assertEquals(1,listeMusic2Children.size()); |
|
|
|
Assert.assertEquals(1, listeMusic2Children.size()); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("--- List of all artists ---"); |
|
|
|
System.out.println("--- List of all artists ---"); |
|
|
|
System.out.println("artistName#albumCount"); |
|
|
|
System.out.println("artistName#albumCount"); |
|
|
|
List<Artist> allArtists = artistDao.getAlphabetialArtists(0,0,musicFolderDao.getAllMusicFolders()); |
|
|
|
List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, musicFolderDao.getAllMusicFolders()); |
|
|
|
allArtists.forEach(artist -> System.out.println(artist.getName()+"#"+artist.getAlbumCount())); |
|
|
|
allArtists.forEach(artist -> System.out.println(artist.getName() + "#" + artist.getAlbumCount())); |
|
|
|
System.out.println("--- *********************** ---"); |
|
|
|
System.out.println("--- *********************** ---"); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("--- List of all albums ---"); |
|
|
|
System.out.println("--- List of all albums ---"); |
|
|
|
System.out.println("name#artist"); |
|
|
|
System.out.println("name#artist"); |
|
|
|
List<Album> allAlbums = albumDao.getAlphabetialAlbums(0,0,true,musicFolderDao.getAllMusicFolders()); |
|
|
|
List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders()); |
|
|
|
allAlbums.forEach(album -> System.out.println(album.getName()+"#"+album.getArtist())); |
|
|
|
allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist())); |
|
|
|
Assert.assertEquals(5,allAlbums.size()); |
|
|
|
Assert.assertEquals(5, allAlbums.size()); |
|
|
|
System.out.println("--- *********************** ---"); |
|
|
|
System.out.println("--- *********************** ---"); |
|
|
|
|
|
|
|
|
|
|
|
List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental",0,0,musicFolderDao.getAllMusicFolders()); |
|
|
|
List<MediaFile> listeSongs = mediaFileDao.getSongsByGenre("Baroque Instrumental", 0, 0, musicFolderDao.getAllMusicFolders()); |
|
|
|
Assert.assertEquals(2,listeSongs.size()); |
|
|
|
Assert.assertEquals(2, listeSongs.size()); |
|
|
|
|
|
|
|
|
|
|
|
// display out metrics report
|
|
|
|
// display out metrics report
|
|
|
|
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) |
|
|
|
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics) |
|
|
@ -165,7 +165,7 @@ public class MediaScannerServiceTestCase { |
|
|
|
File musicFile = artistDir.toPath().resolve(fileName).toFile(); |
|
|
|
File musicFile = artistDir.toPath().resolve(fileName).toFile(); |
|
|
|
IOUtils.copy(resource.getInputStream(), new FileOutputStream(musicFile)); |
|
|
|
IOUtils.copy(resource.getInputStream(), new FileOutputStream(musicFile)); |
|
|
|
|
|
|
|
|
|
|
|
MusicFolder musicFolder = new MusicFolder(1, temporaryFolder.getRoot(),"Music",true,new Date()); |
|
|
|
MusicFolder musicFolder = new MusicFolder(1, temporaryFolder.getRoot(), "Music", true, new Date()); |
|
|
|
musicFolderDao.createMusicFolder(musicFolder); |
|
|
|
musicFolderDao.createMusicFolder(musicFolder); |
|
|
|
settingsService.clearMusicFolderCache(); |
|
|
|
settingsService.clearMusicFolderCache(); |
|
|
|
TestCaseUtils.execScan(mediaScannerService); |
|
|
|
TestCaseUtils.execScan(mediaScannerService); |
|
|
|