Package org.apache.vysper.xml.decoder

Examples of org.apache.vysper.xml.decoder.XMLStreamTokenizer


*/
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());
       
    }
View Full Code Here


        assertEquals("plain termination", 6, protocolDecoderOutput.size());
       
    }

    public void testDecoderPartial() throws Exception {
        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
        MockIoSession session = new MockIoSession();
        IoBuffer firstByteBuffer = createByteBuffer();
        IoBuffer secondByteBuffer = createByteBuffer();
       
        String stanzaPart1 = "<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='ht";
        String stanzaPart2 = "tp://etherx.jabber.org/streams' version='1.0'>";

        MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();

        IoBuffer prolog = createByteBuffer();
        prolog.putString(StanzaWriter.XML_PROLOG + "\n\r", CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, prolog, protocolDecoderOutput);
        assertEquals(1, protocolDecoderOutput.size());
       
        firstByteBuffer.putString(stanzaPart1, CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, firstByteBuffer, protocolDecoderOutput);
        assertEquals(2, protocolDecoderOutput.size());
        String content = ((XMLText)protocolDecoderOutput.get(1)).getText();
        assertEquals("\n\r", content);


        secondByteBuffer.putString(stanzaPart2, CHARSET_ENCODER_UTF8).flip();
        decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
        assertEquals(3, protocolDecoderOutput.size());
    }
View Full Code Here

        decoder.decode(session, secondByteBuffer, protocolDecoderOutput);
        assertEquals(3, protocolDecoderOutput.size());
    }

    public void testCRLFInElement() throws Exception {
        XMLStreamTokenizer decoder = new XMLStreamTokenizer();
        MockIoSession session = new MockIoSession();
        IoBuffer byteBuffer = createByteBuffer();
       
        String stanza =
        "<stream:stream\n" +
                "     from='juliet@example.com'\n" +
                "     to='example.com'\n" +
                "     version='1.0'\n" +
                "     xml:lang='en'\n" +
                "     xmlns='jabber:client'\n" +
                "     xmlns:stream='http://etherx.jabber.org/streams'>";
       
        MockProtocolDecoderOutput protocolDecoderOutput = new MockProtocolDecoderOutput();

        byteBuffer.putString(stanza, CHARSET_ENCODER_UTF8).flip();
        try {
            decoder.decode(session, byteBuffer, protocolDecoderOutput);
        } catch(Throwable th) {
            int lkjl = 0;
        }
        assertEquals(1, protocolDecoderOutput.size());
        XMLElement stanzaParsed = (XMLElement) protocolDecoderOutput.get(0);
View Full Code Here

  public ProtocolEncoder getEncoder(IoSession s) throws Exception {
        return new StanzaWriterProtocolEncoder();
    }

  public ProtocolDecoder getDecoder(IoSession s) throws Exception {
        return new XMLStreamTokenizer(new StanzaBuilderFactory());
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xml.decoder.XMLStreamTokenizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.