mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-06-13 15:14:54 +02:00
e98d42790a
This commit adds - SmackReactor / NIO - a framework for finite state machine connections - support for Java 8 - pretty printed XML debug output It also - reworks the integration test framework - raises the minimum Android API level to 19 - introduces XmppNioTcpConnection Furthermore fixes SMACK-801 (at least partly). Java 8 language features are available, but not all runtime library methods. For that we would need to raise the Android API level to 24 or higher.
91 lines
3.6 KiB
Java
91 lines
3.6 KiB
Java
/**
|
|
*
|
|
* Copyright 2015-2019 Florian Schmaus
|
|
*
|
|
* 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;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import java.io.IOException;
|
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
|
import org.jivesoftware.smack.filter.AndFilter;
|
|
import org.jivesoftware.smack.filter.FromMatchesFilter;
|
|
import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
|
|
import org.jivesoftware.smack.packet.Message;
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|
|
|
import org.igniterealtime.smack.inttest.AbstractSmackSpecificLowLevelIntegrationTest;
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
|
import org.igniterealtime.smack.inttest.TestNotPossibleException;
|
|
|
|
public class StreamManagementTest extends AbstractSmackSpecificLowLevelIntegrationTest<XMPPTCPConnection> {
|
|
|
|
public StreamManagementTest(SmackIntegrationTestEnvironment<?> environment) throws Exception {
|
|
super(environment, XMPPTCPConnection.class);
|
|
XMPPTCPConnection connection = getSpecificUnconnectedConnection();
|
|
connection.connect().login();
|
|
if (!connection.isSmAvailable()) {
|
|
throw new TestNotPossibleException("XEP-198: Stream Mangement not supported by service");
|
|
}
|
|
}
|
|
|
|
@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();
|
|
}
|
|
}
|
|
|
|
private static void send(String messageString, XMPPConnection from, XMPPConnection to)
|
|
throws NotConnectedException, InterruptedException {
|
|
Message message = new Message(to.getUser());
|
|
message.setBody(messageString);
|
|
from.sendStanza(message);
|
|
}
|
|
|
|
private static void assertMessageWithBodyReceived(String body, StanzaCollector collector) throws InterruptedException {
|
|
Message message = collector.nextResult();
|
|
assertNotNull(message);
|
|
assertEquals(body, message.getBody());
|
|
}
|
|
}
|