KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2 * $RCSfile$
3 * $Revision: 2729 $
4 * $Date: 2005-08-26 23:21:24 -0300 (Fri, 26 Aug 2005) $
5 *
6 * Copyright (C) 2002-2003 Jive Software. All rights reserved.
7 * ====================================================================
8 * The Jive Software License (based on Apache Software License, Version 1.1)
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. The end-user documentation included with the redistribution,
23 * if any, must include the following acknowledgment:
24 * "This product includes software developed by
25 * Jive Software (http://www.jivesoftware.com)."
26 * Alternately, this acknowledgment may appear in the software itself,
27 * if and wherever such third-party acknowledgments normally appear.
28 *
29 * 4. The names "Smack" and "Jive Software" must not be used to
30 * endorse or promote products derived from this software without
31 * prior written permission. For written permission, please
32 * contact webmaster@jivesoftware.com.
33 *
34 * 5. Products derived from this software may not be called "Smack",
35 * nor may "Smack" appear in their name, without prior written
36 * permission of Jive Software.
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 */

52
53 package org.jivesoftware.smackx;
54
55 import java.util.Iterator JavaDoc;
56
57 import org.jivesoftware.smack.XMPPException;
58 import org.jivesoftware.smack.test.SmackTestCase;
59 import org.jivesoftware.smackx.packet.DiscoverInfo;
60
61
62 /**
63  * Tests the service discovery functionality.
64  *
65  * @author Gaston Dombiak
66  */

67 public class ServiceDiscoveryManagerTest extends SmackTestCase {
68
69     /**
70      * Constructor for ServiceDiscoveryManagerTest.
71      * @param arg0
72      */

73     public ServiceDiscoveryManagerTest(String JavaDoc arg0) {
74         super(arg0);
75     }
76
77     /**
78      * Tests info discovery of a Smack client.
79      */

80     public void testSmackInfo() {
81
82         ServiceDiscoveryManager discoManager = ServiceDiscoveryManager
83                 .getInstanceFor(getConnection(0));
84         try {
85             // Discover the information of another Smack client
86
DiscoverInfo info = discoManager.discoverInfo(getFullJID(1));
87             // Check the identity of the Smack client
88
Iterator JavaDoc identities = info.getIdentities();
89             assertTrue("No identities were found", identities.hasNext());
90             DiscoverInfo.Identity identity = (DiscoverInfo.Identity)identities.next();
91             assertEquals("Name in identity is wrong", ServiceDiscoveryManager.getIdentityName(),
92                     identity.getName());
93             assertEquals("Category in identity is wrong", "client", identity.getCategory());
94             assertEquals("Type in identity is wrong", ServiceDiscoveryManager.getIdentityType(),
95                     identity.getType());
96             assertFalse("More identities were found", identities.hasNext());
97         }
98         catch (Exception JavaDoc e) {
99             e.printStackTrace();
100             fail(e.getMessage());
101         }
102     }
103
104     /**
105      * Tests that ensures that Smack answers a 404 error when the disco#info includes a node.
106      */

107     public void testInfoWithNode() {
108
109         ServiceDiscoveryManager discoManager = ServiceDiscoveryManager
110                 .getInstanceFor(getConnection(0));
111         try {
112             // Discover the information of another Smack client
113
discoManager.discoverInfo(getFullJID(1), "some node");
114             // Check the identity of the Smack client
115
fail("Unexpected identities were returned instead of a 404 error");
116         }
117         catch (XMPPException e) {
118             assertEquals("Incorrect error", 404, e.getXMPPError().getCode());
119         }
120         catch (Exception JavaDoc e) {
121             e.printStackTrace();
122             fail(e.getMessage());
123         }
124     }
125
126     /**
127      * Tests service discovery of XHTML support.
128      */

129     public void testXHTMLFeature() {
130         // Check for local XHTML service support
131
// By default the XHTML service support is enabled in all the connections
132
assertTrue(XHTMLManager.isServiceEnabled(getConnection(0)));
133         assertTrue(XHTMLManager.isServiceEnabled(getConnection(1)));
134         // Check for XHTML support in connection1 from connection2
135
// Must specify a full JID and not a bare JID. Ensure that the server is working ok.
136
assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getBareJID(0)));
137         // Using a full JID check that the other client supports XHTML.
138
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0)));
139
140         // Disable the XHTML Message support in connection1
141
XHTMLManager.setServiceEnabled(getConnection(0), false);
142         // Check for local XHTML service support
143
assertFalse(XHTMLManager.isServiceEnabled(getConnection(0)));
144         assertTrue(XHTMLManager.isServiceEnabled(getConnection(1)));
145         // Check for XHTML support in connection1 from connection2
146
assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0)));
147     }
148
149     /**
150      * Tests support for publishing items to another entity.
151      */

152     public void testDiscoverPublishItemsSupport() {
153         try {
154             boolean canPublish = ServiceDiscoveryManager.getInstanceFor(getConnection(0))
155                     .canPublishItems(getServiceName());
156             assertFalse("Messenger does not support publishing...so far!!", canPublish);
157         }
158         catch (Exception JavaDoc e) {
159             fail(e.getMessage());
160         }
161
162     }
163
164     /**
165      * Tests publishing items to another entity.
166      */

167     /*public void testPublishItems() {
168         DiscoverItems itemsToPublish = new DiscoverItems();
169         DiscoverItems.Item itemToPublish = new DiscoverItems.Item("pubsub.shakespeare.lit");
170         itemToPublish.setName("Avatar");
171         itemToPublish.setNode("romeo/avatar");
172         itemToPublish.setAction(DiscoverItems.Item.UPDATE_ACTION);
173         itemsToPublish.addItem(itemToPublish);
174         
175         try {
176             ServiceDiscoveryManager.getInstanceFor(getConnection(0)).publishItems(getServiceName(),
177                     itemsToPublish);
178         }
179         catch (Exception e) {
180             fail(e.getMessage());
181         }
182         
183     }*/

184
185     protected int getMaxConnections() {
186         return 2;
187     }
188 }
189
Popular Tags