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());
}
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));
}
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");
}
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);
}
}
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);
}
}
Aggregations