diff --git a/.gitignore b/.gitignore
index 0fa8aaa..ae8bf7b 100755
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
+target/
diff --git a/.project b/.project
deleted file mode 100755
index 12fdcaf..0000000
--- a/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- YouAreEll
-
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.m2e.core.maven2Nature
-
-
diff --git a/Client/pom.xml b/Client/pom.xml
index ff427b8..7f267c3 100755
--- a/Client/pom.xml
+++ b/Client/pom.xml
@@ -7,9 +7,33 @@
com.zipcoder.ZipChat
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 11
+ 11
+
+
+
+
4.0.0
Client
-
+
+
+ junit
+ junit
+ RELEASE
+ test
+
+
+ com.google.code.gson
+ gson
+ RELEASE
+
+
\ No newline at end of file
diff --git a/Client/src/main/java/controllers/IdController.java b/Client/src/main/java/controllers/IdController.java
index 77ff160..d68e7ae 100755
--- a/Client/src/main/java/controllers/IdController.java
+++ b/Client/src/main/java/controllers/IdController.java
@@ -2,14 +2,23 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
+import java.util.TreeMap;
import models.Id;
+import views.IdTextView;
+import youareell.Command;
public class IdController {
private HashMap allIds;
- Id myId;
+ Id tmpId;
+
+ private TransactionController tctrl;
+ public IdController(TransactionController tt) {
+ this.tctrl = tt;
+ }
public ArrayList getIds() {
return null;
}
@@ -25,5 +34,13 @@ public Id postId(Id id) {
public Id putId(Id id) {
return null;
}
-
+
+ public void doCommand(Command cmd) {
+ if (cmd.getCmd() == Command.Verb.GETIDS) {
+ List ids = tctrl.getIds();
+ for (int i = 0; i < 10; i++) {
+ System.out.println(new IdTextView(ids.get(i)).toString());
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Client/src/main/java/controllers/MessageController.java b/Client/src/main/java/controllers/MessageController.java
index f9462ed..98bc3cc 100755
--- a/Client/src/main/java/controllers/MessageController.java
+++ b/Client/src/main/java/controllers/MessageController.java
@@ -2,20 +2,38 @@
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import models.Id;
import models.Message;
+import views.IdTextView;
+import views.MessageTextView;
+import youareell.Command;
public class MessageController {
+ private TransactionController tctrl;
+
+ public MessageController(TransactionController tt) {
+ this.tctrl = tt;
+ }
+
private HashSet messagesSeen;
// why a HashSet??
public ArrayList getMessages() {
- return null;
+ return new ArrayList<>(messagesSeen);
}
public ArrayList getMessagesForId(Id Id) {
- return null;
+ ArrayList messages = new ArrayList<>();
+ ArrayList allMessages = getMessages();
+
+ for (Message m : allMessages){
+ if (m.getToid().equals(Id)){
+ messages.add(m);
+ }
+ }
+ return messages;
}
public Message getMessageForSequence(String seq) {
return null;
@@ -27,5 +45,18 @@ public ArrayList getMessagesFromFriend(Id myId, Id friendId) {
public Message postMessage(Id myId, Id toId, Message msg) {
return null;
}
-
+
+ public void doCommand(Command cmd) {
+ if (cmd.getCmd() == Command.Verb.GETMESG) {
+ List msgs = tctrl.getMessages();
+ for (int i = 0; i < 10; i++) {
+ System.out.println(new MessageTextView(msgs.get(i)).toString());
+ }
+ }
+ if (cmd.getCmd() == Command.Verb.POSTMSG) {
+ Message result = tctrl.postMessage(cmd.getArg(1), cmd.getArg(2), cmd.getRest(3));
+ System.out.println(new MessageTextView(result).toString());
+ }
+
+ }
}
\ No newline at end of file
diff --git a/Client/src/main/java/controllers/ServerController.java b/Client/src/main/java/controllers/ServerController.java
index 9a03699..6840ad9 100755
--- a/Client/src/main/java/controllers/ServerController.java
+++ b/Client/src/main/java/controllers/ServerController.java
@@ -1,32 +1,35 @@
-import spiffyUrlManipulator
+package controllers;
-public class ServerController() {
+
+
+// Maybe I don't need this.
+public class ServerController {
private String rootURL = "http://zipcode.rocks:8085";
private ServerController svr = new ServerController();
private ServerController() {}
- public static shared() {
+ public ServerController shared() {
return svr;
}
- public JsonString idGet() {
- // url -> /ids/
- // send the server a get with url
- // return json from server
- }
- public JsonString idPost(Id) {
- // url -> /ids/
- // create json from Id
- // request
- // reply
- // return json
- }
- public JsonString idPut(Id) {
- // url -> /ids/
- }
-
+// public JsonString idGet() {
+// // url -> /ids/
+// // send the server a get with url
+// // return json from server
+// }
+// public JsonString idPost(Id) {
+// // url -> /ids/
+// // create json from Id
+// // request
+// // reply
+// // return json
+// }
+// public JsonString idPut(Id) {
+// // url -> /ids/
+// }
+//
}
diff --git a/Client/src/main/java/controllers/TransactionController.java b/Client/src/main/java/controllers/TransactionController.java
index fc47c58..8c7d65c 100755
--- a/Client/src/main/java/controllers/TransactionController.java
+++ b/Client/src/main/java/controllers/TransactionController.java
@@ -1,22 +1,131 @@
package controllers;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
import models.Id;
+import models.Message;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
public class TransactionController {
private String rootURL = "http://zipcode.rocks:8085";
- private MessageController msgCtrl;
- private IdController idCtrl;
+ private HttpClient client = HttpClient.newHttpClient();
- public TransactionController(MessageController m, IdController j) {}
+
+ public TransactionController() {}
+
+ public String getIdsString() { //public List getIds() {
+ try {
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(new URI(rootURL+"/ids"))
+ .GET()
+ .build();
+ HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ return ""+response.body();
+ } catch (URISyntaxException | IOException | InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
public List getIds() {
+ String idsstring = this.getIdsString();
+ Gson gson = new Gson();
+ Type listType = new TypeToken>() {}.getType();
+ List idList = new Gson().fromJson(idsstring, listType);
+ return idList;
+ }
+ public List getMessages() {
+ String msgstring = this.getMessagesString();
+ Gson gson = new Gson();
+ Type listType = new TypeToken>() {}.getType();
+ List msgList = new Gson().fromJson(msgstring, listType);
+ return msgList;
+ }
+ public String getMessagesString() { //public List getIds() {
+ try {
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(new URI(rootURL+"/messages"))
+ .GET()
+ .build();
+ HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ return ""+response.body();
+ } catch (URISyntaxException | IOException | InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Id postId(String name, String ghname) {
+ try {
+ Id newID = new Id(name,ghname);
+ Gson gson = new Gson();
+ String toSendId = gson.toJson(newID);
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(new URI(rootURL+"/ids"))
+ .POST(HttpRequest.BodyPublishers.ofString(toSendId))
+ .setHeader("Content-type", "application/json")
+ .build();
+ HttpResponse response = null;
+ response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ if (response.statusCode() == 200) {
+ System.out.println("After POST " + response.body());
+
+ newID = gson.fromJson("" + response.body(), Id.class);
+ return newID;
+ } else {
+ System.out.println("Failure of POST" + response.statusCode());
+ }
+
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ return new Id("failllll!!!","codeNoWork!!!!");
}
- public String postId(String idtoRegister, String githubName) {
- Id tid = new Id(idtoRegister, githubName);
- tid = idCtrl.postId(tid);
- return ("Id registered.");
+
+ public Message postMessage(String toHandle, String fromHandle, String messageBody) {
+ // well no, you do need to do *some* coding.
+ try {
+ Message newMsg = new Message(messageBody,fromHandle,toHandle);
+ Gson gson = new Gson();
+
+ String toSendId = gson.toJson(newMsg);
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(new URI(rootURL+"/ids/"+fromHandle+"/messages"))
+ .POST(HttpRequest.BodyPublishers.ofString(toSendId))
+ .setHeader("Content-type", "application/json")
+ .build();
+ HttpResponse response = null;
+ response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ if (response.statusCode() == 200) {
+ System.out.println("After POST " + response.body());
+
+ newMsg = gson.fromJson("" + response.body(), Message.class);
+ return newMsg;
+ } else {
+ System.out.println("Failure of POST" + response.statusCode());
+ System.out.println("Error: "+response.toString());
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+
+ return new Message("huh?", "what?", "zyzzy!!");
}
}
diff --git a/Client/src/main/java/models/Id.java b/Client/src/main/java/models/Id.java
index 3837d59..0370232 100755
--- a/Client/src/main/java/models/Id.java
+++ b/Client/src/main/java/models/Id.java
@@ -1,6 +1,6 @@
package models;
-/*
+/*
* POJO for an Id object
*/
public class Id {
@@ -8,7 +8,10 @@ public class Id {
private String name = "";
private String github = "";
- public Id (String name, String githubId) {}
+ public Id (String name, String githubId) {
+ this.name = name;
+ this.github = githubId;
+ }
public String getUid() {
return uid;
@@ -38,4 +41,4 @@ public void setGithub(String github) {
public String toString() {
return this.name + " (" + this.github + ") ";
}
-}
\ No newline at end of file
+}
diff --git a/Client/src/main/java/models/Message.java b/Client/src/main/java/models/Message.java
index 51db326..48dad12 100755
--- a/Client/src/main/java/models/Message.java
+++ b/Client/src/main/java/models/Message.java
@@ -13,33 +13,33 @@
*
*/
-public class Message implements Comparable {
+public class Message { //implements Comparable {
private String message = "";
- private String toId = "";
- private String fromId = "";
- private String timestamp = "";
- private String seqId = "";
+ private String toid = "";
+ private String fromid = "";
+ private transient String timestamp = "-";
+ private transient String sequence = "-";
public Message (String message, String fromId, String toId) {
this.message = message;
- this.fromId = fromId;
- this.toId = toId;
+ this.fromid = fromId;
+ this.toid = toId;
}
public Message (String message, String fromId) {
this.message = message;
- this.fromId = fromId;
- this.toId = "";
+ this.fromid = fromId;
+ this.toid = "";
}
@Override
public String toString() {
- return "to: " + this.toId + "\nfrom: "+ this.fromId + "\n" + this.message + "\n----\n";
+ return "to: " + this.toid + ", from: "+ this.fromid + ", " + this.message + ";";
}
- public int compareTo(Object o) {
- return this.seqId.compareTo(((Message) o).getSeqId());
+ public int compareTo(Message o) {
+ return this.sequence.compareTo(o.getSequence());
}
public String getMessage() {
@@ -50,27 +50,27 @@ public void setMessage(String message) {
this.message = message;
}
- public String getToId() {
- return toId;
+ public String getToid() {
+ return toid;
}
- public void setToId(String toId) {
- this.toId = toId;
+ public void setToid(String toid) {
+ this.toid = toid;
}
public String getFromId() {
- return fromId;
+ return fromid;
}
public void setFromId(String fromId) {
- this.fromId = fromId;
+ this.fromid = fromId;
}
public String getTimestamp() {
return timestamp;
}
- public String getSeqId() {
- return seqId;
+ public String getSequence() {
+ return sequence;
}
}
\ No newline at end of file
diff --git a/Client/src/main/java/views/MessageTextView.java b/Client/src/main/java/views/MessageTextView.java
index 5945f01..2a7a2cc 100755
--- a/Client/src/main/java/views/MessageTextView.java
+++ b/Client/src/main/java/views/MessageTextView.java
@@ -1,9 +1,15 @@
package views;
+import models.Id;
import models.Message;
public class MessageTextView {
- public String toString(Message m) {
- return m.toString();
+ private Message msg;
+ public MessageTextView(Message msgToDisplay) {
+ this.msg = msgToDisplay;
+ }
+
+ public String toString() {
+ return this.msg.toString();
}
}
\ No newline at end of file
diff --git a/Client/src/main/java/views/SimpleShell.java b/Client/src/main/java/views/SimpleShell.java
index 2b0c362..8908905 100755
--- a/Client/src/main/java/views/SimpleShell.java
+++ b/Client/src/main/java/views/SimpleShell.java
@@ -14,119 +14,119 @@
// Simple Shell is a Console view for youareell.YouAreEll.
public class SimpleShell {
-
- public static void prettyPrint(String output) {
- // yep, make an effort to format things nicely, eh?
- System.out.println(output);
- }
- public static void main(String[] args) throws java.io.IOException {
-
- YouAreEll urll = new YouAreEll(new MessageController(), new IdController());
-
- String commandLine;
- BufferedReader console = new BufferedReader
- (new InputStreamReader(System.in));
-
- ProcessBuilder pb = new ProcessBuilder();
- List history = new ArrayList();
- int index = 0;
- //we break out with
- while (true) {
- //read what the user enters
- System.out.println("cmd? ");
- commandLine = console.readLine();
-
- //input parsed into array of strings(command and arguments)
- String[] commands = commandLine.split(" ");
- List list = new ArrayList();
-
- //if the user entered a return, just loop again
- if (commandLine.equals(""))
- continue;
- if (commandLine.equals("exit")) {
- System.out.println("bye!");
- break;
- }
-
- //loop through to see if parsing worked
- for (int i = 0; i < commands.length; i++) {
- //System.out.println(commands[i]); //***check to see if parsing/split worked***
- list.add(commands[i]);
-
- }
- System.out.print(list); //***check to see if list was added correctly***
- history.addAll(list);
- try {
- //display history of shell with index
- if (list.get(list.size() - 1).equals("history")) {
- for (String s : history)
- System.out.println((index++) + " " + s);
- continue;
- }
-
- // Specific Commands.
-
- // ids
- if (list.contains("ids")) {
- String results = webber.get_ids();
- SimpleShell.prettyPrint(results);
- continue;
- }
-
- // messages
- if (list.contains("messages")) {
- String results = webber.get_messages();
- SimpleShell.prettyPrint(results);
- continue;
- }
- // you need to add a bunch more.
-
- //!! command returns the last command in history
- if (list.get(list.size() - 1).equals("!!")) {
- pb.command(history.get(history.size() - 2));
-
- }//! command
- else if (list.get(list.size() - 1).charAt(0) == '!') {
- int b = Character.getNumericValue(list.get(list.size() - 1).charAt(1));
- if (b <= history.size())//check if integer entered isn't bigger than history size
- pb.command(history.get(b));
- } else {
- pb.command(list);
- }
-
- // // wait, wait, what curiousness is this?
- // Process process = pb.start();
-
- // //obtain the input stream
- // InputStream is = process.getInputStream();
- // InputStreamReader isr = new InputStreamReader(is);
- // BufferedReader br = new BufferedReader(isr);
-
- // //read output of the process
- // String line;
- // while ((line = br.readLine()) != null)
- // System.out.println(line);
- // br.close();
-
-
- }
-
- //catch ioexception, output appropriate message, resume waiting for input
- catch (IOException e) {
- System.out.println("Input Error, Please try again!");
- }
- // So what, do you suppose, is the meaning of this comment?
- /** The steps are:
- * 1. parse the input to obtain the command and any parameters
- * 2. create a ProcessBuilder object
- * 3. start the process
- * 4. obtain the output stream
- * 5. output the contents returned by the command
- */
-
- }
-
-
- }
+//
+// public static void prettyPrint(String output) {
+// // yep, make an effort to format things nicely, eh?
+// System.out.println(output);
+// }
+// public static void main(String[] args) throws java.io.IOException {
+//
+// YouAreEll urll = new YouAreEll(new MessageController(), new IdController());
+//
+// String commandLine;
+// BufferedReader console = new BufferedReader
+// (new InputStreamReader(System.in));
+//
+// ProcessBuilder pb = new ProcessBuilder();
+// List history = new ArrayList();
+// int index = 0;
+// //we break out with
+// while (true) {
+// //read what the user enters
+// System.out.println("cmd? ");
+// commandLine = console.readLine();
+//
+// //input parsed into array of strings(command and arguments)
+// String[] commands = commandLine.split(" ");
+// List list = new ArrayList();
+//
+// //if the user entered a return, just loop again
+// if (commandLine.equals(""))
+// continue;
+// if (commandLine.equals("exit")) {
+// System.out.println("bye!");
+// break;
+// }
+//
+// //loop through to see if parsing worked
+// for (int i = 0; i < commands.length; i++) {
+// //System.out.println(commands[i]); //***check to see if parsing/split worked***
+// list.add(commands[i]);
+//
+// }
+// System.out.print(list); //***check to see if list was added correctly***
+// history.addAll(list);
+// try {
+// //display history of shell with index
+// if (list.get(list.size() - 1).equals("history")) {
+// for (String s : history)
+// System.out.println((index++) + " " + s);
+// continue;
+// }
+//
+// // Specific Commands.
+//
+// // ids
+// if (list.contains("ids")) {
+// String results = webber.get_ids();
+// SimpleShell.prettyPrint(results);
+// continue;
+// }
+//
+// // messages
+// if (list.contains("messages")) {
+// String results = webber.get_messages();
+// SimpleShell.prettyPrint(results);
+// continue;
+// }
+// // you need to add a bunch more.
+//
+// //!! command returns the last command in history
+// if (list.get(list.size() - 1).equals("!!")) {
+// pb.command(history.get(history.size() - 2));
+//
+// }//! command
+// else if (list.get(list.size() - 1).charAt(0) == '!') {
+// int b = Character.getNumericValue(list.get(list.size() - 1).charAt(1));
+// if (b <= history.size())//check if integer entered isn't bigger than history size
+// pb.command(history.get(b));
+// } else {
+// pb.command(list);
+// }
+//
+// // // wait, wait, what curiousness is this?
+// // Process process = pb.start();
+//
+// // //obtain the input stream
+// // InputStream is = process.getInputStream();
+// // InputStreamReader isr = new InputStreamReader(is);
+// // BufferedReader br = new BufferedReader(isr);
+//
+// // //read output of the process
+// // String line;
+// // while ((line = br.readLine()) != null)
+// // System.out.println(line);
+// // br.close();
+//
+//
+// }
+//
+// //catch ioexception, output appropriate message, resume waiting for input
+// catch (IOException e) {
+// System.out.println("Input Error, Please try again!");
+// }
+// // So what, do you suppose, is the meaning of this comment?
+// /** The steps are:
+// * 1. parse the input to obtain the command and any parameters
+// * 2. create a ProcessBuilder object
+// * 3. start the process
+// * 4. obtain the output stream
+// * 5. output the contents returned by the command
+// */
+//
+// }
+//
+//
+// }
}
\ No newline at end of file
diff --git a/Client/src/main/java/youareell/Command.java b/Client/src/main/java/youareell/Command.java
new file mode 100644
index 0000000..685bbaf
--- /dev/null
+++ b/Client/src/main/java/youareell/Command.java
@@ -0,0 +1,139 @@
+package youareell;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+// Command read in string and then interprets the string for the controllers to handle.
+public class Command {
+
+ public enum Verb {
+ POSTID("postid"),
+ GETIDS("getids"),
+ GETMESG("messages"),
+ POSTMSG("send"),
+ // you may need to add more here...
+ // for more commands
+ MYMSGS("mymessages"),
+ QUIT("quit"),
+ HELP("help"),
+ ERR("error"),
+ NOOP("");
+
+ public final String str;
+
+ Verb(String str) {
+ this.str = str;
+ }
+
+ private static final Map ENUM_MAP;
+
+ public String getString() {
+ return this.str;
+ }
+
+ // Build an immutable map of String name to enum pairs.
+ // Any Map impl can be used.
+
+ static {
+ Map map = new ConcurrentHashMap();
+ for (Verb instance : Verb.values()) {
+ map.put(instance.getString().toLowerCase(),instance);
+ }
+ ENUM_MAP = Collections.unmodifiableMap(map);
+ }
+
+ public static Verb get (String name) {
+ return ENUM_MAP.getOrDefault(name.toLowerCase(), Verb.ERR);
+ }
+
+ }
+ private static BufferedReader reader = new BufferedReader(
+ new InputStreamReader(System.in));
+
+ // Reading data using readLine
+ public static Command getCommand(String prompt) {
+ while (true) { //infinite loop! (because we stay here until valid command or QUIT
+ try {
+ System.out.println(prompt);
+ String inputFromUser = reader.readLine();
+ Command cmd = new Command();
+ cmd.interpret(inputFromUser);
+ return cmd; // jump out of loop
+ } catch (IOException e) {
+ System.out.println("command error, try again.");
+ }
+ }
+ }
+
+ private Verb currentCmd = Verb.NOOP;
+ private String[] tokens;
+ public String getArg(int idx) {
+ if (idx > tokens.length) {
+ return null;
+ }
+ return tokens[idx];
+ }
+ public String getRest(int idx) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = idx; i < tokens.length; i++) {
+ sb.append(tokens[i]);
+ sb.append(" ");
+ }
+ return sb.toString();
+ }
+
+ public Command() {}
+ private Command(Verb v) { this.currentCmd = v;}
+
+ public Command interpret(String s) {
+ System.out.println("interpreting ["+s+"]");
+
+ tokens = s.split(" ");
+ Verb verb = Verb.get(tokens[0]);
+ this.currentCmd = verb;
+ return this;
+ }
+
+ private Command noOp() {
+ this.currentCmd = Verb.NOOP;
+ return this;
+ }
+
+ public Command.Verb getCmd() {
+ return this.currentCmd;
+ }
+ public boolean isIdCmd() {
+ // as you add ENUMs, add more to this condition.
+ if (this.currentCmd == Verb.POSTID
+ || this.currentCmd == Verb.GETIDS) return true;
+ return false;
+ }
+
+ public boolean isMsgCmd() {
+ // as you add ENUMs, add more to this condition.
+ if (this.currentCmd == Verb.POSTMSG
+ || this.currentCmd == Verb.GETMESG || this.currentCmd == Verb.MYMSGS) return true;
+ return false;
+ }
+
+ public boolean isHelp() {
+ if (this.currentCmd == Verb.HELP) return true;
+ return false;
+ }
+
+ public void printHelp() {
+ System.out.println("print help? what help where?");
+ }
+
+ public boolean isQuit() {
+ if (this.currentCmd == Verb.QUIT) return true;
+ return false;
+ }
+
+ private class BadCommand extends Exception {
+ }
+}
diff --git a/Client/src/main/java/youareell/YouAreEll.java b/Client/src/main/java/youareell/YouAreEll.java
index f054690..15ce0d5 100755
--- a/Client/src/main/java/youareell/YouAreEll.java
+++ b/Client/src/main/java/youareell/YouAreEll.java
@@ -2,30 +2,58 @@
import controllers.*;
+import javax.swing.*;
+
public class YouAreEll {
TransactionController tt;
+ IdController idctrl;
+ MessageController msgctrl;
- public YouAreEll (TransactionController t) {
- this.tt = t;
+ public YouAreEll (){
+ this.tt = new TransactionController();
+ this.idctrl = new IdController(this.tt);
+ this.msgctrl = new MessageController(this.tt);
}
public static void main(String[] args) {
- // hmm: is this Dependency Injection?
- YouAreEll urlhandler = new YouAreEll(
- new TransactionController(
- new MessageController(), new IdController()
- ));
- System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
- System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
+ YouAreEll shell = new YouAreEll();
+ shell.start();
+ }
+
+ private void start() {
+ this.hello();
+ boolean done = false;
+ while (!done) {
+ Command cmd = Command.getCommand("Z?");
+ if (cmd.isIdCmd()) {
+ this.idctrl.doCommand(cmd);
+ continue;
+ }
+ if (cmd.isMsgCmd()) {
+ this.msgctrl.doCommand(cmd);
+ continue;
+ }
+ if (cmd.isHelp()) {
+ cmd.printHelp();
+ continue;
+ }
+ if (cmd.isQuit()) {
+ done = true;
+ continue;
+ }
+ this.displayErr("Unknown command. Type `help` for examples.");
+ }
+
}
- public String get_ids() {
- return tt.makecall("/ids", "GET", "");
+ private void displayErr(String s) {
+ System.err.println(s);
}
- public String get_messages() {
- return MakeURLCall("/messages", "GET", "");
+ private void hello() {
+ String hellomsg = "Z Client by kyounger.\nhi ya.";
+ System.out.println(hellomsg);
}
diff --git a/Client/src/test/java/controllers/TransactionControllerTest.java b/Client/src/test/java/controllers/TransactionControllerTest.java
new file mode 100644
index 0000000..573c837
--- /dev/null
+++ b/Client/src/test/java/controllers/TransactionControllerTest.java
@@ -0,0 +1,60 @@
+package controllers;
+
+import models.Id;
+import models.Message;
+
+import java.util.List;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+
+public class TransactionControllerTest {
+
+ @org.junit.Test
+ public void testGetIds() {
+ TransactionController tctrl = new TransactionController();
+ String result = tctrl.getIdsString();
+ System.out.println(result);
+ }
+
+ @org.junit.Test
+ public void testGetIdsObjs() {
+ TransactionController tctrl = new TransactionController();
+ List list = tctrl.getIds();
+ System.out.println(list);
+ }
+
+ @org.junit.Test
+ public void testGetMessages() {
+ TransactionController tctrl = new TransactionController();
+ String result = tctrl.getMessagesString();
+ System.out.println(result);
+ }
+
+ @org.junit.Test
+ public void testGetMessageObjs() {
+ TransactionController tctrl = new TransactionController();
+ List list = tctrl.getMessages();
+ System.out.println(list);
+ }
+
+ @org.junit.Test
+ public void testPostId() {
+ TransactionController tctrl = new TransactionController();
+ Id result = tctrl.postId("Bilbo", "TheBilboBaggins");
+ System.out.println(result.toString());
+ }
+
+ @org.junit.Test
+ public void testPostMessage() {
+ TransactionController tctrl = new TransactionController();
+ Message result = tctrl.postMessage("torvalds", "xt0fer", "Can you hear me now?!");
+ System.out.println(result.toString());
+ }
+
+
+// @org.junit.Test
+// public void postId() {
+// }
+}
diff --git a/pom.xml b/pom.xml
deleted file mode 100755
index 60e1a81..0000000
--- a/pom.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 4.0.0
-
- com.zipcoder.ZipChat
- YouAreEll
- pom
- 1.0-SNAPSHOT
-
- Client
-
-
-
-
- com.fasterxml.jackson.core
- jackson-databind
- [2.9.9,)
-
-
-