use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class ChatConnectionTest method chatMatchedOnJIDWhenNoThreadJidMode.
@Test
public void chatMatchedOnJIDWhenNoThreadJidMode() {
TestMessageListener msgListener = new TestMessageListener();
TestChatManagerListener listener = new TestChatManagerListener(msgListener);
cm.setMatchMode(ChatManager.MatchMode.SUPPLIED_JID);
cm.addChatListener(listener);
Stanza incomingChat = createChatMessage(null, true);
processServerMessage(incomingChat);
Chat newChat = listener.getNewChat();
assertNotNull(newChat);
cm.removeChatListener(listener);
// Should match on chat with full jid
incomingChat = createChatMessage(null, true);
processServerMessage(incomingChat);
assertEquals(2, msgListener.getNumMessages());
// Should not match on chat with bare jid
TestChatManagerListener listener2 = new TestChatManagerListener();
cm.addChatListener(listener2);
incomingChat = createChatMessage(null, false);
processServerMessage(incomingChat);
assertEquals(2, msgListener.getNumMessages());
assertNotNull(listener2.getNewChat());
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class RosterVersioningTest method answerWithEmptyRosterResult.
private void answerWithEmptyRosterResult() {
// We expect that the roster request is the only packet sent. This is not part of the specification,
// but a shortcut in the test implementation.
Stanza sentPacket = connection.getSentPacket();
if (sentPacket instanceof RosterPacket) {
final IQ emptyIQ = IQ.createResultIQ((RosterPacket) sentPacket);
connection.processStanza(emptyIQ);
} else {
assertTrue("Expected to get a RosterPacket ", false);
}
}
use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class MamIntegrationTest method mamPageTest.
@SmackIntegrationTest
public void mamPageTest() throws TimeoutException, Exception {
final int messagesPerPage = 10;
final int numPages = 3;
final int totalMessages = messagesPerPage * numPages;
final List<Message> outgoingMessages = new ArrayList<>(totalMessages);
final EntityBareJid userOne = conOne.getUser().asEntityBareJid();
final EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
final SimpleResultSyncPoint allMessagesReceived = new SimpleResultSyncPoint();
final String lastMessageArchiveUid = mamManagerConTwo.getMessageUidOfLatestMessage();
for (int i = 0; i < totalMessages; i++) {
String messageBody = "MAM Page Test " + testRunId + ' ' + (i + 1);
Message message = StanzaBuilder.buildMessage().to(userTwo).setBody(messageBody).build();
outgoingMessages.add(message);
}
final String lastBody = outgoingMessages.get(outgoingMessages.size() - 1).getBody();
final StanzaListener stanzaListener = new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
Message message = (Message) stanza;
if (message.getBody().equals(lastBody)) {
allMessagesReceived.signal();
}
}
};
conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
try {
for (Message message : outgoingMessages) {
conOne.sendStanza(message);
}
allMessagesReceived.waitForResult(timeout);
} finally {
conTwo.removeAsyncStanzaListener(stanzaListener);
}
MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSize(messagesPerPage).limitResultsToJid(userOne).afterUid(lastMessageArchiveUid).build();
MamQuery mamQuery = mamManagerConTwo.queryArchive(mamQueryArgs);
assertFalse(mamQuery.isComplete());
assertEquals(messagesPerPage, mamQuery.getMessageCount());
List<List<Message>> pages = new ArrayList<>(numPages);
pages.add(mamQuery.getMessages());
for (int additionalPageRequestNum = 0; additionalPageRequestNum < numPages - 1; additionalPageRequestNum++) {
List<Message> page = mamQuery.pageNext(messagesPerPage);
boolean isLastQuery = additionalPageRequestNum == numPages - 2;
if (isLastQuery) {
assertTrue(mamQuery.isComplete());
} else {
assertFalse(mamQuery.isComplete());
}
assertEquals(messagesPerPage, page.size());
pages.add(page);
}
List<Message> queriedMessages = new ArrayList<>(totalMessages);
for (List<Message> messages : pages) {
queriedMessages.addAll(messages);
}
assertEquals(outgoingMessages.size(), queriedMessages.size());
for (int i = 0; i < outgoingMessages.size(); i++) {
Message outgoingMessage = outgoingMessages.get(i);
Message queriedMessage = queriedMessages.get(i);
assertEquals(outgoingMessage.getBody(), queriedMessage.getBody());
}
}
use of org.jivesoftware.smack.packet.Stanza 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.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.
the class JingleManager method initJingleSessionRequestListeners.
/**
* Register the listenerJingles, waiting for a Jingle stanza that tries to
* establish a new session.
*/
private void initJingleSessionRequestListeners() {
StanzaFilter initRequestFilter = new StanzaFilter() {
// Return true if we accept this packet
@Override
public boolean accept(Stanza pin) {
if (pin instanceof IQ) {
IQ iq = (IQ) pin;
if (iq.getType().equals(IQ.Type.set)) {
if (iq instanceof Jingle) {
Jingle jin = (Jingle) pin;
if (jin.getAction().equals(JingleActionEnum.SESSION_INITIATE)) {
return true;
}
}
}
}
return false;
}
};
jingleSessionRequestListeners = new ArrayList<>();
// Start a packet listener for session initiation requests
connection.addAsyncStanzaListener(new StanzaListener() {
@Override
public void processStanza(Stanza packet) {
triggerSessionRequested((Jingle) packet);
}
}, initRequestFilter);
}
Aggregations