Search in sources :

Example 36 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class SearchIndexUpdateServiceTest method failingServiceInvocation.

@Test
public void failingServiceInvocation() {
    FailingUpdateService failingService = new FailingUpdateService();
    SearchIndexUpdateProgress progress;
    Assert.assertNotNull(progress = failingService.getProgress());
    Assert.assertEquals(SearchIndexUpdateProgress.NOT_INITIALIZED, progress.getTotalOperations());
    Assert.assertEquals(SearchIndexUpdateProgress.NOT_INITIALIZED, progress.getFinishedOperations());
    try {
        failingService.updateSearchIndex();
        Assert.fail();
    } catch (ApplicationException e) {
    }
    Assert.assertNotNull(progress = failingService.getProgress());
    Assert.assertEquals(FailingUpdateService.TOTAL_CALCULATIONS, progress.getTotalOperations());
    Assert.assertEquals(FailingUpdateService.FAIL_INDEX, progress.getFinishedOperations());
    failingService.reset();
    Assert.assertNotNull(progress = failingService.getProgress());
    Assert.assertEquals(SearchIndexUpdateProgress.NOT_INITIALIZED, progress.getTotalOperations());
    Assert.assertEquals(SearchIndexUpdateProgress.NOT_INITIALIZED, progress.getFinishedOperations());
}
Also used : SearchIndexUpdateProgress(com.github.hakko.musiccabinet.domain.model.aggr.SearchIndexUpdateProgress) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) Test(org.junit.Test)

Example 37 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class AlbumInfoClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = AlbumInfoClient.METHOD;
    final String artistName = "The Beatles";
    final String albumName = "Sergeant Pepper's Lonely Hearts Club Band";
    new AlbumInfoClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ALBUM_GET_INFO, wi.getCallType());
            Assert.assertTrue(albumName.equals(wi.getAlbum().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            assertHasParameter(params, PARAM_ALBUM, albumName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getAlbumInfo(new Album(artistName, albumName));
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) Album(com.github.hakko.musiccabinet.domain.model.music.Album) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 38 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class ArtistSimilarityClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistSimilarityClient.METHOD;
    final String artistName = "madonna";
    new ArtistSimilarityClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_SIMILAR, wi.getCallType());
            Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getArtistSimilarity(new Artist(artistName));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 39 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class ArtistTopTracksClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistTopTracksClient.METHOD;
    final String artistName = "madonna";
    new ArtistTopTracksClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_TOP_TRACKS, wi.getCallType());
            Assert.assertTrue(artistName.equals(wi.getArtist().getName()));
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_ARTIST, artistName);
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getTopTracks(new Artist(artistName));
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Test(org.junit.Test)

Example 40 with ApplicationException

use of com.github.hakko.musiccabinet.exception.ApplicationException in project musiccabinet by hakko.

the class TagTopArtistsClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = TagTopArtistsClient.METHOD;
    final Tag tag = new Tag(0, "sludge");
    new TagTopArtistsClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.TAG_GET_TOP_ARTISTS, wi.getCallType());
            Assert.assertEquals(tag, wi.getTag());
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_TAG, tag.getName());
            return null;
        }

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getTopArtists(tag);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) WebserviceHistoryService(com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService) WebserviceInvocation(com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation) Tag(com.github.hakko.musiccabinet.domain.model.music.Tag) Test(org.junit.Test)

Aggregations

ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)43 Test (org.junit.Test)20 NameValuePair (org.apache.http.NameValuePair)18 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)14 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)11 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)11 Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)10 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)10 ArrayList (java.util.ArrayList)8 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)7 IOException (java.io.IOException)6 Track (com.github.hakko.musiccabinet.domain.model.music.Track)4 ArtistUserTag (com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag)2 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)2 LastFmGroup (com.github.hakko.musiccabinet.domain.model.library.LastFmGroup)2 Period (com.github.hakko.musiccabinet.domain.model.library.Period)2 Album (com.github.hakko.musiccabinet.domain.model.music.Album)2 MBArtist (com.github.hakko.musiccabinet.domain.model.music.MBArtist)2 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)2 ArtistInfoParserImpl (com.github.hakko.musiccabinet.parser.lastfm.ArtistInfoParserImpl)2