Преглед на файлове

setter to inject mock URL

Trinh Tong преди 6 години
родител
ревизия
b0423dca78

+ 3
- 3
Client/src/main/java/SimpleShell.java Целия файл

@@ -1,6 +1,6 @@
1
-import idtest.IdController;
2
-import messagetest.MessageController;
3
-import messagetest.SendController;
1
+import id.IdController;
2
+import message.MessageController;
3
+import message.SendController;
4 4
 import shellutilities.YouAreEll;
5 5
 
6 6
 import java.io.BufferedReader;

Client/src/main/java/idtest/Id.java → Client/src/main/java/id/Id.java Целия файл

@@ -1,4 +1,4 @@
1
-package idtest;
1
+package id;
2 2
 
3 3
 public class Id {
4 4
     public String userid, name, github;

Client/src/main/java/idtest/IdController.java → Client/src/main/java/id/IdController.java Целия файл

@@ -1,18 +1,18 @@
1
-package idtest;
1
+package id;
2 2
 
3 3
 import shellutilities.Console;
4 4
 import shellutilities.RequestType;
5 5
 import shellutilities.YouAreEll;
6 6
 
7
-import java.io.IOException;
8
-
9 7
 public class IdController {
8
+
10 9
     private YouAreEll url;
11 10
     private final String MAIN_URL = "/ids";
12 11
     private Console c;
13 12
     private String[] userLine;
14 13
     private int size;
15 14
 
15
+
16 16
     public IdController(String [] cmds) {
17 17
         c = new Console();
18 18
         url = new YouAreEll();
@@ -20,12 +20,14 @@ public class IdController {
20 20
         size = cmds.length;
21 21
     }
22 22
 
23
-    public void idController() throws IOException {
23
+    public void setUrl(YouAreEll url) {
24
+        this.url = url;
25
+    }
26
+
27
+    public void idController() {
24 28
 
25 29
         if (size > 1) {
26
-            Id tempId = idCreator(getSpecificId(userLine[2]).replaceAll("^\"|\"$", ""),
27
-                    userLine[1],
28
-                    userLine[2]);
30
+            Id tempId = idCreator();
29 31
 
30 32
             if (!idExists(userLine[2])) {
31 33
                 c.print("Putting updated entry");
@@ -38,33 +40,33 @@ public class IdController {
38 40
         } else {
39 41
             try {
40 42
                 PrettyPrintId.prettyPrintJsonArray(get_ids());
41
-            } catch (IOException e) {
43
+            } catch (Exception e) {
42 44
                 c.print("Could not gather Id's try again?");
43 45
             }
44 46
         }
45 47
     }
46 48
 
47
-    public boolean idExists(String github) throws IOException {
49
+    public boolean idExists(String github) {
48 50
         return (getSpecificId(github).equals(""));
49 51
     }
50 52
 
51
-    public static Id idCreator(String id, String name, String github) {
52
-        return new Id(id, name, github);
53
+    public  Id idCreator() {
54
+        return new Id("", userLine[1], userLine[2]);
53 55
     }
54 56
 
55
-    private String get_ids() throws IOException {
57
+    private String get_ids() {
56 58
         return url.MakeURLCall(MAIN_URL, RequestType.GET, "");
57 59
     }
58 60
 
59
-    private String getSpecificId(String github) throws IOException {
61
+    private String getSpecificId(String github){
60 62
         return url.MakeURLCall(MAIN_URL + "/" + github, RequestType.GET, "");
61 63
     }
62 64
 
63
-    private String post_id(String payload) throws IOException {
65
+    private String post_id(String payload) {
64 66
         return url.MakeURLCall(MAIN_URL, RequestType.POST, payload);
65 67
     }
66 68
 
67
-    private String put_id(String payload) throws IOException {
69
+    private String put_id(String payload) {
68 70
         return url.MakeURLCall(MAIN_URL, RequestType.PUT, payload);
69 71
     }
70 72
 

Client/src/main/java/idtest/PrettyPrintId.java → Client/src/main/java/id/PrettyPrintId.java Целия файл

@@ -1,4 +1,4 @@
1
-package idtest;
1
+package id;
2 2
 
3 3
 import com.fasterxml.jackson.core.type.TypeReference;
4 4
 import com.fasterxml.jackson.databind.ObjectMapper;

Client/src/main/java/messagetest/Message.java → Client/src/main/java/message/Message.java Целия файл

@@ -1,4 +1,4 @@
1
-package messagetest;
1
+package message;
2 2
 
3 3
 import com.fasterxml.jackson.annotation.JsonIgnore;
4 4
 

Client/src/main/java/messagetest/MessageController.java → Client/src/main/java/message/MessageController.java Целия файл

@@ -1,4 +1,4 @@
1
-package messagetest;
1
+package message;
2 2
 
3 3
 import shellutilities.Console;
4 4
 import shellutilities.RequestType;

Client/src/main/java/messagetest/PrettyPrintMessage.java → Client/src/main/java/message/PrettyPrintMessage.java Целия файл

@@ -1,4 +1,4 @@
1
-package messagetest;
1
+package message;
2 2
 
3 3
 import com.fasterxml.jackson.core.type.TypeReference;
4 4
 import com.fasterxml.jackson.databind.ObjectMapper;

Client/src/main/java/messagetest/SendController.java → Client/src/main/java/message/SendController.java Целия файл

@@ -1,6 +1,6 @@
1
-package messagetest;
1
+package message;
2 2
 
3
-import idtest.IdController;
3
+import id.IdController;
4 4
 import shellutilities.Console;
5 5
 import shellutilities.RequestType;
6 6
 import shellutilities.YouAreEll;
@@ -50,7 +50,7 @@ public class SendController  {
50 50
     private boolean toIdValid() {
51 51
         try {
52 52
             return idCheck.idExists(userLine[userLine.length-1]);
53
-        } catch (IOException e) {
53
+        } catch (Exception e) {
54 54
             return false;
55 55
         }
56 56
     }

Client/src/test/java/idtest/IdControllerTest.java → Client/src/test/java/id/IdControllerTest.java Целия файл

@@ -1,4 +1,4 @@
1
-package idtest;
1
+package id;
2 2
 
3 3
 import static com.github.tomakehurst.wiremock.client.WireMock.*;
4 4
 import static org.testng.Assert.*;
@@ -6,7 +6,6 @@ import static org.testng.Assert.*;
6 6
 import com.github.tomakehurst.wiremock.WireMockServer;
7 7
 import org.apache.http.HttpResponse;
8 8
 import org.apache.http.client.methods.HttpGet;
9
-import org.testng.Assert;
10 9
 import org.testng.annotations.*;
11 10
 import shellutilities.YouAreEll;
12 11
 
@@ -21,10 +20,14 @@ public class IdControllerTest {
21 20
 
22 21
     @BeforeSuite
23 22
     public void beforeAll() {
23
+
24 24
         wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
25 25
         wireMockServer.start();
26 26
         urlClient = new YouAreEll("http://localhost:" + wireMockServer.port());
27 27
 
28
+        ic = new IdController(new String[] {"ids", "dodoname", "dodogit"});
29
+        ic.setUrl(urlClient);
30
+
28 31
     }
29 32
 
30 33
     @AfterSuite
@@ -66,15 +69,18 @@ public class IdControllerTest {
66 69
 
67 70
     @Test
68 71
     public void testIdCreator() {
69
-        String[] commands = new String[] {"ids", "dodoname", "dodogit"};
70 72
 
71 73
         Id testId = new Id("", "dodoname", "dodogit");
72
-        IdController ic = new IdController(commands);
73 74
 
74
-        Id newId = IdController.idCreator("", "dodoname", "dodogit");
75
+        Id newId = ic.idCreator();
75 76
 
76 77
         assertEquals(testId.github, newId.github);
77 78
         assertEquals(testId.name, newId.name);
79
+    }
80
+
81
+    @Test
82
+    public void testGetSpecificIds() {
83
+
78 84
 
79 85
     }
80 86
 }

Client/src/test/java/messagetest/MessageControllerTest.java → Client/src/test/java/message/MessageControllerTest.java Целия файл

@@ -1,4 +1,4 @@
1
-package messagetest;
1
+package message;
2 2
 
3 3
 public class MessageControllerTest {
4 4
 }

+ 4
- 0
Client/src/test/java/message/SendControllerTest.java Целия файл

@@ -0,0 +1,4 @@
1
+package message;
2
+
3
+public class SendControllerTest {
4
+}