2005-04-22 06:24:25 +02:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2005-04-22 06:24:25 +02:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2005-04-22 06:24:25 +02: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;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.PacketCollector;
|
|
|
|
import org.jivesoftware.smack.filter.PacketIDFilter;
|
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
|
|
|
import org.jivesoftware.smack.test.SmackTestCase;
|
|
|
|
import org.jivesoftware.smackx.packet.Version;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case to ensure that Smack is able to get and parse correctly iq:version packets.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
public class VersionTest extends SmackTestCase {
|
|
|
|
|
|
|
|
public VersionTest(String arg0) {
|
|
|
|
super(arg0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the version of the server and make sure that all the required data is present
|
|
|
|
*
|
|
|
|
* Note: This test expects the server to answer an iq:version packet.
|
|
|
|
*/
|
|
|
|
public void testGetServerVersion() {
|
|
|
|
Version version = new Version();
|
2014-06-06 02:20:45 +02:00
|
|
|
version.setType(IQ.Type.get);
|
2005-08-27 04:21:24 +02:00
|
|
|
version.setTo(getServiceName());
|
2005-04-22 06:24:25 +02:00
|
|
|
|
|
|
|
// Create a packet collector to listen for a response.
|
2015-02-05 11:17:27 +01:00
|
|
|
PacketCollector collector = getConnection(0).createPacketCollector(new PacketIDFilter(version.getStanzaId()));
|
2005-04-22 06:24:25 +02:00
|
|
|
|
2015-03-04 21:44:43 +01:00
|
|
|
getConnection(0).sendStanza(version);
|
2005-04-22 06:24:25 +02:00
|
|
|
|
|
|
|
// Wait up to 5 seconds for a result.
|
|
|
|
IQ result = (IQ)collector.nextResult(5000);
|
|
|
|
// Close the collector
|
|
|
|
collector.cancel();
|
|
|
|
|
|
|
|
assertNotNull("No result from the server", result);
|
|
|
|
|
2014-06-06 02:20:45 +02:00
|
|
|
assertEquals("Incorrect result type", IQ.Type.result, result.getType());
|
2005-04-22 06:24:25 +02:00
|
|
|
assertNotNull("No name specified in the result", ((Version)result).getName());
|
|
|
|
assertNotNull("No version specified in the result", ((Version)result).getVersion());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getMaxConnections() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|