Package org.apache.vysper.xmpp.stanza

Examples of org.apache.vysper.xmpp.stanza.Stanza


                    .addAttribute("from", "me@vysper.org")
                    .addAttribute("to", "vysper.org")
                    .addNamespaceAttribute("jabber:client")
                .build()
        );
        Stanza stanza = waitForStanza(session);
        assertNotNull(stanza);
        System.out.println(DenseStanzaLogRenderer.render(stanza));
        session.send(
                new StanzaBuilder("starttls", "urn:ietf:params:xml:ns:xmpp-tls")
                    .addAttribute("from", "me@vysper.org")
View Full Code Here


    }

    private Stanza waitForStanza(StanzaSession session) {
        long inTime = System.currentTimeMillis();
        while (System.currentTimeMillis() < inTime + 10000) {
            Stanza stanza = session.poll();
            if (stanza != null) return stanza;
            try { Thread.sleep(10); } catch (InterruptedException e) { e.printStackTrace(); }
        }

        return null;
View Full Code Here

     * only return the first stanza from the given xml
     */
    protected abstract Stanza getFirstStanzaFromXML(String xml) throws ParsingException;

    public void testSimple() throws ParsingException {
        Stanza stanza = getFirstStanzaFromXML("<test>leeklf</test>");
        assertEquals("stanza simple text", "test", stanza.getName());
        assertNotNull("empty attr", stanza.getAttributes());
        assertEquals("zero attr", 0, stanza.getAttributes().size());

        stanza = getFirstStanzaFromXML("<test2/><next>...");
        assertEquals("stanza simple text2", "test2", stanza.getName());
    }
View Full Code Here

        assertSequenceOfTwo("<test_uno></test_uno><!--NOT ALLOWED COMMENT BETWEEN STANZAS --><test_due></test_due>");
    }

    private void assertSequenceOfTwo(String xml) throws ParsingException {
        StreamParser stringStreamParser = createStreamParser(xml);
        Stanza stanza = stringStreamParser.getNextStanza();
        assertEquals("stanza 1", "test_uno", stanza.getName());
        stanza = stringStreamParser.getNextStanza();
        assertEquals("stanza 2", "test_due", stanza.getName());
        stanza = stringStreamParser.getNextStanza();
        assertNull("stanza 3 not existing", stanza);
    }
View Full Code Here

            fail("must raise exception");
        } catch (Exception e) {
            // fall thru
        }

        Stanza stanza = getFirstStanzaFromXML("<test>leeklf<test></test></test>");
        assertEquals("inners", 2, stanza.getInnerFragments().size());
        assertEquals("inner w/same name", "test", ((XMLElement) stanza.getInnerFragments().get(1)).getName());
    }
View Full Code Here

        assertEquals("inner w/same name", "test", ((XMLElement) stanza.getInnerFragments().get(1)).getName());
    }

    public void testAttributes() throws ParsingException {
        String xml = "<testAttr at1=\"av1\" at2=\"av2\" />";
        Stanza stanza = getFirstStanzaFromXML(xml);
        assertEquals("attributes length", 2, stanza.getAttributes().size());
        assertEquals("stanza name", "testAttr", stanza.getName());
        List<Attribute> attributes = stanza.getAttributes();

        // inner attribues are immutable
        int size = attributes.size();
        try {
            attributes.add(new Attribute("not", "insertable"));
View Full Code Here

        }
    }

    public void testNestedFragments() throws ParsingException {
        String xml = "<test_uno><inner><inner_x></inner_x>payload_1</inner>payload_2</test_uno>";
        Stanza stanza = getFirstStanzaFromXML(xml);

        List<XMLFragment> innerFragments = stanza.getInnerFragments();

        // inner frags are immutable
        int size = innerFragments.size();
        try {
            innerFragments.add(new XMLText("not insertable"));
View Full Code Here

        String sequence = "<stream:stream\n" +
                            "    to='example.com'\n" +
                            "    xmlns='jabber:client'\n" +
                            "    xmlns:stream='http://etherx.jabber.org/streams'\n" +
                            "    version='1.0' />";
        Stanza stanza = getFirstStanzaFromXML(sequence);
        String name = stanza.getName();
        assertEquals("name", "stream", name);
    }
View Full Code Here

        "<?xml version='1.0'?><stream:stream from='example.com' id='someid' " +
        " xmlns='jabber:client'" +
        " xmlns:stream='http://etherx.jabber.org/streams' version='1.0' />";

       
        Stanza stanza = getFirstStanzaFromXML(xml);
        assertEquals("stream start", "stream", stanza.getName());
    }
View Full Code Here

        EntityImpl toEntity = EntityImpl.parse("userTo@vysper.org");
        TestSessionContext sessionContext = TestSessionContext.createSessionContext(toEntity);
        sessionContext.setSessionState(SessionState.AUTHENTICATED);
        resourceRegistry.bindSession(sessionContext);

        Stanza stanza = StanzaBuilder.createMessageStanza(fromEntity, toEntity, "en", "Hello").build();

        try {
            stanzaRelay.relay(toEntity, stanza, new IgnoreFailureStrategy());
            Stanza recordedStanza = sessionContext.getNextRecordedResponse(1000);
            assertNotNull("stanza delivered", recordedStanza);
            assertEquals("Hello", recordedStanza.getSingleInnerElementsNamed("body").getSingleInnerText().getText());
        } catch (DeliveryException e) {
            throw e;
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.stanza.Stanza

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.