Search in sources :

Example 6 with UploadResponse

use of com.trovebox.android.common.net.UploadResponse in project mobile-android by photo.

the class TroveboxApiTest method testPhotoUploadAndDetailsEdit.

public void testPhotoUploadAndDetailsEdit() throws Exception {
    File file = createTestFileForUpload();
    UploadMetaData settings = new UploadMetaData();
    String title = "Android";
    String description = "Nice picture of an android";
    String tags = "test";
    boolean priv = false;
    settings.setTitle(title);
    settings.setDescription(description);
    settings.setTags(tags);
    settings.setPrivate(priv);
    try {
        UploadResponse resp = mApi.uploadPhoto(file, settings, null);
        assertTrue(resp.isSuccess());
        assertNotNull(resp.getPhoto());
        try {
            Photo photo = resp.getPhoto();
            assertNotNull(photo);
            assertTrue(photo.getTags().size() >= 1);
            // assertEquals("test", resp.getPhoto().getTags().get(0));
            assertEquals(title, photo.getTitle());
            assertEquals(description, photo.getDescription());
            assertFalse(photo.isPrivate());
            title = "Android (Edited)";
            description = "Nice picture of an android (Edited)";
            tags = "edited";
            Collection<String> tagsCollection = new ArrayList<String>();
            tagsCollection.add("edited");
            priv = true;
            PhotoResponse photoResp = mApi.updatePhotoDetails(photo.getId(), title, description, tagsCollection, Photo.PERMISSION_PRIVATE);
            photo = photoResp.getPhoto();
            assertTrue(photoResp.isSuccess());
            assertNotNull(photo);
            assertTrue(photo.getTags().size() == 1);
            assertEquals(tags, photo.getTags().get(0));
            assertEquals(title, photo.getTitle());
            assertEquals(description, photo.getDescription());
            assertTrue(photo.isPrivate() == priv);
        } finally {
            // remove uploaded photo
            mApi.deletePhoto(resp.getPhoto().getId());
        }
    } catch (Exception e) {
        fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
    }
    file.delete();
}
Also used : UploadResponse(com.trovebox.android.common.net.UploadResponse) ArrayList(java.util.ArrayList) PhotoResponse(com.trovebox.android.common.net.PhotoResponse) UploadMetaData(com.trovebox.android.common.net.UploadMetaData) Photo(com.trovebox.android.common.model.Photo) File(java.io.File) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 7 with UploadResponse

use of com.trovebox.android.common.net.UploadResponse in project mobile-android by photo.

the class UploadResponseTest method testResponse.

public void testResponse() throws JSONException {
    JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo_upload);
    UploadResponse response = new UploadResponse(json);
    assertNotNull(response);
    assertTrue(response.isSuccess());
    assertNotNull(response.getPhoto());
}
Also used : UploadResponse(com.trovebox.android.common.net.UploadResponse) JSONObject(org.json.JSONObject)

Aggregations

UploadResponse (com.trovebox.android.common.net.UploadResponse)7 File (java.io.File)6 UploadMetaData (com.trovebox.android.common.net.UploadMetaData)5 IOException (java.io.IOException)4 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 JSONException (org.json.JSONException)4 Photo (com.trovebox.android.common.model.Photo)3 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)3 ProgressListener (com.trovebox.android.common.net.HttpEntityWithProgress.ProgressListener)2 ArrayList (java.util.ArrayList)2 Notification (android.app.Notification)1 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 AssetManager (android.content.res.AssetManager)1 Uri (android.net.Uri)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Solo (com.jayway.android.robotium.solo.Solo)1 Token (com.trovebox.android.common.model.Token)1 PhotoResponse (com.trovebox.android.common.net.PhotoResponse)1 TokenResponse (com.trovebox.android.common.net.TokenResponse)1