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();
}
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);
}
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;
}
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();
}
Aggregations