From 4543e857c067b72bf441e4c3f6401cf410834654 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 10 Oct 2017 10:30:07 +0300 Subject: xmpp: resource-constraint processing test --- .../main/java/com/juick/components/JuickBot.java | 6 +++--- .../com/juick/xmpp/server/XMPPServerTests.java | 23 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'juick-xmpp') diff --git a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java index 205e3f90..a9ee9698 100644 --- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java +++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java @@ -204,9 +204,6 @@ public class JuickBot implements StanzaListener, AutoCloseable { } public boolean incomingMessage(Message msg) { - if (StringUtils.isBlank(msg.getBody())) { - return false; - } if (msg.getType() != null && msg.getType().equals(Message.Type.ERROR)) { StanzaError error = msg.getExtension(StanzaError.class); if (error != null && error.getCondition().equals(Condition.RESOURCE_CONSTRAINT)) { @@ -218,6 +215,9 @@ public class JuickBot implements StanzaListener, AutoCloseable { } return false; } + if (StringUtils.isBlank(msg.getBody())) { + return false; + } String username = msg.getTo().getLocal(); User user_from; diff --git a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java index 99264613..fde88787 100644 --- a/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java +++ b/juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java @@ -1,9 +1,11 @@ package com.juick.xmpp.server; +import com.juick.components.JuickBot; import com.juick.components.XMPPServer; import com.juick.components.configuration.XmppAppConfiguration; import com.juick.configuration.MockDataConfiguration; import com.juick.server.configuration.BaseWebConfiguration; +import com.juick.service.UserService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,11 +17,17 @@ import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import rocks.xmpp.addr.Jid; +import rocks.xmpp.core.stanza.model.Message; +import rocks.xmpp.core.stanza.model.StanzaError; +import rocks.xmpp.core.stanza.model.errors.Condition; +import rocks.xmpp.core.stanza.model.server.ServerMessage; import javax.inject.Inject; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -37,6 +45,10 @@ public class XMPPServerTests { private WebApplicationContext wac; @Inject private XMPPServer server; + @Inject + private JuickBot bot; + @Inject + private UserService userService; private MockMvc mockMvc; @@ -49,4 +61,15 @@ public class XMPPServerTests { mockMvc.perform(get("http://localhost:8080/status")).andExpect(status().isOk()); assertThat(server.getJid().toEscapedString(), equalTo("juick.com")); } + @Test + public void botIsUpAndProcessingResourceConstraints() { + StanzaError stanzaError = new StanzaError(StanzaError.Type.CANCEL, Condition.RESOURCE_CONSTRAINT); + Message msg = ServerMessage.from(new Message()); + msg.setType(Message.Type.ERROR); + msg.addExtension(stanzaError); + Jid from = Jid.of("localhost"); + msg.setFrom(from); + when(userService.setActiveStatusForJID(from.toEscapedString(), UserService.ActiveStatus.Inactive)).thenReturn(true); + bot.incomingMessage(msg); + } } -- cgit v1.2.3