package org.jivesoftware.smack.packet;
import static org.junit.Assert.*;
import org.jivesoftware.smack.TestUtils;
import org.jivesoftware.smack.packet.StreamError;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
public class StreamErrorTest {
@Test
public void testParsingOfSimpleStreamError() {
StreamError error = null;
final String xml =
// Usually the stream:stream element has more attributes (to, version, ...)
// We omit those, since they are not relevant for testing
"" +
"" +
" +" +
"" +
"";
try {
XmlPullParser parser = TestUtils.getParser(xml, "error");
error = PacketParserUtils.parseStreamError(parser);
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(error);
assertEquals("conflict", error.getCode());
}
@Test
public void testParsingOfStreamErrorWithText() {
StreamError error = null;
final String xml =
// Usually the stream:stream element has more attributes (to, version, ...)
// We omit those, since they are not relevant for testing
"" +
"" +
"" +
"" +
"Replaced by new connection" +
"" +
"" +
"";
try {
XmlPullParser parser = TestUtils.getParser(xml, "error");
error = PacketParserUtils.parseStreamError(parser);
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(error);
assertEquals("conflict", error.getCode());
assertEquals("Replaced by new connection", error.getText());
}
@Test
public void testParsingOfStreamErrorWithTextAndOptionalElement() {
StreamError error = null;
final String xml =
// Usually the stream:stream element has more attributes (to, version, ...)
// We omit those, since they are not relevant for testing
"" +
"" +
"" +
"" +
"Replaced by new connection" +
"" +
"" +
"Text contents of application-specific condition element: Foo Bar" +
"" +
"" +
"";
try {
XmlPullParser parser = TestUtils.getParser(xml, "error");
error = PacketParserUtils.parseStreamError(parser);
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(error);
assertEquals("conflict", error.getCode());
assertEquals("Replaced by new connection", error.getText());
// As of now, Smack ignores application-specific condition elements, so we don't
// test them.
}
}