KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > VersionTest


1 /**
2  * $RCSfile$
3  * $Revision: 2729 $
4  * $Date: 2005-08-26 23:21:24 -0300 (Fri, 26 Aug 2005) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smackx;
22
23 import org.jivesoftware.smack.PacketCollector;
24 import org.jivesoftware.smack.XMPPConnection;
25 import org.jivesoftware.smack.filter.PacketIDFilter;
26 import org.jivesoftware.smack.packet.IQ;
27 import org.jivesoftware.smack.test.SmackTestCase;
28 import org.jivesoftware.smackx.packet.Version;
29
30 /**
31  * Test case to ensure that Smack is able to get and parse correctly iq:version packets.
32  *
33  * @author Gaston Dombiak
34  */

35 public class VersionTest extends SmackTestCase {
36
37     public VersionTest(String JavaDoc arg0) {
38         super(arg0);
39     }
40
41     /**
42      * Get the version of the server and make sure that all the required data is present
43      *
44      * Note: This test expects the server to answer an iq:version packet.
45      */

46     public void testGetServerVersion() {
47         Version version = new Version();
48         version.setType(IQ.Type.GET);
49         version.setTo(getServiceName());
50
51         // Create a packet collector to listen for a response.
52
PacketCollector collector = getConnection(0).createPacketCollector(new PacketIDFilter(version.getPacketID()));
53
54         getConnection(0).sendPacket(version);
55
56         // Wait up to 5 seconds for a result.
57
IQ result = (IQ)collector.nextResult(5000);
58         // Close the collector
59
collector.cancel();
60
61         assertNotNull("No result from the server", result);
62
63         assertEquals("Incorrect result type", IQ.Type.RESULT, result.getType());
64         assertNotNull("No name specified in the result", ((Version)result).getName());
65         assertNotNull("No version specified in the result", ((Version)result).getVersion());
66     }
67
68     protected int getMaxConnections() {
69         return 1;
70     }
71
72     protected void setUp() throws Exception JavaDoc {
73         XMPPConnection.DEBUG_ENABLED = false;
74         super.setUp();
75     }
76 }
77
Popular Tags