use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class OutgoingMessageListenerIntegrationTest method outgoingMessageListenerTest.
@SmackIntegrationTest
public void outgoingMessageListenerTest() throws Exception {
final String body = StringUtils.randomString(16);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
final OutgoingChatMessageListener listener = new OutgoingChatMessageListener() {
@Override
public void newOutgoingMessage(EntityBareJid to, MessageBuilder messageBuilder, Chat chat) {
Message message = messageBuilder.build();
if (message.getBody().equals(body)) {
syncPoint.signal();
}
}
};
EntityBareJid peer = conTwo.getUser().asEntityBareJid();
try {
chatManagerOne.addOutgoingListener(listener);
Chat chat = chatManagerOne.chatWith(peer);
chat.send(body);
syncPoint.waitForResult(timeout);
} finally {
chatManagerOne.removeOutgoingListener(listener);
}
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class MessageFasteningElementsTest method hasFasteningElementTest.
@Test
public void hasFasteningElementTest() {
MessageBuilder messageBuilderWithFasteningElement = StanzaBuilder.buildMessage().setBody("Hi!").addExtension(FasteningElement.builder().setOriginId("origin-id-1").build());
MessageBuilder messageBuilderWithoutFasteningElement = StanzaBuilder.buildMessage().setBody("Ho!");
assertTrue(FasteningElement.hasFasteningElement(messageBuilderWithFasteningElement));
assertFalse(FasteningElement.hasFasteningElement(messageBuilderWithoutFasteningElement));
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class DeliveryReceiptTest method receiptManagerAutoReplyTest.
@Test
public void receiptManagerAutoReplyTest() throws Exception {
DummyConnection c = new DummyConnection();
c.connect();
DeliveryReceiptManager drm = DeliveryReceiptManager.getInstanceFor(c);
drm.setAutoReceiptMode(AutoReceiptMode.always);
assertEquals(AutoReceiptMode.always, drm.getAutoReceiptMode());
// test auto-receipts
MessageBuilder messageBuilder = StanzaBuilder.buildMessage("test-receipt-request").to("julia@capulet.com").from("romeo@montague.com").ofType(Message.Type.normal);
DeliveryReceiptRequest.addTo(messageBuilder);
// the DRM will send a reply-packet
c.processStanza(messageBuilder.build());
Stanza reply = c.getSentPacket();
DeliveryReceipt r = DeliveryReceipt.from((Message) reply);
assertThat("romeo@montague.com", equalsCharSequence(reply.getTo()));
assertEquals("test-receipt-request", r.getId());
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class DeliveryReceiptTest method receiptTest.
@Test
public void receiptTest() throws Exception {
XmlPullParser parser;
String control;
control = XMLBuilder.create("message").a("from", "romeo@montague.com").e("request").a("xmlns", "urn:xmpp:receipts").asString(outputProperties);
parser = PacketParserUtils.getParserFor(control);
Message p = PacketParserUtils.parseMessage(parser);
DeliveryReceiptRequest drr = p.getExtension(DeliveryReceiptRequest.class);
assertNotNull(drr);
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p));
MessageBuilder messageBuilder = StanzaBuilder.buildMessage("request-id").to("romeo@montague.com").ofType(Message.Type.normal);
assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(messageBuilder.build()));
DeliveryReceiptRequest.addTo(messageBuilder);
assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(messageBuilder.build()));
}
use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.
the class ChatConnectionTest method createChatPacket.
private static MessageBuilder createChatPacket(final String threadId, final boolean isEntityFullJid) {
MessageBuilder chatMsg = StanzaBuilder.buildMessage().ofType(Message.Type.chat).to(JidTestUtil.BARE_JID_1);
chatMsg.setBody("the body message - " + System.currentTimeMillis());
Jid jid;
if (isEntityFullJid) {
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
} else {
jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
}
chatMsg.from(jid);
if (threadId != null) {
chatMsg.setThread(threadId);
}
return chatMsg;
}
Aggregations