KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > xmpp > XmppTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 /**
27  * @version $Revision: 468026 $
28  */

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 JavaDoc[] args) {
36         block = true;
37         TestRunner.run(XmppTest.class);
38     }
39
40     public void testConnect() throws Exception JavaDoc {
41         //ConnectionConfiguration config = new ConnectionConfiguration("localhost", 61222);
42
//config.setDebuggerEnabled(true);
43

44         try {
45             //SmackConfiguration.setPacketReplyTimeout(1000);
46
//XMPPConnection con = new XMPPConnection(config);
47
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 JavaDoc
75     protected void setUp() throws Exception JavaDoc {
76         broker.start();
77     }
78
79
80     @Override JavaDoc
81     protected void tearDown() throws Exception JavaDoc {
82         broker.stop();
83     }
84 }
85
Popular Tags