Search in sources :

Example 1 with Token

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);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Token(com.trovebox.android.common.model.Token)

Example 2 with 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);
}
Also used : JSONObject(org.json.JSONObject) Parcel(android.os.Parcel) JSONException(org.json.JSONException) Token(com.trovebox.android.common.model.Token)

Example 3 with Token

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

Aggregations

Token (com.trovebox.android.common.model.Token)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)2 Parcel (android.os.Parcel)1 Photo (com.trovebox.android.common.model.Photo)1 PhotosResponse (com.trovebox.android.common.net.PhotosResponse)1 TokenResponse (com.trovebox.android.common.net.TokenResponse)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 ClientProtocolException (org.apache.http.client.ClientProtocolException)1