Search in sources :

Example 26 with MessageBuilder

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);
    }
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Message(org.jivesoftware.smack.packet.Message) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 27 with MessageBuilder

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));
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with MessageBuilder

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());
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) Test(org.junit.jupiter.api.Test)

Example 29 with MessageBuilder

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()));
}
Also used : Message(org.jivesoftware.smack.packet.Message) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) XmlPullParser(org.jivesoftware.smack.xml.XmlPullParser) Test(org.junit.jupiter.api.Test)

Example 30 with MessageBuilder

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;
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Jid(org.jxmpp.jid.Jid)

Aggregations

MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)34 Message (org.jivesoftware.smack.packet.Message)10 XMPPConnection (org.jivesoftware.smack.XMPPConnection)9 Test (org.junit.jupiter.api.Test)8 Test (org.junit.Test)7 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)5 Stanza (org.jivesoftware.smack.packet.Stanza)3 RosterExchange (org.jivesoftware.smackx.xroster.packet.RosterExchange)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Date (java.util.Date)2 DummyConnection (org.jivesoftware.smack.DummyConnection)2 AndFilter (org.jivesoftware.smack.filter.AndFilter)2 XmlElement (org.jivesoftware.smack.packet.XmlElement)2 OpenPgpMessage (org.jivesoftware.smackx.ox.OpenPgpMessage)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1