use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.
the class LoginIntegrationTest method testInvalidLogin.
/**
* Check that the server is returning the correct error when trying to login using an invalid
* (i.e. non-existent) user.
*
* @throws InterruptedException
* @throws XMPPException
* @throws IOException
* @throws SmackException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
@SmackIntegrationTest
public void testInvalidLogin() throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException {
final String nonExistentUserString = StringUtils.insecureRandomString(24);
XMPPTCPConnectionConfiguration conf = getConnectionConfiguration().setUsernameAndPassword(nonExistentUserString, "invalidPassword").build();
XMPPTCPConnection connection = new XMPPTCPConnection(conf);
connection.connect();
try {
connection.login();
fail("Exception expected");
} catch (SASLErrorException e) {
assertEquals(SASLError.not_authorized, e.getSASLFailure().getSASLError());
}
}
use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.
the class StreamManagementTest method testStreamManagement.
@SmackIntegrationTest
public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException, SmackException, IOException, XMPPException {
final String body1 = "Hi, what's up? " + testRunId;
final String body2 = "Hi, what's up? I've been just instantly shutdown" + testRunId;
final String body3 = "Hi, what's up? I've been just resumed" + testRunId;
final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter(MessageWithBodiesFilter.INSTANCE, FromMatchesFilter.createFull(conOne.getUser())));
try {
send(body1, conOne, conTwo);
assertMessageWithBodyReceived(body1, collector);
conOne.instantShutdown();
send(body2, conOne, conTwo);
// Reconnect with xep198
conOne.connect().login();
assertMessageWithBodyReceived(body2, collector);
send(body3, conOne, conTwo);
assertMessageWithBodyReceived(body3, collector);
} finally {
collector.cancel();
}
}
use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.
the class WaitForClosingStreamElementTest method waitForClosingStreamElementTest.
@SmackIntegrationTest
public void waitForClosingStreamElementTest(XMPPTCPConnection connection) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
connection.disconnect();
Field closingStreamReceivedField = connection.getClass().getDeclaredField("closingStreamReceived");
closingStreamReceivedField.setAccessible(true);
SynchronizationPoint<?> closingStreamReceived = (SynchronizationPoint<?>) closingStreamReceivedField.get(connection);
assertTrue(closingStreamReceived.wasSuccessful());
}
use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.
the class LowLevelRosterIntegrationTest method testPresenceEventListenersOffline.
@SmackIntegrationTest
public void testPresenceEventListenersOffline(final XMPPTCPConnection conOne, final XMPPTCPConnection conTwo) throws TimeoutException, Exception {
RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
final Roster rosterOne = Roster.getInstanceFor(conOne);
final Roster rosterTwo = Roster.getInstanceFor(conTwo);
// TODO create Roster.createEntry() with boolean flag for subscribe or not.
rosterOne.createEntry(conTwo.getUser().asBareJid(), "Con Two", null);
rosterTwo.createEntry(conOne.getUser().asBareJid(), "Con One", null);
// TODO Change timeout form '5000' to something configurable.
final long timeout = 5000;
RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
final SimpleResultSyncPoint offlineTriggered = new SimpleResultSyncPoint();
rosterOne.addPresenceEventListener(new AbstractPresenceEventListener() {
@Override
public void presenceUnavailable(FullJid jid, Presence presence) {
if (!jid.equals(conTwo.getUser())) {
return;
}
offlineTriggered.signal();
}
});
// Disconnect conTwo, this should cause an 'unavilable' presence to be send from conTwo to
// conOne.
conTwo.disconnect();
Boolean result = offlineTriggered.waitForResult(timeout);
if (!result) {
throw new Exception("presenceUnavailable() was not called");
}
}
use of org.igniterealtime.smack.inttest.SmackIntegrationTest in project Smack by igniterealtime.
the class EntityCapsTest method testPreventDiscoInfo.
/**
* Test if entity caps actually prevent a disco info request and reply.
*
* @throws XMPPException
* @throws InterruptedException
* @throws NotConnectedException
* @throws NoResponseException
*
*/
@SmackIntegrationTest
public void testPreventDiscoInfo() throws XMPPException, NoResponseException, NotConnectedException, InterruptedException {
final String dummyFeature = getNewDummyFeature();
conOne.addPacketSendingListener(new StanzaListener() {
@Override
public void processStanza(Stanza stanza) {
discoInfoSend = true;
}
}, new AndFilter(new StanzaTypeFilter(DiscoverInfo.class), IQTypeFilter.GET));
// add a bogus feature so that con1 ver won't match con0's
sdmTwo.addFeature(dummyFeature);
dropCapsCache();
// discover that
DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
// that discovery should cause a disco#info
assertTrue(discoInfoSend);
assertTrue(info.containsFeature(dummyFeature));
discoInfoSend = false;
// discover that
info = sdmOne.discoverInfo(conTwo.getUser());
// that discovery shouldn't cause a disco#info
assertFalse(discoInfoSend);
assertTrue(info.containsFeature(dummyFeature));
}
Aggregations