1 20 21 package org.jivesoftware.smack; 22 23 import org.jivesoftware.smack.test.SmackTestCase; 24 import org.jivesoftware.smack.packet.IQ; 25 import org.jivesoftware.smack.filter.PacketFilter; 26 import org.jivesoftware.smack.filter.AndFilter; 27 import org.jivesoftware.smack.filter.PacketIDFilter; 28 import org.jivesoftware.smack.filter.PacketTypeFilter; 29 30 35 public class IQTest extends SmackTestCase { 36 37 public IQTest(String arg0) { 38 super(arg0); 39 } 40 41 45 public void testInvalidNamespace() { 46 IQ iq = new IQ() { 47 public String getChildElementXML() { 48 StringBuffer buf = new StringBuffer (); 49 buf.append("<query xmlns=\"jabber:iq:anything\">"); 50 buf.append("</query>"); 51 return buf.toString(); 52 } 53 }; 54 55 PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getPacketID()), 56 new PacketTypeFilter(IQ.class)); 57 PacketCollector collector = getConnection(0).createPacketCollector(filter); 58 getConnection(0).sendPacket(iq); 60 61 IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout()); 62 collector.cancel(); 64 if (result == null) { 65 fail("No response from server"); 66 } 67 else if (result.getType() != IQ.Type.ERROR) { 68 fail("The server didn't reply with an error packet"); 69 } 70 else { 71 assertEquals("Server answered an incorrect error code", 503, result.getError().getCode()); 72 } 73 } 74 75 protected int getMaxConnections() { 76 return 1; 77 } 78 } 79 | Popular Tags |