2013-02-07 15:19:47 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2013-02-07 15:19:47 +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.
|
|
|
|
*/
|
2003-10-14 01:12:34 +02:00
|
|
|
|
|
|
|
package org.jivesoftware.smackx;
|
|
|
|
|
2004-08-04 21:54:17 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
|
2004-10-31 04:37:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException;
|
2004-07-12 15:36:13 +02:00
|
|
|
import org.jivesoftware.smack.test.SmackTestCase;
|
2004-08-04 21:54:17 +02:00
|
|
|
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
2012-10-26 12:47:55 +02:00
|
|
|
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
|
2003-10-14 01:12:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the service discovery functionality.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2003-10-14 01:12:34 +02:00
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2004-07-12 15:36:13 +02:00
|
|
|
public class ServiceDiscoveryManagerTest extends SmackTestCase {
|
2003-10-14 01:12:34 +02:00
|
|
|
|
|
|
|
public ServiceDiscoveryManagerTest(String arg0) {
|
|
|
|
super(arg0);
|
|
|
|
}
|
|
|
|
|
2004-08-04 21:54:17 +02:00
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Tests info discovery of a Smack client.
|
2004-08-04 21:54:17 +02:00
|
|
|
*/
|
|
|
|
public void testSmackInfo() {
|
|
|
|
|
|
|
|
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager
|
|
|
|
.getInstanceFor(getConnection(0));
|
|
|
|
try {
|
|
|
|
// Discover the information of another Smack client
|
2013-03-18 09:40:35 +01:00
|
|
|
DiscoverInfo info = discoManager.discoverInfo(getFullJID(1));
|
2004-08-04 21:54:17 +02:00
|
|
|
// Check the identity of the Smack client
|
2012-10-26 12:47:55 +02:00
|
|
|
Iterator<Identity> identities = info.getIdentities();
|
2004-08-04 21:54:17 +02:00
|
|
|
assertTrue("No identities were found", identities.hasNext());
|
2012-10-26 12:47:55 +02:00
|
|
|
Identity identity = identities.next();
|
2013-10-22 16:43:23 +02:00
|
|
|
assertEquals("Name in identity is wrong", discoManager.getIdentityName(),
|
2004-08-04 21:54:17 +02:00
|
|
|
identity.getName());
|
|
|
|
assertEquals("Category in identity is wrong", "client", identity.getCategory());
|
2013-10-22 16:43:23 +02:00
|
|
|
assertEquals("Type in identity is wrong", discoManager.getIdentityType(),
|
2004-08-04 21:54:17 +02:00
|
|
|
identity.getType());
|
|
|
|
assertFalse("More identities were found", identities.hasNext());
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-31 04:37:05 +01:00
|
|
|
/**
|
|
|
|
* Tests that ensures that Smack answers a 404 error when the disco#info includes a node.
|
|
|
|
*/
|
|
|
|
public void testInfoWithNode() {
|
|
|
|
|
|
|
|
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager
|
|
|
|
.getInstanceFor(getConnection(0));
|
|
|
|
try {
|
|
|
|
// Discover the information of another Smack client
|
|
|
|
discoManager.discoverInfo(getFullJID(1), "some node");
|
|
|
|
// Check the identity of the Smack client
|
|
|
|
fail("Unexpected identities were returned instead of a 404 error");
|
|
|
|
}
|
|
|
|
catch (XMPPException e) {
|
|
|
|
assertEquals("Incorrect error", 404, e.getXMPPError().getCode());
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-14 01:12:34 +02:00
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Tests service discovery of XHTML support.
|
2003-10-14 01:12:34 +02:00
|
|
|
*/
|
|
|
|
public void testXHTMLFeature() {
|
2003-12-19 19:22:42 +01:00
|
|
|
// Check for local XHTML service support
|
|
|
|
// By default the XHTML service support is enabled in all the connections
|
2004-07-12 15:36:13 +02:00
|
|
|
assertTrue(XHTMLManager.isServiceEnabled(getConnection(0)));
|
|
|
|
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1)));
|
2004-09-10 23:39:56 +02:00
|
|
|
// Check for XHTML support in connection1 from connection2
|
2018-05-09 23:06:12 +02:00
|
|
|
// Must specify a full JID and not a bare JID. Ensure that the server is working ok.
|
2004-09-10 23:39:56 +02:00
|
|
|
assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getBareJID(0)));
|
2018-05-09 23:06:12 +02:00
|
|
|
// Using a full JID check that the other client supports XHTML.
|
2004-09-10 23:39:56 +02:00
|
|
|
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0)));
|
2005-08-27 04:21:24 +02:00
|
|
|
|
2003-10-14 01:12:34 +02:00
|
|
|
// Disable the XHTML Message support in connection1
|
2004-07-12 15:36:13 +02:00
|
|
|
XHTMLManager.setServiceEnabled(getConnection(0), false);
|
2018-05-09 23:06:12 +02:00
|
|
|
// Check for local XHTML service support
|
2004-07-12 15:36:13 +02:00
|
|
|
assertFalse(XHTMLManager.isServiceEnabled(getConnection(0)));
|
|
|
|
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1)));
|
2018-05-09 23:06:12 +02:00
|
|
|
// Check for XHTML support in connection1 from connection2
|
2004-07-12 15:36:13 +02:00
|
|
|
assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0)));
|
2003-10-14 01:12:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-08-05 18:57:57 +02:00
|
|
|
* Tests support for publishing items to another entity.
|
2003-10-14 01:12:34 +02:00
|
|
|
*/
|
2004-08-05 18:57:57 +02:00
|
|
|
public void testDiscoverPublishItemsSupport() {
|
|
|
|
try {
|
|
|
|
boolean canPublish = ServiceDiscoveryManager.getInstanceFor(getConnection(0))
|
2015-05-18 16:48:23 +02:00
|
|
|
.canPublishItems(getXMPPServiceDomain());
|
2005-12-13 23:43:24 +01:00
|
|
|
assertFalse("Wildfire does not support publishing...so far!!", canPublish);
|
2004-08-05 18:57:57 +02:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
2003-10-14 01:12:34 +02:00
|
|
|
|
2004-08-05 18:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests publishing items to another entity.
|
|
|
|
*/
|
|
|
|
/*public void testPublishItems() {
|
2003-10-14 01:12:34 +02:00
|
|
|
DiscoverItems itemsToPublish = new DiscoverItems();
|
|
|
|
DiscoverItems.Item itemToPublish = new DiscoverItems.Item("pubsub.shakespeare.lit");
|
|
|
|
itemToPublish.setName("Avatar");
|
|
|
|
itemToPublish.setNode("romeo/avatar");
|
|
|
|
itemToPublish.setAction(DiscoverItems.Item.UPDATE_ACTION);
|
|
|
|
itemsToPublish.addItem(itemToPublish);
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2003-10-14 01:12:34 +02:00
|
|
|
try {
|
2015-05-18 16:48:23 +02:00
|
|
|
ServiceDiscoveryManager.getInstanceFor(getConnection(0)).publishItems(getXMPPServiceDomain(),
|
2004-08-05 18:57:57 +02:00
|
|
|
itemsToPublish);
|
2003-10-14 01:12:34 +02:00
|
|
|
}
|
2004-08-05 18:57:57 +02:00
|
|
|
catch (Exception e) {
|
2003-10-14 01:12:34 +02:00
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2003-10-14 01:12:34 +02:00
|
|
|
}*/
|
|
|
|
|
2004-07-12 15:36:13 +02:00
|
|
|
protected int getMaxConnections() {
|
|
|
|
return 2;
|
2003-10-14 01:12:34 +02:00
|
|
|
}
|
|
|
|
}
|