Search in sources :

Example 61 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class IoTControlIntegrationTest method controlTest.

/**
 * Connection one provides a thing, which is controlled by connection two.
 *
 * @throws Exception if an exception occurs.
 * @throws TimeoutException if there was a timeout.
 */
@SmackIntegrationTest
public // @SmackSerialIntegrationTest
void controlTest() throws Exception {
    final String key = StringUtils.randomString(12);
    final String sn = StringUtils.randomString(12);
    final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
    Thing controlThing = Thing.builder().setKey(key).setSerialNumber(sn).setControlRequestHandler(new ThingControlRequest() {

        @Override
        public void processRequest(Jid from, Collection<SetData> setData) throws XMPPErrorException {
            if (!from.equals(conTwo.getUser())) {
                return;
            }
            for (final SetData data : setData) {
                if (!data.getName().equals(testRunId))
                    continue;
                if (!(data instanceof SetBoolData))
                    continue;
                SetBoolData boolData = (SetBoolData) data;
                if (boolData.getBooleanValue()) {
                    syncPoint.signal();
                    break;
                }
            }
        }
    }).build();
    IoTControlManagerOne.installThing(controlThing);
    try {
        IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
        SetData data = new SetBoolData(testRunId, true);
        IoTSetResponse response = IoTControlManagerTwo.setUsingIq(conOne.getUser(), data);
        assertNotNull(response);
    } finally {
        IoTControlManagerOne.uninstallThing(controlThing);
        IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    }
    syncPoint.waitForResult(timeout);
}
Also used : Jid(org.jxmpp.jid.Jid) ThingControlRequest(org.jivesoftware.smackx.iot.control.ThingControlRequest) Collection(java.util.Collection) SetBoolData(org.jivesoftware.smackx.iot.control.element.SetBoolData) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) SetData(org.jivesoftware.smackx.iot.control.element.SetData) IoTSetResponse(org.jivesoftware.smackx.iot.control.element.IoTSetResponse) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 62 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class XmppConnectionIntegrationTest method allToAllMessageSendTest.

