2015-03-18 09:52:33 +01:00
|
|
|
/**
|
|
|
|
*
|
2020-04-04 13:03:31 +02:00
|
|
|
* Copyright 2015-2020 Florian Schmaus
|
2015-03-18 09:52:33 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smack;
|
|
|
|
|
2020-04-12 21:54:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
2015-04-22 22:32:19 +02:00
|
|
|
|
2015-03-18 09:52:33 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2015-04-22 22:32:19 +02:00
|
|
|
import org.jivesoftware.smack.filter.AndFilter;
|
|
|
|
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
|
|
|
import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
|
2015-03-18 09:52:33 +01:00
|
|
|
import org.jivesoftware.smack.packet.Message;
|
|
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|
|
|
|
2019-02-04 08:59:39 +01:00
|
|
|
import org.igniterealtime.smack.inttest.AbstractSmackSpecificLowLevelIntegrationTest;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
|
|
|
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
2020-04-12 21:54:18 +02:00
|
|
|
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2019-02-04 08:59:39 +01:00
|
|
|
public class StreamManagementTest extends AbstractSmackSpecificLowLevelIntegrationTest<XMPPTCPConnection> {
|
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public StreamManagementTest(SmackIntegrationTestEnvironment environment) throws Exception {
|
2019-02-04 08:59:39 +01:00
|
|
|
super(environment, XMPPTCPConnection.class);
|
|
|
|
XMPPTCPConnection connection = getSpecificUnconnectedConnection();
|
|
|
|
connection.connect().login();
|
|
|
|
if (!connection.isSmAvailable()) {
|
|
|
|
throw new TestNotPossibleException("XEP-198: Stream Mangement not supported by service");
|
|
|
|
}
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SmackIntegrationTest
|
2015-04-25 22:46:56 +02:00
|
|
|
public void testStreamManagement(XMPPTCPConnection conOne, XMPPTCPConnection conTwo) throws InterruptedException,
|
|
|
|
SmackException, IOException, XMPPException {
|
2015-04-22 22:32:19 +02:00
|
|
|
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;
|
|
|
|
|
2017-01-03 11:12:34 +01:00
|
|
|
final StanzaCollector collector = conTwo.createStanzaCollector(new AndFilter(
|
2015-04-22 22:32:19 +02:00
|
|
|
MessageWithBodiesFilter.INSTANCE,
|
|
|
|
FromMatchesFilter.createFull(conOne.getUser())));
|
|
|
|
|
|
|
|
try {
|
|
|
|
send(body1, conOne, conTwo);
|
|
|
|
assertMessageWithBodyReceived(body1, collector);
|
2015-03-18 09:52:33 +01:00
|
|
|
|
2015-04-22 22:32:19 +02:00
|
|
|
conOne.instantShutdown();
|
2015-03-18 09:52:33 +01:00
|
|
|
|
2015-04-22 22:32:19 +02:00
|
|
|
send(body2, conOne, conTwo);
|
2015-03-18 09:52:33 +01:00
|
|
|
|
2015-04-22 22:32:19 +02:00
|
|
|
// Reconnect with xep198
|
|
|
|
conOne.connect().login();
|
|
|
|
assertMessageWithBodyReceived(body2, collector);
|
2015-03-18 09:52:33 +01:00
|
|
|
|
2015-04-22 22:32:19 +02:00
|
|
|
send(body3, conOne, conTwo);
|
|
|
|
assertMessageWithBodyReceived(body3, collector);
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
collector.cancel();
|
|
|
|
}
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void send(String messageString, XMPPConnection from, XMPPConnection to)
|
|
|
|
throws NotConnectedException, InterruptedException {
|
2019-10-24 15:45:08 +02:00
|
|
|
Message message = from.getStanzaFactory().buildMessageStanza()
|
|
|
|
.to(to.getUser())
|
|
|
|
.setBody(messageString)
|
|
|
|
.build();
|
2015-03-18 09:52:33 +01:00
|
|
|
from.sendStanza(message);
|
|
|
|
}
|
2015-04-22 22:32:19 +02:00
|
|
|
|
2017-01-03 11:12:34 +01:00
|
|
|
private static void assertMessageWithBodyReceived(String body, StanzaCollector collector) throws InterruptedException {
|
2015-04-22 22:32:19 +02:00
|
|
|
Message message = collector.nextResult();
|
|
|
|
assertNotNull(message);
|
|
|
|
assertEquals(body, message.getBody());
|
|
|
|
}
|
2015-03-18 09:52:33 +01:00
|
|
|
}
|