Search in sources :

Example 11 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class JdbcAlbumInfoDaoTest method handlesAlbumWithIdenticalTitleByDifferentArtists.

@Test
public void handlesAlbumWithIdenticalTitleByDifferentArtists() {
    deleteAlbumInfos();
    deleteLibraryTracks();
    createLibraryTracks(aiHurts, aiSchuller);
    dao.createAlbumInfo(Arrays.asList(aiHurts, aiSchuller));
    for (AlbumInfo ai : Arrays.asList(aiHurts, aiSchuller)) {
        List<AlbumInfo> dbInfos = dao.getAlbumInfosForArtist(ai.getAlbum().getArtist().getId());
        Assert.assertNotNull(dbInfos);
        Assert.assertEquals(1, dbInfos.size());
        AlbumInfo dbInfo = dbInfos.get(0);
        Assert.assertEquals(ai.getAlbum().getName(), dbInfo.getAlbum().getName());
        Assert.assertEquals(ai.getAlbum().getArtist(), dbInfo.getAlbum().getArtist());
    }
}
Also used : AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) Test(org.junit.Test)

Example 12 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class JdbcAlbumInfoDaoTest method createLibraryTracks.

private void createLibraryTracks(AlbumInfo... albumInfos) {
    List<File> files = new ArrayList<>();
    for (AlbumInfo ai : albumInfos) {
        String artistName = ai.getAlbum().getArtist().getName();
        String albumName = ai.getAlbum().getName();
        files.add(getFile(artistName, albumName, null));
    }
    UnittestLibraryUtil.submitFile(libraryAdditionDao, files);
}
Also used : AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) ArrayList(java.util.ArrayList) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File)

Example 13 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class AlbumInfoHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (parsing) {
        String chars = characterData.toString();
        if (TAG_NAME.equals(qName)) {
            albumInfo = new AlbumInfo();
            albumInfo.setAlbum(new Album(chars));
        } else if (TAG_ARTIST.equals(qName)) {
            albumInfo.getAlbum().setArtist(new Artist(chars));
        } else if (TAG_IMAGE.equals(qName)) {
            if (ATTR_SMALL.equals(imageSize)) {
                albumInfo.setSmallImageUrl(validateUrl(chars));
            } else if (ATTR_MEDIUM.equals(imageSize)) {
                albumInfo.setMediumImageUrl(validateUrl(chars));
            } else if (ATTR_LARGE.equals(imageSize)) {
                albumInfo.setLargeImageUrl(validateUrl(chars));
            } else if (ATTR_EXTRA_LARGE.equals(imageSize)) {
                albumInfo.setExtraLargeImageUrl(validateUrl(chars));
            }
        } else if (TAG_LISTENERS.equals(qName)) {
            albumInfo.setListeners(toInt(chars));
        } else if (TAG_PLAY_COUNT.equals(qName)) {
            albumInfo.setPlayCount(toInt(chars));
            parsing = false;
        }
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) Album(com.github.hakko.musiccabinet.domain.model.music.Album)

Example 14 with AlbumInfo

use of com.github.hakko.musiccabinet.domain.model.music.AlbumInfo in project musiccabinet by hakko.

the class AlbumInfoParserTest method resourceFileCorrectlyParsed.

@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
    AlbumInfoParser parser = new AlbumInfoParserImpl(new ResourceUtil(ALBUM_INFO_FILE).getInputStream());
    AlbumInfo albumInfo = parser.getAlbumInfo();
    assertEquals(new Artist("Nirvana"), albumInfo.getAlbum().getArtist());
    assertEquals(SMALL_IMAGE_URL, albumInfo.getSmallImageUrl());
    assertEquals(MEDIUM_IMAGE_URL, albumInfo.getMediumImageUrl());
    assertEquals(LARGE_IMAGE_URL, albumInfo.getLargeImageUrl());
    assertEquals(EXTRA_LARGE_IMAGE_URL, albumInfo.getExtraLargeImageUrl());
    assertEquals(LISTENERS, albumInfo.getListeners());
    assertEquals(PLAY_COUNT, albumInfo.getPlayCount());
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ResourceUtil(com.github.hakko.musiccabinet.util.ResourceUtil) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) Test(org.junit.Test)

Aggregations

AlbumInfo (com.github.hakko.musiccabinet.domain.model.music.AlbumInfo)14 Test (org.junit.Test)5 Album (com.github.hakko.musiccabinet.domain.model.music.Album)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)2 AlbumInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParserImpl)2 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)2 DataAccessException (org.springframework.dao.DataAccessException)2 File (com.github.hakko.musiccabinet.domain.model.library.File)1 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)1 AlbumInfoParser (com.github.hakko.musiccabinet.parser.lastfm.AlbumInfoParser)1 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 RowCallbackHandler (org.springframework.jdbc.core.RowCallbackHandler)1