import java.io.IOException;
import org.junit.Test;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
public class TestClient {
/** 测试get请求方式 */
@Test
public void testGet() throws IOException {
String url = "http://localhost:8182/test/hello/1001";
ClientResource client = new ClientResource(url);
Representation representation = client.get();// get
System.out.println("*******get测试结果********");
System.out.println(representation.getText());
}
/** 测试post请求方式 */
@Test
public void testPost() throws IOException {
Form form = new Form();
form.add("name", "zhuxun");
form.add("sex", "M");
String url = "http://localhost:8182/test/hello/1001";
ClientResource client = new ClientResource(url);
// 以post方式提交表单
Representation representation = client.post(form); // post
System.out.println("*******post测试结果********");
System.out.println(representation.getText());
}
/** 测试put请求方式 */
@Test
public void testPut() throws IOException {
Form form = new Form();
form.add("name", "zhuxun");
form.add("sex", "M");
String url = "http://localhost:8182/test/hello/1001";
ClientResource client = new ClientResource(url);
// 以post方式提交表单
Representation representation = client.put(form,
MediaType.APPLICATION_JAVA_OBJECT); // put
System.out.println("*******put测试结果********");
System.out.println(representation.getText());
}
/** 测试delete请求方式 */
@Test
public void testDelete() throws IOException {
String url = "http://localhost:8182/test/hello/1001";
ClientResource client = new ClientResource(url);
Representation representation = client.delete();// delete
System.out.println("*******delete测试结果********");
System.out.println(representation.getText());
}
}
客户端测试类
最新推荐文章于 2023-03-24 16:09:13 发布