Browse Source

testing idcontroller

Trinh Tong 6 years ago
parent
commit
5983cfd85d

+ 9
- 4
Client/src/main/java/message/MessageController.java View File

1
 package message;
1
 package message;
2
 
2
 
3
+import org.apache.http.HttpResponse;
3
 import shellutilities.Console;
4
 import shellutilities.Console;
4
 import shellutilities.RequestType;
5
 import shellutilities.RequestType;
5
 import shellutilities.YouAreEll;
6
 import shellutilities.YouAreEll;
20
         size = userLine.length;
21
         size = userLine.length;
21
     }
22
     }
22
 
23
 
24
+    public void setUrl(YouAreEll url) {
25
+        this.url = url;
26
+    }
27
+
23
     public void messageController() throws IOException {
28
     public void messageController() throws IOException {
24
         if (size > 1) {
29
         if (size > 1) {
25
             try {
30
             try {
26
-                PrettyPrintMessage.prettyPrintMessageArray(getMessageToId(userLine[1]));
31
+                PrettyPrintMessage.prettyPrintMessageArray(url.readCalls(getMessageToId(userLine[1])));
27
             } catch (NullPointerException nullEx) {
32
             } catch (NullPointerException nullEx) {
28
                 c.print("Not a valid github name.");
33
                 c.print("Not a valid github name.");
29
             }
34
             }
30
             // Get messages for me from friend #### URL: /ids/:mygithubid/from/:friendgithubid
35
             // Get messages for me from friend #### URL: /ids/:mygithubid/from/:friendgithubid
31
             // get messages from sequence #### URL: /ids/:mygithubid/messages/:sequence
36
             // get messages from sequence #### URL: /ids/:mygithubid/messages/:sequence
32
         } else {
37
         } else {
33
-            PrettyPrintMessage.prettyPrintMessageArray(get_messages());
38
+            PrettyPrintMessage.prettyPrintMessageArray(url.readCalls(get_messages()));
34
         }
39
         }
35
     }
40
     }
36
 
41
 
37
-    public String get_messages() throws IOException {
42
+    public HttpResponse get_messages() throws IOException {
38
         return url.MakeURLCall(MAIN_URL, RequestType.GET, "");
43
         return url.MakeURLCall(MAIN_URL, RequestType.GET, "");
39
     }
44
     }
40
 
45
 
41
-    public String getMessageToId(String github) throws IOException {
46
+    public HttpResponse getMessageToId(String github) throws IOException {
42
 //        http://zipcode.rocks:8085/ids/jard/messages
47
 //        http://zipcode.rocks:8085/ids/jard/messages
43
         return url.MakeURLCall("/ids/" + github + MAIN_URL, RequestType.GET, "");
48
         return url.MakeURLCall("/ids/" + github + MAIN_URL, RequestType.GET, "");
44
     }
49
     }

+ 10
- 5
Client/src/main/java/message/SendController.java View File

1
 package message;
1
 package message;
2
 
2
 
3
 import id.IdController;
3
 import id.IdController;
4
+import org.apache.http.HttpResponse;
4
 import shellutilities.Console;
5
 import shellutilities.Console;
5
 import shellutilities.RequestType;
6
 import shellutilities.RequestType;
6
 import shellutilities.YouAreEll;
7
 import shellutilities.YouAreEll;
23
 
24
 
24
     }
25
     }
25
 
26
 
27
+    public void setUrl(YouAreEll url) {
28
+        this.url = url;
29
+    }
30
+
26
     public void sendController() {
31
     public void sendController() {
27
         try {
32
         try {
28
             if (size > 3) {
33
             if (size > 3) {
29
                 if (!toIdValid()) {
34
                 if (!toIdValid()) {
30
-                    PrettyPrintMessage.prettyPrintSingleMessage(postMessage(userLine[1],
31
-                            messageCreator(userLine[1], "", getRawMsg()).toString()));
35
+                    PrettyPrintMessage.prettyPrintSingleMessage(url.readCalls(postMessage(userLine[1],
36
+                            messageCreator().toString())));
32
                 } else if (toIdValid()) {
37
                 } else if (toIdValid()) {
33
                     //#### URL: /ids/:mygithubid/from/:friendgithubid
38
                     //#### URL: /ids/:mygithubid/from/:friendgithubid
34
                 }
39
                 }
55
         }
60
         }
56
     }
61
     }
57
 
62
 
58
-    private Message messageCreator(String fromId, String toId, String message) {
59
-        return new Message("", "", fromId, toId, message);
63
+    private Message messageCreator() {
64
+        return new Message("", "", userLine[1], userLine[userLine.length - 1], getRawMsg());
60
     }
65
     }
61
 
66
 
62
-    private String postMessage(String fromId, String payload) throws IOException {
67
+    private HttpResponse postMessage(String fromId, String payload) throws IOException {
63
         return url.MakeURLCall("/ids/" + fromId + "/messages", RequestType.POST, payload);
68
         return url.MakeURLCall("/ids/" + fromId + "/messages", RequestType.POST, payload);
64
     }
69
     }
65
 }
70
 }

