Merge lp:~ubuntuone-client-engineering/ubuntuone-music-java-library/playlist-args-and-request-refactor into lp:ubuntuone-music-java-library

Proposed by Michał Karnicki on 2012-11-08
Status: Merged
Merged at revision: 31
Proposed branch: lp:~ubuntuone-client-engineering/ubuntuone-music-java-library/playlist-args-and-request-refactor
Merge into: lp:ubuntuone-music-java-library
Diff against target: 860 lines (+241/-149)
33 files modified
src/main/com/ubuntuone/api/music/U1MusicAPI.java (+12/-12)
src/main/com/ubuntuone/api/music/json/U1AlbumJson.java (+1/-1)
src/main/com/ubuntuone/api/music/json/U1ArtistJson.java (+1/-1)
src/main/com/ubuntuone/api/music/json/U1CustomJson.java (+23/-9)
src/main/com/ubuntuone/api/music/json/U1PlaylistJson.java (+1/-1)
src/main/com/ubuntuone/api/music/json/U1SongJson.java (+1/-1)
src/main/com/ubuntuone/api/music/request/U1AlbumListener.java (+1/-1)
src/main/com/ubuntuone/api/music/request/U1ArtListener.java (+1/-1)
src/main/com/ubuntuone/api/music/request/U1ArtistListener.java (+1/-1)
src/main/com/ubuntuone/api/music/request/U1CallbackListener.java (+47/-0)
src/main/com/ubuntuone/api/music/request/U1DownloadListener.java (+2/-2)
src/main/com/ubuntuone/api/music/request/U1PlaylistListener.java (+1/-1)
src/main/com/ubuntuone/api/music/request/U1RequestListener.java (+0/-47)
src/main/com/ubuntuone/api/music/request/U1SongListener.java (+1/-1)
src/main/com/ubuntuone/api/music/util/FailureListener.java (+18/-0)
src/main/com/ubuntuone/api/music/util/RequestListener.java (+6/-39)
src/main/com/ubuntuone/api/music/util/ResultRequestListener.java (+67/-0)
src/test/com/ubuntuone/api/music/CreatePlaylistTest.java (+3/-3)
src/test/com/ubuntuone/api/music/DeletePlaylistTest.java (+5/-5)
src/test/com/ubuntuone/api/music/GetAlbumsTest.java (+1/-1)
src/test/com/ubuntuone/api/music/GetArtTest.java (+1/-1)
src/test/com/ubuntuone/api/music/GetArtistsTest.java (+1/-1)
src/test/com/ubuntuone/api/music/GetPlaylistTest.java (+1/-1)
src/test/com/ubuntuone/api/music/GetPlaylistsTest.java (+1/-1)
src/test/com/ubuntuone/api/music/GetSongStreamTest.java (+1/-1)
src/test/com/ubuntuone/api/music/GetSongsTest.java (+1/-1)
src/test/com/ubuntuone/api/music/UpdatePlaylistTest.java (+2/-2)
src/test/com/ubuntuone/api/music/json/U1AlbumJsonTest.java (+1/-1)
src/test/com/ubuntuone/api/music/json/U1ArtistJsonTest.java (+1/-1)
src/test/com/ubuntuone/api/music/json/U1CustomJsonTest.java (+26/-2)
src/test/com/ubuntuone/api/music/json/U1PlaylistJsonTest.java (+1/-1)
src/test/com/ubuntuone/api/music/json/U1SongJsonTest.java (+1/-1)
src/test/com/ubuntuone/music/util/U1ResponseBuilder.java (+10/-8)
To merge this branch: bzr merge lp:~ubuntuone-client-engineering/ubuntuone-music-java-library/playlist-args-and-request-refactor
Reviewer Review Type Date Requested Status
Brian Curtin (community) 2012-11-08 Approve on 2012-11-08
Review via email: mp+133587@code.launchpad.net

Commit message

Refactor RequestListener, so that ResultRequestListener is a parametrized class, while ResultListener has a no-arg onSuccess callback method.

Description of the change

When PUTing playlist to music API v2, name and song_id_list in request JSON body should be optional (at least one of them should be provided), so that it is easy to rename the playlist and update song list without touching its name. Updated JSON generating method, with tests.

Refactored RequestListener class to ResultRequestListener, which has parametrized type argument of onSuccess(.) callback, and introduced RequestListener, which has no argument in onSuccess() callback, for better code readability.

To test, branch and run:
$ ant test

To post a comment you must log in.
Brian Curtin (brian.curtin) wrote :

