aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-10-10 11:18:01 +0300
committerGravatar Vitaly Takmazov2017-10-10 11:18:01 +0300
commit119966076222901579efa4b5378e227baff35de9 (patch)
tree0bb512ed4710932d753820d074c9469d3cb0fca8
parent4543e857c067b72bf441e4c3f6401cf410834654 (diff)
xmpp: add real message to resource-constraint test
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/JuickBot.java2
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java2
-rw-r--r--juick-xmpp/src/test/java/com/juick/xmpp/server/XMPPServerTests.java12
3 files changed, 7 insertions, 9 deletions
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 a9ee9698..5df24d16 100644
--- a/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
+++ b/juick-xmpp/src/main/java/com/juick/components/JuickBot.java
@@ -205,7 +205,7 @@ public class JuickBot implements StanzaListener, AutoCloseable {
public boolean incomingMessage(Message msg) {
if (msg.getType() != null && msg.getType().equals(Message.Type.ERROR)) {
- StanzaError error = msg.getExtension(StanzaError.class);
+ StanzaError error = msg.getError();
if (error != null && error.getCondition().equals(Condition.RESOURCE_CONSTRAINT)) {
// offline query is full, deactivating this jid
if (userService.setActiveStatusForJID(msg.getFrom().toEscapedString(), UserService.ActiveStatus.Inactive)) {
diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
index cb2bb681..29d57d53 100644
--- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
+++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
@@ -372,7 +372,7 @@ public class XMPPServer implements ConnectionListener, AutoCloseable {
return !Arrays.asList(brokenSSLhosts).contains(connection.to.toEscapedString());
}
- protected Stanza parse(String xml) {
+ public Stanza parse(String xml) {
try {
Unmarshaller unmarshaller = session.createUnmarshaller();
return (Stanza)unmarshaller.unmarshal(new StringReader(xml));
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 fde88787..ccc4f1d4 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
@@ -19,6 +19,7 @@ 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.Stanza;
import rocks.xmpp.core.stanza.model.StanzaError;
import rocks.xmpp.core.stanza.model.errors.Condition;
import rocks.xmpp.core.stanza.model.server.ServerMessage;
@@ -63,13 +64,10 @@ public class XMPPServerTests {
}
@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);
+ String xmlMessage = "<message xmlns=\"jabber:server\" from=\"renha@bitcheese.net\" to=\"juick@juick.com/Juick\" 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>";
+ Jid from = Jid.of("renha@bitcheese.net");
when(userService.setActiveStatusForJID(from.toEscapedString(), UserService.ActiveStatus.Inactive)).thenReturn(true);
- bot.incomingMessage(msg);
+ Stanza msg = server.parse(xmlMessage);
+ bot.incomingMessage((ServerMessage)msg);
}
}