use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class ExplicitMessageEncryptionElementTest method addToMessageTest.
@Test
public void addToMessageTest() {
Message message = StanzaBuilder.buildMessage().build();
// Check inital state (no elements)
assertNull(ExplicitMessageEncryptionElement.from(message));
assertFalse(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl));
List<XmlElement> extensions = message.getExtensions();
assertEquals(0, extensions.size());
MessageBuilder messageBuilder = StanzaBuilder.buildMessage();
// Add OMEMO
ExplicitMessageEncryptionElement.set(messageBuilder, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl);
message = messageBuilder.build();
extensions = message.getExtensions();
assertEquals(1, extensions.size());
assertTrue(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl));
assertTrue(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl.getNamespace()));
assertFalse(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.openpgpV0));
assertFalse(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.openpgpV0.getNamespace()));
ExplicitMessageEncryptionElement.set(messageBuilder, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.openpgpV0);
message = messageBuilder.build();
extensions = message.getExtensions();
assertEquals(2, extensions.size());
assertTrue(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.openpgpV0));
assertTrue(ExplicitMessageEncryptionElement.hasProtocol(message, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl));
// Check, if adding additional OMEMO wont add another element
ExplicitMessageEncryptionElement.set(messageBuilder, ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl);
message = messageBuilder.build();
extensions = message.getExtensions();
assertEquals(2, extensions.size());
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class Node method getSubscriptions.
private List<Subscription> getSubscriptions(SubscriptionsNamespace subscriptionsNamespace, List<XmlElement> additionalExtensions, Collection<XmlElement> returnedExtensions) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
PubSubElementType pubSubElementType = subscriptionsNamespace.type;
PubSub pubSub = createPubsubPacket(IQ.Type.get, new NodeExtension(pubSubElementType, getId()));
if (additionalExtensions != null) {
for (XmlElement pe : additionalExtensions) {
pubSub.addExtension(pe);
}
}
PubSub reply = sendPubsubPacket(pubSub);
if (returnedExtensions != null) {
returnedExtensions.addAll(reply.getExtensions());
}
SubscriptionsExtension subElem = reply.getExtension(pubSubElementType);
return subElem.getSubscriptions();
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class RSMManager method page.
Collection<XmlElement> page(int max) {
List<XmlElement> packetExtensions = new LinkedList<>();
packetExtensions.add(new RSMSet(max));
return packetExtensions;
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class JingleProviderTest method testReasonElementWithExtraElement.
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testReasonElementWithExtraElement(SmackTestUtil.XmlPullParserKind parserKind) throws XmlPullParserException, IOException, SmackParsingException {
String xml = "<iq from='juliet@capulet.lit/balcony'" + " id='le71fa63'" + " to='romeo@montague.lit/orchard'" + " type='set'>" + "<jingle xmlns='urn:xmpp:jingle:1'" + " action='session-terminate'" + " sid='a73sjjvkla37jfea'>" + "<reason>" + "<success/>" + "<my-element xmlns='https://example.org' foo='bar'/>" + "</reason>" + "</jingle>" + "</iq>";
Jingle jingle = SmackTestUtil.parse(xml, JingleProvider.class, parserKind);
JingleReason jingleReason = jingle.getReason();
assertEquals(JingleReason.Reason.success, jingleReason.asEnum());
XmlElement element = jingleReason.getElement();
// TODO: Use JUnit 5.8's assertInstanceOf when possible
// assertInstanceOf(StandardExtesionElement.class, extraElement);
assertTrue(element instanceof StandardExtensionElement);
StandardExtensionElement extraElement = (StandardExtensionElement) element;
assertEquals("https://example.org", extraElement.getNamespace());
assertEquals("bar", extraElement.getAttributes().get("foo"));
}
use of org.jivesoftware.smack.packet.XmlElement in project Smack by igniterealtime.
the class ItemValidationTest method parseSimplePayloadItem.
@Test
public void parseSimplePayloadItem() throws Exception {
String itemContent = "<foo xmlns='smack:test'>Some text</foo>";
XmlPullParser parser = PacketParserUtils.getParserFor("<message from='pubsub.myserver.com' to='francisco@denmark.lit' id='foo'>" + "<event xmlns='http://jabber.org/protocol/pubsub#event'>" + "<items node='testNode'>" + "<item id='testid1' >" + itemContent + "</item>" + "</items>" + "</event>" + "</message>");
Stanza message = PacketParserUtils.parseMessage(parser);
XmlElement eventExt = message.getExtension(PubSubNamespace.event.getXmlns());
EventElement event = (EventElement) eventExt;
NamedElement itemExt = ((ItemsExtension) event.getExtensions().get(0)).items.get(0);
assertTrue(itemExt instanceof PayloadItem<?>);
PayloadItem<?> item = (PayloadItem<?>) itemExt;
assertEquals("testid1", item.getId());
assertTrue(item.getPayload() instanceof SimplePayload);
SimplePayload payload = (SimplePayload) item.getPayload();
assertEquals("foo", payload.getElementName());
assertEquals("smack:test", payload.getNamespace());
assertXmlSimilar(itemContent, payload.toXML().toString());
}
Aggregations