aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-server/src/test/java')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java51
1 files changed, 27 insertions, 24 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index d3dc7b58..6c232167 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -24,7 +24,8 @@ import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
import com.juick.server.EmailManager;
-import com.juick.server.XMPPBot;
+import com.juick.server.CommandsManager;
+import com.juick.server.XMPPConnection;
import com.juick.server.XMPPServer;
import com.juick.server.helpers.AnonymousUser;
import com.juick.server.helpers.TagStats;
@@ -94,7 +95,9 @@ public class ServerTests {
@Inject
private XMPPServer server;
@Inject
- private XMPPBot bot;
+ private CommandsManager commandsManager;
+ @Inject
+ private XMPPConnection router;
@Inject
private SubscriptionService subscriptionService;
@Inject
@@ -509,15 +512,15 @@ public class ServerTests {
assertThat(from, equalTo(msg.getFrom()));
boolean isActive = jdbcTemplate.queryForObject("SELECT active FROM jids WHERE user_id=?", Integer.class, renhaId) == 1;
assertThat(isActive, equalTo(true));
- bot.incomingMessage((ServerMessage)msg);
+ router.incomingMessage((ServerMessage)msg);
isActive = jdbcTemplate.queryForObject("SELECT active FROM jids WHERE user_id=?", Integer.class, renhaId) == 1;
assertThat(isActive, equalTo(false));
}
@Test
public void botCommandsTests() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
- assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG"));
+ assertThat(commandsManager.processCommand(new User(), Jid.of("test@localhost"), "PING").get(), is("PONG"));
// subscription commands have two lines, others have 1
- assertThat(bot.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(32));
+ assertThat(commandsManager.processCommand(new User(), Jid.of("test@localhost"), "help").get().split("\n").length, is(32));
}
@Test
@@ -525,10 +528,10 @@ public class ServerTests {
int uid = userService.createUser("me", "secret");
User user = userService.getUserByUID(uid).orElse(new User());
Tag yo = tagService.getTag("yo", true);
- bot.incomingMessageJuick(user, Jid.of("test@localhost"), "*yo yoyo");
+ router.incomingMessageJuick(user, Jid.of("test@localhost"), "*yo yoyo");
int mid = messagesService.createMessage(uid, "yoyo", null, Collections.singletonList(yo));
assertEquals("should be message", true,
- bot.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid)).get().startsWith("@me"));
+ commandsManager.processCommand(user, Jid.of("test@localhost"), String.format("#%d", mid)).get().startsWith("@me"));
mid = messagesService.getUserBlog(user.getUid(), -1, 0).stream().reduce((first, second) -> second).get();
assertEquals("text should match", "yoyo",
messagesService.getMessage(mid).getText());
@@ -538,9 +541,9 @@ public class ServerTests {
User readerUser = userService.getUserByUID(readerUid).orElse(new User());
Jid dummyJid = Jid.of("dummy@localhost");
assertEquals("should be subscribed", "Subscribed",
- bot.processCommand(readerUser, dummyJid, "S #" + mid).get());
+ commandsManager.processCommand(readerUser, dummyJid, "S #" + mid).get());
assertEquals("should be favorited", "Message is added to your recommendations",
- bot.processCommand(readerUser, dummyJid, "! #" + mid).get());
+ commandsManager.processCommand(readerUser, dummyJid, "! #" + mid).get());
int rid = messagesService.createReply(mid, 0, uid, "comment", null);
assertEquals("number of subscribed users should match", 1,
subscriptionService.getUsersSubscribedToComments(
@@ -552,7 +555,7 @@ public class ServerTests {
messagesService.getMessage(mid),
messagesService.getReply(mid, rid)).size());
assertEquals("should be subscribed", "Subscribed to @" + user.getName(),
- bot.processCommand(readerUser, Jid.of("dummy@localhost"), "S @" + user.getName()).get());
+ commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "S @" + user.getName()).get());
List<User> friends = userService.getUserFriends(readerUid);
assertEquals("number of friend users should match", 2,
friends.size());
@@ -563,57 +566,57 @@ public class ServerTests {
String expectedThirdReply = "Reply posted.\n#" + mid + "/3 "
+ "https://juick.com/" + mid + "#3";
assertEquals("should be second reply", expectedSecondReply,
- bot.processCommand(user, Jid.of("test@localhost"), "#" + mid + " yoyo").get());
+ commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " yoyo").get());
assertEquals("should be third reply", expectedThirdReply,
- bot.processCommand(user, Jid.of("test@localhost"), "#" + mid + "/2 yoyo").get());
+ commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + "/2 yoyo").get());
Message reply = messagesService.getReplies(mid).stream().filter(m -> m.getRid() == 3).findFirst()
.orElse(new Message());
assertEquals("should be reply to second comment", 2, reply.getReplyto());
assertEquals("tags should NOT be updated", "It is not your message",
- bot.processCommand(readerUser, Jid.of("dummy@localhost"), "#" + mid + " *yo *there").get());
+ commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "#" + mid + " *yo *there").get());
assertEquals("tags should be updated", "Tags are updated",
- bot.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there").get());
+ commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there").get());
assertEquals("number of tags should match", 2,
tagService.getMessageTags(mid).size());
assertEquals("should be blacklisted", "Tag added to your blacklist",
- bot.processCommand(readerUser, Jid.of("dummy@localhost"), "BL *there").get());
+ commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "BL *there").get());
assertEquals("number of subscribed users should match", 0,
subscriptionService.getSubscribedUsers(uid, mid).size());
assertEquals("tags should be updated", "Tags are updated",
- bot.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there").get());
+ commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid + " *there").get());
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",
- bot.processCommand(taggerUser, Jid.of("tagger@localhost"), "S *yo").get());
+ commandsManager.processCommand(taggerUser, Jid.of("tagger@localhost"), "S *yo").get());
assertEquals("number of subscribed users should match", 2,
subscriptionService.getSubscribedUsers(uid, mid).size());
assertEquals("should be unsubscribed", "Unsubscribed from yo",
- bot.processCommand(taggerUser, Jid.of("tagger@localhost"), "U *yo").get());
+ commandsManager.processCommand(taggerUser, Jid.of("tagger@localhost"), "U *yo").get());
assertEquals("number of subscribed users should match", 1,
subscriptionService.getSubscribedUsers(uid, mid).size());
assertEquals("number of readers should match", 1,
userService.getUserReaders(uid).size());
- String readerFeed = bot.processCommand(readerUser, Jid.of("dummy@localhost"), "#").get();
+ String readerFeed = commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "#").get();
assertEquals("description should match", true, readerFeed.startsWith("Your feed"));
assertEquals("should be unsubscribed", "Unsubscribed from @" + user.getName(),
- bot.processCommand(readerUser, Jid.of("dummy@localhost"), "U @" + user.getName()).get());
+ commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "U @" + user.getName()).get());
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,
- bot.processCommand(readerUser, Jid.of("dummy@localhost"), "u #" + mid).get());
+ commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "u #" + mid).get());
assertEquals("number of subscribed users should match", 0,
subscriptionService.getUsersSubscribedToComments(messagesService.getMessage(mid),
messagesService.getReply(mid, rid)).size());
assertNotEquals("should NOT be deleted", String.format("Message %s deleted", mid),
- bot.processCommand(readerUser, Jid.of("dummy@localhost"), "D #" + mid).get());
+ commandsManager.processCommand(readerUser, Jid.of("dummy@localhost"), "D #" + mid).get());
assertEquals("should be deleted", "Message deleted",
- bot.processCommand(user, Jid.of("test@localhost"), "D #" + mid).get());
+ commandsManager.processCommand(user, Jid.of("test@localhost"), "D #" + mid).get());
assertEquals("should be not found", "Message not found",
- bot.processCommand(user, Jid.of("test@localhost"), "#" + mid).get());
+ commandsManager.processCommand(user, Jid.of("test@localhost"), "#" + mid).get());
}
@Test
public void mailParserTest() throws Exception {