1 18 package org.apache.activemq.transport.xmpp; 19 20 import junit.framework.TestCase; 21 import junit.textui.TestRunner; 22 import org.jivesoftware.smack.Chat; 23 import org.jivesoftware.smack.XMPPConnection; 24 import org.jivesoftware.smack.XMPPException; 25 26 29 public class XmppTest extends TestCase { 30 31 protected static boolean block = false; 32 33 private XmppBroker broker = new XmppBroker(); 34 35 public static void main(String [] args) { 36 block = true; 37 TestRunner.run(XmppTest.class); 38 } 39 40 public void testConnect() throws Exception { 41 44 try { 45 XMPPConnection con = new XMPPConnection("localhost", 61222); 48 con.login("amq-user", "amq-pwd"); 49 Chat chat = con.createChat("test@localhost"); 50 for (int i = 0; i < 10; i++) { 51 System.out.println("Sending message: " + i); 52 chat.sendMessage("Hello from Message: " + i); 53 } 54 System.out.println("Sent all messages!"); 55 } 56 catch (XMPPException e) { 57 if (block) { 58 System.out.println("Caught: " + e); 59 e.printStackTrace(); 60 } 61 else { 62 throw e; 63 } 64 } 65 if (block) { 66 Thread.sleep(20000); 67 System.out.println("Press any key to quit!: "); 68 System.in.read(); 69 } 70 System.out.println("Done!"); 71 } 72 73 74 @Override 75 protected void setUp() throws Exception { 76 broker.start(); 77 } 78 79 80 @Override 81 protected void tearDown() throws Exception { 82 broker.stop(); 83 } 84 } 85 | Popular Tags |