Search in sources :

Example 81 with Stanza

use of org.jivesoftware.smack.packet.Stanza 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 82 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class PingTest method checkSendingPing.

@Test
public void checkSendingPing() throws InterruptedException, SmackException, IOException, XMPPException {
    DummyConnection dummyCon = getAuthenticatedDummyConnection();
    PingManager pinger = PingManager.getInstanceFor(dummyCon);
    try {
        pinger.ping(DUMMY_AT_EXAMPLE_ORG);
    } catch (SmackException e) {
    // Ignore the fact the server won't answer for this unit test.
    }
    Stanza sentPacket = dummyCon.getSentPacket();
    assertTrue(sentPacket instanceof Ping);
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) ThreadedDummyConnection(org.jivesoftware.smack.ThreadedDummyConnection) SmackException(org.jivesoftware.smack.SmackException) Stanza(org.jivesoftware.smack.packet.Stanza) Ping(org.jivesoftware.smackx.ping.packet.Ping) Test(org.junit.jupiter.api.Test)

Example 83 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class ChatConnectionTest method chatNotFoundWithDiffThreadBaseJid.

/**
 * Confirm that an existing chat created with a base jid is not matched to an incoming chat message that has a
 * different id and the same user as a base jid.
 */
@Test
public void chatNotFoundWithDiffThreadBaseJid() {
    Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
    Stanza incomingChat = createChatMessage(outgoing.getThreadID() + "ff", false);
    processServerMessage(incomingChat);
    Chat newChat = listener.getNewChat();
    assertNotNull(newChat);
    assertFalse(newChat == outgoing);
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) Test(org.junit.Test)

Example 84 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class ChatConnectionTest method chatFoundWhenNoThreadEntityFullJid.

/**
 * Confirm that an existing chat created with a base jid is matched to an incoming chat message that has no thread
 * id and the user is a full jid.
 */
@Test
public void chatFoundWhenNoThreadEntityFullJid() {
    Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
    Stanza incomingChat = createChatMessage(null, true);
    processServerMessage(incomingChat);
    Chat newChat = listener.getNewChat();
    assertNotNull(newChat);
    assertTrue(newChat == outgoing);
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) Test(org.junit.Test)

Example 85 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class ChatConnectionTest method chatFoundWhenNoThreadBaseJid.

/**
 * Confirm that an existing chat created with a base jid is matched to an incoming chat message that has no thread
 * id and the user is a base jid.
 */
@Test
public void chatFoundWhenNoThreadBaseJid() {
    Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
    Stanza incomingChat = createChatMessage(null, false);
    processServerMessage(incomingChat);
    Chat newChat = listener.getNewChat();
    assertNotNull(newChat);
    assertTrue(newChat == outgoing);
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) Test(org.junit.Test)

Aggregations

Stanza (org.jivesoftware.smack.packet.Stanza)101 StanzaListener (org.jivesoftware.smack.StanzaListener)24 Test (org.junit.Test)22 IQ (org.jivesoftware.smack.packet.IQ)20 Test (org.junit.jupiter.api.Test)18 XMPPConnection (org.jivesoftware.smack.XMPPConnection)14 Message (org.jivesoftware.smack.packet.Message)14 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 Jid (org.jxmpp.jid.Jid)11 IOException (java.io.IOException)9 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)8 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)8 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)7 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)7 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)6 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)6 Protocol (org.jivesoftware.util.Protocol)6 EntityFullJid (org.jxmpp.jid.EntityFullJid)6 LinkedList (java.util.LinkedList)5