annotate test/RequestTest.java @ 23:cad8e054fe4b

modifying getConsensus action
author one
date Tue, 02 Oct 2012 23:46:55 +0900
parents 6506b8742343
children 81d1d7c7bcde
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
1 import javax.ws.rs.core.MediaType;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
2
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
3 import models.NodeModel;
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
4
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
5 import org.json.JSONException;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
6 import org.json.JSONObject;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
7
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
8 import com.sun.jersey.api.client.Client;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
9 import com.sun.jersey.api.client.ClientResponse;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
10 import com.sun.jersey.api.client.WebResource;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
11
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
12
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
13 public class RequestTest {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
14 final static String SERVER_ROOT_URI = "http://localhost:9000";
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
16 public static void main(String[] args) throws JSONException {
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
17 String user1 = "akifumi";
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
18 String user2 = "takaaki";
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
19 String user3 = "yosiaki";
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
20
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
21 createUser(user1);
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
22 createUser(user2);
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
23 createUser(user3);
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
24
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
25 String[] users = {user2,user3};
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
26 createClaim(user1, users);
6506b8742343 modified getUser
one
parents: 21
diff changeset
27 createClaim(user1, users);
6506b8742343 modified getUser
one
parents: 21
diff changeset
28
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
29 /*
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
30 getUser(user1);
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
31 getUserInfo(user2,"requests/");
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
32 getUserInfo(user2,"claims/");
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
33 */
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
34
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
35 getUserInfo(user3,"requests/");
21
e113f946c9c1 modified getUserClaims
one
parents: 20
diff changeset
36 getUserInfo(user3,"claims/");
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
37 getUserInfo(user3,"consensus/");
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
38
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
39 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
40
18
one
parents: 16
diff changeset
41 public static void createClaim(String author, String[] users) throws JSONException {
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
42 JSONObject toulmin = new JSONObject();
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
43 toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
44 toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
45 toulmin.put(NodeModel.QUALIFIER, "絶対");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
46 toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
47 toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
48 toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
49 toulmin.put(NodeModel.REBUTTLE,"");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
50
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
51 JSONObject jobj = new JSONObject();
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
52 jobj.put(NodeModel.TOULMIN, toulmin);
18
one
parents: 16
diff changeset
53 jobj.put(NodeModel.L_AUTHOR, author);
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
54 jobj.put(NodeModel.USERS,users);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
55 jobj.put(NodeModel.TYPE, "unanimously");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
56
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
57 final String uri = SERVER_ROOT_URI + "/claims/create";
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
58 WebResource resource = Client.create().resource(uri);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
59 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
60 .entity(jobj.toString())
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
61 .post(ClientResponse.class);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
62 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
63 System.out.println(response.getEntity(String.class));
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
64
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
65 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
66
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
67 public static void getUserInfo(String name, String preUri) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
68 final String uri = SERVER_ROOT_URI + "/users/"+preUri+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
69 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
70 ClientResponse response = resource.get(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
71 System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
72 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
73 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
74
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
75 public static void createUser(String name) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
76 final String uri = SERVER_ROOT_URI + "/users/create/"+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
77 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
78 ClientResponse response = resource.put(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
79 System.out.println(String.format("PUT on [%s], status code [%d]", uri, response.getStatus()));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
80 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
81
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
82 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
83
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
84 public static void getUser(String name) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
85 final String uri = SERVER_ROOT_URI + "/users/browse/"+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
86 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
87 ClientResponse response = resource.get(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
88 System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
89 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
90 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
91
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
92
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
93 public static void postName() throws JSONException {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
94 final String uri = SERVER_ROOT_URI + "/hello";
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
95 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
96 JSONObject jobj = new JSONObject();
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
97 jobj.put("name","taro");
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
98 // ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
99 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
100 .entity(jobj.toString())
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
101 .post(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
102 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
103 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
104
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
105 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
106
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
107
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
108
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
109 }