Search in sources :

Example 6 with SmackIntegrationTest

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());
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) SASLErrorException(org.jivesoftware.smack.sasl.SASLErrorException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 7 with SmackIntegrationTest

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();
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 8 with SmackIntegrationTest

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());
}
Also used : Field(java.lang.reflect.Field) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 9 with SmackIntegrationTest

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");
    }
}
Also used : FullJid(org.jxmpp.jid.FullJid) Presence(org.jivesoftware.smack.packet.Presence) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) TimeoutException(java.util.concurrent.TimeoutException) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 10 with SmackIntegrationTest

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));
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)19 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)14 AndFilter (org.jivesoftware.smack.filter.AndFilter)4 Message (org.jivesoftware.smack.packet.Message)4 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 TimeoutException (java.util.concurrent.TimeoutException)2 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 ThreadFilter (org.jivesoftware.smack.filter.ThreadFilter)2 Presence (org.jivesoftware.smack.packet.Presence)2 MucCreateConfigFormHandle (org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 Jid (org.jxmpp.jid.Jid)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1