소스 검색

testing idcontroller

Trinh Tong 6 년 전
부모
커밋
5983cfd85d

+ 9
- 4
Client/src/main/java/message/MessageController.java 파일 보기

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

+ 10
- 5
Client/src/main/java/message/SendController.java 파일 보기

@@ -1,6 +1,7 @@
1 1
 package message;
2 2
 
3 3
 import id.IdController;
4
+import org.apache.http.HttpResponse;
4 5
 import shellutilities.Console;
5 6
 import shellutilities.RequestType;
6 7
 import shellutilities.YouAreEll;
@@ -23,12 +24,16 @@ public class SendController  {
23 24
 
24 25
     }
25 26
 
27
+    public void setUrl(YouAreEll url) {
28
+        this.url = url;
29
+    }
30
+
26 31
     public void sendController() {
27 32
         try {
28 33
             if (size > 3) {
29 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 37
                 } else if (toIdValid()) {
33 38
                     //#### URL: /ids/:mygithubid/from/:friendgithubid
34 39
                 }
@@ -55,11 +60,11 @@ public class SendController  {
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 68
         return url.MakeURLCall("/ids/" + fromId + "/messages", RequestType.POST, payload);
64 69
     }
65 70
 }

+ 0
- 1
Client/src/main/java/shellutilities/YouAreEll.java 파일 보기

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

+ 19
- 6
Client/src/test/java/id/IdControllerTest.java 파일 보기

@@ -44,26 +44,29 @@ public class IdControllerTest {
44 44
     public void getIdsSuccess() throws IOException {
45 45
         String response = new Id("userId", "name", "githubId").toString().replace("\n", "");
46 46
 
47
-        wireMockServer.stubFor(
47
+            wireMockServer.stubFor(
48 48
             get(urlEqualTo("/ids"))
49 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 60
     @Test
59 61
     public void testGetIdFail() throws IOException {
60
-        // No body sent
62
+
61 63
         wireMockServer.stubFor(
62 64
                 get(urlEqualTo("/ids"))
63 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 70
         assertEquals(result.getStatusLine().getStatusCode(), 404);
68 71
     }
69 72
 
@@ -80,7 +83,17 @@ public class IdControllerTest {
80 83
 
81 84
     @Test
82 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
 }