Search in sources :

Example 1 with CarbonExtension

use of org.jivesoftware.smackx.carbons.packet.CarbonExtension in project Smack by igniterealtime.

the class CarbonTest method carbonReceivedTest.

@Test
public void carbonReceivedTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;
    control = XMLBuilder.create("received").e("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);
    assertEquals(CarbonExtension.Direction.received, cc.getDirection());
    // check end of tag
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("received", parser.getName());
}
Also used : CarbonManagerProvider(org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider) CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) XmlPullParser(org.xmlpull.v1.XmlPullParser) ExperimentalInitializerTest(org.jivesoftware.smackx.ExperimentalInitializerTest) Test(org.junit.Test)

Example 2 with CarbonExtension

use of org.jivesoftware.smackx.carbons.packet.CarbonExtension in project Smack by igniterealtime.

the class CarbonManagerProvider method parse.

@Override
public CarbonExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
    Direction dir = Direction.valueOf(parser.getName());
    Forwarded fwd = null;
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG && parser.getName().equals("forwarded")) {
            fwd = FORWARDED_PROVIDER.parse(parser);
        } else if (eventType == XmlPullParser.END_TAG && dir == Direction.valueOf(parser.getName()))
            done = true;
    }
    if (fwd == null)
        throw new SmackException("sent/received must contain exactly one <forwarded> tag");
    return new CarbonExtension(dir, fwd);
}
Also used : CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) SmackException(org.jivesoftware.smack.SmackException) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) Direction(org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction)

Example 3 with CarbonExtension

use of org.jivesoftware.smackx.carbons.packet.CarbonExtension in project Smack by igniterealtime.

the class CarbonTest method carbonSentTest.

@Test
public void carbonSentTest() throws Exception {
    XmlPullParser parser;
    String control;
    CarbonExtension cc;
    Forwarded fwd;
    control = XMLBuilder.create("sent").e("forwarded").a("xmlns", "urn:xmpp:forwarded:0").e("message").a("from", "romeo@montague.com").asString(outputProperties);
    parser = PacketParserUtils.getParserFor(control);
    cc = new CarbonManagerProvider().parse(parser);
    fwd = cc.getForwarded();
    // meta
    assertEquals(CarbonExtension.Direction.sent, cc.getDirection());
    // no delay in packet
    assertEquals(null, fwd.getDelayInformation());
    // check message
    assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom()));
    // check end of tag
    assertEquals(XmlPullParser.END_TAG, parser.getEventType());
    assertEquals("sent", parser.getName());
}
Also used : CarbonManagerProvider(org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider) CarbonExtension(org.jivesoftware.smackx.carbons.packet.CarbonExtension) XmlPullParser(org.xmlpull.v1.XmlPullParser) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) ExperimentalInitializerTest(org.jivesoftware.smackx.ExperimentalInitializerTest) Test(org.junit.Test)

Aggregations

CarbonExtension (org.jivesoftware.smackx.carbons.packet.CarbonExtension)3 ExperimentalInitializerTest (org.jivesoftware.smackx.ExperimentalInitializerTest)2 CarbonManagerProvider (org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider)2 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)2 Test (org.junit.Test)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 SmackException (org.jivesoftware.smack.SmackException)1 Direction (org.jivesoftware.smackx.carbons.packet.CarbonExtension.Direction)1