Java tutorial
/* * Copyright 2012-2014 glodon paas All right reserved. This software is the confidential and proprietary information of * glodon paas ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only * in accordance with the terms of the license agreement you entered into with glodon paas. */ package com.glodon.paas.document.api; import static com.glodon.paas.consts.StringConst.*; import static org.junit.Assert.*; import java.net.URLDecoder; import java.util.List; import java.util.Map; import org.apache.http.HttpResponse; import org.apache.http.message.BasicHeader; import org.codehaus.jackson.type.TypeReference; import org.junit.Test; import com.glodon.paas.document.api.bean.File; /** * FileRestAPITest.java?? rest api ut * * @author admin 2013-4-12 ?4:01:15 */ public class PublicRestAPITest extends AbstractDocumentAPITest { @Test public void publishFile() throws Exception { File folder = getFile(simpleCall(createPost("/file/1/2/3?folder")), null); String str = simpleCall(createPost("/public/" + folder.getId())); Map<String, String> map = this.convertString2Obj(str, new TypeReference<Map<String, String>>() { }); assertNotNull(map.get(PUBLIC_TOKEN)); assertNotNull(map.get(RESULT)); folder = getFile(simpleCall(createGet("/file/" + folder.getId() + "?meta")), "meta"); assertTrue(folder.isPubliced()); } @Test public void publicList() throws Exception { List<File> files = getFiles(simpleCall(createGet("/public"))); assertEquals(0, files.size()); this.publishFile(); files = getFiles(simpleCall(createGet("/public"))); assertEquals(1, files.size()); } @Test public void downloadPublicFile() throws Exception { File folder = getFile(simpleCall(createPost("/file/1/2/3?folder")), null); simpleCall(createPost("/public/" + folder.getId())); HttpResponse responseResult = call( createGet("/public/file/download/" + folder.getId(), new BasicHeader("User-Agent", "msie"))); String name = URLDecoder.decode(responseResult.getHeaders("Content-Disposition")[0].toString(), "UTF-8"); assertEquals("Content-Disposition: attachment; filename=\"3.zip\"", name); } @Test public void deletePublicFile() throws Exception { File m1 = getFile(simpleCall(createPost("/file/1?folder")), null); simpleCall(createPost("/public/" + m1.getId())); m1 = getFile(simpleCall(createGet("/file/" + m1.getId() + "?meta")), "meta"); assertTrue(m1.isPubliced()); simpleCall(createDelete("/file/" + m1.getId())); m1 = getFile(simpleCall(createGet("/file/" + m1.getId() + "?meta")), "meta"); assertTrue(m1.isDeleted()); simpleCall(createPut("/file/" + m1.getId() + "?restore")); m1 = getFile(simpleCall(createGet("/file/" + m1.getId() + "?meta")), "meta"); assertFalse(m1.isDeleted()); assertFalse(m1.isPubliced()); } }