annotate test/RequestTest.java @ 24:81d1d7c7bcde

create getConsensus action. but this action can not test because there is no createMention action.
author one
date Wed, 03 Oct 2012 01:46:43 +0900
parents cad8e054fe4b
children 97b249d9fad1
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);
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
28 /*
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
29 HashSet<Object> set = new HashSet<Object>();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
30 set.add("1");
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
31 set.add("2");
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
32 set.add("3");
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
33 Iterator<Object> iter = set.iterator();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
34 while (iter.hasNext() ) {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
35 Object o = iter.next();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
36 System.out.println("o = "+o);
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
37 }
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
38
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
39 Iterator<Object> iter2 = set.iterator();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
40 while (iter2.hasNext() ) {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
41 Object o = iter2.next();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
42 System.out.println("o = "+o);
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
43 if (set.remove("2")) {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
44 iter2 = set.iterator();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
45 }
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
46 }*/
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
47
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
48 /*
22
6506b8742343 modified getUser
one
parents: 21
diff changeset
49 getUser(user1);
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
50 getUserInfo(user2,"claims/");
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
51 */
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
52
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
53 getUserInfo(user2,"requests/");
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
54 getUserInfo(user3,"requests/");
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
55 // getUserInfo(user3,"claims/");
23
cad8e054fe4b modifying getConsensus action
one
parents: 22
diff changeset
56 getUserInfo(user3,"consensus/");
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
57
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
58 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
59
18
one
parents: 16
diff changeset
60 public static void createClaim(String author, String[] users) throws JSONException {
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
61 JSONObject toulmin = new JSONObject();
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
62 toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
63 toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
64 toulmin.put(NodeModel.QUALIFIER, "絶対");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
65 toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
66 toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
67 toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc...");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
68 toulmin.put(NodeModel.REBUTTLE,"");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
69
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
70 JSONObject jobj = new JSONObject();
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
71 jobj.put(NodeModel.TOULMIN, toulmin);
18
one
parents: 16
diff changeset
72 jobj.put(NodeModel.L_AUTHOR, author);
16
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
73 jobj.put(NodeModel.USERS,users);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
74 jobj.put(NodeModel.TYPE, "unanimously");
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
75
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
76 final String uri = SERVER_ROOT_URI + "/claims/create";
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
77 WebResource resource = Client.create().resource(uri);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
78 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
79 .entity(jobj.toString())
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
80 .post(ClientResponse.class);
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
81 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
82 System.out.println(response.getEntity(String.class));
7cdc9d19834f modified createClaim
one
parents: 15
diff changeset
83
15
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
84 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
85
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
86 public static void getUserInfo(String name, String preUri) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
87 final String uri = SERVER_ROOT_URI + "/users/"+preUri+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
88 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
89 ClientResponse response = resource.get(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
90 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
91 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
92 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
93
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
94 public static void createUser(String name) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
95 final String uri = SERVER_ROOT_URI + "/users/create/"+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
96 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
97 ClientResponse response = resource.put(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
98 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
99 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
100
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
101 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
102
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
103 public static void getUser(String name) {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
104 final String uri = SERVER_ROOT_URI + "/users/browse/"+name;
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
105 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
106 ClientResponse response = resource.get(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
107 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
108 System.out.println(response.getEntity(String.class));
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
109 }
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
110
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
111
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
112 public static void postName() throws JSONException {
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
113 final String uri = SERVER_ROOT_URI + "/hello";
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
114 WebResource resource = Client.create().resource(uri);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
115 JSONObject jobj = new JSONObject();
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
116 jobj.put("name","taro");
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
117 // ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
118 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
119 .entity(jobj.toString())
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
120 .post(ClientResponse.class);
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
121 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
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
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
126
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
127
0adbec4c7091 add jersey libraries and RequestTest.java
one
parents:
diff changeset
128 }