From 7293d22f1aa731610849a8657b8ae462eb67eee2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 19 Dec 2016 15:02:56 +0300 Subject: juick-server: drop json part from JuickProtocol reply --- .../com/juick/api/controllers/TelegramWebhook.java | 2 +- .../src/main/java/com/juick/demo/DemoApp.java | 2 +- .../com/juick/server/protocol/JuickProtocol.java | 121 +++++++++------------ .../com/juick/server/protocol/ProtocolReply.java | 17 +-- .../main/java/com/juick/components/XMPPBot.java | 2 +- src/test/java/com/juick/tests/ApiTests.java | 51 +++------ 6 files changed, 75 insertions(+), 120 deletions(-) diff --git a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java index 90929711..22f588e0 100644 --- a/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java +++ b/juick-api/src/main/java/com/juick/api/controllers/TelegramWebhook.java @@ -74,7 +74,7 @@ public class TelegramWebhook { tgBot.telegramNotify(message.from().id().longValue(), msg, msgUrl); } /* else { ProtocolReply reply = protocol.getReply(user_from, text); - telegramNotify(message.from().id().longValue(), reply.getDescription(), null); + telegramNotify(message.from().id().longValue(), reply.getResult(), null); }*/ } } diff --git a/juick-demo/src/main/java/com/juick/demo/DemoApp.java b/juick-demo/src/main/java/com/juick/demo/DemoApp.java index 0c9390dd..ccc86a40 100644 --- a/juick-demo/src/main/java/com/juick/demo/DemoApp.java +++ b/juick-demo/src/main/java/com/juick/demo/DemoApp.java @@ -62,7 +62,7 @@ public class DemoApp { String input; while ((input = reader.readLine()) != null) { ProtocolReply reply = juickProtocol.getReply(ugnich, input); - out.println(reply.getDescription()); + out.println(reply.getResult()); out.flush(); } } catch (IOException | NoSuchMethodException e) { diff --git a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java index 111a434a..6f61e4d6 100644 --- a/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java +++ b/juick-server/src/main/java/com/juick/server/protocol/JuickProtocol.java @@ -11,6 +11,7 @@ import com.juick.server.helpers.TagStats; import com.juick.server.protocol.annotation.UserCommand; import com.juick.service.*; import com.juick.util.TagUtils; +import org.apache.commons.lang3.math.NumberUtils; import javax.inject.Inject; import java.lang.reflect.InvocationTargetException; @@ -88,8 +89,7 @@ public class JuickProtocol { String body = input.substring(TagUtils.toString(tags).length()); int mid = messagesService.createMessage(user.getUid(), body, null, tags); subscriptionService.subscribeMessage(mid, user.getUid()); - return new ProtocolReply("New message posted.\n#" + mid + " " + baseUri + mid, - Optional.of(json.writeValueAsString(Collections.singletonList(messagesService.getMessage(mid))))); + return new ProtocolReply("New message posted.\n#" + mid + " " + baseUri + mid); } @UserCommand(pattern = "^#(\\++)$", help = "#+ - Show last Juick messages (#++ - second page, ...)") @@ -99,7 +99,7 @@ public class JuickProtocol { List mids = messagesService.getAll(user.getUid(), page); List messages = messagesService.getMessages(mids); return new ProtocolReply("Last messages: \n" + String.join("\n", messages.stream().map(PlainTextFormatter::formatPost) - .collect(Collectors.toList())), Optional.of(json.writeValueAsString(messages))); + .collect(Collectors.toList()))); } @UserCommand(pattern = "^\\s*bl\\s*$", patternFlags = Pattern.CASE_INSENSITIVE, @@ -130,7 +130,7 @@ public class JuickProtocol { if (txt.isEmpty()) { txt = "You don't have any users or tags in your blacklist."; } - return new ProtocolReply(txt, Optional.empty()); + return new ProtocolReply(txt); } @UserCommand(pattern = "^bl\\s+@([^\\s\\n\\+]+)", patternFlags = Pattern.CASE_INSENSITIVE, @@ -140,12 +140,12 @@ public class JuickProtocol { if (blUser != null) { PrivacyQueriesService.PrivacyResult result = privacyQueriesService.blacklistUser(from, blUser); if (result == PrivacyQueriesService.PrivacyResult.Added) { - return new ProtocolReply("User added to your blacklist", Optional.empty()); + return new ProtocolReply("User added to your blacklist"); } else { - return new ProtocolReply("User removed from your blacklist", Optional.empty()); + return new ProtocolReply("User removed from your blacklist"); } } - return new ProtocolReply("User not found", Optional.empty()); + return new ProtocolReply("User not found"); } @UserCommand(pattern = "^bl\\s\\*(\\S+)$", patternFlags = Pattern.CASE_INSENSITIVE, @@ -157,13 +157,13 @@ public class JuickProtocol { if (tag != null) { PrivacyQueriesService.PrivacyResult result = privacyQueriesService.blacklistTag(from, tag); if (result == PrivacyQueriesService.PrivacyResult.Added) { - return new ProtocolReply("Tag added to your blacklist", Optional.empty()); + return new ProtocolReply("Tag added to your blacklist"); } else { - return new ProtocolReply("Tag removed from your blacklist", Optional.empty()); + return new ProtocolReply("Tag removed from your blacklist"); } } } - return new ProtocolReply("Tag not found", Optional.empty()); + return new ProtocolReply("Tag not found"); } @UserCommand(pattern = "@", help = "@ - Show recommendations and popular personal blogs") @@ -187,7 +187,7 @@ public class JuickProtocol { } else { msg.append("\nNo top users. Empty DB? ;)"); } - return new ProtocolReply(msg.toString(), Optional.empty()); + return new ProtocolReply(msg.toString()); } @UserCommand(pattern = "\\*", help = "* - Show your tags") @@ -196,7 +196,7 @@ public class JuickProtocol { String msg = "Your tags: (tag - messages)\n" + tags.stream() .map(t -> String.format("\n*%s - %d", t.getTag().getName(), t.getUsageCount())).collect(Collectors.joining()); - return new ProtocolReply(msg, Optional.empty()); + return new ProtocolReply(msg); } @UserCommand(pattern = "!", help = "! - Show your favorite messages") @@ -205,9 +205,9 @@ public class JuickProtocol { if (mids.size() > 0) { List messages = messagesService.getMessages(mids); return new ProtocolReply("Favorite messages: \n" + String.join("\n", messages.stream().map(PlainTextFormatter::formatPost) - .collect(Collectors.toList())), Optional.of(json.writeValueAsString(messages))); + .collect(Collectors.toList()))); } - return new ProtocolReply("No favorite messages, try to \"like\" something ;)", Optional.empty()); + return new ProtocolReply("No favorite messages, try to \"like\" something ;)"); } @UserCommand(pattern = "^\\@([^\\s\\n\\+]+)(\\+?)$", @@ -220,31 +220,25 @@ public class JuickProtocol { List messages = messagesService.getMessages(mids); return new ProtocolReply(String.format("Last messages from @%s:\n%s", arguments[0], String.join("\n", messages.stream() - .map(PlainTextFormatter::formatPost).collect(Collectors.toList()))), - Optional.of(json.writeValueAsString(messages))); + .map(PlainTextFormatter::formatPost).collect(Collectors.toList())))); } - return new ProtocolReply("User not found", Optional.empty()); + return new ProtocolReply("User not found"); } @UserCommand(pattern = "^\\s*d\\s*\\#([0-9]+)\\s*$", patternFlags = Pattern.CASE_INSENSITIVE, help = "D #12345 - delete the message") public ProtocolReply commandDel(User user, String... args) { - try { - int mid = Integer.parseInt(args[0]); - if (messagesService.deleteMessage(user.getUid(), mid)) { - return new ProtocolReply(String.format("Message %s deleted", mid), Optional.empty()); - } - } catch (NumberFormatException e) { - return new ProtocolReply("Error", Optional.empty()); + int mid = NumberUtils.toInt(args[0], 0); + if (messagesService.deleteMessage(user.getUid(), mid)) { + return new ProtocolReply(String.format("Message %s deleted", mid)); } - return new ProtocolReply("Error", Optional.empty()); + return new ProtocolReply("Error"); } @UserCommand(pattern = "^\\s*login\\s*$", patternFlags = Pattern.CASE_INSENSITIVE, help = "LOGIN - log in to Juick website") public ProtocolReply commandLogin(User user, String... arguments) { - return new ProtocolReply(baseUri + "?" + userService.getHashByUID(user.getUid()), - Optional.empty()); + return new ProtocolReply(baseUri + "?" + userService.getHashByUID(user.getUid())); } @UserCommand(pattern = "^(#+)$", help = "# - Show last messages from your feed (## - second page, ...)") @@ -255,8 +249,7 @@ public class JuickProtocol { List messages = messagesService.getMessages(mids); // TODO: add instructions for empty feed return new ProtocolReply("Your feed: \n" + String.join("\n", - messages.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList())), - Optional.of(json.writeValueAsString(messages))); + messages.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList()))); } @UserCommand(pattern = "^\\s*(on|off)\\s*$", patternFlags = Pattern.CASE_INSENSITIVE, @@ -273,17 +266,16 @@ public class JuickProtocol { } if (userService.setActiveStatusForJID(user.getJid(), newStatus)) { - return new ProtocolReply(retValUpdated, Optional.empty()); + return new ProtocolReply(retValUpdated); } else { - return new ProtocolReply(String.format("Subscriptions status for %s was not changed", user.getJid()), - Optional.empty()); + return new ProtocolReply(String.format("Subscriptions status for %s was not changed", user.getJid())); } } @UserCommand(pattern = "^\\s*ping\\s*$", patternFlags = Pattern.CASE_INSENSITIVE, help = "PING - returns you a PONG") public ProtocolReply commandPing(User user, String[] input) { - return new ProtocolReply("PONG", Optional.empty()); + return new ProtocolReply("PONG"); } @UserCommand(pattern = "^\\@(\\S+)\\s+([\\s\\S]+)$", help = "@username message - send PM to username") @@ -344,9 +336,9 @@ public class JuickProtocol { */ } if (ret == 200) { - return new ProtocolReply("Private message sent", Optional.empty()); + return new ProtocolReply("Private message sent"); } else { - return new ProtocolReply("Error " + ret, Optional.empty()); + return new ProtocolReply("Error " + ret); } } @@ -357,7 +349,7 @@ public class JuickProtocol { try { mid = Integer.parseInt(arguments[0]); } catch (NumberFormatException e) { - return new ProtocolReply("Error", Optional.empty()); + return new ProtocolReply("Error"); } Message msg = messagesService.getMessage(mid); if (msg != null) { @@ -365,13 +357,11 @@ public class JuickProtocol { List replies = messagesService.getReplies(mid); replies.add(0, msg); return new ProtocolReply(String.join("\n", - replies.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList())), - Optional.of(json.writeValueAsString(replies))); + replies.stream().map(PlainTextFormatter::formatPost).collect(Collectors.toList()))); } - return new ProtocolReply(PlainTextFormatter.formatPost(msg), - Optional.of(json.writeValueAsString(Collections.singletonList(msg)))); + return new ProtocolReply(PlainTextFormatter.formatPost(msg)); } - return new ProtocolReply("Message not found", Optional.empty()); + return new ProtocolReply("Message not found"); } @UserCommand(pattern = "^(#|\\.)(\\d+)((\\.|\\-|\\/)(\\d+))?\\s([\\s\\S]+)", help = "#1234 *tag *tag2 - edit tags\n#1234 text - reply to message") @@ -380,27 +370,21 @@ public class JuickProtocol { try { mid = Integer.parseInt(args[1]); } catch (NumberFormatException e) { - return new ProtocolReply("Error", Optional.empty()); - } - int rid; - try { - rid = Integer.parseInt(args[4]); - } catch (NumberFormatException e) { - rid = 0; + return new ProtocolReply("Error"); } + int rid = NumberUtils.toInt(args[4], 0); String txt = args[5]; List messageTags = tagService.fromString(txt, true); if (messageTags.size() > 0) { if (user.getUid() != messagesService.getMessageAuthor(mid).getUid()) { - return new ProtocolReply("It is not your message", Optional.empty()); + return new ProtocolReply("It is not your message"); } tagService.updateTags(mid, messageTags); - return new ProtocolReply("Tags are updated", Optional.empty()); + return new ProtocolReply("Tags are updated"); } else { int newrid = messagesService.createReply(mid, rid, user.getUid(), txt, null); return new ProtocolReply("Reply posted.\n#" + mid + "/" + newrid + " " - + baseUri + mid + "/" + newrid, - Optional.of(json.writeValueAsString(Collections.singletonList(messagesService.getReply(mid, newrid))))); + + baseUri + mid + "/" + newrid); } } @@ -408,23 +392,18 @@ public class JuickProtocol { patternFlags = Pattern.CASE_INSENSITIVE) public ProtocolReply commandSubscribeMessage(User user, String... args) { boolean subscribe = args[0].equalsIgnoreCase("s"); - int mid; - try { - mid = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - return new ProtocolReply("Error", Optional.empty()); - } + int mid = NumberUtils.toInt(args[1], 0); if (subscribe) { if (subscriptionService.subscribeMessage(mid, user.getUid())) { - return new ProtocolReply("Subscribed", Optional.empty()); + return new ProtocolReply("Subscribed"); } } else { if (subscriptionService.unSubscribeMessage(mid, user.getUid())) { - return new ProtocolReply("Unsubscribed from #" + mid, Optional.empty()); + return new ProtocolReply("Unsubscribed from #" + mid); } - return new ProtocolReply("You was not subscribed to #" + mid, Optional.empty()); + return new ProtocolReply("You was not subscribed to #" + mid); } - return new ProtocolReply("Error", Optional.empty()); + return new ProtocolReply("Error"); } @UserCommand(pattern = "^(s|u)\\s+\\@(\\S+)$", help = "S @user - subscribe to user's posts", patternFlags = Pattern.CASE_INSENSITIVE) @@ -434,18 +413,18 @@ public class JuickProtocol { if (toUser.getUid() > 0) { if (subscribe) { if (subscriptionService.subscribeUser(user, toUser)) { - return new ProtocolReply("Subscribed", Optional.empty()); + return new ProtocolReply("Subscribed"); // TODO: notification // TODO: already subscribed case } } else { if (subscriptionService.unSubscribeUser(user, toUser)) { - return new ProtocolReply("Unsubscribed from @" + toUser.getName(), Optional.empty()); + return new ProtocolReply("Unsubscribed from @" + toUser.getName()); } - return new ProtocolReply("You was not subscribed to @" + toUser.getName(), Optional.empty()); + return new ProtocolReply("You was not subscribed to @" + toUser.getName()); } } - return new ProtocolReply("Error", Optional.empty()); + return new ProtocolReply("Error"); } @UserCommand(pattern = "^(s|u)\\s+\\*(\\S+)$", help = "S *tag - subscribe to tag" + "\nU *tag - unsubscribe from tag", patternFlags = Pattern.CASE_INSENSITIVE) @@ -454,15 +433,15 @@ public class JuickProtocol { Tag tag = tagService.getTag(args[1], true); if (subscribe) { if (subscriptionService.subscribeTag(user, tag)) { - return new ProtocolReply("Subscribed", Optional.empty()); + return new ProtocolReply("Subscribed"); } } else { if (subscriptionService.unSubscribeTag(user, tag)) { - return new ProtocolReply("Unsubscribed from " + tag.getName(), Optional.empty()); + return new ProtocolReply("Unsubscribed from " + tag.getName()); } - return new ProtocolReply("You was not subscribed to " + tag.getName(), Optional.empty()); + return new ProtocolReply("You was not subscribed to " + tag.getName()); } - return new ProtocolReply("Error", Optional.empty()); + return new ProtocolReply("Error"); } @UserCommand(pattern = "^\\s*help\\s*$", patternFlags = Pattern.CASE_INSENSITIVE, @@ -472,7 +451,7 @@ public class JuickProtocol { .filter(m -> m.isAnnotationPresent(UserCommand.class)) .map(m -> m.getAnnotation(UserCommand.class).help()) .collect(Collectors.toList()); - return new ProtocolReply(String.join("\n", commandsHelp), Optional.empty()); + return new ProtocolReply(String.join("\n", commandsHelp)); } public String getBaseUri() { diff --git a/juick-server/src/main/java/com/juick/server/protocol/ProtocolReply.java b/juick-server/src/main/java/com/juick/server/protocol/ProtocolReply.java index d9d36a5d..f3483187 100644 --- a/juick-server/src/main/java/com/juick/server/protocol/ProtocolReply.java +++ b/juick-server/src/main/java/com/juick/server/protocol/ProtocolReply.java @@ -1,23 +1,16 @@ package com.juick.server.protocol; -import java.util.Optional; - /** * Created by vitalyster on 08.04.2016. */ public class ProtocolReply { - private Optional json; - private String description; + private String result; - public ProtocolReply(String text, Optional json) { - this.description = text; - this.json = json; - } - public String getDescription() { - return description; + public ProtocolReply(String text) { + this.result = text; } - public Optional getJson() { - return json; + public String getResult() { + return result; } } diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java b/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java index 6b716630..9f5d076a 100644 --- a/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java +++ b/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java @@ -76,7 +76,7 @@ public class XMPPBot implements AutoCloseable { try { ProtocolReply reply = juickProtocol.getReply(user, text); Message replyMessage = new Message(message.getFrom(), Message.Type.CHAT); - replyMessage.setBody(reply.getDescription()); + replyMessage.setBody(reply.getResult()); replyMessage.setFrom(juickJid); component.send(replyMessage); } catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException | JsonProcessingException ex) { 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 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()); } } -- cgit v1.2.3