Search in sources :

Example 21 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class IncomingMessageListenerIntegrationTest method test.

@SmackIntegrationTest
public void test() throws Exception {
    final String body = StringUtils.randomString(16);
    final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
    final IncomingChatMessageListener listener = new IncomingChatMessageListener() {

        @Override
        public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
            if (body.equals(message.getBody())) {
                syncPoint.signal();
            }
        }
    };
    try {
        chatManagerTwo.addIncomingListener(listener);
        Chat chat = chatManagerOne.chatWith(conTwo.getUser().asEntityBareJid());
        chat.send(body);
        syncPoint.waitForResult(timeout);
    } finally {
        chatManagerTwo.removeIncomingListener(listener);
    }
}
Also used : 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 22 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class EntityCapsTest method testPreventDiscoInfo.

/**
 * Test if entity caps actually prevent a disco info request and reply.
 *
 * @throws Exception if exception.
 */
@SmackIntegrationTest
public void testPreventDiscoInfo() throws Exception {
    final String dummyFeature = getNewDummyFeature();
    final AtomicBoolean discoInfoSend = new AtomicBoolean();
    conOne.addStanzaSendingListener(new StanzaListener() {

        @Override
        public void processStanza(Stanza stanza) {
            discoInfoSend.set(true);
        }
    }, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET));
    addFeatureAndWaitForPresence(conOne, conTwo, dummyFeature);
    dropCapsCache();
    // discover that
    DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
    // that discovery should cause a disco#info
    assertTrue(discoInfoSend.get());
    assertTrue(info.containsFeature(dummyFeature), "The info response '" + info + "' does not contain the expected feature '" + dummyFeature + '\'');
    discoInfoSend.set(false);
    // discover that
    info = sdmOne.discoverInfo(conTwo.getUser());
    // that discovery shouldn't cause a disco#info
    assertFalse(discoInfoSend.get());
    assertTrue(info.containsFeature(dummyFeature));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 23 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class ChatStateIntegrationTest method testChatStateListeners.

@SmackIntegrationTest
public void testChatStateListeners() throws Exception {
    ChatStateManager manOne = ChatStateManager.getInstance(conOne);
    ChatStateManager manTwo = ChatStateManager.getInstance(conTwo);
    // Add chatState listeners.
    manTwo.addChatStateListener(this::composingListener);
    manTwo.addChatStateListener(this::activeListener);
    Chat chatOne = ChatManager.getInstanceFor(conOne).chatWith(conTwo.getUser().asEntityBareJid());
    // Test, if setCurrentState works and the chatState arrives
    manOne.setCurrentState(ChatState.composing, chatOne);
    composingSyncPoint.waitForResult(timeout);
    // Test, if the OutgoingMessageInterceptor successfully adds a chatStateExtension of "active" to
    // an outgoing chat message and if it arrives at the other side.
    Chat chat = ChatManager.getInstanceFor(conOne).chatWith(conTwo.getUser().asEntityBareJid());
    chat.send("Hi!");
    activeSyncPoint.waitForResult(timeout);
}
Also used : ChatStateManager(org.jivesoftware.smackx.chatstates.ChatStateManager) Chat(org.jivesoftware.smack.chat2.Chat) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 24 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class MultiUserChatEntityIntegrationTest method mucTestForDiscoveringRoomItems.

/**
 * Asserts that a MUC Service returns disco info for a room's items.
 *
 * <p>From XEP-0045 § 6.5:</p>
 * <blockquote>
 * An entity MAY also query a specific chat room for its associated items. An implementation MAY return a list
 * of existing occupants if that information is publicly available, or return no list at all if this information is
 * kept private.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestForDiscoveringRoomItems() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-discoitems");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    createMuc(mucAsSeenByOne, Resourcepart.from("one-" + randomString));
    DiscoverItems roomItems;
    try {
        roomItems = ServiceDiscoveryManager.getInstanceFor(conTwo).discoverItems(mucAddress);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
    assertEquals(1, roomItems.getItems().size());
}
Also used : DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 25 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class MultiUserChatEntityIntegrationTest method mucTestForDiscoveringFeatures.

/**
 * Asserts that a MUC service can have its features discovered
 *
 * <p>From XEP-0045 § 6.2:</p>
 * <blockquote>
 * An entity may wish to discover if a service implements the Multi-User Chat protocol; in order to do so, it
 * sends a service discovery information ("disco#info") query to the MUC service's JID. The service MUST return
 * its identity and the features it supports.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestForDiscoveringFeatures() throws Exception {
    DiscoverInfo info = mucManagerOne.getMucServiceDiscoInfo(mucManagerOne.getMucServiceDomains().get(0));
    assertTrue(info.getIdentities().size() > 0);
    assertTrue(info.getFeatures().size() > 0);
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)66 EntityBareJid (org.jxmpp.jid.EntityBareJid)30 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)25 XMPPException (org.jivesoftware.smack.XMPPException)23 SmackException (org.jivesoftware.smack.SmackException)20 Resourcepart (org.jxmpp.jid.parts.Resourcepart)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)17 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)17 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 Message (org.jivesoftware.smack.packet.Message)9 TimeoutException (java.util.concurrent.TimeoutException)8 Presence (org.jivesoftware.smack.packet.Presence)7 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)6 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)6 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)6 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)6 Assertions (org.junit.jupiter.api.Assertions)6