Search in sources :

Example 41 with Stanza

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

the class ChatConnectionTest method chatMatchedOnJIDWhenNoThreadBareMode.

// No thread behaviour
@Test
public void chatMatchedOnJIDWhenNoThreadBareMode() {
    // ChatManager.MatchMode.BARE_JID is the default, so setting required.
    TestMessageListener msgListener = new TestMessageListener();
    TestChatManagerListener listener = new TestChatManagerListener(msgListener);
    cm.addChatListener(listener);
    Stanza incomingChat = createChatMessage(null, true);
    processServerMessage(incomingChat);
    Chat newChat = listener.getNewChat();
    assertNotNull(newChat);
    // Should match on chat with full jid
    incomingChat = createChatMessage(null, true);
    processServerMessage(incomingChat);
    assertEquals(2, msgListener.getNumMessages());
    // Should match on chat with bare jid
    incomingChat = createChatMessage(null, false);
    processServerMessage(incomingChat);
    assertEquals(3, msgListener.getNumMessages());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) Test(org.junit.Test)

Example 42 with Stanza

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

the class Protocol method verifyAll.

/**
 * Verifies the request/response pairs by checking if their numbers match
 * and executes the verification for each pair.
 */
@SuppressWarnings("unchecked")
public void verifyAll() {
    // CHECKSTYLE:OFF
    assertEquals(requests.size(), responsesList.size());
    if (printProtocol)
        System.out.println("=================== Start ===============\n");
    for (int i = 0; i < requests.size(); i++) {
        Stanza request = requests.get(i);
        Stanza response = responsesList.get(i);
        if (printProtocol) {
            System.out.println("------------------- Request -------------\n");
            System.out.println(XmlUtil.prettyFormatXml(request.toXML()));
            System.out.println("------------------- Response ------------\n");
            if (response != null) {
                System.out.println(XmlUtil.prettyFormatXml(response.toXML()));
            } else {
                System.out.println("No response");
            }
        }
        Verification<Stanza, Stanza>[] verifications = (Verification<Stanza, Stanza>[]) verificationList.get(i);
        if (verifications != null) {
            for (Verification<Stanza, Stanza> verification : verifications) {
                verification.verify(request, response);
            }
        }
    }
    if (printProtocol)
        System.out.println("=================== End =================\n");
// CHECKSTYLE:ON
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza)

Example 43 with Stanza

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

the class ChatConnectionTest method chatFoundWithSameThreadBaseJid.

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

Example 44 with Stanza

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

the class ChatConnectionTest method chatMatchedOnJIDWhenNoThreadNoneMode.

@Test
public void chatMatchedOnJIDWhenNoThreadNoneMode() {
    TestMessageListener msgListener = new TestMessageListener();
    TestChatManagerListener listener = new TestChatManagerListener(msgListener);
    cm.setMatchMode(ChatManager.MatchMode.NONE);
    cm.addChatListener(listener);
    Stanza incomingChat = createChatMessage(null, true);
    processServerMessage(incomingChat);
    Chat newChat = listener.getNewChat();
    assertNotNull(newChat);
    assertEquals(1, msgListener.getNumMessages());
    cm.removeChatListener(listener);
    // Should not match on chat with full jid
    TestChatManagerListener listener2 = new TestChatManagerListener();
    cm.addChatListener(listener2);
    incomingChat = createChatMessage(null, true);
    processServerMessage(incomingChat);
    assertEquals(1, msgListener.getNumMessages());
    assertNotNull(newChat);
    cm.removeChatListener(listener2);
    // Should not match on chat with bare jid
    TestChatManagerListener listener3 = new TestChatManagerListener();
    cm.addChatListener(listener3);
    incomingChat = createChatMessage(null, false);
    processServerMessage(incomingChat);
    assertEquals(1, msgListener.getNumMessages());
    assertNotNull(listener3.getNewChat());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) Test(org.junit.Test)

Example 45 with Stanza

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

the class ChatConnectionTest method chatNotFoundWithDiffThreadEntityFullJid.

/**
 * 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 base jid.
 */
@Test
public void chatNotFoundWithDiffThreadEntityFullJid() {
    Chat outgoing = cm.createChat(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, null);
    Stanza incomingChat = createChatMessage(outgoing.getThreadID() + "ff", true);
    processServerMessage(incomingChat);
    Chat newChat = listener.getNewChat();
    assertNotNull(newChat);
    assertFalse(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