Mercurial > hg > Members > nobuyasu > Consensus
view test/RequestTest.java @ 21:e113f946c9c1
modified getUserClaims
author | one |
---|---|
date | Tue, 02 Oct 2012 22:55:16 +0900 |
parents | 34ea98c5a18c |
children | 6506b8742343 |
line wrap: on
line source
import javax.ws.rs.core.MediaType; import models.NodeModel; import org.json.JSONException; import org.json.JSONObject; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; public class RequestTest { final static String SERVER_ROOT_URI = "http://localhost:9000"; public static void main(String[] args) throws JSONException { String user1 = "akifumi"; String user2 = "takaaki"; String user3 = "yosiaki"; createUser(user1); createUser(user2); createUser(user3); /* getUser("akifumi"); getUserInfo("akifumi","claims/"); getUserInfo("akifumi","consensus/"); */ String[] users = {user2,user3}; // createClaim(user1, users); // createClaim(user1, users); getUserInfo(user2,"requests/"); getUserInfo(user3,"requests/"); getUserInfo(user1,"claims/"); getUserInfo(user2,"claims/"); getUserInfo(user3,"claims/"); } public static void createClaim(String author, String[] users) throws JSONException { JSONObject toulmin = new JSONObject(); toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。"); toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。"); toulmin.put(NodeModel.QUALIFIER, "絶対"); toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc..."); toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc..."); toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc..."); toulmin.put(NodeModel.REBUTTLE,""); JSONObject jobj = new JSONObject(); jobj.put(NodeModel.TOULMIN, toulmin); jobj.put(NodeModel.L_AUTHOR, author); jobj.put(NodeModel.USERS,users); jobj.put(NodeModel.TYPE, "unanimously"); final String uri = SERVER_ROOT_URI + "/claims/create"; WebResource resource = Client.create().resource(uri); ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON) .entity(jobj.toString()) .post(ClientResponse.class); System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus())); System.out.println(response.getEntity(String.class)); } public static void getUserInfo(String name, String preUri) { final String uri = SERVER_ROOT_URI + "/users/"+preUri+name; WebResource resource = Client.create().resource(uri); ClientResponse response = resource.get(ClientResponse.class); System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus())); System.out.println(response.getEntity(String.class)); } public static void createUser(String name) { final String uri = SERVER_ROOT_URI + "/users/create/"+name; WebResource resource = Client.create().resource(uri); ClientResponse response = resource.put(ClientResponse.class); System.out.println(String.format("PUT on [%s], status code [%d]", uri, response.getStatus())); System.out.println(response.getEntity(String.class)); } public static void getUser(String name) { final String uri = SERVER_ROOT_URI + "/users/browse/"+name; WebResource resource = Client.create().resource(uri); ClientResponse response = resource.get(ClientResponse.class); System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus())); System.out.println(response.getEntity(String.class)); } public static void postName() throws JSONException { final String uri = SERVER_ROOT_URI + "/hello"; WebResource resource = Client.create().resource(uri); JSONObject jobj = new JSONObject(); jobj.put("name","taro"); // ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON) .entity(jobj.toString()) .post(ClientResponse.class); System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus())); System.out.println(response.getEntity(String.class)); } }