use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MessageMarkupTest method listTest.
@Test
public void listTest() throws Exception {
String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<list start='31' end='89'>" + "<li start='31'/>" + "<li start='47'/>" + "<li start='61'/>" + "<li start='69'/>" + "</list>" + "</markup>";
MarkupElement.Builder m = MarkupElement.getBuilder();
m = m.beginList().addEntry(31, 47).addEntry(47, 61).addEntry(61, 69).addEntry(69, 89).endList();
assertXmlSimilar(xml, m.build().toXML().toString());
XmlPullParser parser = TestUtils.getParser(xml);
MarkupElement parsed = new MarkupElementProvider().parse(parser);
List<MarkupElement.MarkupChildElement> children = parsed.getChildElements();
assertEquals(1, children.size());
ListElement list = (ListElement) children.get(0);
assertEquals(31, list.getStart());
assertEquals(89, list.getEnd());
assertEquals(4, list.getEntries().size());
assertEquals(list.getStart(), list.getEntries().get(0).getStart());
assertEquals(47, list.getEntries().get(1).getStart());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MessageMarkupTest method emphasisTest.
@Test
public void emphasisTest() throws Exception {
String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<span start='9' end='15'>" + "<emphasis/>" + "</span>" + "</markup>";
MarkupElement.Builder m = MarkupElement.getBuilder();
m.setEmphasis(9, 15);
assertXmlSimilar(xml, m.build().toXML().toString());
XmlPullParser parser = TestUtils.getParser(xml);
MarkupElement parsed = new MarkupElementProvider().parse(parser);
List<MarkupElement.MarkupChildElement> children = parsed.getChildElements();
assertEquals(1, children.size());
SpanElement spanElement = (SpanElement) children.get(0);
assertEquals(9, spanElement.getStart());
assertEquals(15, spanElement.getEnd());
assertEquals(1, spanElement.getStyles().size());
assertEquals(SpanElement.SpanStyle.emphasis, spanElement.getStyles().iterator().next());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class MessageMarkupTest method codeBlockTest.
@Test
public void codeBlockTest() throws Exception {
String xml = "<markup xmlns='urn:xmpp:markup:0'>" + "<bcode start='23' end='48'/>" + "</markup>";
MarkupElement.Builder m = MarkupElement.getBuilder();
m.setCodeBlock(23, 48);
assertXmlSimilar(xml, m.build().toXML().toString());
XmlPullParser parser = TestUtils.getParser(xml);
MarkupElement parsed = new MarkupElementProvider().parse(parser);
List<MarkupElement.MarkupChildElement> children = parsed.getChildElements();
assertEquals(1, children.size());
CodeBlockElement codeBlock = (CodeBlockElement) children.get(0);
assertEquals(23, codeBlock.getStart());
assertEquals(48, codeBlock.getEnd());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class CarbonTest method carbonSentTest.
@Test
public void carbonSentTest() throws Exception {
XmlPullParser parser;
String control;
CarbonExtension cc;
Forwarded<Message> 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
assertEquals("romeo@montague.com", fwd.getForwardedStanza().getFrom().toString());
// check end of tag
assertEquals(XmlPullParser.Event.END_ELEMENT, parser.getEventType());
assertEquals("sent", parser.getName());
}
use of org.jivesoftware.smack.xml.XmlPullParser in project Smack by igniterealtime.
the class ReceivedExtensionTest method checkReceivedProvider.
@Test
public void checkReceivedProvider() throws Exception {
XmlPullParser parser = PacketParserUtils.getParserFor(receivedExtension);
ReceivedExtension receivedExtension1 = new ReceivedProvider().parse(parser);
assertEquals("message-1", receivedExtension1.getId());
Message message = PacketParserUtils.parseStanza(receivedMessageStanza);
ReceivedExtension receivedExtension2 = ReceivedExtension.from(message);
assertEquals("message-1", receivedExtension2.getId());
}
Aggregations