Search in sources :

Example 6 with PhotosResponse

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

the class TroveboxApiTest method testCreateTokenForPhoto.

public void testCreateTokenForPhoto() throws Exception {
    File file = createTestFileForUpload();
    boolean priv = true;
    UploadMetaData settings = new UploadMetaData();
    String title = "Android";
    String description = "Nice picture of an android";
    String tags = "test";
    settings.setTitle(title);
    settings.setDescription(description);
    settings.setTags(tags);
    settings.setPrivate(priv);
    try {
        String hash = SHA1Utils.computeSha1ForFile(file.getAbsolutePath());
        PhotosResponse photos = mApi.getPhotos(hash);
        assertTrue(photos.isSuccess());
        boolean created = false;
        Photo photo;
        if (photos.getPhotos().size() > 0) {
            photo = photos.getPhotos().get(0);
        } else {
            UploadResponse resp = mApi.uploadPhoto(file, settings, null);
            assertTrue(resp.isSuccess());
            assertNotNull(resp.getPhoto());
            photo = resp.getPhoto();
            created = true;
        }
        try {
            assertNotNull(photo);
            assertTrue(photo.getTags().size() >= 1);
            // assertEquals("test", resp.getPhoto().getTags().get(0));
            assertEquals(title, photo.getTitle());
            assertEquals(description, photo.getDescription());
            assertEquals(priv, photo.isPrivate());
            TokenResponse tokenResponse = mApi.createTokenForPhoto(photo.getId());
            assertEquals(tokenResponse.getCode(), 201);
            Token token = tokenResponse.getToken();
            assertNotNull(token);
            assertEquals(token.getType(), "photo");
            assertEquals(token.getData(), photo.getId());
            assertNotNull(token.getId());
            assertFalse(token.getId().isEmpty());
            System.out.println(token.getDateExpires());
            assertNotNull(token.getDateExpires());
        } finally {
            if (created) {
                // remove uploaded photo
                mApi.deletePhoto(photo.getId());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception should not happen: " + e.getClass().getSimpleName() + " - " + e.getMessage());
    }
    file.delete();
}
Also used : UploadResponse(com.trovebox.android.common.net.UploadResponse) TokenResponse(com.trovebox.android.common.net.TokenResponse) UploadMetaData(com.trovebox.android.common.net.UploadMetaData) PhotosResponse(com.trovebox.android.common.net.PhotosResponse) Photo(com.trovebox.android.common.model.Photo) Token(com.trovebox.android.common.model.Token) File(java.io.File) ClientProtocolException(org.apache.http.client.ClientProtocolException) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 7 with PhotosResponse

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

the class TroveboxApiTest method testPhotos.

public void testPhotos() throws ClientProtocolException, IllegalStateException, IOException, JSONException {
    PhotosResponse resp = mApi.getPhotos();
    assertNotNull(resp);
    assertEquals(1, resp.getCurrentPage());
    assertNotSame(0, resp.getTotalRows());
    assertNotNull(resp.getPhotos());
    assertNotSame(0, resp.getPhotos().size());
}
Also used : PhotosResponse(com.trovebox.android.common.net.PhotosResponse)

Aggregations

PhotosResponse (com.trovebox.android.common.net.PhotosResponse)7 UploadResponse (com.trovebox.android.common.net.UploadResponse)3 File (java.io.File)3 Solo (com.jayway.android.robotium.solo.Solo)2 Photo (com.trovebox.android.common.model.Photo)2 ProgressListener (com.trovebox.android.common.net.HttpEntityWithProgress.ProgressListener)2 UploadMetaData (com.trovebox.android.common.net.UploadMetaData)2 CountDownLatch (java.util.concurrent.CountDownLatch)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 ListAdapter (android.widget.ListAdapter)1 ListView (android.widget.ListView)1 GalleryAdapterExt (com.trovebox.android.common.fragment.gallery.GalleryFragment.GalleryAdapterExt)1 Token (com.trovebox.android.common.model.Token)1 Paging (com.trovebox.android.common.net.Paging)1 PhotoResponse (com.trovebox.android.common.net.PhotoResponse)1