mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 18:29:45 +02:00
Introduce StanzaBuilder
As first step to immutable Stanza types.
This commit is contained in:
parent
926c5892ad
commit
5db6191110
134 changed files with 2576 additions and 764 deletions
|
@ -88,10 +88,11 @@ public final class DnsOverXmppManager extends Manager {
|
|||
try {
|
||||
response = resolver.resolve(query);
|
||||
} catch (IOException exception) {
|
||||
StanzaError.Builder errorBuilder = StanzaError.getBuilder()
|
||||
StanzaError errorBuilder = StanzaError.getBuilder()
|
||||
.setType(Type.CANCEL)
|
||||
.setCondition(Condition.internal_server_error)
|
||||
.setDescriptiveEnText("Exception while resolving your DNS query", exception)
|
||||
.build()
|
||||
;
|
||||
|
||||
IQ errorResponse = IQ.createErrorResponse(iqRequest, errorBuilder);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,8 +20,12 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.MessageView;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
@ -33,6 +37,8 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement {
|
|||
|
||||
public static final String NAMESPACE = "urn:xmpp:eme:0";
|
||||
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
public enum ExplicitMessageEncryptionProtocol {
|
||||
|
||||
/**
|
||||
|
@ -154,14 +160,12 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement {
|
|||
* @param protocolNamespace namespace
|
||||
* @return true if message has EME element for that namespace, otherwise false
|
||||
*/
|
||||
public static boolean hasProtocol(Message message, String protocolNamespace) {
|
||||
List<ExtensionElement> extensionElements = message.getExtensions(
|
||||
ExplicitMessageEncryptionElement.ELEMENT,
|
||||
ExplicitMessageEncryptionElement.NAMESPACE);
|
||||
public static boolean hasProtocol(MessageView message, String protocolNamespace) {
|
||||
List<ExplicitMessageEncryptionElement> emeElements = message
|
||||
.getExtensions(ExplicitMessageEncryptionElement.class);
|
||||
|
||||
for (ExtensionElement extensionElement : extensionElements) {
|
||||
ExplicitMessageEncryptionElement e = (ExplicitMessageEncryptionElement) extensionElement;
|
||||
if (e.getEncryptionNamespace().equals(protocolNamespace)) {
|
||||
for (ExplicitMessageEncryptionElement emeElement : emeElements) {
|
||||
if (emeElement.getEncryptionNamespace().equals(protocolNamespace)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +180,7 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement {
|
|||
* @param protocol protocol
|
||||
* @return true if message has EME element for that namespace, otherwise false
|
||||
*/
|
||||
public static boolean hasProtocol(Message message, ExplicitMessageEncryptionProtocol protocol) {
|
||||
public static boolean hasProtocol(MessageView message, ExplicitMessageEncryptionProtocol protocol) {
|
||||
return hasProtocol(message, protocol.namespace);
|
||||
}
|
||||
|
||||
|
@ -184,10 +188,10 @@ public class ExplicitMessageEncryptionElement implements ExtensionElement {
|
|||
* Add an EME element containing the specified {@code protocol} namespace to the message.
|
||||
* In case there is already an element with that protocol, we do nothing.
|
||||
*
|
||||
* @param message message
|
||||
* @param message a message builder.
|
||||
* @param protocol encryption protocol
|
||||
*/
|
||||
public static void set(Message message, ExplicitMessageEncryptionProtocol protocol) {
|
||||
public static void set(MessageBuilder message, ExplicitMessageEncryptionProtocol protocol) {
|
||||
if (!hasProtocol(message, protocol.namespace)) {
|
||||
message.addExtension(new ExplicitMessageEncryptionElement(protocol));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2017 Florian Schmaus
|
||||
* Copyright 2017-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +16,10 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.hints.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.MessageView;
|
||||
|
||||
/**
|
||||
* A "store" hint. Messages with this hint should be stored in permanent stores or archives.
|
||||
|
@ -29,6 +32,8 @@ public final class StoreHint extends MessageProcessingHint {
|
|||
|
||||
public static final String ELEMENT = "store";
|
||||
|
||||
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
||||
|
||||
private StoreHint() {
|
||||
}
|
||||
|
||||
|
@ -47,15 +52,15 @@ public final class StoreHint extends MessageProcessingHint {
|
|||
return MessageProcessingHintType.store;
|
||||
}
|
||||
|
||||
public static StoreHint from(Message message) {
|
||||
return message.getExtension(ELEMENT, NAMESPACE);
|
||||
public static StoreHint from(MessageView message) {
|
||||
return message.getExtension(QNAME);
|
||||
}
|
||||
|
||||
public static boolean hasHint(Message message) {
|
||||
public static boolean hasHint(MessageView message) {
|
||||
return from(message) != null;
|
||||
}
|
||||
|
||||
public static void set(Message message) {
|
||||
public static void set(MessageBuilder message) {
|
||||
message.overrideExtension(INSTANCE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2016 Florian Schmaus
|
||||
* Copyright © 2016-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,19 +17,25 @@
|
|||
package org.jivesoftware.smackx.iot.control.element;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.IqBuilder;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
|
||||
public class IoTSetResponse extends IQ {
|
||||
|
||||
public static final String ELEMENT = "setResponse";
|
||||
public static final String NAMESPACE = Constants.IOT_CONTROL_NAMESPACE;
|
||||
|
||||
public IoTSetResponse(IqBuilder iqBuilder) {
|
||||
super(iqBuilder, ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
// TODO: Deprecate when stanza build is ready.
|
||||
public IoTSetResponse() {
|
||||
super(ELEMENT, NAMESPACE);
|
||||
}
|
||||
|
||||
public IoTSetResponse(IoTSetRequest iotSetRequest) {
|
||||
this();
|
||||
initializeAsResultFor(iotSetRequest);
|
||||
this(StanzaBuilder.buildIqResultFor(iotSetRequest));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -125,10 +125,14 @@ public final class IoTDataManager extends IoTManager {
|
|||
@Override
|
||||
public void momentaryReadOut(List<? extends IoTDataField> results) {
|
||||
IoTFieldsExtension iotFieldsExtension = IoTFieldsExtension.buildFor(dataRequest.getSequenceNr(), true, thing.getNodeInfo(), results);
|
||||
Message message = new Message(dataRequest.getFrom());
|
||||
message.addExtension(iotFieldsExtension);
|
||||
|
||||
XMPPConnection connection = connection();
|
||||
Message message = connection.getStanzaFactory().buildMessageStanza()
|
||||
.to(dataRequest.getFrom())
|
||||
.addExtension(iotFieldsExtension)
|
||||
.build();
|
||||
try {
|
||||
connection().sendStanza(message);
|
||||
connection.sendStanza(message);
|
||||
}
|
||||
catch (NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send read-out response " + message, e);
|
||||
|
|
|
@ -140,8 +140,10 @@ public final class IoTProvisioningManager extends Manager {
|
|||
+ " is already not subscribed to our presence.");
|
||||
return;
|
||||
}
|
||||
Presence unsubscribed = new Presence(Presence.Type.unsubscribed);
|
||||
unsubscribed.setTo(unfriendJid);
|
||||
Presence unsubscribed = connection.getStanzaFactory().buildPresenceStanza()
|
||||
.ofType(Presence.Type.unsubscribed)
|
||||
.to(unfriendJid)
|
||||
.build();
|
||||
connection.sendStanza(unsubscribed);
|
||||
}
|
||||
}, UNFRIEND_MESSAGE);
|
||||
|
@ -162,7 +164,10 @@ public final class IoTProvisioningManager extends Manager {
|
|||
// friendship requests.
|
||||
final XMPPConnection connection = connection();
|
||||
Friend friendNotification = new Friend(connection.getUser().asBareJid());
|
||||
Message notificationMessage = new Message(friendJid, friendNotification);
|
||||
Message notificationMessage = connection.getStanzaFactory().buildMessageStanza()
|
||||
.to(friendJid)
|
||||
.addExtension(friendNotification)
|
||||
.build();
|
||||
connection.sendStanza(notificationMessage);
|
||||
} else {
|
||||
// Check is the message was send from a thing we previously
|
||||
|
@ -359,8 +364,11 @@ public final class IoTProvisioningManager extends Manager {
|
|||
}
|
||||
|
||||
public void sendFriendshipRequest(BareJid bareJid) throws NotConnectedException, InterruptedException {
|
||||
Presence presence = new Presence(Presence.Type.subscribe);
|
||||
presence.setTo(bareJid);
|
||||
XMPPConnection connection = connection();
|
||||
Presence presence = connection.getStanzaFactory().buildPresenceStanza()
|
||||
.ofType(Presence.Type.subscribe)
|
||||
.to(bareJid)
|
||||
.build();
|
||||
|
||||
friendshipRequestedCache.put(bareJid, null);
|
||||
|
||||
|
@ -379,9 +387,12 @@ public final class IoTProvisioningManager extends Manager {
|
|||
|
||||
public void unfriend(Jid friend) throws NotConnectedException, InterruptedException {
|
||||
if (isMyFriend(friend)) {
|
||||
Presence presence = new Presence(Presence.Type.unsubscribed);
|
||||
presence.setTo(friend);
|
||||
connection().sendStanza(presence);
|
||||
XMPPConnection connection = connection();
|
||||
Presence presence = connection.getStanzaFactory().buildPresenceStanza()
|
||||
.ofType(Presence.Type.unsubscribed)
|
||||
.to(friend)
|
||||
.build();
|
||||
connection.sendStanza(presence);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ import org.jivesoftware.smack.filter.MessageTypeFilter;
|
|||
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightAffiliationsIQ;
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightChangeAffiliationsIQ;
|
||||
import org.jivesoftware.smackx.muclight.element.MUCLightConfigurationIQ;
|
||||
|
@ -126,9 +126,9 @@ public class MultiUserChatLight {
|
|||
* @throws InterruptedException if the calling thread was interrupted.
|
||||
*/
|
||||
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
|
||||
Message message = createMessage();
|
||||
MessageBuilder message = buildMessage();
|
||||
message.setBody(text);
|
||||
connection.sendStanza(message);
|
||||
connection.sendStanza(message.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,9 +157,28 @@ public class MultiUserChatLight {
|
|||
* Creates a new Message to send to the chat room.
|
||||
*
|
||||
* @return a new Message addressed to the chat room.
|
||||
* @deprecated use {@link #buildMessage()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove when stanza builder is ready.
|
||||
public Message createMessage() {
|
||||
return new Message(room, Message.Type.groupchat);
|
||||
return connection.getStanzaFactory().buildMessageStanza()
|
||||
.ofType(Message.Type.groupchat)
|
||||
.to(room)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new message builder for messages send to this MUC room.
|
||||
*
|
||||
* @return a new message builder.
|
||||
*/
|
||||
public MessageBuilder buildMessage() {
|
||||
return connection.getStanzaFactory()
|
||||
.buildMessageStanza()
|
||||
.ofType(Message.Type.groupchat)
|
||||
.to(room)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,10 +188,23 @@ public class MultiUserChatLight {
|
|||
* the message.
|
||||
* @throws NotConnectedException if the XMPP connection is not connected.
|
||||
* @throws InterruptedException if the calling thread was interrupted.
|
||||
* @deprecated use {@link #sendMessage(MessageBuilder)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.5.
|
||||
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
|
||||
message.setTo(room);
|
||||
message.setType(Message.Type.groupchat);
|
||||
sendMessage(message.asBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a Message to the chat room.
|
||||
*
|
||||
* @param messageBuilder the message.
|
||||
* @throws NotConnectedException if the XMPP connection is not connected.
|
||||
* @throws InterruptedException if the calling thread was interrupted.
|
||||
*/
|
||||
public void sendMessage(MessageBuilder messageBuilder) throws NotConnectedException, InterruptedException {
|
||||
Message message = messageBuilder.to(room).ofType(Message.Type.groupchat).build();
|
||||
connection.sendStanza(message);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,9 @@ public class RemoteDisablingProvider extends ExtensionElementProvider<RemoteDisa
|
|||
|
||||
String affiliation = parser.getAttributeValue("", "affiliation");
|
||||
if (affiliation == null || !affiliation.equals("none")) {
|
||||
return null;
|
||||
// TODO: Is this correct? We previously returned null here, but was certainly wrong, as
|
||||
// providers should always return an element or throw.
|
||||
throw new IOException("Invalid affiliation: " + affiliation);
|
||||
}
|
||||
}
|
||||
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.chat_markers;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -28,7 +29,6 @@ import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.Acknowle
|
|||
import org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
public class AcknowledgedExtensionTest {
|
||||
|
||||
|
@ -39,9 +39,10 @@ public class AcknowledgedExtensionTest {
|
|||
|
||||
@Test
|
||||
public void checkDisplayedExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster"));
|
||||
message.setStanzaId("message-2");
|
||||
message.addExtension(new ChatMarkersElements.AcknowledgedExtension("message-1"));
|
||||
Message message = StanzaBuilder.buildMessage("message-2")
|
||||
.to("northumberland@shakespeare.lit/westminster")
|
||||
.addExtension(new ChatMarkersElements.AcknowledgedExtension("message-1"))
|
||||
.build();
|
||||
assertEquals(acknowledgedMessageStanza, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.chat_markers;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -28,7 +29,6 @@ import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.Displaye
|
|||
import org.jivesoftware.smackx.chat_markers.provider.DisplayedProvider;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
public class DisplayedExtensionTest {
|
||||
|
||||
|
@ -39,9 +39,10 @@ public class DisplayedExtensionTest {
|
|||
|
||||
@Test
|
||||
public void checkDisplayedExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster"));
|
||||
message.setStanzaId("message-2");
|
||||
message.addExtension(new ChatMarkersElements.DisplayedExtension("message-1"));
|
||||
Message message = StanzaBuilder.buildMessage("message-2")
|
||||
.to("northumberland@shakespeare.lit/westminster")
|
||||
.addExtension(new ChatMarkersElements.DisplayedExtension("message-1"))
|
||||
.build();
|
||||
assertEquals(displayedMessageStanza, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.chat_markers;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
||||
|
@ -39,10 +40,12 @@ public class MarkableExtensionTest {
|
|||
|
||||
@Test
|
||||
public void checkMarkableExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("ingrichard@royalty.england.lit/throne"));
|
||||
message.setStanzaId("message-1");
|
||||
message.setBody("My lord, dispatch; read o'er these articles.");
|
||||
message.addExtension(ChatMarkersElements.MarkableExtension.INSTANCE);
|
||||
Message message = StanzaBuilder.buildMessage("message-1")
|
||||
.to(JidCreate.from("ingrichard@royalty.england.lit/throne"))
|
||||
.setBody("My lord, dispatch; read o'er these articles.")
|
||||
.addExtension(ChatMarkersElements.MarkableExtension.INSTANCE)
|
||||
.build();
|
||||
|
||||
assertEquals(markableMessageStanza, message.toXML().toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jivesoftware.smackx.chat_markers;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -28,7 +29,6 @@ import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.Received
|
|||
import org.jivesoftware.smackx.chat_markers.provider.ReceivedProvider;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
public class ReceivedExtensionTest {
|
||||
|
||||
|
@ -39,9 +39,10 @@ public class ReceivedExtensionTest {
|
|||
|
||||
@Test
|
||||
public void checkReceivedExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster"));
|
||||
message.setStanzaId("message-2");
|
||||
message.addExtension(new ChatMarkersElements.ReceivedExtension("message-1"));
|
||||
Message message = StanzaBuilder.buildMessage("message-2")
|
||||
.to("northumberland@shakespeare.lit/westminster")
|
||||
.addExtension(new ChatMarkersElements.ReceivedExtension("message-1"))
|
||||
.build();
|
||||
assertEquals(receivedMessageStanza, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.List;
|
|||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.MessageBuilder;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
||||
import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement;
|
||||
|
@ -35,7 +37,7 @@ public class ExplicitMessageEncryptionElementTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void addToMessageTest() {
|
||||
Message message = new Message();
|
||||
Message message = StanzaBuilder.buildMessage().build();
|
||||
|
||||
// Check inital state (no elements)
|
||||
assertNull(ExplicitMessageEncryptionElement.from(message));
|
||||
|
@ -45,9 +47,12 @@ public class ExplicitMessageEncryptionElementTest extends SmackTestSuite {
|
|||
List<ExtensionElement> extensions = message.getExtensions();
|
||||
assertEquals(0, extensions.size());
|
||||
|
||||
MessageBuilder messageBuilder = StanzaBuilder.buildMessage();
|
||||
// Add OMEMO
|
||||
ExplicitMessageEncryptionElement.set(message,
|
||||
ExplicitMessageEncryptionElement.set(messageBuilder,
|
||||
ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl);
|
||||
|
||||
message = messageBuilder.build();
|
||||
extensions = message.getExtensions();
|
||||
assertEquals(1, extensions.size());
|
||||
assertTrue(ExplicitMessageEncryptionElement.hasProtocol(message,
|
||||
|
@ -59,8 +64,10 @@ public class ExplicitMessageEncryptionElementTest extends SmackTestSuite {
|
|||
assertFalse(ExplicitMessageEncryptionElement.hasProtocol(message,
|
||||
ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.openpgpV0.getNamespace()));
|
||||
|
||||
ExplicitMessageEncryptionElement.set(message,
|
||||
ExplicitMessageEncryptionElement.set(messageBuilder,
|
||||
ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.openpgpV0);
|
||||
|
||||
message = messageBuilder.build();
|
||||
extensions = message.getExtensions();
|
||||
assertEquals(2, extensions.size());
|
||||
assertTrue(ExplicitMessageEncryptionElement.hasProtocol(message,
|
||||
|
@ -69,9 +76,10 @@ public class ExplicitMessageEncryptionElementTest extends SmackTestSuite {
|
|||
ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl));
|
||||
|
||||
// Check, if adding additional OMEMO wont add another element
|
||||
ExplicitMessageEncryptionElement.set(message,
|
||||
ExplicitMessageEncryptionElement.set(messageBuilder,
|
||||
ExplicitMessageEncryptionElement.ExplicitMessageEncryptionProtocol.omemoVAxolotl);
|
||||
|
||||
message = messageBuilder.build();
|
||||
extensions = message.getExtensions();
|
||||
assertEquals(2, extensions.size());
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.TimeZone;
|
|||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Message.Type;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.packet.StreamOpen;
|
||||
|
||||
import org.jivesoftware.smackx.delay.packet.DelayInformation;
|
||||
|
@ -62,21 +63,21 @@ public class QueryArchiveTest extends MamTest {
|
|||
|
||||
@Test
|
||||
public void checkMamQueryResults() throws Exception {
|
||||
Message message = new Message();
|
||||
message.setStanzaId("iasd207");
|
||||
message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
|
||||
message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
|
||||
Message message = StanzaBuilder.buildMessage("iasd207")
|
||||
.from("coven@chat.shakespeare.lit")
|
||||
.to("hag66@shakespeare.lit/pda")
|
||||
.build();
|
||||
|
||||
GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date date = calendar.getTime();
|
||||
|
||||
DelayInformation delay = new DelayInformation(date);
|
||||
Message forwardedMessage = new Message();
|
||||
forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
|
||||
forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
|
||||
forwardedMessage.setType(Type.chat);
|
||||
forwardedMessage.setBody("Thrice the brinded cat hath mew.");
|
||||
Message forwardedMessage = StanzaBuilder.buildMessage("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2")
|
||||
.from(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"))
|
||||
.ofType(Type.chat)
|
||||
.setBody("Thrice the brinded cat hath mew.")
|
||||
.build();
|
||||
|
||||
Forwarded forwarded = new Forwarded(delay, forwardedMessage);
|
||||
|
||||
|
|
|
@ -18,7 +18,9 @@ package org.jivesoftware.smackx.push_notifications;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
|
@ -56,18 +58,12 @@ public class RemoteDisablingPushNotificationsTest {
|
|||
|
||||
@Test
|
||||
public void checkWrongRemoteDisablighPushNotifications() throws Exception {
|
||||
Message message1 = PacketParserUtils.parseStanza(wrongRemoteDisabling1);
|
||||
RemoteDisablingExtension remoteDisablingExtension1 = RemoteDisablingExtension.from(message1);
|
||||
assertNull(remoteDisablingExtension1);
|
||||
assertThrows(IOException.class, () -> PacketParserUtils.parseStanza(wrongRemoteDisabling1));
|
||||
|
||||
Message message2 = PacketParserUtils.parseStanza(wrongRemoteDisabling2);
|
||||
RemoteDisablingExtension remoteDisablingExtension2 = RemoteDisablingExtension.from(message2);
|
||||
assertNull(remoteDisablingExtension2);
|
||||
assertThrows(IOException.class, () -> PacketParserUtils.parseStanza(wrongRemoteDisabling2));
|
||||
|
||||
Message message3 = PacketParserUtils.parseStanza(wrongRemoteDisabling3);
|
||||
assertNotNull(message3);
|
||||
// RemoteDisablingExtension remoteDisablingExtension3 = RemoteDisablingExtension.from(message3);
|
||||
// assertNull(remoteDisablingExtension3);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
|
@ -70,7 +71,7 @@ public class StableUniqueStanzaIdTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void fromMessageTest() {
|
||||
Message message = new Message();
|
||||
Message message = StanzaBuilder.buildMessage().build();
|
||||
assertFalse(OriginIdElement.hasOriginId(message));
|
||||
assertFalse(StanzaIdElement.hasStanzaId(message));
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.StanzaBuilder;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.xml.XmlPullParser;
|
||||
|
@ -40,7 +41,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
public void emptySpoilerTest() throws Exception {
|
||||
final String xml = "<spoiler xmlns='urn:xmpp:spoiler:0'/>";
|
||||
|
||||
Message message = new Message();
|
||||
Message message = StanzaBuilder.buildMessage().build();
|
||||
SpoilerElement.addSpoiler(message);
|
||||
|
||||
SpoilerElement empty = message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
|
@ -59,7 +60,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
public void hintSpoilerTest() throws Exception {
|
||||
final String xml = "<spoiler xmlns='urn:xmpp:spoiler:0'>Love story end</spoiler>";
|
||||
|
||||
Message message = new Message();
|
||||
Message message = StanzaBuilder.buildMessage().build();
|
||||
SpoilerElement.addSpoiler(message, "Love story end");
|
||||
|
||||
SpoilerElement withHint = message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
|
@ -79,7 +80,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
public void i18nHintSpoilerTest() throws Exception {
|
||||
final String xml = "<spoiler xml:lang='de' xmlns='urn:xmpp:spoiler:0'>Der Kuchen ist eine Lüge!</spoiler>";
|
||||
|
||||
Message message = new Message();
|
||||
Message message = StanzaBuilder.buildMessage().build();
|
||||
SpoilerElement.addSpoiler(message, "de", "Der Kuchen ist eine Lüge!");
|
||||
|
||||
SpoilerElement i18nHint = message.getExtension(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);
|
||||
|
@ -98,7 +99,7 @@ public class SpoilerTest extends SmackTestSuite {
|
|||
|
||||
@Test
|
||||
public void getSpoilersTest() {
|
||||
Message m = new Message();
|
||||
Message m = StanzaBuilder.buildMessage().build();
|
||||
assertTrue(SpoilerElement.getSpoilers(m).isEmpty());
|
||||
|
||||
SpoilerElement.addSpoiler(m);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue