diff options
Diffstat (limited to 'juick-server/src/test')
-rw-r--r-- | juick-server/src/test/java/com/juick/server/tests/ServerTests.java | 26 |
1 files changed, 23 insertions, 3 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 d30b1303..43bc119e 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 @@ -58,6 +58,9 @@ import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.stanza.model.Stanza; +import rocks.xmpp.core.stanza.model.StanzaError; +import rocks.xmpp.core.stanza.model.client.ClientMessage; +import rocks.xmpp.core.stanza.model.errors.Condition; import rocks.xmpp.core.stanza.model.server.ServerMessage; import javax.inject.Inject; @@ -533,13 +536,30 @@ public class ServerTests { renhaId = userService.createUser("renha", "umnnbt"); Jid from = Jid.of("renha@serverstorageisfull.tld"); jdbcTemplate.update("INSERT INTO jids(user_id,jid,active) VALUES(?,?,?)", renhaId, from.toEscapedString(), 1); - String xmlMessage = "<message xmlns=\"jabber:server\" from=\"renha@serverstorageisfull.tld\" to=\"" + botJid.toEscapedString() + "\" type=\"error\"><body>Reply by @LexX</body><juick xmlns=\"http://juick.com/message\" mid=\"2885759\" privacy=\"1\" replyto=\"0\" rid=\"8\" ts=\"2017-10-10 07:41:10\"><body>Похоже нынче можно публично заявлять о своем веганстве. </body><user xmlns=\"http://juick.com/user\" uname=\"LexX\" uid=\"6340\"></user></juick><error type=\"wait\"><resource-constraint xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"></resource-constraint><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">Your contact offline message queue is full. The message has been discarded.</text></error></message>"; + rocks.xmpp.core.stanza.model.Message xmppMessage = new rocks.xmpp.core.stanza.model.Message(); + xmppMessage.setType(rocks.xmpp.core.stanza.model.Message.Type.ERROR); + xmppMessage.setFrom(from); + xmppMessage.setTo(botJid); + StanzaError err = new StanzaError(StanzaError.Type.CANCEL, Condition.RESOURCE_CONSTRAINT); + xmppMessage.setError(err); Function<Integer, Boolean> isActive = f -> jdbcTemplate.queryForObject("SELECT active FROM jids WHERE user_id=?", Integer.class, f) == 1; assertThat(isActive.apply(renhaId), equalTo(true)); - server.onStanzaReceived(xmlMessage); + ClientMessage result = router.incomingMessage(xmppMessage); + assertNull(result); assertThat(isActive.apply(renhaId), equalTo(false)); - commandsManager.processCommand(userService.getUserByJID(from.asBareJid().toEscapedString()), "On", URI.create(StringUtils.EMPTY)); + xmppMessage.setError(null); + xmppMessage.setType(rocks.xmpp.core.stanza.model.Message.Type.CHAT); + xmppMessage.setBody("On"); + result = router.incomingMessage(xmppMessage); + assertThat(result.getBody(), equalTo("XMPP notifications are activated")); assertTrue(isActive.apply(renhaId)); + xmppMessage.setBody("*test test"); + result = router.incomingMessage(xmppMessage); + assertThat(result.getBody(), startsWith("New message posted")); + xmppMessage.setFrom(Jid.of(String.valueOf(renhaId), "uid.juick.com", "perl")); + xmppMessage.setBody("PING"); + result = router.incomingMessage(xmppMessage); + assertThat(result.getBody(), equalTo("PONG")); } @Test public void botCommandsTests() throws Exception { |