1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Add support for <text/> elements in SM's <failed/> element

Also introduce AbstractTextElement and StanzaErrorTextElement.

Fixes SMACK-760.
This commit is contained in:
Florian Schmaus 2017-06-17 11:43:49 +02:00
parent 1448fa4632
commit 813219179f
5 changed files with 158 additions and 13 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Vyacheslav Blinov
* Copyright 2014 Vyacheslav Blinov, 2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,8 +26,10 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import org.jivesoftware.smack.packet.StanzaErrorTextElement;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.sm.packet.StreamManagement;
import org.jivesoftware.smack.util.PacketParserUtils;
@ -104,6 +106,30 @@ public class ParseStreamManagementTest {
assertTrue(failedPacket.getXMPPErrorCondition() == errorCondition);
}
@Test
public void testParseFailedWithTExt() throws XmlPullParserException, IOException {
// @formatter:off
final String failedNonza = "<failed h='20' xmlns='urn:xmpp:sm:3'>"
+ "<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
+ "<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>"
+ "Previous session timed out"
+ "</text>"
+ "</failed>";
// @formatter:on
XmlPullParser parser = PacketParserUtils.getParserFor(failedNonza);
StreamManagement.Failed failed = ParseStreamManagement.failed(parser);
assertEquals(XMPPError.Condition.item_not_found, failed.getXMPPErrorCondition());
List<StanzaErrorTextElement> textElements = failed.getTextElements();
assertEquals(1, textElements.size());
StanzaErrorTextElement textElement = textElements.get(0);
assertEquals("Previous session timed out", textElement.getText());
assertEquals("en", textElement.getLang());
}
@Test
public void testParseResumed() throws Exception {
long handledPackets = 42;
@ -139,7 +165,6 @@ public class ParseStreamManagementTest {
assertThat(acknowledgementPacket.getHandledCount(), equalTo(handledPackets));
}
private static Properties initOutputProperties() {
Properties properties = new Properties();
properties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");