Search in sources :

Example 6 with SmackIntegrationTest

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

the class MoodIntegrationTest method testNotification.

/**
 * Verifies that a notification is sent when a publication is received, assuming that notification filtering
 * has been adjusted to allow for the notification to be delivered.
 *
 * @throws Exception if the test fails
 */
@SmackIntegrationTest
public void testNotification() throws Exception {
    Mood data = Mood.satisfied;
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint moodReceived = new SimpleResultSyncPoint();
    final PepEventListener<MoodElement> moodListener = (jid, moodElement, id, message) -> {
        if (moodElement.getMood().equals(data)) {
            moodReceived.signal();
        }
    };
    try {
        // Register ConTwo's interest in receiving mood notifications, and wait for that interest to have been propagated.
        registerListenerAndWait(mm2, ServiceDiscoveryManager.getInstanceFor(conTwo), moodListener);
        // Publish the data.
        // for the purpose of this test, this needs not be blocking/use publishAndWait();
        mm1.setMood(data);
        // Wait for the data to be received.
        try {
            moodReceived.waitForResult(timeout);
        } catch (TimeoutException e) {
            Assertions.fail("Expected to receive a PEP notification, but did not.");
        }
    } finally {
        unregisterListener(mm2, moodListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 7 with SmackIntegrationTest

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

the class MultiUserChatIntegrationTest method mucJoinTest.

/**
 * Asserts that when a user joins a room, they are themselves included on the list of users notified (self-presence).
 *
 * <p>From XEP-0045 § 7.2.2:</p>
 * <blockquote>
 * ...the service MUST also send presence from the new participant's occupant JID to the full JIDs of all the
 * occupants (including the new occupant)
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucJoinTest() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-join");
    MultiUserChat muc = mucManagerOne.getMultiUserChat(mucAddress);
    try {
        Presence reflectedJoinPresence = muc.join(Resourcepart.from("nick-one"));
        MUCUser mucUser = MUCUser.from(reflectedJoinPresence);
        assertNotNull(mucUser);
        assertTrue(mucUser.getStatus().contains(MUCUser.Status.PRESENCE_TO_SELF_110));
        assertEquals(mucAddress + "/nick-one", reflectedJoinPresence.getFrom().toString());
        assertEquals(conOne.getUser().asEntityFullJidIfPossible().toString(), reflectedJoinPresence.getTo().toString());
    } finally {
        tryDestroy(muc);
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Presence(org.jivesoftware.smack.packet.Presence) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 8 with SmackIntegrationTest

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

the class MultiUserChatIntegrationTest method mucTest.

@SmackIntegrationTest
public void mucTest() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest-message");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByTwo.addMessageListener(new MessageListener() {

        @Override
        public void processMessage(Message message) {
            String body = message.getBody();
            if (mucMessage.equals(body)) {
                resultSyncPoint.signal(body);
            }
        }
    });
    createMuc(mucAsSeenByOne, "one-" + randomString);
    mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
    mucAsSeenByOne.sendMessage(mucMessage);
    try {
        resultSyncPoint.waitForResult(timeout);
    } catch (TimeoutException e) {
        throw new AssertionError("Failed to receive presence", e);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) MessageListener(org.jivesoftware.smack.MessageListener) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) TimeoutException(java.util.concurrent.TimeoutException) XMPPException(org.jivesoftware.smack.XMPPException) TimeoutException(java.util.concurrent.TimeoutException) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 9 with SmackIntegrationTest

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucRoleTestForRemovingModerator.

/**
 * Asserts that a user who undergoes a role change receives that change as a presence update
 *
 * <p>From XEP-0045 § 5.1.3:</p>
 * <blockquote>
 * ...a MUC service implementation MUST change the occupant's role to reflect the change and communicate the change
 * to all occupants...
 * </blockquote>
 *
 * <p>From XEP-0045 § 9.7:</p>
 * <blockquote>
 * The service MUST then send updated presence from this individual to all occupants, indicating the removal of
 * moderator status...
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucRoleTestForRemovingModerator() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
    mucAsSeenByTwo.addUserStatusListener(new UserStatusListener() {

        @Override
        public void moderatorRevoked() {
            resultSyncPoint.signal("done");
        }
    });
    createMuc(mucAsSeenByOne, "one-" + randomString);
    try {
        final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByOne.grantModerator(nicknameTwo);
        mucAsSeenByOne.revokeModerator(nicknameTwo);
        resultSyncPoint.waitForResult(timeout);
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackException(org.jivesoftware.smack.SmackException) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 10 with SmackIntegrationTest

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

the class MultiUserChatRolesAffiliationsPrivilegesIntegrationTest method mucTestPersistentAffiliation.

/**
 * Asserts that an affiliation is persistent between visits to the room.
 *
 * <p>From XEP-0045 § 5.2:</p>
 * <blockquote>
 * These affiliations are long-lived in that they persist across a user's visits to the room and are not affected
 * by happenings in the room...Affiliations are granted, revoked, and maintained based on the user's bare JID, not
 * the nick as with roles.
 * </blockquote>
 *
 * @throws Exception when errors occur
 */
@SmackIntegrationTest
public void mucTestPersistentAffiliation() throws Exception {
    EntityBareJid mucAddress = getRandomRoom("smack-inttest");
    MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
    MultiUserChat mucAsSeenByThree = mucManagerThree.getMultiUserChat(mucAddress);
    final Resourcepart nicknameOne = Resourcepart.from("one-" + randomString);
    final Resourcepart nicknameTwo = Resourcepart.from("two-" + randomString);
    final Resourcepart nicknameThree = Resourcepart.from("three-" + randomString);
    createMuc(mucAsSeenByOne, nicknameOne);
    try {
        mucAsSeenByTwo.join(nicknameTwo);
        mucAsSeenByThree.join(nicknameThree);
        mucAsSeenByOne.grantOwnership(conTwo.getUser().asBareJid());
        mucAsSeenByOne.grantAdmin(conThree.getUser().asBareJid());
        mucAsSeenByTwo.leave();
        mucAsSeenByThree.leave();
        Presence p2 = mucAsSeenByTwo.join(nicknameTwo);
        Presence p3 = mucAsSeenByThree.join(nicknameThree);
        assertEquals(MUCAffiliation.owner, MUCUser.from(p2).getItem().getAffiliation());
        assertEquals(MUCAffiliation.admin, MUCUser.from(p3).getItem().getAffiliation());
    } finally {
        tryDestroy(mucAsSeenByOne);
    }
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) EntityBareJid(org.jxmpp.jid.EntityBareJid) Resourcepart(org.jxmpp.jid.parts.Resourcepart) 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