annotate test/RequestTest.java @ 26:ad7cfb1f9d03

modified checkconsensus
author one
date Wed, 03 Oct 2012 03:52:03 +0900
parents 97b249d9fad1
children e246e0dac9c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
1 import java.lang.reflect.Array;
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
2 import java.util.ArrayList;
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
3 import java.util.Iterator;
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
4
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
5 import javax.ws.rs.core.MediaType;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
6
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
7 import models.NodeModel;
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
8
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
9 import org.json.JSONException;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
10 import org.json.JSONObject;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
11
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
12 import com.sun.jersey.api.client.Client;
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
13 import com.sun.jersey.api.client.ClientHandlerException;
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
14 import com.sun.jersey.api.client.ClientResponse;
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
15 import com.sun.jersey.api.client.UniformInterfaceException;
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
16 import com.sun.jersey.api.client.WebResource;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
17
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
18
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
19 public class RequestTest {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
20 final static String SERVER_ROOT_URI = "http://localhost:9000";
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
21
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
22 public static void main(String[] args) throws JSONException {
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
23 String user1 = "akifumi";
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
24 String user2 = "takaaki";
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
25 String user3 = "yosiaki";
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
26
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
27 createUser(user1);
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
28 createUser(user2);
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
29 createUser(user3);
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
30
26
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
31 String[] users1 = {user2,user3};
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
32 // createClaim(user1, users1);
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
33 String[] users2 = {user2};
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
34 // createClaim(user1, users2);
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
35
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
36
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
37 getUser(user1);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
38 getUserInfo(user1,"claims/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
39
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
40
26
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
41 String[] users3 = {user1};
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
42
26
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
43 createMention(user2, users3, NodeModel.L_QUESTION, "5");
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
44 createMention(user3, users3, NodeModel.L_REFUTATION, "5");
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
45
26
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
46 createMention(user2, users3, NodeModel.L_QUESTION, "10");
ad7cfb1f9d03 modified checkconsensus
one
parents: 25
diff changeset
47 createMention(user3, users3, NodeModel.L_REFUTATION, "10");
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
48
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
49
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
50 getUserInfo(user1,"claims/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
51 getUserInfo(user1,"consensus/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
52 getUserInfo(user1,"requests/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
53
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
54 getUserInfo(user2,"claims/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
55 getUserInfo(user2,"consensus/");
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
56
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
57 getUserInfo(user3,"claims/");
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
58 getUserInfo(user3,"consensus/");
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
59
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
60 /*
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
61 getUserInfo(user3,"requests/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
62 getUserInfo(user3,"claims/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
63 getUserInfo(user2,"consensus/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
64 getUserInfo(user3,"consensus/");
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
65 */
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
66 }
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
67
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
68 public static void createMention(String author, String[] users, String type, Object id) throws JSONException {
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
69 JSONObject jobj = createClaimParameter(author, users);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
70 final String uri = SERVER_ROOT_URI + "/claims/"+type+"/"+id+"/create";
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
71 WebResource resource = Client.create().resource(uri);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
72 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
73 .entity(jobj.toString())
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
74 .post(ClientResponse.class);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
75 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
76 System.out.println(response.getEntity(String.class));
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
77 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
78
18
one
parents: 16
diff changeset
79 public static void createClaim(String author, String[] users) throws JSONException {
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
80 JSONObject jobj = createClaimParameter(author, users);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
81 final String uri = SERVER_ROOT_URI + "/claims/create";
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
82 WebResource resource = Client.create().resource(uri);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
83 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
84 .entity(jobj.toString())
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
85 .post(ClientResponse.class);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
86 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
87 System.out.println(response.getEntity(String.class));
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
88 }
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
89
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
90 public static JSONObject createClaimParameter(String author, String[] users) throws JSONException {
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
91 JSONObject toulmin = new JSONObject();
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
92 toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
93 toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
94 toulmin.put(NodeModel.QUALIFIER, "絶対");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
95 toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
96 toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
97 toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
98 toulmin.put(NodeModel.REBUTTLE,"");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
99
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
100 JSONObject jobj = new JSONObject();
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
101 jobj.put(NodeModel.TOULMIN, toulmin);
18
one
parents: 16
diff changeset
102 jobj.put(NodeModel.L_AUTHOR, author);
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
103 jobj.put(NodeModel.USERS,users);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
104 jobj.put(NodeModel.TYPE, "unanimously");
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
105 return jobj;
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
106
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
107 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
108
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
109 public static void getUserInfo(String name, String preUri) throws ClientHandlerException, UniformInterfaceException, JSONException {
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
110 final String uri = SERVER_ROOT_URI + "/users/"+preUri+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
111 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
112 ClientResponse response = resource.get(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
113 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
114 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
115 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
116
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
117 public static void createUser(String name) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
118 final String uri = SERVER_ROOT_URI + "/users/create/"+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
119 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
120 ClientResponse response = resource.put(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
121 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
122 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
123
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
124 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
125
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
126 public static void getUser(String name) throws ClientHandlerException, UniformInterfaceException, JSONException {
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
127 final String uri = SERVER_ROOT_URI + "/users/browse/"+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
128 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
129 ClientResponse response = resource.get(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
130 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
131 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
132 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
133
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
134
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
135 public static void postName() throws JSONException {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
136 final String uri = SERVER_ROOT_URI + "/hello";
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
137 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
138 JSONObject jobj = new JSONObject();
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
139 jobj.put("name","taro");
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
140 // ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
141 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
142 .entity(jobj.toString())
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
143 .post(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
144 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
145 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
146
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
147 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
148
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
149
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
150
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
151 }