*/
public class XMLStreamTokenizerTestCase extends TestCase {
private static final CharsetEncoder CHARSET_ENCODER_UTF8 = CharsetUtil.UTF8_ENCODER;
public void testDecoderSimple() throws Exception {
XMLStreamTokenizer decoder = new XMLStreamTokenizer();
MockIoSession session = new MockIoSession();
IoBuffer firstByteBuffer = createByteBuffer();
IoBuffer secondByteBuffer = createByteBuffer();
String stanza = StanzaWriter.XML_PROLOG + "\n\r" +
"<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>" +
"<trailing-stanza/>";
firstByteBuffer.putString(stanza, CHARSET_ENCODER_UTF8).flip();
MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();
decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
assertEquals(4, protocolDecoderOutput.size());
secondByteBuffer.putString("<next></next>", CHARSET_ENCODER_UTF8).flip();
decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
assertEquals(5, protocolDecoderOutput.size());
IoBuffer emptyBuffer = createByteBuffer().putString("eee", CHARSET_ENCODER_UTF8).flip();
decoder.decode(session, emptyBuffer, protocolDecoderOutput);
assertEquals("plain must be terminated by <", 5, protocolDecoderOutput.size());
IoBuffer termBuffer = createByteBuffer().putString("<r>", CHARSET_ENCODER_UTF8).flip();
decoder.decode(session, termBuffer, protocolDecoderOutput);
// eee is now terminated, but r is not balanced yet
assertEquals("plain termination", 6, protocolDecoderOutput.size());
}