+ 0
- 1
Client/src/main/java/shellutilities/YouAreEll.java View File

39
         try {
39
         try {
40
             switch (req) {
40
             switch (req) {
41
                 case GET:
41
                 case GET:
42
-                    System.out.println("Entering get...");
43
                     return getCall(baseUrl + mainUrl);
42
                     return getCall(baseUrl + mainUrl);
44
 
43
 
45
                 case POST:
44
                 case POST:

+ 19
- 6
Client/src/test/java/id/IdControllerTest.java View File

44
     public void getIdsSuccess() throws IOException {
44
     public void getIdsSuccess() throws IOException {
45
         String response = new Id("userId", "name", "githubId").toString().replace("\n", "");
45
         String response = new Id("userId", "name", "githubId").toString().replace("\n", "");
46
 
46
 
47
-        wireMockServer.stubFor(
47
+            wireMockServer.stubFor(
48
             get(urlEqualTo("/ids"))
48
             get(urlEqualTo("/ids"))
49
                 .willReturn(aResponse().withStatus(200).withBody(response))
49
                 .willReturn(aResponse().withStatus(200).withBody(response))
50
         );
50
         );
51
 
51
 
52
-        HttpResponse result = urlClient.client.execute(new HttpGet(urlClient.baseUrl + "/ids"));
52
+//        HttpResponse result = urlClient.client.execute(new HttpGet(urlClient.baseUrl + "/ids"));
53
 
53
 
54
-        assertEquals(result.getStatusLine().getStatusCode(), 200);
55
-        assertEquals(urlClient.readCalls(result), response);
54
+        HttpResponse output = ic.get_ids();
55
+
56
+        assertEquals(output.getStatusLine().getStatusCode(), 200);
57
+        assertEquals(urlClient.readCalls(output), response);
56
     }
58
     }
57
 
59
 
58
     @Test
60
     @Test
59
     public void testGetIdFail() throws IOException {
61
     public void testGetIdFail() throws IOException {
60
-        // No body sent
62
+
61
         wireMockServer.stubFor(
63
         wireMockServer.stubFor(
62
                 get(urlEqualTo("/ids"))
64
                 get(urlEqualTo("/ids"))
63
                         .willReturn(aResponse().withStatus(404))
65
                         .willReturn(aResponse().withStatus(404))
64
         );
66
         );
65
 
67
 
66
-        HttpResponse result = urlClient.client.execute(new HttpGet(urlClient.baseUrl + "/ids"));
68
+        HttpResponse result = ic.get_ids();
69
+//        HttpResponse result = ic.get_ids();
67
         assertEquals(result.getStatusLine().getStatusCode(), 404);
70
         assertEquals(result.getStatusLine().getStatusCode(), 404);
68
     }
71
     }
69
 
72
 
80
 
83
 
81
     @Test
84
     @Test
82
     public void testGetSpecificIds() {
85
     public void testGetSpecificIds() {
86
+        String response = "nullId";
83
 
87
 
88
+        wireMockServer.stubFor(
89
+                get(urlEqualTo("/ids/githubId"))
90
+                        .willReturn(aResponse().withStatus(200).withBody(response))
91
+        );
92
+
93
+        HttpResponse result =  ic.getSpecificId("githubId");
94
+
95
+        assertEquals(result.getStatusLine().getStatusCode(), 200);
96
+        assertEquals(urlClient.readCalls(result), response);
84
 
97
 
85
     }
98
     }
86
 }
99
 }