use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.
the class PostgreSQLUtil method loadFunction.
/**
* Load a named SQL function to database.
*
* If a previous version with the same name exists, it is dropped by a call to
* function drop_procedure (creation of this function is part of database set-up).
*
* @param rc RequestContext for call
* @param functionName Name of function
* @param functionBody Body of function
* @throws ApplicationException On failure
*/
public static void loadFunction(JdbcTemplateDao dao, PostgreSQLFunction dbFunction) throws ApplicationException {
JdbcTemplate jdbcTemplate = dao.getJdbcTemplate();
// initialize drop procedure, if database has been dropped
jdbcTemplate.execute(new ResourceUtil(DROP_FUNCTION.getURI()).getContent());
// drop previous function version, if necessary
jdbcTemplate.queryForInt("select util.drop_function( ?,? )", dbFunction.getSchema(), dbFunction.getFunctionName());
// load new function body
jdbcTemplate.execute(new ResourceUtil(dbFunction.getURI()).getContent());
}
use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.
the class UserLovedTracksServiceTest method updatesStarredTracksWhenImportIsOnlyAllowedForOneUser.
/*
* User story: user1 has starred track2, user2 has starred track3 & track4.
* When importing loved tracks, user2 is unavailable and user1 has loved track1.
* Expected outcome: afterwards, user1 has starred track1 & 2 and user2 track3 & 4.
*/
@Test
public void updatesStarredTracksWhenImportIsOnlyAllowedForOneUser() throws ApplicationException {
lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER1));
lastFmDao.createOrUpdateLastFmUser(new LastFmUser(USER2));
LastFmUser user1 = lastFmDao.getLastFmUser(USER1), user2 = lastFmDao.getLastFmUser(USER2);
Track track1 = new Track("Frank Ocean", "Lost"), track2 = new Track("Kate Bush", "Cloudbusting"), track3 = new Track("Adele", "Skyfall"), track4 = new Track("Kath Bloom", "Fall Again");
File f1, f2, f3, f4;
deleteLovedAndStarredTracks();
submitFile(additionDao, asList(f1 = getFile(track1), f2 = getFile(track2), f3 = getFile(track3), f4 = getFile(track4)));
int track1Id = browserDao.getTrackId(f1), track2Id = browserDao.getTrackId(f2), track3Id = browserDao.getTrackId(f3), track4Id = browserDao.getTrackId(f4);
LastFmSettingsService lastFmSettingsService = mock(LastFmSettingsService.class);
when(lastFmSettingsService.getLastFmUsers()).thenReturn(asList(user1, user2));
when(lastFmSettingsService.isSyncStarredAndLovedTracks()).thenReturn(true);
UserLovedTracksClient userLovedTracksClient = mock(UserLovedTracksClient.class);
when(userLovedTracksClient.getUserLovedTracks(user1, (short) 0)).thenReturn(new WSResponse(new ResourceUtil(LOVED_TRACKS_FILE, UTF8).getContent()));
when(userLovedTracksClient.getUserLovedTracks(user2, (short) 0)).thenReturn(new WSResponse(false, 403, "Forbidden"));
UserLovedTracksService userLovedTracksService = new UserLovedTracksService();
userLovedTracksService.setLastFmSettingsService(lastFmSettingsService);
userLovedTracksService.setUserLovedTracksClient(userLovedTracksClient);
userLovedTracksService.setUserLovedTracksDao(userLovedTracksDao);
userLovedTracksService.setStarService(mock(StarService.class));
userLovedTracksService.setTrackLoveClient(mock(TrackLoveClient.class));
starDao.starTrack(user1, track2Id);
starDao.starTrack(user2, track3Id);
starDao.starTrack(user2, track4Id);
userLovedTracksService.updateSearchIndex();
assertEquals(sort(asList(track1Id, track2Id)), sort(starDao.getStarredTrackIds(user1)));
assertEquals(sort(asList(track3Id, track4Id)), sort(starDao.getStarredTrackIds(user2)));
}
use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.
the class UserTopArtistsServiceTest method createArtistInfosAndLocalFiles.
private void createArtistInfosAndLocalFiles() throws ApplicationException {
Map<Artist, ArtistInfo> artistInfos = new HashMap<>();
List<File> files = new ArrayList<>();
for (Period period : Period.values()) {
String fileName = format(TOP_ARTISTS_FILE, period.getDescription());
for (Artist artist : new UserTopArtistsParserImpl(new ResourceUtil(fileName, UTF8).getInputStream()).getArtists()) {
artistInfos.put(artist, new ArtistInfo(artist));
files.add(UnittestLibraryUtil.getFile(artist.getName(), "A", "T"));
}
}
artistInfoDao.createArtistInfo(new ArrayList<ArtistInfo>(artistInfos.values()));
submitFile(additionDao, files);
}
use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.
the class TrackSimilarityParserTest method resourceFileCorrectlyParsed.
@Test
public void resourceFileCorrectlyParsed() throws ApplicationException {
TrackSimilarityParser parser = new TrackSimilarityParserImpl(new ResourceUtil(TRACK_SIMILARITY_FILE).getInputStream());
assertNotNull(parser.getTrack());
assertNotNull(parser.getTrackRelations());
assertTrue(parser.getTrack().getArtist().getName().equals("Cher"));
assertTrue(parser.getTrack().getName().equals("Believe"));
assertEquals(parser.getTrackRelations().size(), 250);
for (TrackRelation tr : parser.getTrackRelations()) {
assertNotNull(tr.getTarget());
assertNotNull(tr.getTarget().getArtist());
}
verifyTrackRelation(parser, 0, "Cher", "Strong Enough", 1.0f);
verifyTrackRelation(parser, 1, "Cher", "All Or Nothing", 0.961879f);
verifyTrackRelation(parser, 2, "Madonna", "Vogue", 0.291088f);
}
use of com.github.hakko.musiccabinet.util.ResourceUtil in project musiccabinet by hakko.
the class UserRecommendedArtistsParserTest method resourceFile2CorrectlyParsed.
@Test
public void resourceFile2CorrectlyParsed() throws ApplicationException {
WSResponse wsResponse = new WSResponse(new ResourceUtil(USER_RECOMMENDED_ARTISTS_FILE2).getContent());
UserRecommendedArtistsParser parser = new UserRecommendedArtistsParserImpl(new StringUtil(wsResponse.getResponseBody()).getInputStream());
List<RecommendedArtist> artists = parser.getArtists();
for (int i = 0; i < EXPECTED_ARTISTS2.size(); i++) {
assertEquals(EXPECTED_ARTISTS2.get(i), artists.get(i));
}
}
Aggregations