Search in sources :

Example 1 with PhotoResponse

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

the class GalleryActivityTest method testLoadsImages.

public void testLoadsImages() throws ClientProtocolException, IllegalStateException, IOException, JSONException, InterruptedException {
    // Setup mock calls and their responses
    PowerMock.reset(getApiMock());
    getApiMock().getPhotos((ReturnSizes) EasyMock.anyObject(), (Collection<String>) EasyMock.anyObject(), (String) EasyMock.anyObject(), null, (String) EasyMock.anyObject(), (Paging) EasyMock.anyObject(), null);
    PowerMock.expectLastCall().andReturn(new PhotosResponse(JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photos_get))).times(2);
    getApiMock().getPhoto((String) EasyMock.anyObject(), (ReturnSizes) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
    PowerMock.expectLastCall().andReturn(new PhotoResponse(RequestType.UNKNOWN, JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo_get))).anyTimes();
    PowerMock.replayAll();
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            getActivity().selectTab(0);
        }
    });
    getInstrumentation().waitForIdleSync();
    CountDownLatch signal = new CountDownLatch(1);
    signal.await(5, TimeUnit.SECONDS);
    // Actual test
    Solo solo = new Solo(getInstrumentation(), getActivity());
    Assert.assertTrue(solo.getCurrentListViews().size() == 1);
    ListView listView = solo.getCurrentListViews().get(0);
    Assert.assertNotNull(listView.getAdapter());
    ListAdapter adapter = listView.getAdapter();
    Assert.assertTrue(adapter instanceof ListAdapterWrapper);
    adapter = ((ListAdapterWrapper) adapter).getWrappedAdapter();
    Assert.assertTrue(adapter instanceof GalleryAdapterExt);
    GalleryAdapterExt gadapter = (GalleryAdapterExt) adapter;
    CommonUtils.debug(GalleryActivityTest.class.getSimpleName(), "start compare");
    assertEquals(2, gadapter.getSuperCount());
    // check if the mock calls were called correctly
    PowerMock.verifyAll();
}
Also used : ListView(android.widget.ListView) PhotoResponse(com.trovebox.android.common.net.PhotoResponse) Solo(com.jayway.android.robotium.solo.Solo) GalleryAdapterExt(com.trovebox.android.common.fragment.gallery.GalleryFragment.GalleryAdapterExt) PhotosResponse(com.trovebox.android.common.net.PhotosResponse) ListAdapterWrapper(org.holoeverywhere.widget.ListAdapterWrapper) CountDownLatch(java.util.concurrent.CountDownLatch) ListAdapter(android.widget.ListAdapter)

Example 2 with PhotoResponse

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

the class PhotoDetailsActivityTest method testPreconditions.

public void testPreconditions() throws JSONException, ClientProtocolException, IllegalStateException, IOException {
    // Setup mock calls and their responses
    PowerMock.reset(getApiMock());
    getApiMock().getPhoto((String) EasyMock.anyObject(), (ReturnSizes) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject());
    PowerMock.expectLastCall().andReturn(new PhotoResponse(RequestType.UNKNOWN, JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo_get))).times(2);
    PowerMock.replayAll();
    Intent intent = new Intent();
    Photo photo = Photo.fromJson(JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_photo));
    intent.putExtra(PhotoDetailsUiFragment.EXTRA_PHOTO, photo);
    setActivityIntent(intent);
    activity = this.getActivity();
    Fragment fragment = activity.getSupportFragmentManager().findFragmentById(android.R.id.content);
    Assert.assertNotNull(fragment);
    Assert.assertTrue(fragment instanceof PhotoDetailsUiFragment);
}
Also used : PhotoResponse(com.trovebox.android.common.net.PhotoResponse) PhotoDetailsUiFragment(com.trovebox.android.app.PhotoDetailsActivity.PhotoDetailsUiFragment) Intent(android.content.Intent) Photo(com.trovebox.android.common.model.Photo) Fragment(android.support.v4.app.Fragment) PhotoDetailsUiFragment(com.trovebox.android.app.PhotoDetailsActivity.PhotoDetailsUiFragment)

Example 3 with PhotoResponse

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

the class PhotoUtils method getThePhotoWithReturnSize.

/**
     * Performs api request to retrieve photo with necessary size
     * 
     * @param photo
     * @param photoSize
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     * @throws JSONException
     */
public static Photo getThePhotoWithReturnSize(Photo photo, ReturnSizes photoSize) throws ClientProtocolException, IOException, JSONException {
    TrackerUtils.trackBackgroundEvent("getThePhotoWithReturnSize", TAG);
    long start = System.currentTimeMillis();
    PhotoResponse response = CommonConfigurationUtils.getApi().getPhoto(photo.getId(), photoSize, photo.getToken(), photo.getHost());
    photo = response.getPhoto();
    TrackerUtils.trackDataLoadTiming(System.currentTimeMillis() - start, "getThePhotoWithReturnSize", TAG);
    return photo;
}
Also used : PhotoResponse(com.trovebox.android.common.net.PhotoResponse)

Example 4 with PhotoResponse

use of com.trovebox.android.common.net.PhotoResponse 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)

Aggregations

PhotoResponse (com.trovebox.android.common.net.PhotoResponse)4 Photo (com.trovebox.android.common.model.Photo)2 Intent (android.content.Intent)1 Fragment (android.support.v4.app.Fragment)1 ListAdapter (android.widget.ListAdapter)1 ListView (android.widget.ListView)1 Solo (com.jayway.android.robotium.solo.Solo)1 PhotoDetailsUiFragment (com.trovebox.android.app.PhotoDetailsActivity.PhotoDetailsUiFragment)1 GalleryAdapterExt (com.trovebox.android.common.fragment.gallery.GalleryFragment.GalleryAdapterExt)1 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)1 UploadMetaData (com.trovebox.android.common.net.UploadMetaData)1 UploadResponse (com.trovebox.android.common.net.UploadResponse)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ClientProtocolException (org.apache.http.client.ClientProtocolException)1 ListAdapterWrapper (org.holoeverywhere.widget.ListAdapterWrapper)1 JSONException (org.json.JSONException)1