use of com.trovebox.android.common.model.Token in project mobile-android by photo.
the class TokenTest method testFromJson.
public void testFromJson() {
Token token;
try {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_token);
token = Token.fromJson(json);
} catch (JSONException e) {
throw new AssertionError("This exception should not be thrown!");
}
testTokenData(token);
}
use of com.trovebox.android.common.model.Token in project mobile-android by photo.
the class TokenTest method testTokenParcelable.
public void testTokenParcelable() {
Token token;
try {
JSONObject json = JSONUtils.getJson(getInstrumentation().getContext(), R.raw.json_token);
token = Token.fromJson(json);
} catch (JSONException e) {
throw new AssertionError("This exception should not be thrown!");
}
testTokenData(token);
Parcel parcel = Parcel.obtain();
token.writeToParcel(parcel, 0);
// done writing, now reset parcel for reading
parcel.setDataPosition(0);
// finish round trip
Token createFromParcel = Token.CREATOR.createFromParcel(parcel);
testTokenData(createFromParcel);
}
use of com.trovebox.android.common.model.Token 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();
}
Aggregations