Search in sources :

Example 56 with SmackIntegrationTest

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

the class EntityCapsTest method testEntityCaps.

@SmackIntegrationTest
public void testEntityCaps() throws XMPPException, InterruptedException, NoResponseException, NotConnectedException, TimeoutException {
    final String dummyFeature = getNewDummyFeature();
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            sdmTwo.addFeature(dummyFeature);
        }
    }, connection, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    waitUntilTrue(new Condition() {

        @Override
        public boolean evaluate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
            DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
            return info.containsFeature(dummyFeature);
        }
    });
    DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
    String u1ver = EntityCapsManager.getNodeVersionByJid(conTwo.getUser());
    assertNotNull(u1ver);
    DiscoverInfo entityInfo = EntityCapsManager.CAPS_CACHE.lookup(u1ver);
    assertNotNull(entityInfo);
    assertEquals(info.toXML().toString(), entityInfo.toXML().toString());
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) ThrowingRunnable(org.jivesoftware.smack.util.Async.ThrowingRunnable) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 57 with SmackIntegrationTest

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

the class EntityCapsTest method testLocalEntityCaps.

@SmackIntegrationTest
public void testLocalEntityCaps() throws InterruptedException, NoResponseException, XMPPErrorException, NotConnectedException {
    final String dummyFeature = getNewDummyFeature();
    DiscoverInfo info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer());
    assertFalse(info.containsFeature(dummyFeature));
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            // This should cause a new presence stanza from con1 with and updated
            // 'ver' String
            sdmTwo.addFeature(dummyFeature);
        }
    }, conOne, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    // The presence stanza should get received by con0 and the data should
    // be recorded in the map
    // Note that while both connections use the same static Entity Caps
    // cache,
    // it's assured that *not* con1 added the data to the Entity Caps cache.
    // Every time the entities features
    // and identities change only a new caps 'ver' is calculated and send
    // with the presence stanza
    // The other connection has to receive this stanza and record the
    // information in order for this test to succeed.
    info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer());
    assertNotNull(info);
    assertTrue(info.containsFeature(dummyFeature));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AndFilter(org.jivesoftware.smack.filter.AndFilter) ThrowingRunnable(org.jivesoftware.smack.util.Async.ThrowingRunnable) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 58 with SmackIntegrationTest

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

the class ChatTest method testProperties.

@SuppressWarnings("deprecation")
@SmackIntegrationTest
public void testProperties() throws Exception {
    org.jivesoftware.smack.chat.Chat newChat = chatManagerOne.createChat(conTwo.getUser());
    StanzaCollector collector = conTwo.createStanzaCollector(new ThreadFilter(newChat.getThreadID()));
    MessageBuilder messageBuilder = StanzaBuilder.buildMessage();
    messageBuilder.setSubject("Subject of the chat");
    messageBuilder.setBody("Body of the chat");
    addProperty(messageBuilder, "favoriteColor", "red");
    addProperty(messageBuilder, "age", 30);
    addProperty(messageBuilder, "distance", 30f);
    addProperty(messageBuilder, "weight", 30d);
    addProperty(messageBuilder, "male", true);
    addProperty(messageBuilder, "birthdate", new Date());
    Message msg = messageBuilder.build();
    newChat.sendMessage(msg);
    Message msg2 = collector.nextResult(2000);
    assertNotNull(msg2, "No message was received");
    assertEquals(msg.getSubject(), msg2.getSubject(), "Subjects are different");
    assertEquals(msg.getBody(), msg2.getBody(), "Bodies are different");
    assertEquals(getProperty(msg, "favoriteColor"), getProperty(msg2, "favoriteColor"), "favoriteColors are different");
    assertEquals(getProperty(msg, "age"), getProperty(msg2, "age"), "ages are different");
    assertEquals(getProperty(msg, "distance"), getProperty(msg2, "distance"), "distances are different");
    assertEquals(getProperty(msg, "weight"), getProperty(msg2, "weight"), "weights are different");
    assertEquals(getProperty(msg, "male"), getProperty(msg2, "male"), "males are different");
    assertEquals(getProperty(msg, "birthdate"), getProperty(msg2, "birthdate"), "birthdates are different");
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Message(org.jivesoftware.smack.packet.Message) ThreadFilter(org.jivesoftware.smack.filter.ThreadFilter) Date(java.util.Date) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 59 with SmackIntegrationTest

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

the class ChatTest method chatManagerTest.

@SuppressWarnings("deprecation")
@SmackIntegrationTest
public void chatManagerTest() {
    ChatManagerListener listener = new ChatManagerListener() {

        @Override
        public void chatCreated(org.jivesoftware.smack.chat.Chat chat, boolean createdLocally) {
            invoked = true;
        }
    };
    try {
        chatManagerOne.addChatListener(listener);
        chatManagerOne.createChat(conTwo.getUser());
        assertTrue(invoked, "TestChatManagerListener wasn't invoked");
    } finally {
        chatManagerOne.removeChatListener(listener);
    }
}
Also used : ChatManagerListener(org.jivesoftware.smack.chat.ChatManagerListener) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 60 with SmackIntegrationTest

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

the class GeolocationIntegrationTest method testNotificationAfterFilterChange.

/**
 * Verifies that a notification for a previously sent publication is received as soon as notification filtering
 * has been adjusted to allow for the notification to be delivered.
 *
 * @throws Exception if the test fails
 */
@SmackIntegrationTest
public void testNotificationAfterFilterChange() throws Exception {
    GeoLocation.Builder builder = GeoLocation.builder();
    GeoLocation data = builder.setAccuracy(12d).setAlt(999d).setAltAccuracy(9d).setArea("Amsterdam").setBearing(9d).setBuilding("Test Building").setCountry("Netherlands").setCountryCode("NL").setDescription("My Description").setFloor("middle").setLat(25.098345d).setLocality("brilliant").setLon(77.992034).setPostalcode("110085").setRegion("North").setRoom("small").setSpeed(250.0d).setStreet("Wall Street").setText("Unit Testing GeoLocation 2").setTimestamp(XmppDateTime.parseDate("2007-02-19")).setTzo("+5:30").setUri(new URI("http://xmpp.org")).build();
    IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
    final SimpleResultSyncPoint geoLocationReceived = new SimpleResultSyncPoint();
    final PepEventListener<GeoLocation> geoLocationListener = (jid, geoLocation, id, message) -> {
        if (geoLocation.equals(data)) {
            geoLocationReceived.signal();
        }
    };
    // TODO Ensure that pre-existing filtering notification excludes geolocation.
    try {
        // Publish the data
        publishAndWait(glm1, ServiceDiscoveryManager.getInstanceFor(conOne), data);
        // Adds listener, which implicitly publishes a disco/info filter for geolocation notification.
        registerListenerAndWait(glm2, ServiceDiscoveryManager.getInstanceFor(conTwo), geoLocationListener);
        // Wait for the data to be received.
        try {
            Object result = geoLocationReceived.waitForResult(timeout);
            // Explicitly assert the success case.
            Assertions.assertNotNull(result, "Expected to receive a PEP notification, but did not.");
        } catch (TimeoutException e) {
            Assertions.fail("Expected to receive a PEP notification, but did not.");
        }
    } finally {
        unregisterListener(glm2, geoLocationListener);
    }
}
Also used : SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) GeoLocationManager(org.jivesoftware.smackx.geoloc.GeoLocationManager) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) XmppDateTime(org.jxmpp.util.XmppDateTime) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) GeoLocation(org.jivesoftware.smackx.geoloc.packet.GeoLocation) URI(java.net.URI) 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)

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