aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-19 15:02:56 +0300
committerGravatar Vitaly Takmazov2016-12-19 15:02:56 +0300
commit7293d22f1aa731610849a8657b8ae462eb67eee2 (patch)
tree49e36037b6cc09c8c37093a4d34a713803382d7a /src/test/java/com
parent16d02ab9e31cd4a68334575499d039d48a5fb0a9 (diff)
juick-server: drop json part from JuickProtocol reply
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/juick/tests/ApiTests.java51
1 files changed, 17 insertions, 34 deletions
diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java
index f72bcc02..17bcc3db 100644
--- a/src/test/java/com/juick/tests/ApiTests.java
+++ b/src/test/java/com/juick/tests/ApiTests.java
@@ -6,7 +6,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
-import com.juick.json.MessageSerializer;
import com.juick.server.helpers.TagStats;
import com.juick.server.protocol.JuickProtocol;
import com.juick.server.protocol.ProtocolReply;
@@ -18,7 +17,6 @@ import com.juick.service.search.SearchService;
import com.juick.www.PageTemplates;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.lang3.StringEscapeUtils;
-import org.json.JSONArray;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -177,28 +175,27 @@ public class ApiTests {
@Test
public void protocolTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, ParseException, JsonProcessingException {
- MessageSerializer json = new MessageSerializer();
assertEquals("juick user should have uid 2", 2, userService.getUIDbyName("juick"));
int uid = userService.createUser("me", "secret");
User user = userService.getUserByUID(uid).orElse(new User());
String expectedMessage = "New message posted";
assertEquals("should be message", true,
- juickProtocol.getReply(user, "*yo yoyo").getDescription().startsWith(expectedMessage));
+ juickProtocol.getReply(user, "*yo yoyo").getResult().startsWith(expectedMessage));
int mid = messagesService.getUserBlog(user.getUid(), -1, 0).stream().reduce((first, second) -> second).get();
assertEquals("text should match", "yoyo",
messagesService.getMessage(mid).getText());
assertEquals("tag should match", "yo",
tagService.getMessageTags(mid).get(0).getTag().getName());
- assertNotEquals("should not be error", "Error", juickProtocol.getReply(user, "#" + mid).getDescription());
- assertEquals("should be PONG", "PONG", juickProtocol.getReply(user, " ping \n ").getDescription());
+ assertNotEquals("should not be error", "Error", juickProtocol.getReply(user, "#" + mid).getResult());
+ assertEquals("should be PONG", "PONG", juickProtocol.getReply(user, " ping \n ").getResult());
int readerUid = userService.createUser("dummyReader", "dummySecret");
User readerUser = userService.getUserByUID(readerUid).orElse(new User());
assertEquals("should be subscribed", "Subscribed",
- juickProtocol.getReply(readerUser, "S #" + mid).getDescription());
+ juickProtocol.getReply(readerUser, "S #" + mid).getResult());
assertEquals("number of subscribed users should match", 1,
subscriptionService.getUsersSubscribedToComments(mid, uid).size());
assertEquals("should be subscribed", "Subscribed",
- juickProtocol.getReply(readerUser, "S @" + user.getName()).getDescription());
+ juickProtocol.getReply(readerUser, "S @" + user.getName()).getResult());
List<User> friends = userService.getUserFriends(readerUid);
assertEquals("number of friend users should match", 2,
friends.size());
@@ -209,65 +206,51 @@ public class ApiTests {
String expectedSecondReply = "Reply posted.\n#" + mid + "/2 "
+ juickProtocol.getBaseUri() + mid + "/2";
assertEquals("should be reply", expectedReply,
- juickProtocol.getReply(user, "#" + mid + " yoyo").getDescription());
+ juickProtocol.getReply(user, "#" + mid + " yoyo").getResult());
assertEquals("should be second reply", expectedSecondReply,
- juickProtocol.getReply(user, "#" + mid + "/1 yoyo").getDescription());
+ juickProtocol.getReply(user, "#" + mid + "/1 yoyo").getResult());
Message reply = messagesService.getReplies(mid).stream().filter(m -> m.getRid() == 2).findFirst()
.orElse(new Message());
assertEquals("should be reply to first comment", 1, reply.getReplyto());
- String jsonReply = juickProtocol.getReply(user, "#" + mid).getJson().orElse("");
- JSONArray jsonMessages = new JSONArray(jsonReply);
- Message receivedMsg = json.deserialize(jsonMessages.getJSONObject(0));
- assertEquals("json should match text", "yoyo", receivedMsg.getText());
- assertEquals("array length should match", 1, jsonMessages.length());
- jsonReply = juickProtocol.getReply(user, "#" + mid+"+").getJson().orElse("");
- jsonMessages = new JSONArray(jsonReply);
- assertEquals("array length should match", 3, jsonMessages.length());
assertNotEquals("tags should NOT be updated", "Tags are updated",
- juickProtocol.getReply(readerUser, "#" + mid + " *yo *there").getDescription());
+ juickProtocol.getReply(readerUser, "#" + mid + " *yo *there").getResult());
assertEquals("tags should be updated", "Tags are updated",
- juickProtocol.getReply(user, "#" + mid + " *there").getDescription());
+ juickProtocol.getReply(user, "#" + mid + " *there").getResult());
assertEquals("number of tags should match", 2,
tagService.getMessageTags(mid).size());
assertEquals("tags should be updated", "Tags are updated",
- juickProtocol.getReply(user, "#" + mid + " *there").getDescription());
+ juickProtocol.getReply(user, "#" + mid + " *there").getResult());
assertEquals("number of tags should match", 1,
tagService.getMessageTags(mid).size());
int taggerUid = userService.createUser("dummyTagger", "dummySecret");
User taggerUser = userService.getUserByUID(taggerUid).orElse(new User());
assertEquals("should be subscribed", "Subscribed",
- juickProtocol.getReply(taggerUser, "S *yo").getDescription());
+ juickProtocol.getReply(taggerUser, "S *yo").getResult());
assertEquals("number of subscribed users should match", 2,
subscriptionService.getSubscribedUsers(uid, mid).size());
assertEquals("should be unsubscribed", "Unsubscribed from yo",
- juickProtocol.getReply(taggerUser, "U *yo").getDescription());
+ juickProtocol.getReply(taggerUser, "U *yo").getResult());
assertEquals("number of subscribed users should match", 1,
subscriptionService.getSubscribedUsers(uid, mid).size());
assertEquals("number of readers should match", 1,
userService.getUserReaders(uid).size());
ProtocolReply readerFeed = juickProtocol.getReply(readerUser, "#");
- assertEquals("description should match", true, readerFeed.getDescription().startsWith("Your feed"));
- String readerUserFeed = readerFeed.getJson().orElse("");
- JSONArray readerUserFeedMessages = new JSONArray(readerUserFeed);
- assertEquals("messages count should match", 1, readerUserFeedMessages.length());
+ assertEquals("description should match", true, readerFeed.getResult().startsWith("Your feed"));
assertEquals("should be unsubscribed", "Unsubscribed from @" + user.getName(),
- juickProtocol.getReply(readerUser, "U @" + user.getName()).getDescription());
+ juickProtocol.getReply(readerUser, "U @" + user.getName()).getResult());
assertEquals("number of readers should match", 0,
userService.getUserReaders(uid).size());
assertEquals("number of friends should match", 1,
userService.getUserFriends(uid).size());
assertEquals("should be unsubscribed", "Unsubscribed from #" + mid,
- juickProtocol.getReply(readerUser, "u #" + mid).getDescription());
+ juickProtocol.getReply(readerUser, "u #" + mid).getResult());
assertEquals("number of subscribed users should match", 0,
subscriptionService.getUsersSubscribedToComments(mid, uid).size());
assertNotEquals("should NOT be deleted", String.format("Message %s deleted", mid),
- juickProtocol.getReply(readerUser, "D #" + mid).getDescription());
+ juickProtocol.getReply(readerUser, "D #" + mid).getResult());
assertEquals("should be deleted", String.format("Message %s deleted", mid),
- juickProtocol.getReply(user, "D #" + mid).getDescription());
+ juickProtocol.getReply(user, "D #" + mid).getResult());
assertEquals("should not have messages", 0, messagesService.getAll(user.getUid(), 0).size());
- String allFeed = juickProtocol.getReply(readerUser, "#").getJson().orElse("");
- JSONArray allFeedMessages = new JSONArray(allFeed);
- assertEquals("messages count should match", 0, allFeedMessages.length());
}
}