Issue #164: Add tests for reading MusicBrainz release tags

master
François-Xavier Thomas 7 years ago
parent c76a92746d
commit b3f432a545
  1. 10
      airsonic-main/src/main/java/org/airsonic/player/dao/MusicFolderDao.java
  2. 4
      airsonic-main/src/test/java/org/airsonic/player/dao/MusicFolderTestData.java
  3. 53
      airsonic-main/src/test/java/org/airsonic/player/service/MediaScannerServiceTestCase.java
  4. BIN
      airsonic-main/src/test/resources/MEDIAS/Music3/TestAlbum/01 - Aria.flac

@ -57,6 +57,16 @@ public class MusicFolderDao extends AbstractDao {
return query(sql, rowMapper);
}
/**
* Return the music folder a the given path
*
* @return Possibly null instance of MusicFolder
*/
public MusicFolder getMusicFolderForPath(String path) {
String sql = "select " + QUERY_COLUMNS + " from music_folder where path = ?";
return queryOne(sql, rowMapper, path);
}
/**
* Creates a new music folder.
*

@ -24,6 +24,10 @@ public class MusicFolderTestData {
return (MusicFolderTestData.resolveBaseMediaPath() + "Music2");
}
public static String resolveMusic3FolderPath() {
return (MusicFolderTestData.resolveBaseMediaPath() + "Music3");
}
public static List<MusicFolder> getTestMusicFolders() {
List<MusicFolder> liste = new ArrayList<>();
File musicDir = new File(MusicFolderTestData.resolveMusicFolderPath());

@ -30,6 +30,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@ -138,7 +139,7 @@ public class MediaScannerServiceTestCase {
System.out.println("--- List of all albums ---");
System.out.println("name#artist");
List<Album> allAlbums = albumDao.getAlphabetialAlbums(0, 0, true, musicFolderDao.getAllMusicFolders());
List<Album> allAlbums = albumDao.getAlphabeticalAlbums(0, 0, true, true, musicFolderDao.getAllMusicFolders());
allAlbums.forEach(album -> System.out.println(album.getName() + "#" + album.getArtist()));
Assert.assertEquals(5, allAlbums.size());
System.out.println("--- *********************** ---");
@ -174,4 +175,54 @@ public class MediaScannerServiceTestCase {
System.out.println(mediaFile.getFile().getPath());
assertNotNull(mediaFile);
}
@Test
public void testMusicBrainzReleaseIdTag() {
// Add the "Music3" folder to the database
File musicFolderFile = new File(MusicFolderTestData.resolveMusic3FolderPath());
MusicFolder musicFolder = new MusicFolder(1, musicFolderFile, "Music3", true, new Date());
musicFolderDao.createMusicFolder(musicFolder);
settingsService.clearMusicFolderCache();
TestCaseUtils.execScan(mediaScannerService);
// Retrieve the "Music3" folder from the database to make
// sure that we don't accidentally operate on other folders
// from previous tests.
musicFolder = musicFolderDao.getMusicFolderForPath(musicFolder.getPath().getPath());
List<MusicFolder> folders = new ArrayList<>();
folders.add(musicFolder);
// Test that the artist is correctly imported
List<Artist> allArtists = artistDao.getAlphabetialArtists(0, 0, folders);
Assert.assertEquals(1, allArtists.size());
Artist artist = allArtists.get(0);
Assert.assertEquals("TestArtist", artist.getName());
Assert.assertEquals(1, artist.getAlbumCount());
// Test that the album is correctly imported, along with its MusicBrainz release ID
List<Album> allAlbums = albumDao.getAlphabeticalAlbums(0, 0, true, true, folders);
Assert.assertEquals(1, allAlbums.size());
Album album = allAlbums.get(0);
Assert.assertEquals("TestAlbum", album.getName());
Assert.assertEquals("TestArtist", album.getArtist());
Assert.assertEquals(1, album.getSongCount());
Assert.assertEquals("0820752d-1043-4572-ab36-2df3b5cc15fa", album.getMusicBrainzReleaseId());
Assert.assertEquals(musicFolderFile.toPath().resolve("TestAlbum").toString(), album.getPath());
// Test that the music file is correctly imported, along with its MusicBrainz release ID
List<MediaFile> albumFiles = mediaFileDao.getChildrenOf(allAlbums.get(0).getPath());
Assert.assertEquals(1, albumFiles.size());
MediaFile file = albumFiles.get(0);
Assert.assertEquals("Aria", file.getTitle());
Assert.assertEquals("flac", file.getFormat());
Assert.assertEquals("TestAlbum", file.getAlbumName());
Assert.assertEquals("TestArtist", file.getArtist());
Assert.assertEquals("TestArtist", file.getAlbumArtist());
Assert.assertEquals(1, (long)file.getTrackNumber());
Assert.assertEquals(2001, (long)file.getYear());
Assert.assertEquals(album.getPath(), file.getParentPath());
Assert.assertEquals(new File(album.getPath()).toPath().resolve("01 - Aria.flac").toString(), file.getPath());
Assert.assertEquals("0820752d-1043-4572-ab36-2df3b5cc15fa", file.getMusicBrainzReleaseId());
}
}

Loading…
Cancel
Save