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

Merge branch '4.2'

This commit is contained in:
Florian Schmaus 2017-06-17 15:55:38 +02:00
commit 2b11074950
736 changed files with 2515 additions and 1378 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.
@ -18,18 +18,6 @@
package org.jivesoftware.smack.sm.provider;
import com.jamesmurty.utils.XMLBuilder;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.sm.packet.StreamManagement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
@ -37,6 +25,20 @@ import static org.junit.Assert.assertEquals;
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;
import com.jamesmurty.utils.XMLBuilder;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class ParseStreamManagementTest {
private static final Properties outputProperties = initOutputProperties();
@ -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");

View file

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smack.tcp;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.Writer;
import java.util.concurrent.BrokenBarrierException;
@ -24,11 +26,10 @@ import java.util.concurrent.CyclicBarrier;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection.PacketWriter;
import org.junit.Test;
import org.jxmpp.stringprep.XmppStringprepException;
import static org.junit.Assert.fail;
public class PacketWriterTest {
volatile boolean shutdown;
volatile boolean prematureUnblocked;