1 52 53 package org.jivesoftware.smackx; 54 55 import java.util.Iterator ; 56 57 import org.jivesoftware.smack.XMPPException; 58 import org.jivesoftware.smack.test.SmackTestCase; 59 import org.jivesoftware.smackx.packet.DiscoverInfo; 60 61 62 67 public class ServiceDiscoveryManagerTest extends SmackTestCase { 68 69 73 public ServiceDiscoveryManagerTest(String arg0) { 74 super(arg0); 75 } 76 77 80 public void testSmackInfo() { 81 82 ServiceDiscoveryManager discoManager = ServiceDiscoveryManager 83 .getInstanceFor(getConnection(0)); 84 try { 85 DiscoverInfo info = discoManager.discoverInfo(getFullJID(1)); 87 Iterator 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 e) { 99 e.printStackTrace(); 100 fail(e.getMessage()); 101 } 102 } 103 104 107 public void testInfoWithNode() { 108 109 ServiceDiscoveryManager discoManager = ServiceDiscoveryManager 110 .getInstanceFor(getConnection(0)); 111 try { 112 discoManager.discoverInfo(getFullJID(1), "some node"); 114 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 e) { 121 e.printStackTrace(); 122 fail(e.getMessage()); 123 } 124 } 125 126 129 public void testXHTMLFeature() { 130 assertTrue(XHTMLManager.isServiceEnabled(getConnection(0))); 133 assertTrue(XHTMLManager.isServiceEnabled(getConnection(1))); 134 assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getBareJID(0))); 137 assertTrue(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0))); 139 140 XHTMLManager.setServiceEnabled(getConnection(0), false); 142 assertFalse(XHTMLManager.isServiceEnabled(getConnection(0))); 144 assertTrue(XHTMLManager.isServiceEnabled(getConnection(1))); 145 assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0))); 147 } 148 149 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 e) { 159 fail(e.getMessage()); 160 } 161 162 } 163 164 167 184 185 protected int getMaxConnections() { 186 return 2; 187 } 188 } 189 | Popular Tags |