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