Without being able to run it, the code reads fine given what I've been told about it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/main/com/ubuntuone/api/music/U1MusicAPI.java'
--- src/main/com/ubuntuone/api/music/U1MusicAPI.java 2012-11-08 16:22:16 +0000
+++ src/main/com/ubuntuone/api/music/U1MusicAPI.java 2012-11-08 22:55:22 +0000
@@ -57,17 +57,17 @@
57import com.ubuntuone.api.music.util.CancelTrigger;57import com.ubuntuone.api.music.util.CancelTrigger;
58import com.ubuntuone.api.music.util.CancelTrigger.RequestCanceledException;58import com.ubuntuone.api.music.util.CancelTrigger.RequestCanceledException;
59import com.ubuntuone.api.music.util.EntityUtils;59import com.ubuntuone.api.music.util.EntityUtils;
60import com.ubuntuone.api.music.util.FailureListener;
60import com.ubuntuone.api.music.util.OnProgressListener;61import com.ubuntuone.api.music.util.OnProgressListener;
61import com.ubuntuone.api.music.util.OnProgressListener.ProgressInputStream;62import com.ubuntuone.api.music.util.OnProgressListener.ProgressInputStream;
62import com.ubuntuone.api.music.util.RequestListener;63import com.ubuntuone.api.music.util.RequestListener.U1RequestListener;
63import com.ubuntuone.api.music.util.RequestListener.U1AlbumRequestListener;
64import com.ubuntuone.api.music.util.RequestListener.U1ArtRequestListener;
65import com.ubuntuone.api.music.util.RequestListener.U1ArtistRequestListener;
66import com.ubuntuone.api.music.util.RequestListener.U1PlaylistRequestListener;
67import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;
68import com.ubuntuone.api.music.util.RequestListener.U1StreamRequestListener;
69import com.ubuntuone.api.music.util.RequestListener.U1VoidRequestListener;
70import com.ubuntuone.api.music.util.ResponseHeader;64import com.ubuntuone.api.music.util.ResponseHeader;
65import com.ubuntuone.api.music.util.ResultRequestListener.U1AlbumRequestListener;
66import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtRequestListener;
67import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtistRequestListener;
68import com.ubuntuone.api.music.util.ResultRequestListener.U1PlaylistRequestListener;
69import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
70import com.ubuntuone.api.music.util.ResultRequestListener.U1StreamRequestListener;
71import com.ubuntuone.api.music.util.StreamUtils;71import com.ubuntuone.api.music.util.StreamUtils;
72import com.ubuntuone.api.sso.authorizer.Authorizer;72import com.ubuntuone.api.sso.authorizer.Authorizer;
73import com.ubuntuone.api.sso.authorizer.AuthorizerException;73import com.ubuntuone.api.sso.authorizer.AuthorizerException;
@@ -402,7 +402,7 @@
402 }402 }
403 HttpResponse response = null;403 HttpResponse response = null;
404 try {404 try {
405 String data = U1CustomJson.toSongIdListJson(name, songIds);405 String data = U1CustomJson.toPlaylistJson(name, songIds);
406 response = resourceClient.request(HttpPost.METHOD_NAME, path, null, data);406 response = resourceClient.request(HttpPost.METHOD_NAME, path, null, data);
407 final int statusCode = getStatusCode(response);407 final int statusCode = getStatusCode(response);
408 if (statusCode == HttpStatus.SC_OK) {408 if (statusCode == HttpStatus.SC_OK) {
@@ -436,7 +436,7 @@
436 }436 }
437 }437 }
438 438
439 public void deletePlaylist(String playlistId, U1VoidRequestListener callback) {439 public void deletePlaylist(String playlistId, U1RequestListener callback) {
440 callback.onStart();440 callback.onStart();
441 String path = resourceClient.getPath(PLAYLISTS, playlistId);441 String path = resourceClient.getPath(PLAYLISTS, playlistId);
442 HttpResponse response = null;442 HttpResponse response = null;
@@ -444,7 +444,7 @@
444 response = resourceClient.request(HttpDelete.METHOD_NAME, path);444 response = resourceClient.request(HttpDelete.METHOD_NAME, path);
445 final int statusCode = getStatusCode(response);445 final int statusCode = getStatusCode(response);
446 if (statusCode == HttpStatus.SC_OK) {446 if (statusCode == HttpStatus.SC_OK) {
447 callback.onSuccess(null);447 callback.onSuccess();
448 } else {448 } else {
449 handleHttpResponse(response, "Could not delete playlist.", callback);449 handleHttpResponse(response, "Could not delete playlist.", callback);
450 }450 }
@@ -608,7 +608,7 @@
608 }608 }
609 609
610 private void handleHttpResponse(HttpResponse response,610 private void handleHttpResponse(HttpResponse response,
611 String message, RequestListener<?> callback) {611 String message, FailureListener callback) {
612 final int statusCode = getStatusCode(response);612 final int statusCode = getStatusCode(response);
613 613
614 switch (statusCode) {614 switch (statusCode) {
615615
=== modified file 'src/main/com/ubuntuone/api/music/json/U1AlbumJson.java'
--- src/main/com/ubuntuone/api/music/json/U1AlbumJson.java 2012-09-04 21:42:33 +0000
+++ src/main/com/ubuntuone/api/music/json/U1AlbumJson.java 2012-11-08 22:55:22 +0000
@@ -34,7 +34,7 @@
3434
35import com.ubuntuone.api.music.U1MusicAPI;35import com.ubuntuone.api.music.U1MusicAPI;
36import com.ubuntuone.api.music.model.U1Album;36import com.ubuntuone.api.music.model.U1Album;
37import com.ubuntuone.api.music.util.RequestListener.U1AlbumRequestListener;37import com.ubuntuone.api.music.util.ResultRequestListener.U1AlbumRequestListener;
3838
39public class U1AlbumJson39public class U1AlbumJson
40{40{
4141
=== modified file 'src/main/com/ubuntuone/api/music/json/U1ArtistJson.java'
--- src/main/com/ubuntuone/api/music/json/U1ArtistJson.java 2012-09-04 21:42:33 +0000
+++ src/main/com/ubuntuone/api/music/json/U1ArtistJson.java 2012-11-08 22:55:22 +0000
@@ -35,7 +35,7 @@
3535
36import com.ubuntuone.api.music.U1MusicAPI;36import com.ubuntuone.api.music.U1MusicAPI;
37import com.ubuntuone.api.music.model.U1Artist;37import com.ubuntuone.api.music.model.U1Artist;
38import com.ubuntuone.api.music.util.RequestListener.U1ArtistRequestListener;38import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtistRequestListener;
3939
40public class U1ArtistJson40public class U1ArtistJson
41{41{
4242
=== modified file 'src/main/com/ubuntuone/api/music/json/U1CustomJson.java'
--- src/main/com/ubuntuone/api/music/json/U1CustomJson.java 2012-09-19 19:17:30 +0000
+++ src/main/com/ubuntuone/api/music/json/U1CustomJson.java 2012-11-08 22:55:22 +0000
@@ -30,22 +30,36 @@
3030
31public class U1CustomJson31public class U1CustomJson
32{32{
33 public static String toSongIdListJson(String name, ArrayList<String> songIds)33 /**
34 throws IOException {34 * Either name or songIds has to be provided. Otherwise, request with such
35 * body will fail.
36 *
37 * @param name
38 * The name of the playlist.
39 * @param songIdList
40 * The song id list of the playlist.
41 * @return Request JSON body.
42 * @throws IOException
43 * If JSON generation fails with IOException.
44 */
45 public static String toPlaylistJson(String name,
46 ArrayList<String> songIdList) throws IOException {
35 final JsonFactory factory = new JsonFactory();47 final JsonFactory factory = new JsonFactory();
36 final StringWriter writer = new StringWriter(128);48 final StringWriter writer = new StringWriter(128);
37 final JsonGenerator g = factory.createJsonGenerator(writer);49 final JsonGenerator g = factory.createJsonGenerator(writer);
38 50
39 g.writeStartObject();51 g.writeStartObject();
40 g.writeStringField("name", name);52 if (name != null) {
41 53 g.writeStringField("name", name);
42 g.writeArrayFieldStart("song_id_list"); {54 }
43 for (String songId: songIds) {55 if (songIdList != null) {
44 g.writeString(songId);56 g.writeArrayFieldStart("song_id_list"); {
57 for (String songId: songIdList) {
58 g.writeString(songId);
59 }
45 }60 }
61 g.writeEndArray();
46 }62 }
47 g.writeEndArray();
48
49 g.writeEndObject();63 g.writeEndObject();
50 g.close();64 g.close();
51 65
5266
=== modified file 'src/main/com/ubuntuone/api/music/json/U1PlaylistJson.java'
--- src/main/com/ubuntuone/api/music/json/U1PlaylistJson.java 2012-09-04 21:42:33 +0000
+++ src/main/com/ubuntuone/api/music/json/U1PlaylistJson.java 2012-11-08 22:55:22 +0000
@@ -35,7 +35,7 @@
3535
36import com.ubuntuone.api.music.U1MusicAPI;36import com.ubuntuone.api.music.U1MusicAPI;
37import com.ubuntuone.api.music.model.U1Playlist;37import com.ubuntuone.api.music.model.U1Playlist;
38import com.ubuntuone.api.music.util.RequestListener.U1PlaylistRequestListener;38import com.ubuntuone.api.music.util.ResultRequestListener.U1PlaylistRequestListener;
3939
40public class U1PlaylistJson40public class U1PlaylistJson
41{41{
4242
=== modified file 'src/main/com/ubuntuone/api/music/json/U1SongJson.java'
--- src/main/com/ubuntuone/api/music/json/U1SongJson.java 2012-09-04 21:42:33 +0000
+++ src/main/com/ubuntuone/api/music/json/U1SongJson.java 2012-11-08 22:55:22 +0000
@@ -34,7 +34,7 @@
3434
35import com.ubuntuone.api.music.U1MusicAPI;35import com.ubuntuone.api.music.U1MusicAPI;
36import com.ubuntuone.api.music.model.U1Song;36import com.ubuntuone.api.music.model.U1Song;
37import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;37import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
3838
39public class U1SongJson39public class U1SongJson
40{40{
4141
=== modified file 'src/main/com/ubuntuone/api/music/request/U1AlbumListener.java'
--- src/main/com/ubuntuone/api/music/request/U1AlbumListener.java 2012-06-07 01:31:25 +0000
+++ src/main/com/ubuntuone/api/music/request/U1AlbumListener.java 2012-11-08 22:55:22 +0000
@@ -23,7 +23,7 @@
2323
24import com.ubuntuone.api.music.client.Failure;24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.model.U1Album;25import com.ubuntuone.api.music.model.U1Album;
26import com.ubuntuone.api.music.util.RequestListener.U1AlbumRequestListener;26import com.ubuntuone.api.music.util.ResultRequestListener.U1AlbumRequestListener;
2727
28public abstract class U1AlbumListener implements U1AlbumRequestListener28public abstract class U1AlbumListener implements U1AlbumRequestListener
29{29{
3030
=== modified file 'src/main/com/ubuntuone/api/music/request/U1ArtListener.java'
--- src/main/com/ubuntuone/api/music/request/U1ArtListener.java 2012-06-18 04:19:36 +0000
+++ src/main/com/ubuntuone/api/music/request/U1ArtListener.java 2012-11-08 22:55:22 +0000
@@ -24,7 +24,7 @@
24import java.io.File;24import java.io.File;
2525
26import com.ubuntuone.api.music.client.Failure;26import com.ubuntuone.api.music.client.Failure;
27import com.ubuntuone.api.music.util.RequestListener.U1ArtRequestListener;27import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtRequestListener;
2828
29public abstract class U1ArtListener implements U1ArtRequestListener29public abstract class U1ArtListener implements U1ArtRequestListener
30{30{
3131
=== modified file 'src/main/com/ubuntuone/api/music/request/U1ArtistListener.java'
--- src/main/com/ubuntuone/api/music/request/U1ArtistListener.java 2012-06-07 01:31:25 +0000
+++ src/main/com/ubuntuone/api/music/request/U1ArtistListener.java 2012-11-08 22:55:22 +0000
@@ -23,7 +23,7 @@
2323
24import com.ubuntuone.api.music.client.Failure;24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.model.U1Artist;25import com.ubuntuone.api.music.model.U1Artist;
26import com.ubuntuone.api.music.util.RequestListener.U1ArtistRequestListener;26import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtistRequestListener;
2727
28public abstract class U1ArtistListener implements U1ArtistRequestListener28public abstract class U1ArtistListener implements U1ArtistRequestListener
29{29{
3030
=== added file 'src/main/com/ubuntuone/api/music/request/U1CallbackListener.java'
--- src/main/com/ubuntuone/api/music/request/U1CallbackListener.java 1970-01-01 00:00:00 +0000
+++ src/main/com/ubuntuone/api/music/request/U1CallbackListener.java 2012-11-08 22:55:22 +0000
@@ -0,0 +1,47 @@
1/*
2 * Ubuntu One Music Java library - communicate with Ubuntu One music API
3 *
4 * Copyright 2012 Canonical Ltd.
5 *
6 * This file is part of Ubuntu One Files Java library.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see http://www.gnu.org/licenses
20 */
21
22package com.ubuntuone.api.music.request;
23
24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.util.RequestListener.U1RequestListener;
26
27/**
28 * Class used for callbacks from methods, that do not return result
29 * in onSuccess(), but simply call it to indicate success.
30 */
31public abstract class U1CallbackListener implements U1RequestListener
32{
33 @Override
34 public void onStart() {
35 }
36
37 @Override
38 public abstract void onSuccess();
39
40 @Override
41 public void onFailure(Failure failure) {
42 }
43
44 @Override
45 public void onFinish() {
46 }
47}
048
=== modified file 'src/main/com/ubuntuone/api/music/request/U1DownloadListener.java'
--- src/main/com/ubuntuone/api/music/request/U1DownloadListener.java 2012-06-19 01:05:51 +0000
+++ src/main/com/ubuntuone/api/music/request/U1DownloadListener.java 2012-11-08 22:55:22 +0000
@@ -24,9 +24,9 @@
24import com.ubuntuone.api.music.client.Failure;24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.util.OnCancelListener;25import com.ubuntuone.api.music.util.OnCancelListener;
26import com.ubuntuone.api.music.util.OnProgressListener;26import com.ubuntuone.api.music.util.OnProgressListener;
27import com.ubuntuone.api.music.util.RequestListener;27import com.ubuntuone.api.music.util.ResultRequestListener;
2828
29public abstract class U1DownloadListener implements RequestListener<Boolean>,29public abstract class U1DownloadListener implements ResultRequestListener<Boolean>,
30 OnProgressListener, OnCancelListener30 OnProgressListener, OnCancelListener
31{31{
32 @Override32 @Override
3333
=== modified file 'src/main/com/ubuntuone/api/music/request/U1PlaylistListener.java'
--- src/main/com/ubuntuone/api/music/request/U1PlaylistListener.java 2012-06-07 01:31:25 +0000
+++ src/main/com/ubuntuone/api/music/request/U1PlaylistListener.java 2012-11-08 22:55:22 +0000
@@ -23,7 +23,7 @@
2323
24import com.ubuntuone.api.music.client.Failure;24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.model.U1Playlist;25import com.ubuntuone.api.music.model.U1Playlist;
26import com.ubuntuone.api.music.util.RequestListener.U1PlaylistRequestListener;26import com.ubuntuone.api.music.util.ResultRequestListener.U1PlaylistRequestListener;
2727
28public abstract class U1PlaylistListener implements U1PlaylistRequestListener28public abstract class U1PlaylistListener implements U1PlaylistRequestListener
29{29{
3030
=== removed file 'src/main/com/ubuntuone/api/music/request/U1RequestListener.java'
--- src/main/com/ubuntuone/api/music/request/U1RequestListener.java 2012-06-18 03:10:10 +0000
+++ src/main/com/ubuntuone/api/music/request/U1RequestListener.java 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1/*
2 * Ubuntu One Music Java library - communicate with Ubuntu One music API
3 *
4 * Copyright 2012 Canonical Ltd.
5 *
6 * This file is part of Ubuntu One Files Java library.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see http://www.gnu.org/licenses
20 */
21
22package com.ubuntuone.api.music.request;
23
24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.util.RequestListener.U1VoidRequestListener;
26
27/**
28 * Class used for callbacks from methods, that do not return result
29 * in onSuccess(), but simply call it to indicate success.
30 */
31public abstract class U1RequestListener implements U1VoidRequestListener
32{
33 @Override
34 public void onStart() {
35 }
36
37 @Override
38 public abstract void onSuccess(Void v);
39
40 @Override
41 public void onFailure(Failure failure) {
42 }
43
44 @Override
45 public void onFinish() {
46 }
47}
480
=== modified file 'src/main/com/ubuntuone/api/music/request/U1SongListener.java'
--- src/main/com/ubuntuone/api/music/request/U1SongListener.java 2012-06-07 01:31:25 +0000
+++ src/main/com/ubuntuone/api/music/request/U1SongListener.java 2012-11-08 22:55:22 +0000
@@ -23,7 +23,7 @@
2323
24import com.ubuntuone.api.music.client.Failure;24import com.ubuntuone.api.music.client.Failure;
25import com.ubuntuone.api.music.model.U1Song;25import com.ubuntuone.api.music.model.U1Song;
26import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;26import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
2727
28public abstract class U1SongListener implements U1SongRequestListener28public abstract class U1SongListener implements U1SongRequestListener
29{29{
3030
=== added file 'src/main/com/ubuntuone/api/music/util/FailureListener.java'
--- src/main/com/ubuntuone/api/music/util/FailureListener.java 1970-01-01 00:00:00 +0000
+++ src/main/com/ubuntuone/api/music/util/FailureListener.java 2012-11-08 22:55:22 +0000
@@ -0,0 +1,18 @@
1package com.ubuntuone.api.music.util;
2
3import org.apache.http.HttpStatus;
4
5import com.ubuntuone.api.music.client.Failure;
6
7public abstract interface FailureListener {
8 /**
9 * Called when the request has failed. The message should be descriptive
10 * in most cases and suitable to display to the user.
11 * {@link Failure#getStatusCode} field can be compared with
12 * {@link HttpStatus} constants for further details.
13 *
14 * @param failure
15 * The {@link Failure} returned.
16 */
17 public void onFailure(Failure failure);
18}
019
=== modified file 'src/main/com/ubuntuone/api/music/util/RequestListener.java'
--- src/main/com/ubuntuone/api/music/util/RequestListener.java 2012-08-27 17:20:36 +0000
+++ src/main/com/ubuntuone/api/music/util/RequestListener.java 2012-11-08 22:55:22 +0000
@@ -21,24 +21,11 @@
2121
22package com.ubuntuone.api.music.util;22package com.ubuntuone.api.music.util;
2323
24import java.io.File;
25import java.io.InputStream;
26
27import org.apache.http.HttpStatus;
28
29import com.ubuntuone.api.music.client.Failure;
30import com.ubuntuone.api.music.model.U1Album;
31import com.ubuntuone.api.music.model.U1Artist;
32import com.ubuntuone.api.music.model.U1Playlist;
33import com.ubuntuone.api.music.model.U1Song;
3424
35/**25/**
36 * Request listener used to track U1 API method execution.26 * Request listener used to track U1 API method execution.
37 *
38 * @param <T>
39 * The type of result returned in {@link RequestListener#onSuccess(T)}.
40 */27 */
41public interface RequestListener<T>28public interface RequestListener extends FailureListener
42{29{
43 /**30 /**
44 * Called when the request processing has started.31 * Called when the request processing has started.
@@ -47,34 +34,14 @@
47 34
48 /**35 /**
49 * Called when the request has successfully completed.36 * Called when the request has successfully completed.
50 * 37 */
51 * @param result38 public void onSuccess();
52 * The request result of type T.
53 */
54 public void onSuccess(T result);
55
56 /**
57 * Called when the request has failed. The message should be descriptive
58 * in most cases and suitable to display to the user.
59 * {@link Failure#getStatusCode} field can be compared with
60 * {@link HttpStatus} constants for further details.
61 *
62 * @param failure
63 * The {@link Failure} returned.
64 */
65 public void onFailure(Failure failure);
66 39
67 /**40 /**
68 * Called when the request processing has finished.41 * Called when the request processing has finished.
69 */42 */
70 public void onFinish();43 public void onFinish();
71 44
72 public interface U1ArtistRequestListener extends RequestListener<U1Artist> {};
73 public interface U1AlbumRequestListener extends RequestListener<U1Album> {};
74 public interface U1SongRequestListener extends RequestListener<U1Song> {};
75 public interface U1PlaylistRequestListener extends RequestListener<U1Playlist> {};
76 public interface U1PlaylistSongRequestListener extends RequestListener<U1Song> {};
77 public interface U1ArtRequestListener extends RequestListener<File> {};
78 public interface U1VoidRequestListener extends RequestListener<Void> {};
79 public interface U1StreamRequestListener extends RequestListener<InputStream> {};
80}
81\ No newline at end of file45\ No newline at end of file
46
47 public interface U1RequestListener extends RequestListener {};
48}
8249
=== added file 'src/main/com/ubuntuone/api/music/util/ResultRequestListener.java'
--- src/main/com/ubuntuone/api/music/util/ResultRequestListener.java 1970-01-01 00:00:00 +0000
+++ src/main/com/ubuntuone/api/music/util/ResultRequestListener.java 2012-11-08 22:55:22 +0000
@@ -0,0 +1,67 @@
1/*
2 * Ubuntu One Music Java library - communicate with Ubuntu One music API
3 *
4 * Copyright 2012 Canonical Ltd.
5 *
6 * This file is part of Ubuntu One Files Java library.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see http://www.gnu.org/licenses
20 */
21
22package com.ubuntuone.api.music.util;
23
24import java.io.File;
25import java.io.InputStream;
26
27import com.ubuntuone.api.music.model.U1Album;
28import com.ubuntuone.api.music.model.U1Artist;
29import com.ubuntuone.api.music.model.U1Playlist;
30import com.ubuntuone.api.music.model.U1Song;
31
32/**
33 * Request listener used to track U1 API method execution.
34 *
35 * @param <T>
36 * The type of result returned in {@link ResultRequestListener#onSuccess(T)}.
37 */
38public interface ResultRequestListener<T> extends FailureListener
39{
40 /**
41 * Called when the request processing has started.
42 */
43 public void onStart();
44
45 /**
46 * Called when the request has successfully completed.
47 *
48 * @param result
49 * The request result of type T.
50 */
51 public void onSuccess(T result);
52
53 /**
54 * Called when the request processing has finished.
55 */
56 public void onFinish();
57
58 public interface U1ArtistRequestListener extends ResultRequestListener<U1Artist> {};
59 public interface U1AlbumRequestListener extends ResultRequestListener<U1Album> {};
60 public interface U1SongRequestListener extends ResultRequestListener<U1Song> {};
61
62 public interface U1PlaylistRequestListener extends ResultRequestListener<U1Playlist> {};
63 public interface U1PlaylistSongRequestListener extends ResultRequestListener<U1Song> {};
64
65 public interface U1ArtRequestListener extends ResultRequestListener<File> {};
66 public interface U1StreamRequestListener extends ResultRequestListener<InputStream> {};
67}
068
=== modified file 'src/test/com/ubuntuone/api/music/CreatePlaylistTest.java'
--- src/test/com/ubuntuone/api/music/CreatePlaylistTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/CreatePlaylistTest.java 2012-11-08 22:55:22 +0000
@@ -48,7 +48,7 @@
48import com.ubuntuone.api.music.json.U1CustomJson;48import com.ubuntuone.api.music.json.U1CustomJson;
49import com.ubuntuone.api.music.model.U1Meta;49import com.ubuntuone.api.music.model.U1Meta;
50import com.ubuntuone.api.music.model.U1Song;50import com.ubuntuone.api.music.model.U1Song;
51import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;51import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
52import com.ubuntuone.music.util.U1ResponseBuilder;52import com.ubuntuone.music.util.U1ResponseBuilder;
53import com.ubuntuone.music.util.U1SongBuilder;53import com.ubuntuone.music.util.U1SongBuilder;
54import com.ubuntuone.music.util.Util;54import com.ubuntuone.music.util.Util;
@@ -125,7 +125,7 @@
125 "/api/music/v2/playlists/");125 "/api/music/v2/playlists/");
126 126
127 httpRequest.setEntity(new StringEntity(U1CustomJson127 httpRequest.setEntity(new StringEntity(U1CustomJson
128 .toSongIdListJson(name, songIdList)));128 .toPlaylistJson(name, songIdList)));
129 129
130 String responseJson = U1ResponseBuilder.toJson(130 String responseJson = U1ResponseBuilder.toJson(
131 meta, U1MusicAPI.SONGS, id, name, song1, song2, song3);131 meta, U1MusicAPI.SONGS, id, name, song1, song2, song3);
@@ -178,7 +178,7 @@
178 "/api/music/v2/playlists/");178 "/api/music/v2/playlists/");
179 179
180 httpRequest.setEntity(new StringEntity(U1CustomJson180 httpRequest.setEntity(new StringEntity(U1CustomJson
181 .toSongIdListJson(name, songIdList)));181 .toPlaylistJson(name, songIdList)));
182 182
183 String responseJson = U1ResponseBuilder.toJson(183 String responseJson = U1ResponseBuilder.toJson(
184 meta, U1MusicAPI.SONGS, id, name, song1, song2, song3);184 meta, U1MusicAPI.SONGS, id, name, song1, song2, song3);
185185
=== modified file 'src/test/com/ubuntuone/api/music/DeletePlaylistTest.java'
--- src/test/com/ubuntuone/api/music/DeletePlaylistTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/DeletePlaylistTest.java 2012-11-08 22:55:22 +0000
@@ -45,7 +45,7 @@
45import com.ubuntuone.api.music.client.BaseClient;45import com.ubuntuone.api.music.client.BaseClient;
46import com.ubuntuone.api.music.client.Failure;46import com.ubuntuone.api.music.client.Failure;
47import com.ubuntuone.api.music.model.U1Meta;47import com.ubuntuone.api.music.model.U1Meta;
48import com.ubuntuone.api.music.util.RequestListener.U1VoidRequestListener;48import com.ubuntuone.api.music.util.RequestListener.U1RequestListener;
49import com.ubuntuone.music.util.U1ResponseBuilder;49import com.ubuntuone.music.util.U1ResponseBuilder;
50import com.ubuntuone.music.util.Util;50import com.ubuntuone.music.util.Util;
51import com.ubuntuone.test.util.DummyAuthorizer;51import com.ubuntuone.test.util.DummyAuthorizer;
@@ -64,7 +64,7 @@
64 private U1MusicAPI musicApi;64 private U1MusicAPI musicApi;
6565
66 String playlistId = "playlistId";66 String playlistId = "playlistId";
67 private U1VoidRequestListener requestCallback;67 private U1RequestListener requestCallback;
68 68
69 @Before69 @Before
70 public void setUp() throws IOException {70 public void setUp() throws IOException {
@@ -75,7 +75,7 @@
75 httpClient = context.mock(HttpClient.class);75 httpClient = context.mock(HttpClient.class);
76 musicApi = new U1MusicAPI("ua/1.0", httpClient, new DummyAuthorizer());76 musicApi = new U1MusicAPI("ua/1.0", httpClient, new DummyAuthorizer());
77 77
78 requestCallback = context.mock(U1VoidRequestListener.class);78 requestCallback = context.mock(U1RequestListener.class);
79 }79 }
80 80
81 @Test81 @Test
@@ -86,7 +86,7 @@
86 inSequence(requestSequence);86 inSequence(requestSequence);
87 87
88 ignoring(httpClient);88 ignoring(httpClient);
89 allowing(requestCallback).onSuccess(with(any(Void.class)));89 allowing(requestCallback).onSuccess();
90 allowing(requestCallback).onFailure(with(any(Failure.class)));90 allowing(requestCallback).onFailure(with(any(Failure.class)));
91 91
92 oneOf(requestCallback).onFinish();92 oneOf(requestCallback).onFinish();
@@ -118,7 +118,7 @@
118 inSequence(requestSequence);118 inSequence(requestSequence);
119 will(returnValue(httpResponse));119 will(returnValue(httpResponse));
120 120
121 oneOf(requestCallback).onSuccess(null);121 oneOf(requestCallback).onSuccess();
122 inSequence(requestSequence);122 inSequence(requestSequence);
123 123
124 oneOf(requestCallback).onFinish();124 oneOf(requestCallback).onFinish();
125125
=== modified file 'src/test/com/ubuntuone/api/music/GetAlbumsTest.java'
--- src/test/com/ubuntuone/api/music/GetAlbumsTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/GetAlbumsTest.java 2012-11-08 22:55:22 +0000
@@ -47,7 +47,7 @@
47import com.ubuntuone.api.music.model.U1Album;47import com.ubuntuone.api.music.model.U1Album;
48import com.ubuntuone.api.music.model.U1Artist;48import com.ubuntuone.api.music.model.U1Artist;
49import com.ubuntuone.api.music.model.U1Meta;49import com.ubuntuone.api.music.model.U1Meta;
50import com.ubuntuone.api.music.util.RequestListener.U1AlbumRequestListener;50import com.ubuntuone.api.music.util.ResultRequestListener.U1AlbumRequestListener;
51import com.ubuntuone.music.util.U1AlbumBuilder;51import com.ubuntuone.music.util.U1AlbumBuilder;
52import com.ubuntuone.music.util.U1ArtistBuilder;52import com.ubuntuone.music.util.U1ArtistBuilder;
53import com.ubuntuone.music.util.U1ResponseBuilder;53import com.ubuntuone.music.util.U1ResponseBuilder;
5454
=== modified file 'src/test/com/ubuntuone/api/music/GetArtTest.java'
--- src/test/com/ubuntuone/api/music/GetArtTest.java 2012-09-19 19:17:30 +0000
+++ src/test/com/ubuntuone/api/music/GetArtTest.java 2012-11-08 22:55:22 +0000
@@ -51,7 +51,7 @@
51import com.ubuntuone.api.music.model.U1Artist;51import com.ubuntuone.api.music.model.U1Artist;
52import com.ubuntuone.api.music.model.U1Song;52import com.ubuntuone.api.music.model.U1Song;
53import com.ubuntuone.api.music.util.HashUtils;53import com.ubuntuone.api.music.util.HashUtils;
54import com.ubuntuone.api.music.util.RequestListener.U1ArtRequestListener;54import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtRequestListener;
55import com.ubuntuone.music.util.U1AlbumBuilder;55import com.ubuntuone.music.util.U1AlbumBuilder;
56import com.ubuntuone.music.util.U1ArtistBuilder;56import com.ubuntuone.music.util.U1ArtistBuilder;
57import com.ubuntuone.music.util.U1SongBuilder;57import com.ubuntuone.music.util.U1SongBuilder;
5858
=== modified file 'src/test/com/ubuntuone/api/music/GetArtistsTest.java'
--- src/test/com/ubuntuone/api/music/GetArtistsTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/GetArtistsTest.java 2012-11-08 22:55:22 +0000
@@ -46,7 +46,7 @@
46import com.ubuntuone.api.music.client.Failure;46import com.ubuntuone.api.music.client.Failure;
47import com.ubuntuone.api.music.model.U1Artist;47import com.ubuntuone.api.music.model.U1Artist;
48import com.ubuntuone.api.music.model.U1Meta;48import com.ubuntuone.api.music.model.U1Meta;
49import com.ubuntuone.api.music.util.RequestListener.U1ArtistRequestListener;49import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtistRequestListener;
50import com.ubuntuone.music.util.U1ArtistBuilder;50import com.ubuntuone.music.util.U1ArtistBuilder;
51import com.ubuntuone.music.util.U1ResponseBuilder;51import com.ubuntuone.music.util.U1ResponseBuilder;
52import com.ubuntuone.music.util.Util;52import com.ubuntuone.music.util.Util;
5353
=== modified file 'src/test/com/ubuntuone/api/music/GetPlaylistTest.java'
--- src/test/com/ubuntuone/api/music/GetPlaylistTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/GetPlaylistTest.java 2012-11-08 22:55:22 +0000
@@ -46,7 +46,7 @@
46import com.ubuntuone.api.music.client.Failure;46import com.ubuntuone.api.music.client.Failure;
47import com.ubuntuone.api.music.model.U1Meta;47import com.ubuntuone.api.music.model.U1Meta;
48import com.ubuntuone.api.music.model.U1Song;48import com.ubuntuone.api.music.model.U1Song;
49import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;49import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
50import com.ubuntuone.music.util.U1ResponseBuilder;50import com.ubuntuone.music.util.U1ResponseBuilder;
51import com.ubuntuone.music.util.U1SongBuilder;51import com.ubuntuone.music.util.U1SongBuilder;
52import com.ubuntuone.music.util.Util;52import com.ubuntuone.music.util.Util;
5353
=== modified file 'src/test/com/ubuntuone/api/music/GetPlaylistsTest.java'
--- src/test/com/ubuntuone/api/music/GetPlaylistsTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/GetPlaylistsTest.java 2012-11-08 22:55:22 +0000
@@ -46,7 +46,7 @@
46import com.ubuntuone.api.music.client.Failure;46import com.ubuntuone.api.music.client.Failure;
47import com.ubuntuone.api.music.model.U1Meta;47import com.ubuntuone.api.music.model.U1Meta;
48import com.ubuntuone.api.music.model.U1Playlist;48import com.ubuntuone.api.music.model.U1Playlist;
49import com.ubuntuone.api.music.util.RequestListener.U1PlaylistRequestListener;49import com.ubuntuone.api.music.util.ResultRequestListener.U1PlaylistRequestListener;
50import com.ubuntuone.music.util.U1PlaylistBuilder;50import com.ubuntuone.music.util.U1PlaylistBuilder;
51import com.ubuntuone.music.util.U1ResponseBuilder;51import com.ubuntuone.music.util.U1ResponseBuilder;
52import com.ubuntuone.music.util.Util;52import com.ubuntuone.music.util.Util;
5353
=== modified file 'src/test/com/ubuntuone/api/music/GetSongStreamTest.java'
--- src/test/com/ubuntuone/api/music/GetSongStreamTest.java 2012-11-08 16:22:16 +0000
+++ src/test/com/ubuntuone/api/music/GetSongStreamTest.java 2012-11-08 22:55:22 +0000
@@ -47,7 +47,7 @@
47import com.ubuntuone.api.music.client.BaseClient;47import com.ubuntuone.api.music.client.BaseClient;
48import com.ubuntuone.api.music.client.Failure;48import com.ubuntuone.api.music.client.Failure;
49import com.ubuntuone.api.music.model.U1Song;49import com.ubuntuone.api.music.model.U1Song;
50import com.ubuntuone.api.music.util.RequestListener.U1StreamRequestListener;50import com.ubuntuone.api.music.util.ResultRequestListener.U1StreamRequestListener;
51import com.ubuntuone.music.util.U1SongBuilder;51import com.ubuntuone.music.util.U1SongBuilder;
52import com.ubuntuone.music.util.Util;52import com.ubuntuone.music.util.Util;
53import com.ubuntuone.test.util.DummyAuthorizer;53import com.ubuntuone.test.util.DummyAuthorizer;
5454
=== modified file 'src/test/com/ubuntuone/api/music/GetSongsTest.java'
--- src/test/com/ubuntuone/api/music/GetSongsTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/GetSongsTest.java 2012-11-08 22:55:22 +0000
@@ -47,7 +47,7 @@
47import com.ubuntuone.api.music.model.U1Album;47import com.ubuntuone.api.music.model.U1Album;
48import com.ubuntuone.api.music.model.U1Meta;48import com.ubuntuone.api.music.model.U1Meta;
49import com.ubuntuone.api.music.model.U1Song;49import com.ubuntuone.api.music.model.U1Song;
50import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;50import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
51import com.ubuntuone.music.util.U1AlbumBuilder;51import com.ubuntuone.music.util.U1AlbumBuilder;
52import com.ubuntuone.music.util.U1ResponseBuilder;52import com.ubuntuone.music.util.U1ResponseBuilder;
53import com.ubuntuone.music.util.U1SongBuilder;53import com.ubuntuone.music.util.U1SongBuilder;
5454
=== modified file 'src/test/com/ubuntuone/api/music/UpdatePlaylistTest.java'
--- src/test/com/ubuntuone/api/music/UpdatePlaylistTest.java 2012-09-28 01:45:13 +0000
+++ src/test/com/ubuntuone/api/music/UpdatePlaylistTest.java 2012-11-08 22:55:22 +0000
@@ -48,7 +48,7 @@
48import com.ubuntuone.api.music.json.U1CustomJson;48import com.ubuntuone.api.music.json.U1CustomJson;
49import com.ubuntuone.api.music.model.U1Meta;49import com.ubuntuone.api.music.model.U1Meta;
50import com.ubuntuone.api.music.model.U1Song;50import com.ubuntuone.api.music.model.U1Song;
51import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;51import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
52import com.ubuntuone.music.util.U1ResponseBuilder;52import com.ubuntuone.music.util.U1ResponseBuilder;
53import com.ubuntuone.music.util.U1SongBuilder;53import com.ubuntuone.music.util.U1SongBuilder;
54import com.ubuntuone.music.util.Util;54import com.ubuntuone.music.util.Util;
@@ -125,7 +125,7 @@
125 "/api/music/v2/playlists/");125 "/api/music/v2/playlists/");
126 126
127 httpRequest.setEntity(new StringEntity(U1CustomJson127 httpRequest.setEntity(new StringEntity(U1CustomJson
128 .toSongIdListJson(name, songList)));128 .toPlaylistJson(name, songList)));
129 129
130 String responseJson = U1ResponseBuilder.toJson(130 String responseJson = U1ResponseBuilder.toJson(
131 meta, U1MusicAPI.SONGS, id, name, song1, song2, song3);131 meta, U1MusicAPI.SONGS, id, name, song1, song2, song3);
132132
=== modified file 'src/test/com/ubuntuone/api/music/json/U1AlbumJsonTest.java'
--- src/test/com/ubuntuone/api/music/json/U1AlbumJsonTest.java 2012-06-12 02:39:48 +0000
+++ src/test/com/ubuntuone/api/music/json/U1AlbumJsonTest.java 2012-11-08 22:55:22 +0000
@@ -35,7 +35,7 @@
35import com.ubuntuone.api.music.U1MusicAPI;35import com.ubuntuone.api.music.U1MusicAPI;
36import com.ubuntuone.api.music.model.U1Album;36import com.ubuntuone.api.music.model.U1Album;
37import com.ubuntuone.api.music.model.U1Meta;37import com.ubuntuone.api.music.model.U1Meta;
38import com.ubuntuone.api.music.util.RequestListener.U1AlbumRequestListener;38import com.ubuntuone.api.music.util.ResultRequestListener.U1AlbumRequestListener;
39import com.ubuntuone.music.util.U1AlbumBuilder;39import com.ubuntuone.music.util.U1AlbumBuilder;
40import com.ubuntuone.music.util.U1ResponseBuilder;40import com.ubuntuone.music.util.U1ResponseBuilder;
4141
4242
=== modified file 'src/test/com/ubuntuone/api/music/json/U1ArtistJsonTest.java'
--- src/test/com/ubuntuone/api/music/json/U1ArtistJsonTest.java 2012-09-04 19:28:22 +0000
+++ src/test/com/ubuntuone/api/music/json/U1ArtistJsonTest.java 2012-11-08 22:55:22 +0000
@@ -35,7 +35,7 @@
35import com.ubuntuone.api.music.U1MusicAPI;35import com.ubuntuone.api.music.U1MusicAPI;
36import com.ubuntuone.api.music.model.U1Artist;36import com.ubuntuone.api.music.model.U1Artist;
37import com.ubuntuone.api.music.model.U1Meta;37import com.ubuntuone.api.music.model.U1Meta;
38import com.ubuntuone.api.music.util.RequestListener.U1ArtistRequestListener;38import com.ubuntuone.api.music.util.ResultRequestListener.U1ArtistRequestListener;
39import com.ubuntuone.music.util.U1ArtistBuilder;39import com.ubuntuone.music.util.U1ArtistBuilder;
40import com.ubuntuone.music.util.U1ResponseBuilder;40import com.ubuntuone.music.util.U1ResponseBuilder;
4141
4242
=== modified file 'src/test/com/ubuntuone/api/music/json/U1CustomJsonTest.java'
--- src/test/com/ubuntuone/api/music/json/U1CustomJsonTest.java 2012-09-19 19:17:30 +0000
+++ src/test/com/ubuntuone/api/music/json/U1CustomJsonTest.java 2012-11-08 22:55:22 +0000
@@ -31,7 +31,7 @@
31public class U1CustomJsonTest31public class U1CustomJsonTest
32{32{
33 @Test33 @Test
34 public void testEncodeU1SongIdListPlaylist() throws IOException {34 public void testToPlaylistJson() throws IOException {
35 final ArrayList<String> songIdList = new ArrayList<String>();35 final ArrayList<String> songIdList = new ArrayList<String>();
36 36
37 songIdList.add("id1");37 songIdList.add("id1");
@@ -39,7 +39,7 @@
39 39
40 String name = "the playlist name";40 String name = "the playlist name";
41 41
42 String json = U1CustomJson.toSongIdListJson(name, songIdList);42 String json = U1CustomJson.toPlaylistJson(name, songIdList);
43 43
44 String expectedJson = "{\"name\":\"" + name + "\"," +44 String expectedJson = "{\"name\":\"" + name + "\"," +
45 "\"song_id_list\":[" +45 "\"song_id_list\":[" +
@@ -48,4 +48,28 @@
48 48
49 assertEquals(expectedJson, json);49 assertEquals(expectedJson, json);
50 }50 }
51
52 @Test
53 public void testToPlaylistJsonNameOnly() throws IOException {
54 String name = "the playlist name";
55
56 String json = U1CustomJson.toPlaylistJson(name, null);
57
58 String expectedJson = "{\"name\":\"" + name + "\"}";
59
60 assertEquals(expectedJson, json);
61 }
62
63 @Test
64 public void testToPlaylistJsonSongIdListOnly() throws IOException {
65 final ArrayList<String> songIdList = new ArrayList<String>();
66 songIdList.add("id1");
67 songIdList.add("id2");
68
69 String json = U1CustomJson.toPlaylistJson(null, songIdList);
70
71 String expectedJson = "{\"song_id_list\":[\"id1\",\"id2\"]}";
72
73 assertEquals(expectedJson, json);
74 }
51}75}
5276
=== modified file 'src/test/com/ubuntuone/api/music/json/U1PlaylistJsonTest.java'
--- src/test/com/ubuntuone/api/music/json/U1PlaylistJsonTest.java 2012-06-12 14:44:04 +0000
+++ src/test/com/ubuntuone/api/music/json/U1PlaylistJsonTest.java 2012-11-08 22:55:22 +0000
@@ -35,7 +35,7 @@
35import com.ubuntuone.api.music.U1MusicAPI;35import com.ubuntuone.api.music.U1MusicAPI;
36import com.ubuntuone.api.music.model.U1Meta;36import com.ubuntuone.api.music.model.U1Meta;
37import com.ubuntuone.api.music.model.U1Playlist;37import com.ubuntuone.api.music.model.U1Playlist;
38import com.ubuntuone.api.music.util.RequestListener.U1PlaylistRequestListener;38import com.ubuntuone.api.music.util.ResultRequestListener.U1PlaylistRequestListener;
39import com.ubuntuone.music.util.U1PlaylistBuilder;39import com.ubuntuone.music.util.U1PlaylistBuilder;
40import com.ubuntuone.music.util.U1ResponseBuilder;40import com.ubuntuone.music.util.U1ResponseBuilder;
4141
4242
=== modified file 'src/test/com/ubuntuone/api/music/json/U1SongJsonTest.java'
--- src/test/com/ubuntuone/api/music/json/U1SongJsonTest.java 2012-06-12 02:39:48 +0000
+++ src/test/com/ubuntuone/api/music/json/U1SongJsonTest.java 2012-11-08 22:55:22 +0000
@@ -35,7 +35,7 @@
35import com.ubuntuone.api.music.U1MusicAPI;35import com.ubuntuone.api.music.U1MusicAPI;
36import com.ubuntuone.api.music.model.U1Meta;36import com.ubuntuone.api.music.model.U1Meta;
37import com.ubuntuone.api.music.model.U1Song;37import com.ubuntuone.api.music.model.U1Song;
38import com.ubuntuone.api.music.util.RequestListener.U1SongRequestListener;38import com.ubuntuone.api.music.util.ResultRequestListener.U1SongRequestListener;
39import com.ubuntuone.music.util.U1ResponseBuilder;39import com.ubuntuone.music.util.U1ResponseBuilder;
40import com.ubuntuone.music.util.U1SongBuilder;40import com.ubuntuone.music.util.U1SongBuilder;
4141
4242
=== modified file 'src/test/com/ubuntuone/music/util/U1ResponseBuilder.java'
--- src/test/com/ubuntuone/music/util/U1ResponseBuilder.java 2012-08-27 17:20:36 +0000
+++ src/test/com/ubuntuone/music/util/U1ResponseBuilder.java 2012-11-08 22:55:22 +0000
@@ -33,6 +33,9 @@
3333
34public class U1ResponseBuilder34public class U1ResponseBuilder
35{35{
36 private static final String META = "meta";
37 private static final String STATUS = "status";
38 private static final String MSG = "msg";
36 private static final String RESPONSE = "response";39 private static final String RESPONSE = "response";
37 40
38 public static String toJson(U1Meta meta, String title, JSONString... items)41 public static String toJson(U1Meta meta, String title, JSONString... items)
@@ -48,24 +51,23 @@
48 final JsonGenerator g = factory.createJsonGenerator(writer);51 final JsonGenerator g = factory.createJsonGenerator(writer);
49 52
50 g.writeStartObject(); {53 g.writeStartObject(); {
51 // meta54 g.writeObjectFieldStart(META); {
52 g.writeObjectFieldStart("meta"); {55 g.writeNumberField(STATUS, meta.getStatus());
53 g.writeNumberField("status", meta.getStatus());56 g.writeStringField(MSG, meta.getMessage());
54 g.writeStringField("msg", meta.getMessage());
55 }57 }
56 g.writeEndObject();58 g.writeEndObject();
57 // response59
58 g.writeObjectFieldStart(RESPONSE); {60 g.writeObjectFieldStart(RESPONSE); {
59 // item array
60 g.writeArrayFieldStart(title);61 g.writeArrayFieldStart(title);
61 if (items != null) {62 if (items != null) {
62 for (JSONString item : items) {63 for (JSONString item : items) {
63 g.writeRawValue(item.toJSONString());64 g.writeRawValue(item.toJSONString());
64 }65 }
65 }66 }
66 g.writeEndArray(); // title67 g.writeEndArray();
67 }68 }
68 g.writeEndObject(); // response69 g.writeEndObject();
70
69 }71 }
70 g.writeEndObject();72 g.writeEndObject();
71 g.close();73 g.close();

Subscribers

People subscribed via source and target branches