@SmackIntegrationTest(connectionCount = 4)
public void allToAllMessageSendTest(List<AbstractXMPPConnection> connections) throws InterruptedException, NotAllMessagesReceivedException, ErrorsWhileSendingOrReceivingException {
    final long seed = 42;
    // 100
    final int messagesPerConnection = 3;
    // 512
    final int maxPayloadChunkSize = 16;
    // 32
    final int maxPayloadChunks = 4;
    // true
    final boolean intermixMessages = false;
    XmppConnectionStressTest.Configuration stressTestConfiguration = new XmppConnectionStressTest.Configuration(seed, messagesPerConnection, maxPayloadChunkSize, maxPayloadChunks, intermixMessages);
    XmppConnectionStressTest stressTest = new XmppConnectionStressTest(stressTestConfiguration);
    stressTest.run(connections, timeout);
    final Level connectionStatsLogLevel = Level.FINE;
    if (LOGGER.isLoggable(connectionStatsLogLevel)) {
        if (connections.get(0) instanceof ModularXmppClientToServerConnection) {
            for (XMPPConnection connection : connections) {
                ModularXmppClientToServerConnection xmppC2sConnection = (ModularXmppClientToServerConnection) connection;
                ModularXmppClientToServerConnection.Stats stats = xmppC2sConnection.getStats();
                LOGGER.log(connectionStatsLogLevel, "Connections stats for " + xmppC2sConnection + ":\n{}", stats);
            }
        }
    }
}
Also used : Level(java.util.logging.Level) XmppConnectionStressTest(org.igniterealtime.smack.XmppConnectionStressTest) ModularXmppClientToServerConnection(org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 63 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class SimpleXmppConnectionIntegrationTest method createConnectionTest.

@SmackIntegrationTest(connectionCount = 2)
public void createConnectionTest(List<AbstractXMPPConnection> connections) throws TimeoutException, Exception {
    final AbstractXMPPConnection conOne = connections.get(0), conTwo = connections.get(1);
    EntityFullJid userTwo = conTwo.getUser();
    final String messageBody = testRunId + ": Hello from the other side!";
    Message message = conTwo.getStanzaFactory().buildMessageStanza().to(userTwo).setBody(messageBody).build();
    final SimpleResultSyncPoint messageReceived = new SimpleResultSyncPoint();
    final StanzaListener stanzaListener = (Stanza stanza) -> {
        if (((Message) stanza).getBody().equals(messageBody)) {
            messageReceived.signal();
        }
    };
    conTwo.addAsyncStanzaListener(stanzaListener, MessageWithBodiesFilter.INSTANCE);
    try {
        conOne.sendStanza(message);
        messageReceived.waitForResult(timeout);
    } finally {
        conTwo.removeAsyncStanzaListener(stanzaListener);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) EntityFullJid(org.jxmpp.jid.EntityFullJid) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 64 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class OutgoingMessageListenerIntegrationTest method outgoingMessageListenerTest.

@SmackIntegrationTest
public void outgoingMessageListenerTest() throws Exception {
    final String body = StringUtils.randomString(16);
    final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
    final OutgoingChatMessageListener listener = new OutgoingChatMessageListener() {

        @Override
        public void newOutgoingMessage(EntityBareJid to, MessageBuilder messageBuilder, Chat chat) {
            Message message = messageBuilder.build();
            if (message.getBody().equals(body)) {
                syncPoint.signal();
            }
        }
    };
    EntityBareJid peer = conTwo.getUser().asEntityBareJid();
    try {
        chatManagerOne.addOutgoingListener(listener);
        Chat chat = chatManagerOne.chatWith(peer);
        chat.send(body);
        syncPoint.waitForResult(timeout);
    } finally {
        chatManagerOne.removeOutgoingListener(listener);
    }
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Message(org.jivesoftware.smack.packet.Message) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) EntityBareJid(org.jxmpp.jid.EntityBareJid) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Example 65 with SmackIntegrationTest

use of org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest in project Smack by igniterealtime.

the class RosterIntegrationTest method subscribeRequestListenerTest.

@SmackIntegrationTest
public void subscribeRequestListenerTest() throws TimeoutException, Exception {
    IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
    final SubscribeListener subscribeListener = new SubscribeListener() {

        @Override
        public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
            if (from.equals(conOne.getUser().asBareJid())) {
                return SubscribeAnswer.Approve;
            }
            return SubscribeAnswer.Deny;
        }
    };
    rosterTwo.addSubscribeListener(subscribeListener);
    final String conTwosRosterName = "ConTwo " + testRunId;
    final SimpleResultSyncPoint addedAndSubscribed = new SimpleResultSyncPoint();
    rosterOne.addRosterListener(new AbstractRosterListener() {

        @Override
        public void entriesAdded(Collection<Jid> addresses) {
            checkIfAddedAndSubscribed(addresses);
        }

        @Override
        public void entriesUpdated(Collection<Jid> addresses) {
            checkIfAddedAndSubscribed(addresses);
        }

        private void checkIfAddedAndSubscribed(Collection<Jid> addresses) {
            for (Jid jid : addresses) {
                if (!jid.equals(conTwo.getUser().asBareJid())) {
                    continue;
                }
                BareJid bareJid = conTwo.getUser().asBareJid();
                RosterEntry rosterEntry = rosterOne.getEntry(bareJid);
                if (rosterEntry == null) {
                    addedAndSubscribed.signalFailure("No roster entry for " + bareJid);
                    return;
                }
                String name = rosterEntry.getName();
                if (StringUtils.isNullOrEmpty(name)) {
                    addedAndSubscribed.signalFailure("Roster entry without name");
                    return;
                }
                if (!rosterEntry.getName().equals(conTwosRosterName)) {
                    addedAndSubscribed.signalFailure("Roster name does not match");
                    return;
                }
                if (!rosterEntry.getType().equals(ItemType.to)) {
                    return;
                }
                addedAndSubscribed.signal();
            }
        }
    });
    try {
        rosterOne.createItemAndRequestSubscription(conTwo.getUser().asBareJid(), conTwosRosterName, null);
        assertTrue(addedAndSubscribed.waitForResult(2 * connection.getReplyTimeout()));
    } finally {
        rosterTwo.removeSubscribeListener(subscribeListener);
    }
}
Also used : Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) BareJid(org.jxmpp.jid.BareJid) Presence(org.jivesoftware.smack.packet.Presence) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Aggregations

SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)66 EntityBareJid (org.jxmpp.jid.EntityBareJid)30 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)25 XMPPException (org.jivesoftware.smack.XMPPException)23 SmackException (org.jivesoftware.smack.SmackException)20 Resourcepart (org.jxmpp.jid.parts.Resourcepart)20 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)17 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)17 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)16 EntityFullJid (org.jxmpp.jid.EntityFullJid)12 Message (org.jivesoftware.smack.packet.Message)9 TimeoutException (java.util.concurrent.TimeoutException)8 Presence (org.jivesoftware.smack.packet.Presence)7 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)6 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)6 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)6 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)6 ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)6 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)6 Assertions (org.junit.jupiter.api.Assertions)6