Mercurial > hg > Members > nobuyasu > Consensus
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 |
rev | line source |
---|---|
15 | 1 import javax.ws.rs.core.MediaType; |
2 | |
16 | 3 import models.NodeModel; |
4 | |
15 | 5 import org.json.JSONException; |
6 import org.json.JSONObject; | |
7 | |
8 import com.sun.jersey.api.client.Client; | |
9 import com.sun.jersey.api.client.ClientResponse; | |
10 import com.sun.jersey.api.client.WebResource; | |
11 | |
12 | |
13 public class RequestTest { | |
14 final static String SERVER_ROOT_URI = "http://localhost:9000"; | |
15 | |
16 public static void main(String[] args) throws JSONException { | |
20 | 17 String user1 = "akifumi"; |
18 String user2 = "takaaki"; | |
19 String user3 = "yosiaki"; | |
15 | 20 |
20 | 21 createUser(user1); |
22 createUser(user2); | |
23 createUser(user3); | |
22 | 24 |
20 | 25 String[] users = {user2,user3}; |
22 | 26 createClaim(user1, users); |
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 | 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 | 48 /* |
22 | 49 getUser(user1); |
23 | 50 getUserInfo(user2,"claims/"); |
51 */ | |
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 | 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 | 56 getUserInfo(user3,"consensus/"); |
20 | 57 |
15 | 58 } |
59 | |
18 | 60 public static void createClaim(String author, String[] users) throws JSONException { |
15 | 61 JSONObject toulmin = new JSONObject(); |
16 | 62 toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。"); |
63 toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。"); | |
64 toulmin.put(NodeModel.QUALIFIER, "絶対"); | |
65 toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc..."); | |
66 toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc..."); | |
67 toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc..."); | |
68 toulmin.put(NodeModel.REBUTTLE,""); | |
69 | |
15 | 70 JSONObject jobj = new JSONObject(); |
16 | 71 jobj.put(NodeModel.TOULMIN, toulmin); |
18 | 72 jobj.put(NodeModel.L_AUTHOR, author); |
16 | 73 jobj.put(NodeModel.USERS,users); |
74 jobj.put(NodeModel.TYPE, "unanimously"); | |
75 | |
76 final String uri = SERVER_ROOT_URI + "/claims/create"; | |
77 WebResource resource = Client.create().resource(uri); | |
78 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON) | |
79 .entity(jobj.toString()) | |
80 .post(ClientResponse.class); | |
81 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus())); | |
82 System.out.println(response.getEntity(String.class)); | |
83 | |
15 | 84 } |
85 | |
86 public static void getUserInfo(String name, String preUri) { | |
87 final String uri = SERVER_ROOT_URI + "/users/"+preUri+name; | |
88 WebResource resource = Client.create().resource(uri); | |
89 ClientResponse response = resource.get(ClientResponse.class); | |
90 System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus())); | |
91 System.out.println(response.getEntity(String.class)); | |
92 } | |
93 | |
94 public static void createUser(String name) { | |
95 final String uri = SERVER_ROOT_URI + "/users/create/"+name; | |
96 WebResource resource = Client.create().resource(uri); | |
97 ClientResponse response = resource.put(ClientResponse.class); | |
98 System.out.println(String.format("PUT on [%s], status code [%d]", uri, response.getStatus())); | |
99 System.out.println(response.getEntity(String.class)); | |
100 | |
101 } | |
102 | |
103 public static void getUser(String name) { | |
104 final String uri = SERVER_ROOT_URI + "/users/browse/"+name; | |
105 WebResource resource = Client.create().resource(uri); | |
106 ClientResponse response = resource.get(ClientResponse.class); | |
107 System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus())); | |
108 System.out.println(response.getEntity(String.class)); | |
109 } | |
110 | |
111 | |
112 public static void postName() throws JSONException { | |
113 final String uri = SERVER_ROOT_URI + "/hello"; | |
114 WebResource resource = Client.create().resource(uri); | |
115 JSONObject jobj = new JSONObject(); | |
116 jobj.put("name","taro"); | |
117 // ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) | |
118 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON) | |
119 .entity(jobj.toString()) | |
120 .post(ClientResponse.class); | |
121 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus())); | |
122 System.out.println(response.getEntity(String.class)); | |
123 | |
124 } | |
125 | |
126 | |
127 | |
128 } |