Search in sources :

Example 1 with ApplicationException

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

the class JdbcDatabaseAdministrationDao method forcePasswordUpdate.

@Override
public void forcePasswordUpdate(String password) throws ApplicationException {
    // we know it's ComboPooledDataSource, as we define it in applicationContext.xml
    // this is the primary reason for using C3P0 rather than Apache DBCP, since it
    // doesn't support password updates.
    ComboPooledDataSource dataSource = getDataSource();
    ComboPooledDataSource initialDataSource = (ComboPooledDataSource) initialJdbcTemplate.getDataSource();
    dataSource.setPassword(password);
    initialDataSource.setPassword(password);
    try {
        dataSource.softResetDefaultUser();
        initialDataSource.softResetDefaultUser();
    } catch (SQLException e) {
        throw new ApplicationException("Password update failed!", e);
    }
    try {
        initialJdbcTemplate.execute("select 1");
    } catch (DataAccessException e) {
        throw new ApplicationException("Password update failed!", e);
    }
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) SQLException(java.sql.SQLException) DataAccessException(org.springframework.dao.DataAccessException)

Example 2 with ApplicationException

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

the class ArtistInfoClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = ArtistInfoClient.METHOD;
    final String artistName = "madonna";
    final String lang = Locale.FRANCE.getLanguage();
    new ArtistInfoClient() {

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

        @Override
        protected WebserviceHistoryService getHistoryService() {
            return Mockito.mock(WebserviceHistoryService.class);
        }
    }.getArtistInfo(new Artist(artistName), lang);
}
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 3 with ApplicationException

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

the class ArtistTopTagsClientTest method validateParameters.

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

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.ARTIST_GET_TOP_TAGS, 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);
        }
    }.getTopTags(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 4 with ApplicationException

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

the class GroupWeeklyArtistChartClientTest method validateParameters.

@Test
public void validateParameters() throws ApplicationException {
    final String method = GroupWeeklyArtistChartClient.METHOD;
    final String lastFmGroup = "Brainwashed";
    new GroupWeeklyArtistChartClient() {

        @Override
        protected WSResponse executeWSRequest(WebserviceInvocation wi, List<NameValuePair> params) throws ApplicationException {
            Assert.assertEquals(Calltype.GROUP_WEEKLY_ARTIST_CHART, wi.getCallType());
            Assert.assertEquals(lastFmGroup, wi.getGroup().getName());
            assertHasParameter(params, PARAM_METHOD, method);
            assertHasParameter(params, PARAM_GROUP, lastFmGroup);
            return null;
        }

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

Example 5 with ApplicationException

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

the class TagUpdateClientTest method validateParametersForAddingTag.

@Test
public void validateParametersForAddingTag() throws ApplicationException {
    final ArtistUserTag artistUserTagAdd = new ArtistUserTag(artist, lastFmUser, tag, 100, true);
    new TagUpdateClient() {

        @Override
        protected WSResponse executeWSRequest(List<NameValuePair> params) throws ApplicationException {
            assertHasParameter(params, PARAM_METHOD, ADD_METHOD);
            assertHasParameter(params, PARAM_ARTIST, artist.getName());
            assertHasParameter(params, PARAM_TAGS, "pop");
            assertHasParameter(params, PARAM_SK, lastFmUser.getSessionKey());
            return null;
        }
    }.updateTag(artistUserTagAdd);
}
Also used : NameValuePair(org.apache.http.NameValuePair) ArtistUserTag(com.github.hakko.musiccabinet.domain.model.aggr.ArtistUserTag) ApplicationException(com.github.hakko.musiccabinet.exception.ApplicationException) 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