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());
}
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);
}
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());
}
Aggregations