2006-01-16 18:27:22 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2005 Jive Software.
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2006-01-16 18:27:22 +01:00
|
|
|
* 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.smackx;
|
|
|
|
|
2007-07-23 04:06:30 +02:00
|
|
|
import org.jivesoftware.smack.*;
|
|
|
|
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2006-09-14 21:16:40 +02:00
|
|
|
import org.jivesoftware.smack.test.SmackTestCase;
|
2007-07-23 04:06:30 +02:00
|
|
|
import org.jivesoftware.smackx.packet.Version;
|
2006-01-16 18:27:22 +01:00
|
|
|
|
|
|
|
/**
|
2014-06-14 11:45:38 +02:00
|
|
|
* Ensure that stream compression (XEP-138) is correctly supported by Smack.
|
2006-01-16 18:27:22 +01:00
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
public class CompressionTest extends SmackTestCase {
|
|
|
|
|
|
|
|
public CompressionTest(String arg0) {
|
|
|
|
super(arg0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that stream compression works fine. It is assumed that the server supports and has
|
|
|
|
* stream compression enabled.
|
|
|
|
*/
|
|
|
|
public void testSuccessCompression() throws XMPPException {
|
|
|
|
|
2006-01-17 21:05:31 +01:00
|
|
|
// Create the configuration for this new connection
|
|
|
|
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
|
|
|
config.setCompressionEnabled(true);
|
|
|
|
config.setSASLAuthenticationEnabled(true);
|
2006-01-16 18:27:22 +01:00
|
|
|
|
2014-04-09 12:16:44 +02:00
|
|
|
XMPPTCPConnection connection = new XMPPConnection(config);
|
2006-09-14 21:16:40 +02:00
|
|
|
connection.connect();
|
2006-01-16 18:27:22 +01:00
|
|
|
|
|
|
|
// Login with the test account
|
|
|
|
connection.login("user0", "user0");
|
2006-01-23 21:56:26 +01:00
|
|
|
|
2014-03-10 09:45:50 +01:00
|
|
|
assertTrue("XMPPConnection is not using stream compression", connection.isUsingCompression());
|
2006-01-23 21:56:26 +01:00
|
|
|
|
2007-07-23 04:06:30 +02:00
|
|
|
// Request the version of the server
|
|
|
|
Version version = new Version();
|
2014-06-06 02:20:45 +02:00
|
|
|
version.setType(IQ.Type.get);
|
2015-05-18 16:48:23 +02:00
|
|
|
version.setTo(getXMPPServiceDomain());
|
2007-07-23 04:06:30 +02:00
|
|
|
|
|
|
|
// Create a packet collector to listen for a response.
|
2017-01-03 11:12:34 +01:00
|
|
|
StanzaCollector collector = connection.createStanzaCollector(new PacketIDFilter(version.getStanzaId()));
|
2007-07-23 04:06:30 +02:00
|
|
|
|
2015-03-04 21:44:43 +01:00
|
|
|
connection.sendStanza(version);
|
2007-07-23 04:06:30 +02:00
|
|
|
|
|
|
|
// Wait up to 5 seconds for a result.
|
|
|
|
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
|
|
|
// Close the collector
|
|
|
|
collector.cancel();
|
|
|
|
|
|
|
|
assertNotNull("No reply was received from the server", result);
|
2014-06-06 02:20:45 +02:00
|
|
|
assertEquals("Incorrect IQ type from server", IQ.Type.result, result.getType());
|
2007-07-23 04:06:30 +02:00
|
|
|
|
2006-01-16 18:27:22 +01:00
|
|
|
// Close connection
|
2006-09-14 21:16:40 +02:00
|
|
|
connection.disconnect();
|
2006-01-16 18:27:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected int getMaxConnections() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Just create an account.
|
|
|
|
*/
|
|
|
|
protected void setUp() throws Exception {
|
|
|
|
super.setUp();
|
2015-05-18 16:48:23 +02:00
|
|
|
XMPPTCPConnection setupConnection = new XMPPConnection(getXMPPServiceDomain());
|
2006-09-14 21:16:40 +02:00
|
|
|
setupConnection.connect();
|
2006-01-16 18:27:22 +01:00
|
|
|
if (!setupConnection.getAccountManager().supportsAccountCreation())
|
|
|
|
fail("Server does not support account creation");
|
|
|
|
|
|
|
|
// Create the test account
|
|
|
|
try {
|
|
|
|
setupConnection.getAccountManager().createAccount("user0", "user0");
|
|
|
|
} catch (XMPPException e) {
|
|
|
|
// Do nothing if the accout already exists
|
|
|
|
if (e.getXMPPError().getCode() != 409) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes the created account for the test.
|
|
|
|
*/
|
|
|
|
protected void tearDown() throws Exception {
|
|
|
|
super.tearDown();
|
2014-04-09 12:16:44 +02:00
|
|
|
XMPPTCPConnection setupConnection = createConnection();
|
2006-09-14 21:16:40 +02:00
|
|
|
setupConnection.connect();
|
2006-01-16 18:27:22 +01:00
|
|
|
setupConnection.login("user0", "user0");
|
|
|
|
// Delete the created account for the test
|
|
|
|
setupConnection.getAccountManager().deleteAccount();
|
|
|
|
// Close the setupConnection
|
2006-09-14 21:16:40 +02:00
|
|
|
setupConnection.disconnect();
|
2006-01-16 18:27:22 +01:00
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|