Package com.renren.api.client.services

Source Code of com.renren.api.client.services.PhotoServiceTest

package com.renren.api.client.services;

import java.util.Date;

import junit.framework.Assert;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Test;

import com.renren.api.client.AbstractServiceTest;
import com.renren.api.client.param.impl.AccessToken;

/**
* @author 李勇(yong.li@opi-corp.com) 2011-2-21
*/
public class PhotoServiceTest extends AbstractServiceTest {

    @Test
    public void testUploadURLImg() {
        long albumId = 544843441;
        String fileName = "http://tx.bdimg.com/sys/portraitn/item/b858696d716970616e940d.jpg";
        String desc = "renren by " + new Date() + " url image";
        JSONObject ret = this.getRenrenApiClient().getPhotoService()
            .uploadURLImg(albumId, fileName, desc,new AccessToken(this.getAccessToken()));
        System.out.println("photo:" + ret);
        Assert.assertEquals(albumId, ret.get("aid"));
    }

    @Test
    public void testUploadLocalImg() {
        long albumId = 544843441;
        String fileName = "D:\\test.jpg";
        String desc = "开放平台 javaSDK 测试" + new Date() + " local image";
        JSONObject ret = this.getRenrenApiClient().getPhotoService()
            .uploadLocalImg(albumId, fileName, desc,new AccessToken(this.getAccessToken()));
        System.out.println("photo:" + ret);
        Assert.assertEquals(albumId, ret.get("aid"));
    }

    @Test
    public void testGetAlbums() {
        long uid = 432801017;
        int page = 1;
        int count = 10;
        String aids = "";
        JSONArray albums = this.getRenrenApiClient().getPhotoService()
            .getAlbums(uid, page, count, aids,new AccessToken(this.getAccessToken()));
        System.out.println(albums.size());
        Assert.assertTrue(albums.size() > -1);
    }

    @Test
    public void testGetPhotos() {
        long uid = 432801017;
        String pids = "5369950424,5369843615";
        String password = "123";
        JSONArray photos = this.getRenrenApiClient().getPhotoService()
            .getPhotos(uid, pids, password,new AccessToken(this.getAccessToken()));
        Assert.assertEquals(2, photos.size());
    }
   
    @Test
    public void testGetPhotosByAid(){
        long uid=432801017;
        long aid=544843441;
        int page=1;
        int count=1;
        String password="123";
        JSONArray photos=this.getRenrenApiClient().getPhotoService().getPhotos(uid, aid, page, count, password,new AccessToken(this.getAccessToken()));
        Assert.assertEquals(1, photos.size());
    }
   
    @Test
    public void testAddComments(){
        int type=0;
        long uid=258707479;
        long pid=5361181884L;
        String content="测试评论"+new Date();
        long rid=0;
        int res=this.getRenrenApiClient().getPhotoService().addComment(uid, pid, content, rid, type, PhotoService.IS_PHOTO,new AccessToken(this.getAccessToken()));
        Assert.assertEquals(res, 1);
    }
   
    @Test
    public void testGetComments(){
        long uid=258707479;
        long pid=5361181884L;
        int count=1;
        int page=1;
        JSONArray comments=this.getRenrenApiClient().getPhotoService().getComments(uid, pid, page, count, PhotoService.IS_PHOTO,new AccessToken(this.getAccessToken()));
        System.out.println(comments.get(0));
        Assert.assertEquals(1, comments.size());
    }
   
    @Test
    public void testAddTagById(){
        long owner_id=432801017;
        long photo_id=5369950424L;
        long tagged_user_id=258707479;
        JSONObject json=this.getRenrenApiClient().getPhotoService().addTag(photo_id, owner_id, 600, 670, 5, 5, 590, 660, tagged_user_id,new AccessToken(this.getAccessToken()));
        long res=(Long)((JSONObject)json.get("tag")).get("id");
        System.out.println(res);
        Assert.assertTrue(res>0);
    }
   
    @Test
    public void testAddTagByName(){
        long owner_id=432801017;
        long photo_id=5369950424L;
        String tagged_user_name="测试";
        JSONObject json=this.getRenrenApiClient().getPhotoService().addTag(photo_id, owner_id, 600, 670, 20, 50, 100, 100, tagged_user_name,new AccessToken(this.getAccessToken()));
        long res=(Long)((JSONObject)json.get("tag")).get("id");
        System.out.println(res);
        Assert.assertTrue(res>0);
    }
   
    @Test
    public void testGetTag(){
        long owner_id=432801017;
        long photo_id=5369950424L;
        int page=2;
        int count=10;
        JSONObject json=this.getRenrenApiClient().getPhotoService().getTags(photo_id, owner_id, page, count,new AccessToken(this.getAccessToken()));
        long total=(Long)json.get("count");
        System.out.println(total);
        Assert.assertTrue(total>0);
    }
}
TOP

Related Classes of com.renren.api.client.services.PhotoServiceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.