1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Introduce StanzaBuilder

As first step to immutable Stanza types.
This commit is contained in:
Florian Schmaus 2019-10-24 15:45:08 +02:00
parent 926c5892ad
commit 5db6191110
134 changed files with 2576 additions and 764 deletions

View file

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.chatstate;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.chatstates.ChatState;
import org.jivesoftware.smackx.chatstates.ChatStateListener;
import org.jivesoftware.smackx.chatstates.ChatStateManager;

View file

@ -32,6 +32,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.StanzaBuilder;
import org.jivesoftware.smackx.mam.MamManager.MamQuery;
import org.jivesoftware.smackx.mam.MamManager.MamQueryArgs;
@ -66,10 +67,12 @@ public class MamIntegrationTest extends AbstractSmackIntegrationTest {
EntityBareJid userOne = conOne.getUser().asEntityBareJid();
EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
Message message = new Message(userTwo);
String messageId = message.ensureStanzaIdSet();
final String messageBody = "Test MAM message (" + testRunId + ')';
message.setBody(messageBody);
Message message = conTwo.getStanzaFactory().buildMessageStanza()
.to(userTwo)
.setBody(messageBody)
.build();
final String messageId = message.getStanzaId();
final SimpleResultSyncPoint messageReceived = new SimpleResultSyncPoint();
@ -122,7 +125,10 @@ public class MamIntegrationTest extends AbstractSmackIntegrationTest {
for (int i = 0; i < totalMessages; i++) {
String messageBody = "MAM Page Test " + testRunId + ' ' + (i + 1);
Message message = new Message(userTwo, messageBody);
Message message = StanzaBuilder.buildMessage()
.to(userTwo)
.setBody(messageBody)
.build();
outgoingMessages.add(message);
}

View file

@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle;
import org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException;
import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException;

View file

@ -18,6 +18,7 @@ package org.jivesoftware.smackx.omemo;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.omemo.listener.OmemoMessageListener;

View file

@ -20,7 +20,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smackx.omemo.element.OmemoBundleElement;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
@ -68,7 +71,10 @@ public class MessageEncryptionIntegrationTest extends AbstractTwoUsersOmemoInteg
new AbstractOmemoMessageListener.PreKeyMessageListener(body1);
bob.addOmemoMessageListener(listener1);
OmemoMessage.Sent e1 = alice.encrypt(bob.getOwnJid(), body1);
alice.getConnection().sendStanza(e1.asMessage(bob.getOwnJid()));
XMPPConnection alicesConnection = alice.getConnection();
MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
alicesConnection.sendStanza(e1.buildMessage(messageBuilder, bob.getOwnJid()));
listener1.getSyncPoint().waitForResult(10 * 1000);
bob.removeOmemoMessageListener(listener1);
@ -88,7 +94,9 @@ public class MessageEncryptionIntegrationTest extends AbstractTwoUsersOmemoInteg
new AbstractOmemoMessageListener.MessageListener(body3);
alice.addOmemoMessageListener(listener3);
OmemoMessage.Sent e3 = bob.encrypt(alice.getOwnJid(), body3);
bob.getConnection().sendStanza(e3.asMessage(alice.getOwnJid()));
XMPPConnection bobsConnection = bob.getConnection();
messageBuilder = bobsConnection.getStanzaFactory().buildMessageStanza();
bobsConnection.sendStanza(e3.buildMessage(messageBuilder, alice.getOwnJid()));
listener3.getSyncPoint().waitForResult(10 * 1000);
alice.removeOmemoMessageListener(listener3);

View file

@ -22,7 +22,10 @@ import java.io.IOException;
import java.util.List;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.jivesoftware.smackx.mam.MamManager;
import org.jivesoftware.smackx.mam.element.MamPrefsIQ;
import org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException;
@ -62,7 +65,10 @@ public class OmemoMamDecryptionTest extends AbstractTwoUsersOmemoIntegrationTest
String body = "This message will be stored in MAM!";
OmemoMessage.Sent encrypted = alice.encrypt(bob.getOwnJid(), body);
alice.getConnection().sendStanza(encrypted.asMessage(bob.getOwnJid()));
XMPPConnection alicesConnection = alice.getConnection();
MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
alicesConnection.sendStanza(encrypted.buildMessage(messageBuilder, bob.getOwnJid()));
MamManager.MamQuery query = bobsMamManager.queryArchive(MamManager.MamQueryArgs.builder().limitResultsToJid(alice.getOwnJid()).build());
assertEquals(1, query.getMessageCount());

View file

@ -28,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smack.roster.RosterEntry;
import org.jivesoftware.smackx.omemo.exceptions.CannotEstablishOmemoSessionException;
import org.jivesoftware.smackx.omemo.exceptions.CorruptedOmemoKeyException;
import org.jivesoftware.smackx.omemo.internal.OmemoCachedDeviceList;

View file

@ -24,6 +24,7 @@ import java.io.IOException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException;
import org.jivesoftware.smackx.omemo.exceptions.ReadOnlyDeviceException;
import org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException;

View file

@ -17,7 +17,9 @@
package org.jivesoftware.smackx.omemo;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.MessageBuilder;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
@ -46,7 +48,10 @@ public class SessionRenegotiationIntegrationTest extends AbstractTwoUsersOmemoIn
new AbstractOmemoMessageListener.PreKeyMessageListener(body1);
OmemoMessage.Sent e1 = alice.encrypt(bob.getOwnJid(), body1);
bob.addOmemoMessageListener(listener1);
alice.getConnection().sendStanza(e1.asMessage(bob.getOwnJid()));
XMPPConnection alicesConnection = alice.getConnection();
MessageBuilder messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
alicesConnection.sendStanza(e1.buildMessage(messageBuilder, bob.getOwnJid()));
listener1.getSyncPoint().waitForResult(10 * 1000);
bob.removeOmemoMessageListener(listener1);
@ -61,7 +66,9 @@ public class SessionRenegotiationIntegrationTest extends AbstractTwoUsersOmemoIn
new AbstractOmemoMessageListener.PreKeyKeyTransportListener();
OmemoMessage.Sent e2 = alice.encrypt(bob.getOwnJid(), body2);
alice.addOmemoMessageListener(listener2);
alice.getConnection().sendStanza(e2.asMessage(bob.getOwnJid()));
messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
alicesConnection.sendStanza(e2.buildMessage(messageBuilder, bob.getOwnJid()));
listener2.getSyncPoint().waitForResult(10 * 1000);
alice.removeOmemoMessageListener(listener2);
@ -70,7 +77,9 @@ public class SessionRenegotiationIntegrationTest extends AbstractTwoUsersOmemoIn
AbstractOmemoMessageListener.MessageListener listener3 = new AbstractOmemoMessageListener.MessageListener(body3);
OmemoMessage.Sent e3 = alice.encrypt(bob.getOwnJid(), body3);
bob.addOmemoMessageListener(listener3);
alice.getConnection().sendStanza(e3.asMessage(bob.getOwnJid()));
messageBuilder = alicesConnection.getStanzaFactory().buildMessageStanza();
alicesConnection.sendStanza(e3.buildMessage(messageBuilder, bob.getOwnJid()));
listener3.getSyncPoint().waitForResult(10 * 1000);
bob.removeOmemoMessageListener(listener3);

View file

@ -19,6 +19,7 @@ package org.jivesoftware.smackx.ox;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.ox.util.OpenPgpPubSubUtil;
import org.jivesoftware.smackx.pep.PepManager;

View file

@ -33,6 +33,7 @@ import java.util.logging.Level;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.ox.callback.backup.AskForBackupCodeCallback;
import org.jivesoftware.smackx.ox.callback.backup.DisplayBackupCodeCallback;
import org.jivesoftware.smackx.ox.callback.backup.SecretKeyBackupSelectionCallback;

View file

@ -27,6 +27,7 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.ox.AbstractOpenPgpIntegrationTest;
import org.jivesoftware.smackx.ox.OpenPgpContact;
import org.jivesoftware.smackx.ox.OpenPgpManager;

View file

@ -22,6 +22,7 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NotLoggedInException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.usertune.element.UserTuneElement;
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
@ -30,7 +31,6 @@ import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil;
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
import org.junit.AfterClass;
import org.jxmpp.jid.BareJid;
public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest {

View file

@ -25,6 +25,8 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.StanzaCollector;
import org.jivesoftware.smack.filter.ThreadFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.StanzaBuilder;
import org.jivesoftware.smackx.xdata.FormField.Type;
import org.jivesoftware.smackx.xdata.packet.DataForm;
@ -96,9 +98,10 @@ public class FormTest extends AbstractSmackIntegrationTest {
StanzaCollector collector2 = conTwo.createStanzaCollector(
new ThreadFilter(chat.getThreadID()));
Message msg = new Message();
msg.setBody("To enter a case please fill out this form and send it back to me");
msg.addExtension(formToSend.getDataFormToSend());
Message msg = StanzaBuilder.buildMessage()
.setBody("To enter a case please fill out this form and send it back to me")
.addExtension(formToSend.getDataFormToSend())
.build();
try {
// Send the message with the form to fill out
@ -130,13 +133,14 @@ public class FormTest extends AbstractSmackIntegrationTest {
completedForm.setAnswer("time", true);
completedForm.setAnswer("age", 20);
// Create a new message to send with the completed form
msg2 = new Message();
msg2.setTo(conOne.getUser().asBareJid());
msg2.setThread(msg.getThread());
msg2.setType(Message.Type.chat);
msg2.setBody("To enter a case please fill out this form and send it back to me");
// Add the completed form to the message
msg2.addExtension(completedForm.getDataFormToSend());
msg2 = StanzaBuilder.buildMessage()
.to(conOne.getUser().asBareJid())
.setThread(msg.getThread())
.ofType(Message.Type.chat)
.setBody("To enter a case please fill out this form and send it back to me")
// Add the completed form to the message
.addExtension(completedForm.getDataFormToSend())
.build();
// Send the message with the completed form
conTwo.sendStanza(msg2);