mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-08 20:11:08 +01:00
smack_1_5_1
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2639 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
aa32e12164
commit
7ae75258be
276 changed files with 40430 additions and 0 deletions
13
CopyOftrunk/test/config/test-case.xml
Normal file
13
CopyOftrunk/test/config/test-case.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- Default configuration for Smack test cases. -->
|
||||
<testcase>
|
||||
|
||||
<!-- Host and port of the XMPP server to use -->
|
||||
<host>localhost</host>
|
||||
<port>5222</port>
|
||||
|
||||
<!-- Chat and MUC domain names to use -->
|
||||
<chat>chat.localhost</chat>
|
||||
<muc>conference.localhost</muc>
|
||||
|
||||
</testcase>
|
||||
131
CopyOftrunk/test/org/jivesoftware/smack/ChatTest.java
Normal file
131
CopyOftrunk/test/org/jivesoftware/smack/ChatTest.java
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the chat functionality.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class ChatTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for ChatTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public ChatTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testProperties() {
|
||||
try {
|
||||
Chat newChat = getConnection(0).createChat(getFullJID(1));
|
||||
Chat newChat2 = new Chat(getConnection(1), getFullJID(0), newChat.getThreadID());
|
||||
|
||||
Message msg = newChat.createMessage();
|
||||
|
||||
msg.setSubject("Subject of the chat");
|
||||
msg.setBody("Body of the chat");
|
||||
msg.setProperty("favoriteColor", "red");
|
||||
msg.setProperty("age", 30);
|
||||
msg.setProperty("distance", 30f);
|
||||
msg.setProperty("weight", 30d);
|
||||
msg.setProperty("male", true);
|
||||
msg.setProperty("birthdate", new Date());
|
||||
newChat.sendMessage(msg);
|
||||
|
||||
Message msg2 = newChat2.nextMessage(2000);
|
||||
assertNotNull("No message was received", msg2);
|
||||
assertEquals("Subjects are different", msg.getSubject(), msg2.getSubject());
|
||||
assertEquals("Bodies are different", msg.getBody(), msg2.getBody());
|
||||
assertEquals(
|
||||
"favoriteColors are different",
|
||||
msg.getProperty("favoriteColor"),
|
||||
msg2.getProperty("favoriteColor"));
|
||||
assertEquals(
|
||||
"ages are different",
|
||||
msg.getProperty("age"),
|
||||
msg2.getProperty("age"));
|
||||
assertEquals(
|
||||
"distances are different",
|
||||
msg.getProperty("distance"),
|
||||
msg2.getProperty("distance"));
|
||||
assertEquals(
|
||||
"weights are different",
|
||||
msg.getProperty("weight"),
|
||||
msg2.getProperty("weight"));
|
||||
assertEquals(
|
||||
"males are different",
|
||||
msg.getProperty("male"),
|
||||
msg2.getProperty("male"));
|
||||
assertEquals(
|
||||
"birthdates are different",
|
||||
msg.getProperty("birthdate"),
|
||||
msg2.getProperty("birthdate"));
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
102
CopyOftrunk/test/org/jivesoftware/smack/FloodTest.java
Normal file
102
CopyOftrunk/test/org/jivesoftware/smack/FloodTest.java
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
* Simple test to measure server performance.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class FloodTest extends SmackTestCase {
|
||||
|
||||
public FloodTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testMessageFlood() {
|
||||
try {
|
||||
Chat chat11 = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat12 = new Chat(getConnection(1), getBareJID(0), chat11.getThreadID());
|
||||
|
||||
Chat chat21 = getConnection(0).createChat(getBareJID(2));
|
||||
Chat chat22 = new Chat(getConnection(2), getBareJID(0), chat21.getThreadID());
|
||||
|
||||
Chat chat31 = getConnection(0).createChat(getBareJID(3));
|
||||
Chat chat32 = new Chat(getConnection(3), getBareJID(0), chat31.getThreadID());
|
||||
|
||||
for (int i=0; i<500; i++) {
|
||||
chat11.sendMessage("Hello_1" + i);
|
||||
chat21.sendMessage("Hello_2" + i);
|
||||
chat31.sendMessage("Hello_3" + i);
|
||||
}
|
||||
for (int i=0; i<500; i++) {
|
||||
assertNotNull("Some message was lost (" + i + ")", chat12.nextMessage(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat22.nextMessage(1000));
|
||||
assertNotNull("Some message was lost (" + i + ")", chat32.nextMessage(1000));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*public void testMUCFlood() {
|
||||
try {
|
||||
int floodNumber = 50000;
|
||||
MultiUserChat chat = new MultiUserChat(getConnection(0), "myroom@" + getMUCDomain());
|
||||
chat.create("phatom");
|
||||
chat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
|
||||
|
||||
MultiUserChat chat2 = new MultiUserChat(getConnection(1), "myroom@" + getMUCDomain());
|
||||
chat2.join("christine");
|
||||
|
||||
for (int i=0; i<floodNumber; i++)
|
||||
{
|
||||
chat.sendMessage("hi");
|
||||
}
|
||||
|
||||
Thread.sleep(200);
|
||||
|
||||
for (int i=0; i<floodNumber; i++)
|
||||
{
|
||||
if (i % 100 == 0) {
|
||||
System.out.println(i);
|
||||
}
|
||||
assertNotNull("Received " + i + " of " + floodNumber + " messages",
|
||||
chat2.nextMessage(SmackConfiguration.getPacketReplyTimeout()));
|
||||
}
|
||||
|
||||
chat.leave();
|
||||
//chat2.leave();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}*/
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
78
CopyOftrunk/test/org/jivesoftware/smack/IQTest.java
Normal file
78
CopyOftrunk/test/org/jivesoftware/smack/IQTest.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||
|
||||
/**
|
||||
* Ensure that the server is handling IQ packets correctly.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class IQTest extends SmackTestCase {
|
||||
|
||||
public IQTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the server responds a 503 error code when the client sends an IQ packet with an
|
||||
* invalid namespace.
|
||||
*/
|
||||
public void testInvalidNamespace() {
|
||||
IQ iq = new IQ() {
|
||||
public String getChildElementXML() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("<query xmlns=\"jabber:iq:anything\">");
|
||||
buf.append("</query>");
|
||||
return buf.toString();
|
||||
}
|
||||
};
|
||||
|
||||
PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getPacketID()),
|
||||
new PacketTypeFilter(IQ.class));
|
||||
PacketCollector collector = getConnection(0).createPacketCollector(filter);
|
||||
// Send the iq packet with an invalid namespace
|
||||
getConnection(0).sendPacket(iq);
|
||||
|
||||
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||
// Stop queuing results
|
||||
collector.cancel();
|
||||
if (result == null) {
|
||||
fail("No response from server");
|
||||
}
|
||||
else if (result.getType() != IQ.Type.ERROR) {
|
||||
fail("The server didn't reply with an error packet");
|
||||
}
|
||||
else {
|
||||
assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
104
CopyOftrunk/test/org/jivesoftware/smack/LoginTest.java
Normal file
104
CopyOftrunk/test/org/jivesoftware/smack/LoginTest.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2004 Jive Software. All rights reserved.
|
||||
*
|
||||
* This software is published under the terms of the GNU Public License (GPL),
|
||||
* a copy of which is included in this distribution.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
* Includes set of login tests.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class LoginTest extends SmackTestCase {
|
||||
|
||||
public LoginTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the server is returning the correct error when trying to login using an invalid
|
||||
* (i.e. non-existent) user.
|
||||
*/
|
||||
public void testInvalidLogin() {
|
||||
try {
|
||||
XMPPConnection connection = new XMPPConnection(getHost(), getPort());
|
||||
try {
|
||||
// Login with an invalid user
|
||||
connection.login("invaliduser" , "invalidpass");
|
||||
connection.close();
|
||||
fail("Invalid user was able to log into the server");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
assertEquals("Incorrect error code while login with an invalid user", 401,
|
||||
e.getXMPPError().getCode());
|
||||
}
|
||||
// Wait here while trying tests with exodus
|
||||
//Thread.sleep(300);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the server handles anonymous users correctly.
|
||||
*/
|
||||
public void testAnonymousLogin() {
|
||||
try {
|
||||
XMPPConnection conn1 = new XMPPConnection(getHost(), getPort());
|
||||
XMPPConnection conn2 = new XMPPConnection(getHost(), getPort());
|
||||
try {
|
||||
// Try to login anonymously
|
||||
conn1.loginAnonymously();
|
||||
conn2.loginAnonymously();
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
// Close the connection
|
||||
conn1.close();
|
||||
conn2.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the server does not allow to log in without specifying a resource.
|
||||
*/
|
||||
public void testLoginWithNoResource() {
|
||||
try {
|
||||
XMPPConnection conn = new XMPPConnection(getHost(), getPort());
|
||||
try {
|
||||
conn.getAccountManager().createAccount("user_1", "user_1");
|
||||
} catch (XMPPException e) {
|
||||
// Do nothing if the accout already exists
|
||||
if (e.getXMPPError().getCode() != 409) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
conn.login("user_1", "user_1", null);
|
||||
fail("User with no resource was able to log into the server");
|
||||
|
||||
} catch (XMPPException e) {
|
||||
assertEquals("Wrong error code returned", 406, e.getXMPPError().getCode());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
139
CopyOftrunk/test/org/jivesoftware/smack/MessageTest.java
Normal file
139
CopyOftrunk/test/org/jivesoftware/smack/MessageTest.java
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.filter.MessageTypeFilter;
|
||||
|
||||
/**
|
||||
* Tests sending messages to other clients.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MessageTest extends SmackTestCase {
|
||||
|
||||
public MessageTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that when a client becomes unavailable all messages sent to the client are stored offline. So that when
|
||||
* the client becomes available again the offline messages are received.
|
||||
*/
|
||||
public void testOfflineMessage() {
|
||||
// Make user2 unavailable
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.UNAVAILABLE));
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
chat.sendMessage("Test 1");
|
||||
chat.sendMessage("Test 2");
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.CHAT));
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
|
||||
|
||||
// Check that offline messages are retrieved by user2 which is now available
|
||||
Message message = (Message) collector.nextResult(2500);
|
||||
assertNotNull(message);
|
||||
message = (Message) collector.nextResult(2000);
|
||||
assertNotNull(message);
|
||||
message = (Message) collector.nextResult(1000);
|
||||
assertNull(message);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that two clients are able to send messages with a body of 4K characters and their
|
||||
* connections are not being closed.
|
||||
*/
|
||||
public void testHugeMessage() {
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(new MessageTypeFilter(Message.Type.CHAT));
|
||||
|
||||
// Create message with a body of 4K characters
|
||||
Message msg = new Message(getFullJID(1), Message.Type.CHAT);
|
||||
StringBuffer sb = new StringBuffer(5000);
|
||||
for (int i=0; i<=4000; i++) {
|
||||
sb.append("X");
|
||||
}
|
||||
msg.setBody(sb.toString());
|
||||
|
||||
// Send the first message
|
||||
getConnection(0).sendPacket(msg);
|
||||
// Check that the connection that sent the message is still connected
|
||||
assertTrue("Connection was closed", getConnection(0).isConnected());
|
||||
// Check that the message was received
|
||||
Message rcv = (Message) collector.nextResult(1000);
|
||||
assertNotNull("No Message was received", rcv);
|
||||
|
||||
// Send the second message
|
||||
getConnection(0).sendPacket(msg);
|
||||
// Check that the connection that sent the message is still connected
|
||||
assertTrue("Connection was closed", getConnection(0).isConnected());
|
||||
// Check that the second message was received
|
||||
rcv = (Message) collector.nextResult(1000);
|
||||
assertNotNull("No Message was received", rcv);
|
||||
|
||||
// Try now sending huge messages over an SSL connection
|
||||
XMPPConnection conn = null;
|
||||
try {
|
||||
conn = new SSLXMPPConnection(getHost());
|
||||
conn.login(getUsername(0), getUsername(0), "Other resource");
|
||||
|
||||
// Send the first message
|
||||
conn.sendPacket(msg);
|
||||
// Check that the connection that sent the message is still connected
|
||||
assertTrue("Connection was closed", conn.isConnected());
|
||||
// Check that the message was received
|
||||
rcv = (Message) collector.nextResult(1000);
|
||||
assertNotNull("No Message was received", rcv);
|
||||
} catch (XMPPException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
finally {
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
XMPPConnection.DEBUG_ENABLED = false;
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
101
CopyOftrunk/test/org/jivesoftware/smack/MessengerLoginTest.java
Normal file
101
CopyOftrunk/test/org/jivesoftware/smack/MessengerLoginTest.java
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MessengerLoginTest extends TestCase {
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
public void setUp() {
|
||||
// override default settings from system properties
|
||||
if (System.getProperty("smack.test.host") != null) {
|
||||
host = System.getProperty("smack.test.host");
|
||||
}
|
||||
if (System.getProperty("smack.test.port") != null) {
|
||||
try {
|
||||
port = Integer.parseInt(System.getProperty("smack.test.port"));
|
||||
}
|
||||
catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
public void testAdminLogin() {
|
||||
|
||||
String username = System.getProperty("smack.test.admin.username");
|
||||
String password = System.getProperty("smack.test.admin.password");
|
||||
String resource = System.getProperty("smack.test.admin.resource");
|
||||
boolean debug = false;
|
||||
try {
|
||||
debug = Boolean.valueOf(System.getProperty("smack.debug")).booleanValue();
|
||||
}
|
||||
catch (Exception ignored) {}
|
||||
|
||||
XMPPConnection.DEBUG_ENABLED = debug;
|
||||
|
||||
try {
|
||||
XMPPConnection con = new XMPPConnection(host, port);
|
||||
con.login(username, password, resource);
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
String message = e.getMessage();
|
||||
if (e.getXMPPError() != null) {
|
||||
message = "XMPPError code: " + e.getXMPPError().getCode() + ", message: "
|
||||
+ e.getXMPPError().getMessage();
|
||||
}
|
||||
/*fail("Login to server " + host + ":" + port + " failed using user/pass/resource: "
|
||||
+ username + "/" + password + "/" + resource + ". Error message: " + message);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
102
CopyOftrunk/test/org/jivesoftware/smack/PacketReaderTest.java
Normal file
102
CopyOftrunk/test/org/jivesoftware/smack/PacketReaderTest.java
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
|
||||
public class PacketReaderTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for PacketReaderTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public PacketReaderTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that when Smack receives a "not implemented IQ" answers with an IQ packet
|
||||
* with error code 501.
|
||||
*/
|
||||
public void testIQNotImplemented() {
|
||||
|
||||
// Create a new type of IQ to send. The new IQ will include a
|
||||
// non-existant namespace to cause the "feature-not-implemented" answer
|
||||
IQ iqPacket = new IQ() {
|
||||
public String getChildElementXML() {
|
||||
return "<query xmlns=\"my:ns:test\"/>";
|
||||
}
|
||||
};
|
||||
iqPacket.setTo(getFullJID(1));
|
||||
iqPacket.setType(IQ.Type.GET);
|
||||
|
||||
// Send the IQ and wait for the answer
|
||||
PacketCollector collector = getConnection(0).createPacketCollector(
|
||||
new PacketIDFilter(iqPacket.getPacketID()));
|
||||
getConnection(0).sendPacket(iqPacket);
|
||||
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
|
||||
if (response == null) {
|
||||
fail("No response from the other user.");
|
||||
}
|
||||
assertEquals("The received IQ is not of type ERROR", IQ.Type.ERROR, response.getType());
|
||||
assertEquals("The error code is not 501", 501, response.getError().getCode());
|
||||
collector.cancel();
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,137 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2004 Jive Software. All rights reserved.
|
||||
*
|
||||
* This software is published under the terms of the GNU Public License (GPL),
|
||||
* a copy of which is included in this distribution.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
|
||||
/**
|
||||
* Ensure that the server is delivering messages to the correct client based on the client's
|
||||
* presence priority.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class PresencePriorityTest extends SmackTestCase {
|
||||
|
||||
public PresencePriorityTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connection(0) will send messages to the bareJID of Connection(1) where the user of
|
||||
* Connection(1) has logged from two different places with different presence priorities.
|
||||
*/
|
||||
public void testMessageToHighestPriority() {
|
||||
boolean wasFiltering = Chat.isFilteredOnThreadID();
|
||||
Chat.setFilteredOnThreadID(false);
|
||||
XMPPConnection conn = null;
|
||||
try {
|
||||
// User_1 will log in again using another resource
|
||||
conn = new XMPPConnection(getHost(), getPort());
|
||||
conn.login(getUsername(1), getUsername(1), "OtherPlace");
|
||||
// Change the presence priorities of User_1
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
|
||||
Presence.Mode.AVAILABLE));
|
||||
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
|
||||
Presence.Mode.AVAILABLE));
|
||||
Thread.sleep(150);
|
||||
// Create the chats between the participants
|
||||
Chat chat0 = new Chat(getConnection(0), getBareJID(1));
|
||||
Chat chat1 = new Chat(getConnection(1), getBareJID(0));
|
||||
Chat chat2 = new Chat(conn, getBareJID(0));
|
||||
|
||||
// Test delivery of message to the presence with highest priority
|
||||
chat0.sendMessage("Hello");
|
||||
assertNotNull("Resource with highest priority didn't receive the message",
|
||||
chat2.nextMessage(2000));
|
||||
assertNull("Resource with lowest priority received the message",
|
||||
chat1.nextMessage(1000));
|
||||
|
||||
// Invert the presence priorities of User_1
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
|
||||
Presence.Mode.AVAILABLE));
|
||||
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
|
||||
Presence.Mode.AVAILABLE));
|
||||
|
||||
Thread.sleep(150);
|
||||
// Test delivery of message to the presence with highest priority
|
||||
chat0.sendMessage("Hello");
|
||||
assertNotNull("Resource with highest priority didn't receive the message",
|
||||
chat1.nextMessage(2000));
|
||||
assertNull("Resource with lowest priority received the message",
|
||||
chat2.nextMessage(1000));
|
||||
|
||||
// User_1 closes his connection
|
||||
chat2 = null;
|
||||
conn.close();
|
||||
Thread.sleep(150);
|
||||
|
||||
// Test delivery of message to the unique presence of the user_1
|
||||
chat0.sendMessage("Hello");
|
||||
assertNotNull("Resource with highest priority didn't receive the message",
|
||||
chat1.nextMessage(2000));
|
||||
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
|
||||
Presence.Mode.AVAILABLE));
|
||||
|
||||
// User_1 will log in again using another resource
|
||||
conn = new XMPPConnection(getHost(), getPort());
|
||||
conn.login(getUsername(1), getUsername(1), "OtherPlace");
|
||||
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
|
||||
Presence.Mode.AVAILABLE));
|
||||
chat2 = new Chat(conn, getBareJID(0));
|
||||
|
||||
Thread.sleep(150);
|
||||
// Test delivery of message to the presence with highest priority
|
||||
chat0.sendMessage("Hello");
|
||||
assertNotNull("Resource with highest priority didn't receive the message",
|
||||
chat1.nextMessage(2000));
|
||||
assertNull("Resource with lowest priority received the message",
|
||||
chat2.nextMessage(1000));
|
||||
|
||||
// Invert the presence priorities of User_1
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE, null, 1,
|
||||
Presence.Mode.AVAILABLE));
|
||||
conn.sendPacket(new Presence(Presence.Type.AVAILABLE, null, 2,
|
||||
Presence.Mode.AVAILABLE));
|
||||
|
||||
Thread.sleep(150);
|
||||
// Test delivery of message to the presence with highest priority
|
||||
chat0.sendMessage("Hello");
|
||||
assertNotNull("Resource with highest priority didn't receive the message",
|
||||
chat2.nextMessage(2000));
|
||||
assertNull("Resource with lowest priority received the message",
|
||||
chat1.nextMessage(1000));
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
finally {
|
||||
// Restore the previous filtering value so we don't affect other test cases
|
||||
Chat.setFilteredOnThreadID(wasFiltering);
|
||||
if (conn != null) {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
XMPPConnection.DEBUG_ENABLED = false;
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
527
CopyOftrunk/test/org/jivesoftware/smack/RosterTest.java
Normal file
527
CopyOftrunk/test/org/jivesoftware/smack/RosterTest.java
Normal file
|
|
@ -0,0 +1,527 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Tests the Roster functionality by creating and removing roster entries.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class RosterTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for RosterTest.
|
||||
* @param name
|
||||
*/
|
||||
public RosterTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create entries in roster groups
|
||||
* 2. Iterate on the groups and remove the entry from each group
|
||||
* 3. Check that the entries are kept as unfiled entries
|
||||
*/
|
||||
public void testDeleteAllRosterGroupEntries() {
|
||||
try {
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends", "Family" });
|
||||
roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" });
|
||||
|
||||
// Wait until the server confirms the new entries
|
||||
while (roster.getEntryCount() != 2) {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
|
||||
Iterator it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
Iterator groups = entry.getGroups();
|
||||
while (groups.hasNext()) {
|
||||
RosterGroup rosterGroup = (RosterGroup) groups.next();
|
||||
rosterGroup.removeEntry(entry);
|
||||
}
|
||||
}
|
||||
// Wait up to 2 seconds
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
(roster.getGroupCount() != 0 &&
|
||||
getConnection(2).getRoster().getEntryCount() != 2)) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
"The number of entries in connection 1 should be 1",
|
||||
1,
|
||||
getConnection(1).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"The number of groups in connection 1 should be 0",
|
||||
0,
|
||||
getConnection(1).getRoster().getGroupCount());
|
||||
|
||||
assertEquals(
|
||||
"The number of entries in connection 2 should be 1",
|
||||
1,
|
||||
getConnection(2).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"The number of groups in connection 2 should be 0",
|
||||
0,
|
||||
getConnection(2).getRoster().getGroupCount());
|
||||
|
||||
assertEquals(
|
||||
"The number of entries in connection 0 should be 2",
|
||||
2,
|
||||
roster.getEntryCount());
|
||||
assertEquals(
|
||||
"The number of groups in connection 0 should be 0",
|
||||
0,
|
||||
roster.getGroupCount());
|
||||
|
||||
cleanUpRoster();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create entries in roster groups
|
||||
* 2. Iterate on all the entries and remove them from the roster
|
||||
* 3. Check that the number of entries and groups is zero
|
||||
*/
|
||||
public void testDeleteAllRosterEntries() {
|
||||
try {
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" });
|
||||
roster.createEntry(getBareJID(2), "gato12", new String[] { "Family" });
|
||||
|
||||
// Wait up to 2 seconds to receive new roster contacts
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 2) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertEquals("Wrong number of entries in connection 0", 2, roster.getEntryCount());
|
||||
|
||||
// Wait up to 2 seconds to receive presences of the new roster contacts
|
||||
initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 5000 &&
|
||||
(roster.getPresence(getBareJID(1)) == null ||
|
||||
roster.getPresence(getBareJID(2)) == null)) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertNotNull("Presence not received", roster.getPresence(getBareJID(1)));
|
||||
assertNotNull("Presence not received", roster.getPresence(getBareJID(2)));
|
||||
|
||||
Iterator it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
roster.removeEntry(entry);
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// Wait up to 2 seconds to receive roster removal notifications
|
||||
initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 && roster.getEntryCount() != 0) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertEquals("Wrong number of entries in connection 0", 0, roster.getEntryCount());
|
||||
assertEquals("Wrong number of groups in connection 0", 0, roster.getGroupCount());
|
||||
|
||||
assertEquals(
|
||||
"Wrong number of entries in connection 1",
|
||||
0,
|
||||
getConnection(1).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"Wrong number of groups in connection 1",
|
||||
0,
|
||||
getConnection(1).getRoster().getGroupCount());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create unfiled entries
|
||||
* 2. Iterate on all the entries and remove them from the roster
|
||||
* 3. Check that the number of entries and groups is zero
|
||||
*/
|
||||
public void testDeleteAllUnfiledRosterEntries() {
|
||||
try {
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), "gato11", null);
|
||||
roster.createEntry(getBareJID(2), "gato12", null);
|
||||
|
||||
Thread.sleep(200);
|
||||
|
||||
Iterator it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
roster.removeEntry(entry);
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
assertEquals("Wrong number of entries in connection 0", 0, roster.getEntryCount());
|
||||
assertEquals("Wrong number of groups in connection 0", 0, roster.getGroupCount());
|
||||
|
||||
assertEquals(
|
||||
"Wrong number of entries in connection 1",
|
||||
0,
|
||||
getConnection(1).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"Wrong number of groups in connection 1",
|
||||
0,
|
||||
getConnection(1).getRoster().getGroupCount());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create an unfiled entry
|
||||
* 2. Change its name
|
||||
* 3. Check that the name has been modified
|
||||
* 4. Reload the whole roster
|
||||
* 5. Check that the name has been modified
|
||||
*/
|
||||
public void testChangeNameToUnfiledEntry() {
|
||||
try {
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), null, null);
|
||||
|
||||
Thread.sleep(200);
|
||||
|
||||
// Change the roster entry name and check if the change was made
|
||||
Iterator it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
entry.setName("gato11");
|
||||
assertEquals("gato11", entry.getName());
|
||||
}
|
||||
// Reload the roster and check the name again
|
||||
roster.reload();
|
||||
Thread.sleep(2000);
|
||||
it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
assertEquals("gato11", entry.getName());
|
||||
}
|
||||
|
||||
cleanUpRoster();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create an unfiled entry with no name
|
||||
* 2. Check that the the entry does not belong to any group
|
||||
* 3. Change its name and add it to a group
|
||||
* 4. Check that the name has been modified and that the entry belongs to a group
|
||||
*/
|
||||
public void testChangeGroupAndNameToUnfiledEntry() {
|
||||
try {
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), null, null);
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
getConnection(1).getRoster().createEntry(getBareJID(0), null, null);
|
||||
|
||||
// Wait up to 5 seconds to receive presences of the new roster contacts
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 5000 &&
|
||||
roster.getPresence(getBareJID(0)) == null) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
//assertNotNull("Presence not received", roster.getPresence(getBareJID(0)));
|
||||
|
||||
Iterator it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
assertFalse("The roster entry belongs to a group", entry.getGroups().hasNext());
|
||||
}
|
||||
|
||||
// Change the roster entry name and check if the change was made
|
||||
roster.createEntry(getBareJID(1), "NewName", new String[] { "Friends" });
|
||||
|
||||
// Reload the roster and check the name again
|
||||
Thread.sleep(200);
|
||||
it = roster.getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
assertEquals("Name of roster entry is wrong", "NewName", entry.getName());
|
||||
assertTrue("The roster entry does not belong to any group", entry.getGroups()
|
||||
.hasNext());
|
||||
}
|
||||
// Wait up to 5 seconds to receive presences of the new roster contacts
|
||||
initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 5000 &&
|
||||
roster.getPresence(getBareJID(1)) == null) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertNotNull("Presence not received", roster.getPresence(getBareJID(1)));
|
||||
|
||||
cleanUpRoster();
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if renaming a roster group works fine.
|
||||
*
|
||||
*/
|
||||
public void testRenameRosterGroup() {
|
||||
try {
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), "gato11", new String[] { "Friends" });
|
||||
roster.createEntry(getBareJID(2), "gato12", new String[] { "Friends" });
|
||||
|
||||
Thread.sleep(200);
|
||||
|
||||
roster.getGroup("Friends").setName("Amigos");
|
||||
|
||||
// Wait up to 2 seconds
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
(roster.getGroup("Friends") != null)) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
assertNull("The group Friends still exists", roster.getGroup("Friends"));
|
||||
assertNotNull("The group Amigos does not exist", roster.getGroup("Amigos"));
|
||||
assertEquals(
|
||||
"Wrong number of entries in the group Amigos",
|
||||
2,
|
||||
roster.getGroup("Amigos").getEntryCount());
|
||||
|
||||
roster.getGroup("Amigos").setName("");
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
assertNull("The group Amigos still exists", roster.getGroup("Amigos"));
|
||||
assertNotNull("The group with no name does not exist", roster.getGroup(""));
|
||||
assertEquals(
|
||||
"Wrong number of entries in the group \"\" ",
|
||||
2,
|
||||
roster.getGroup("").getEntryCount());
|
||||
|
||||
cleanUpRoster();
|
||||
Thread.sleep(200);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test presence management.
|
||||
*/
|
||||
public void testRosterPresences() {
|
||||
try {
|
||||
Presence presence = null;
|
||||
|
||||
// Create another connection for the same user of connection 1
|
||||
XMPPConnection conn4 = new XMPPConnection(getHost());
|
||||
conn4.login(getUsername(1), getUsername(1), "Home");
|
||||
|
||||
// Add a new roster entry
|
||||
Roster roster = getConnection(0).getRoster();
|
||||
roster.createEntry(getBareJID(1), "gato11", null);
|
||||
|
||||
// Wait up to 2 seconds
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
(roster.getPresence(getBareJID(1)) == null)) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
// Check that a presence is returned for a user
|
||||
presence = roster.getPresence(getBareJID(1));
|
||||
assertNotNull("Returned a null Presence for an existing user", presence);
|
||||
|
||||
// Check that the right presence is returned for a user+resource
|
||||
presence = roster.getPresenceResource(getUsername(1) + "@" + conn4.getHost() + "/Home");
|
||||
assertEquals(
|
||||
"Returned the wrong Presence",
|
||||
StringUtils.parseResource(presence.getFrom()),
|
||||
"Home");
|
||||
|
||||
// Check that the right presence is returned for a user+resource
|
||||
presence = roster.getPresenceResource(getFullJID(1));
|
||||
assertEquals(
|
||||
"Returned the wrong Presence",
|
||||
StringUtils.parseResource(presence.getFrom()),
|
||||
"Smack");
|
||||
|
||||
// Check that the no presence is returned for a non-existent user+resource
|
||||
presence = roster.getPresenceResource("noname@" + getHost() + "/Smack");
|
||||
assertNull("Returned a Presence for a non-existing user", presence);
|
||||
|
||||
// Check that the returned presences are correct
|
||||
Iterator presences = roster.getPresences(getBareJID(1));
|
||||
int count = 0;
|
||||
while (presences.hasNext()) {
|
||||
count++;
|
||||
presences.next();
|
||||
}
|
||||
assertEquals("Wrong number of returned presences", count, 2);
|
||||
|
||||
// Close the connection so one presence must go
|
||||
conn4.close();
|
||||
|
||||
// Check that the returned presences are correct
|
||||
presences = roster.getPresences(getBareJID(1));
|
||||
count = 0;
|
||||
while (presences.hasNext()) {
|
||||
count++;
|
||||
presences.next();
|
||||
}
|
||||
assertEquals("Wrong number of returned presences", count, 1);
|
||||
|
||||
Thread.sleep(200);
|
||||
cleanUpRoster();
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up all the entries in the roster
|
||||
*/
|
||||
private void cleanUpRoster() {
|
||||
// Delete all the entries from the roster
|
||||
Iterator it = getConnection(0).getRoster().getEntries();
|
||||
while (it.hasNext()) {
|
||||
RosterEntry entry = (RosterEntry) it.next();
|
||||
try {
|
||||
getConnection(0).getRoster().removeEntry(entry);
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
// Wait up to 2 seconds to receive roster removal notifications
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
getConnection(0).getRoster().getEntryCount() != 0) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
// Wait up to 2 seconds to receive roster removal notifications
|
||||
initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
getConnection(1).getRoster().getEntryCount() != 0) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
"Wrong number of entries in connection 0",
|
||||
0,
|
||||
getConnection(0).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"Wrong number of groups in connection 0",
|
||||
0,
|
||||
getConnection(0).getRoster().getGroupCount());
|
||||
|
||||
assertEquals(
|
||||
"Wrong number of entries in connection 1",
|
||||
0,
|
||||
getConnection(1).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"Wrong number of groups in connection 1",
|
||||
0,
|
||||
getConnection(1).getRoster().getGroupCount());
|
||||
|
||||
assertEquals(
|
||||
"Wrong number of entries in connection 2",
|
||||
0,
|
||||
getConnection(2).getRoster().getEntryCount());
|
||||
assertEquals(
|
||||
"Wrong number of groups in connection 2",
|
||||
0,
|
||||
getConnection(2).getRoster().getGroupCount());
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
//XMPPConnection.DEBUG_ENABLED = false;
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* A test case for the AndFilter class.
|
||||
*/
|
||||
public class AndFilterTest extends TestCase {
|
||||
|
||||
public void testNullArgs() {
|
||||
PacketFilter filter = null;
|
||||
try {
|
||||
AndFilter and = new AndFilter(filter, filter);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAccept() {
|
||||
MockPacketFilter trueFilter = new MockPacketFilter(true);
|
||||
MockPacketFilter falseFilter = new MockPacketFilter(false);
|
||||
|
||||
MockPacket packet = new MockPacket();
|
||||
|
||||
AndFilter andFilter = new AndFilter(trueFilter, trueFilter);
|
||||
assertTrue(andFilter.accept(packet));
|
||||
|
||||
andFilter = new AndFilter(trueFilter, falseFilter);
|
||||
assertFalse(andFilter.accept(packet));
|
||||
|
||||
andFilter = new AndFilter(falseFilter, trueFilter);
|
||||
assertFalse(andFilter.accept(packet));
|
||||
|
||||
andFilter = new AndFilter(falseFilter, falseFilter);
|
||||
assertFalse(andFilter.accept(packet));
|
||||
|
||||
andFilter = new AndFilter();
|
||||
andFilter.addFilter(trueFilter);
|
||||
andFilter.addFilter(trueFilter);
|
||||
andFilter.addFilter(falseFilter);
|
||||
andFilter.addFilter(trueFilter);
|
||||
assertFalse(andFilter.accept(packet));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* A test case for the FromContainsFilter class.
|
||||
*/
|
||||
public class FromContainsFilterTest extends TestCase {
|
||||
|
||||
public void testNullArgs() {
|
||||
try {
|
||||
new FromContainsFilter(null);
|
||||
fail("Parameter can not be null");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAccept() {
|
||||
MockFromPacket packet = new MockFromPacket("foo@bar.com");
|
||||
|
||||
FromContainsFilter fromContainsFilter = new FromContainsFilter("");
|
||||
assertTrue(fromContainsFilter.accept(packet));
|
||||
|
||||
fromContainsFilter = new FromContainsFilter("foo");
|
||||
assertTrue(fromContainsFilter.accept(packet));
|
||||
|
||||
fromContainsFilter = new FromContainsFilter("foo@bar.com");
|
||||
assertTrue(fromContainsFilter.accept(packet));
|
||||
|
||||
fromContainsFilter = new FromContainsFilter("bar@foo.com");
|
||||
assertFalse(fromContainsFilter.accept(packet));
|
||||
|
||||
fromContainsFilter = new FromContainsFilter("blah-stuff,net");
|
||||
assertFalse(fromContainsFilter.accept(packet));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the MockPacket class to always give an expected From field.
|
||||
*/
|
||||
private class MockFromPacket extends MockPacket {
|
||||
private String from;
|
||||
public MockFromPacket(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
public String getFrom() {
|
||||
return from;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* A test case for the NotFilter class.
|
||||
*/
|
||||
public class NotFilterTest extends TestCase {
|
||||
|
||||
public void testNullArgs() {
|
||||
PacketFilter filter = null;
|
||||
try {
|
||||
NotFilter or = new NotFilter(filter);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAccept() {
|
||||
MockPacketFilter trueFilter = new MockPacketFilter(true);
|
||||
MockPacketFilter falseFilter = new MockPacketFilter(false);
|
||||
|
||||
MockPacket packet = new MockPacket();
|
||||
|
||||
NotFilter NotFilter = new NotFilter(trueFilter);
|
||||
assertFalse(NotFilter.accept(packet));
|
||||
|
||||
NotFilter = new NotFilter(falseFilter);
|
||||
assertTrue(NotFilter.accept(packet));
|
||||
}
|
||||
}
|
||||
133
CopyOftrunk/test/org/jivesoftware/smack/filter/OrFilterTest.java
Normal file
133
CopyOftrunk/test/org/jivesoftware/smack/filter/OrFilterTest.java
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* A test case for the OrFilter class.
|
||||
*/
|
||||
public class OrFilterTest extends TestCase {
|
||||
|
||||
public void testNullArgs() {
|
||||
PacketFilter filter = null;
|
||||
try {
|
||||
OrFilter or = new OrFilter(filter, filter);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAccept() {
|
||||
MockPacketFilter trueFilter = new MockPacketFilter(true);
|
||||
MockPacketFilter falseFilter = new MockPacketFilter(false);
|
||||
|
||||
MockPacket packet = new MockPacket();
|
||||
|
||||
// Testing TT == T
|
||||
OrFilter orFilter = new OrFilter(trueFilter, trueFilter);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing TF = F
|
||||
orFilter = new OrFilter(trueFilter, falseFilter);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing FT = F
|
||||
orFilter = new OrFilter(falseFilter, trueFilter);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing FF = F
|
||||
orFilter = new OrFilter(falseFilter, falseFilter);
|
||||
assertFalse(orFilter.accept(packet));
|
||||
|
||||
// Testing TTTT = T
|
||||
orFilter = new OrFilter(
|
||||
new OrFilter(trueFilter, trueFilter), new OrFilter(trueFilter, trueFilter)
|
||||
);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing TFTT = F
|
||||
orFilter = new OrFilter(
|
||||
new OrFilter(trueFilter, falseFilter), new OrFilter(trueFilter, trueFilter)
|
||||
);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing TTFT = F
|
||||
orFilter = new OrFilter(
|
||||
new OrFilter(trueFilter, trueFilter), new OrFilter(falseFilter, trueFilter)
|
||||
);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing TTTF = F
|
||||
orFilter = new OrFilter(
|
||||
new OrFilter(trueFilter, trueFilter), new OrFilter(trueFilter, falseFilter)
|
||||
);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
|
||||
// Testing FFFF = F
|
||||
orFilter = new OrFilter(
|
||||
new OrFilter(falseFilter, falseFilter), new OrFilter(falseFilter, falseFilter)
|
||||
);
|
||||
assertFalse(orFilter.accept(packet));
|
||||
|
||||
orFilter = new OrFilter();
|
||||
orFilter.addFilter(trueFilter);
|
||||
orFilter.addFilter(trueFilter);
|
||||
orFilter.addFilter(falseFilter);
|
||||
orFilter.addFilter(trueFilter);
|
||||
assertTrue(orFilter.accept(packet));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* A test case for the PacketIDFilter class.
|
||||
*/
|
||||
public class PacketIDFilterTest extends TestCase {
|
||||
|
||||
public void testNullArgs() {
|
||||
try {
|
||||
new PacketIDFilter(null);
|
||||
fail("Parameter can not be null");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAccept() {
|
||||
MockIDPacket packet = new MockIDPacket("foo");
|
||||
|
||||
PacketIDFilter packetIDFilter = new PacketIDFilter("");
|
||||
assertFalse(packetIDFilter.accept(packet));
|
||||
|
||||
packetIDFilter = new PacketIDFilter("foo");
|
||||
assertTrue(packetIDFilter.accept(packet));
|
||||
|
||||
packetIDFilter = new PacketIDFilter("fOO");
|
||||
assertFalse(packetIDFilter.accept(packet));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the MockPacket class to always give an expected packet ID field.
|
||||
*/
|
||||
private class MockIDPacket extends MockPacket {
|
||||
private String id;
|
||||
public MockIDPacket(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getPacketID() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* Test cases for the PacketTypeFilter class.
|
||||
*/
|
||||
public class PacketTypeFilterTest extends TestCase {
|
||||
|
||||
private class Dummy {}
|
||||
|
||||
private class InnerClassDummy {
|
||||
public class DummyPacket extends Packet {
|
||||
public String toXML() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public DummyPacket getInnerInstance() {
|
||||
return new DummyPacket();
|
||||
}
|
||||
}
|
||||
|
||||
private static class StaticInnerClassDummy {
|
||||
public static class StaticDummyPacket extends Packet {
|
||||
public String toXML() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static StaticDummyPacket getInnerInstance() {
|
||||
return new StaticDummyPacket();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case for the constructor of PacketTypeFilter objects.
|
||||
*/
|
||||
public void testConstructor() {
|
||||
// Test a class that is not a subclass of Packet
|
||||
try {
|
||||
new PacketTypeFilter(Dummy.class);
|
||||
fail("Parameter must be a subclass of Packet.");
|
||||
}
|
||||
catch (IllegalArgumentException e) {}
|
||||
|
||||
// Test a class that is a subclass of Packet
|
||||
try {
|
||||
new PacketTypeFilter(MockPacket.class);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
fail();
|
||||
}
|
||||
|
||||
// Test another class which is a subclass of Packet
|
||||
try {
|
||||
new PacketTypeFilter(IQ.class);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
fail();
|
||||
}
|
||||
|
||||
// Test an internal class which is a subclass of Packet
|
||||
try {
|
||||
new PacketTypeFilter(InnerClassDummy.DummyPacket.class);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
fail();
|
||||
}
|
||||
|
||||
// Test an internal static class which is a static subclass of Packet
|
||||
try {
|
||||
new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test case to test the accept() method of PacketTypeFilter objects.
|
||||
*/
|
||||
public void testAccept() {
|
||||
Packet packet = new MockPacket();
|
||||
PacketTypeFilter filter = new PacketTypeFilter(MockPacket.class);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet = (new InnerClassDummy()).getInnerInstance();
|
||||
filter = new PacketTypeFilter(InnerClassDummy.DummyPacket.class);
|
||||
assertTrue(filter.accept(packet));
|
||||
|
||||
packet = StaticInnerClassDummy.getInnerInstance();
|
||||
filter = new PacketTypeFilter(StaticInnerClassDummy.StaticDummyPacket.class);
|
||||
assertTrue(filter.accept(packet));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.filter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
/**
|
||||
* A test case for the ToContainsFilter class.
|
||||
*/
|
||||
public class ToContainsFilterTest extends TestCase {
|
||||
|
||||
public void testNullArgs() {
|
||||
try {
|
||||
new ToContainsFilter(null);
|
||||
fail("Parameter can not be null");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAccept() {
|
||||
MockToPacket packet = new MockToPacket("foo@bar.com");
|
||||
|
||||
ToContainsFilter toContainsFilter = new ToContainsFilter("");
|
||||
assertTrue(toContainsFilter.accept(packet));
|
||||
|
||||
toContainsFilter = new ToContainsFilter("foo");
|
||||
assertTrue(toContainsFilter.accept(packet));
|
||||
|
||||
toContainsFilter = new ToContainsFilter("foo@bar.com");
|
||||
assertTrue(toContainsFilter.accept(packet));
|
||||
|
||||
toContainsFilter = new ToContainsFilter("bar@foo.com");
|
||||
assertFalse(toContainsFilter.accept(packet));
|
||||
|
||||
toContainsFilter = new ToContainsFilter("blah-stuff,net");
|
||||
assertFalse(toContainsFilter.accept(packet));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the MockPacket class to always give an expected To field.
|
||||
*/
|
||||
private class MockToPacket extends MockPacket {
|
||||
private String to;
|
||||
public MockToPacket(String to) {
|
||||
this.to = to;
|
||||
}
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A mock implementation of the Packet abstract class. Implements toXML() by returning null.
|
||||
*/
|
||||
public class MockPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Returns null always.
|
||||
* @return null
|
||||
*/
|
||||
public String toXML() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
|
||||
/**
|
||||
* A mock implementation of the PacketFilter class. Pass in the value you want the
|
||||
* accept(..) method to return.
|
||||
*/
|
||||
public class MockPacketFilter implements PacketFilter {
|
||||
|
||||
private boolean acceptValue;
|
||||
|
||||
public MockPacketFilter(boolean acceptValue) {
|
||||
this.acceptValue = acceptValue;
|
||||
}
|
||||
|
||||
public boolean accept(Packet packet) {
|
||||
return acceptValue;
|
||||
}
|
||||
|
||||
}
|
||||
370
CopyOftrunk/test/org/jivesoftware/smack/test/SmackTestCase.java
Normal file
370
CopyOftrunk/test/org/jivesoftware/smack/test/SmackTestCase.java
Normal file
|
|
@ -0,0 +1,370 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jivesoftware.smack.test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.xmlpull.v1.*;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Base class for all the test cases which provides a pre-configured execution context. This
|
||||
* means that any test case that subclassifies this base class will have access to a pool of
|
||||
* connections and to the user of each connection. The maximum number of connections in the pool
|
||||
* can be controlled by the message {@link #getMaxConnections()} which every subclass must
|
||||
* implement.<p>
|
||||
*
|
||||
* This base class defines a default execution context (i.e. host, port, chat domain and muc
|
||||
* domain) which can be found in the file "config/test-case.xml". However, each subclass could
|
||||
* redefine the default configuration by providing its own configuration file (if desired). The
|
||||
* name of the configuration file must be of the form <test class name>.xml (e.g. RosterTest.xml).
|
||||
* The file must be placed in the folder "config". This folder is where the default configuration
|
||||
* file is being held.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public abstract class SmackTestCase extends TestCase {
|
||||
|
||||
private String host = "localhost";
|
||||
private int port = 5222;
|
||||
|
||||
private String chatDomain = "chat.localhost";
|
||||
private String mucDomain = "conference.localhost";
|
||||
|
||||
private XMPPConnection[] connections = null;
|
||||
|
||||
/**
|
||||
* Constructor for SmackTestCase.
|
||||
* @param arg0
|
||||
*/
|
||||
public SmackTestCase(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of connections to initialize for this test case. All the
|
||||
* initialized connections will be connected to the server using a new test account for
|
||||
* each conection.
|
||||
*
|
||||
* @return the maximum number of connections to initialize for this test case.
|
||||
*/
|
||||
protected abstract int getMaxConnections();
|
||||
|
||||
/**
|
||||
* Returns a SocketFactory that will be used to create the socket to the XMPP server. By
|
||||
* default no SocketFactory is used but subclasses my want to redefine this method.<p>
|
||||
*
|
||||
* A custom SocketFactory allows fine-grained control of the actual connection to the XMPP
|
||||
* server. A typical use for a custom SocketFactory is when connecting through a SOCKS proxy.
|
||||
*
|
||||
* @return a SocketFactory that will be used to create the socket to the XMPP server.
|
||||
*/
|
||||
protected SocketFactory getSocketFactory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XMPPConnection located at the requested position. Each test case holds a
|
||||
* pool of connections which is initialized while setting up the test case. The maximum
|
||||
* number of connections is controlled by the message {@link #getMaxConnections()} which
|
||||
* every subclass must implement.<p>
|
||||
*
|
||||
* If the requested position is greater than the connections size then an
|
||||
* IllegalArgumentException will be thrown.
|
||||
*
|
||||
* @param index the position in the pool of the connection to look for.
|
||||
* @return the XMPPConnection located at the requested position.
|
||||
*/
|
||||
protected XMPPConnection getConnection(int index) {
|
||||
if (index > getMaxConnections()) {
|
||||
throw new IllegalArgumentException("Index out of bounds");
|
||||
}
|
||||
return connections[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the user (e.g. johndoe) that is using the connection
|
||||
* located at the requested position.
|
||||
*
|
||||
* @param index the position in the pool of the connection to look for.
|
||||
* @return the user of the user (e.g. johndoe).
|
||||
*/
|
||||
protected String getUsername(int index) {
|
||||
if (index > getMaxConnections()) {
|
||||
throw new IllegalArgumentException("Index out of bounds");
|
||||
}
|
||||
return "user" + index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bare XMPP address of the user (e.g. johndoe@jabber.org) that is
|
||||
* using the connection located at the requested position.
|
||||
*
|
||||
* @param index the position in the pool of the connection to look for.
|
||||
* @return the bare XMPP address of the user (e.g. johndoe@jabber.org).
|
||||
*/
|
||||
protected String getBareJID(int index) {
|
||||
return getUsername(index) + "@" + getConnection(index).getHost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full XMPP address of the user (e.g. johndoe@jabber.org/Smack) that is
|
||||
* using the connection located at the requested position.
|
||||
*
|
||||
* @param index the position in the pool of the connection to look for.
|
||||
* @return the full XMPP address of the user (e.g. johndoe@jabber.org/Smack).
|
||||
*/
|
||||
protected String getFullJID(int index) {
|
||||
return getBareJID(index) + "/Smack";
|
||||
}
|
||||
|
||||
protected String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
protected int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default groupchat service domain.
|
||||
*
|
||||
* @return the default groupchat service domain.
|
||||
*/
|
||||
protected String getChatDomain() {
|
||||
return chatDomain;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default MUC service domain.
|
||||
*
|
||||
* @return the default MUC service domain.
|
||||
*/
|
||||
protected String getMUCDomain() {
|
||||
return mucDomain;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
init();
|
||||
if (getMaxConnections() < 1) {
|
||||
return;
|
||||
}
|
||||
connections = new XMPPConnection[getMaxConnections()];
|
||||
try {
|
||||
// Connect to the server
|
||||
for (int i = 0; i < getMaxConnections(); i++) {
|
||||
if (getSocketFactory() == null) {
|
||||
connections[i] = new XMPPConnection(host, port);
|
||||
}
|
||||
else {
|
||||
connections[i] = new XMPPConnection(host, port, getSocketFactory());
|
||||
}
|
||||
}
|
||||
// Use the host name that the server reports. This is a good idea in most
|
||||
// cases, but could fail if the user set a hostname in their XMPP server
|
||||
// that will not resolve as a network connection.
|
||||
host = connections[0].getHost();
|
||||
// Create the test accounts
|
||||
if (!getConnection(0).getAccountManager().supportsAccountCreation())
|
||||
fail("Server does not support account creation");
|
||||
|
||||
for (int i = 0; i < getMaxConnections(); i++) {
|
||||
// Create the test account
|
||||
try {
|
||||
getConnection(i).getAccountManager().createAccount("user" + i, "user" + i);
|
||||
} catch (XMPPException e) {
|
||||
// Do nothing if the accout already exists
|
||||
if (e.getXMPPError().getCode() != 409) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
// Login with the new test account
|
||||
getConnection(i).login("user" + i, "user" + i);
|
||||
}
|
||||
// Let the server process the available presences
|
||||
Thread.sleep(150);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
|
||||
for (int i = 0; i < getMaxConnections(); i++) {
|
||||
// Delete the created account for the test
|
||||
getConnection(i).getAccountManager().deleteAccount();
|
||||
// Close the connection
|
||||
getConnection(i).close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the context of the test case. We will first try to load the configuration from
|
||||
* a file whose name is conformed by the test case class name plus an .xml extension
|
||||
* (e.g RosterTest.xml). If no file was found under that name then we will try to load the
|
||||
* default configuration for all the test cases from the file "config/test-case.xml".
|
||||
*
|
||||
*/
|
||||
private void init() {
|
||||
try {
|
||||
boolean found = false;
|
||||
// Try to load the configutation from an XML file specific for this test case
|
||||
Enumeration resources =
|
||||
ClassLoader.getSystemClassLoader().getResources(getConfigurationFilename());
|
||||
while (resources.hasMoreElements()) {
|
||||
found = parseURL((URL) resources.nextElement());
|
||||
}
|
||||
// If none was found then try to load the configuration from the default configuration
|
||||
// file (i.e. "config/test-case.xml")
|
||||
if (!found) {
|
||||
resources = ClassLoader.getSystemClassLoader().getResources("config/test-case.xml");
|
||||
while (resources.hasMoreElements()) {
|
||||
found = parseURL((URL) resources.nextElement());
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
System.err.println("File config/test-case.xml not found. Using default config.");
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given URL was found and parsed without problems. The file provided
|
||||
* by the URL must contain information useful for the test case configuration, such us,
|
||||
* host and port of the server.
|
||||
*
|
||||
* @param url the url of the file to parse.
|
||||
* @return true if the given URL was found and parsed without problems.
|
||||
*/
|
||||
private boolean parseURL(URL url) {
|
||||
boolean parsedOK = false;
|
||||
InputStream systemStream = null;
|
||||
try {
|
||||
systemStream = url.openStream();
|
||||
XmlPullParser parser = new MXParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(systemStream, "UTF-8");
|
||||
int eventType = parser.getEventType();
|
||||
do {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if (parser.getName().equals("host")) {
|
||||
host = parser.nextText();
|
||||
}
|
||||
else if (parser.getName().equals("port")) {
|
||||
port = parseIntProperty(parser, port);
|
||||
;
|
||||
}
|
||||
else if (parser.getName().equals("chat")) {
|
||||
chatDomain = parser.nextText();
|
||||
}
|
||||
else if (parser.getName().equals("muc")) {
|
||||
mucDomain = parser.nextText();
|
||||
}
|
||||
}
|
||||
eventType = parser.next();
|
||||
}
|
||||
while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
parsedOK = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
systemStream.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return parsedOK;
|
||||
}
|
||||
|
||||
private static int parseIntProperty(XmlPullParser parser, int defaultValue) throws Exception {
|
||||
try {
|
||||
return Integer.parseInt(parser.nextText());
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
nfe.printStackTrace();
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the configuration file related to <b>this</b> test case. By default all
|
||||
* the test cases will use the same configuration file. However, it's possible to override the
|
||||
* default configuration by providing a file of the form <test case class name>.xml
|
||||
* (e.g. RosterTest.xml).
|
||||
*
|
||||
* @return the name of the configuration file related to this test case.
|
||||
*/
|
||||
private String getConfigurationFilename() {
|
||||
String fullClassName = this.getClass().getName();
|
||||
int firstChar = fullClassName.lastIndexOf('.') + 1;
|
||||
return "config/" + fullClassName.substring(firstChar) + ".xml";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,236 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* A test case for the StringUtils class.
|
||||
*/
|
||||
public class StringUtilsTest extends TestCase {
|
||||
|
||||
public void testEscapeForXML() {
|
||||
String input = null;
|
||||
|
||||
assertNull(StringUtils.escapeForXML(null));
|
||||
|
||||
input = "<b>";
|
||||
assertEquals("<b>", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "\"";
|
||||
assertEquals(""", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "&";
|
||||
assertEquals("&", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "<b>\n\t\r</b>";
|
||||
assertEquals("<b>\n\t\r</b>", StringUtils.escapeForXML(input));
|
||||
|
||||
input = " & ";
|
||||
assertEquals(" & ", StringUtils.escapeForXML(input));
|
||||
|
||||
input = " \" ";
|
||||
assertEquals(" " ", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "> of me <";
|
||||
assertEquals("> of me <", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "> of me & you<";
|
||||
assertEquals("> of me & you<", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "& <";
|
||||
assertEquals("& <", StringUtils.escapeForXML(input));
|
||||
|
||||
input = "&";
|
||||
assertEquals("&", StringUtils.escapeForXML(input));
|
||||
}
|
||||
|
||||
public void testHash() {
|
||||
// Test null
|
||||
// @TODO - should the StringUtils.hash(String) method be fixed to handle null input?
|
||||
try {
|
||||
StringUtils.hash(null);
|
||||
fail();
|
||||
}
|
||||
catch (NullPointerException npe) {
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
// Test empty String
|
||||
String result = StringUtils.hash("");
|
||||
assertEquals("da39a3ee5e6b4b0d3255bfef95601890afd80709", result);
|
||||
|
||||
// Test a known hash
|
||||
String adminInHash = "d033e22ae348aeb5660fc2140aec35850c4da997";
|
||||
result = StringUtils.hash("admin");
|
||||
assertEquals(adminInHash, result);
|
||||
|
||||
// Test a random String - make sure all resulting characters are valid hash characters
|
||||
// and that the returned string is 32 characters long.
|
||||
String random = "jive software blah and stuff this is pretty cool";
|
||||
result = StringUtils.hash(random);
|
||||
assertTrue(isValidHash(result));
|
||||
|
||||
// Test junk input:
|
||||
String junk = "\n\n\t\b\r!@(!)^(#)@+_-\u2031\u09291\u00A9\u00BD\u0394\u00F8";
|
||||
result = StringUtils.hash(junk);
|
||||
assertTrue(isValidHash(result));
|
||||
}
|
||||
|
||||
/* ----- Utility methods and vars ----- */
|
||||
|
||||
private final String HASH_CHARS = "0123456789abcdef";
|
||||
|
||||
/**
|
||||
* Returns true if the input string is valid md5 hash, false otherwise.
|
||||
*/
|
||||
private boolean isValidHash(String result) {
|
||||
boolean valid = true;
|
||||
for (int i=0; i<result.length(); i++) {
|
||||
char c = result.charAt(i);
|
||||
if (HASH_CHARS.indexOf(c) < 0) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void testEncodeHex() {
|
||||
String input = "";
|
||||
String output = "";
|
||||
assertEquals(new String(StringUtils.encodeHex(input.getBytes())),
|
||||
new String(output.getBytes()));
|
||||
|
||||
input = "foo bar 123";
|
||||
output = "666f6f2062617220313233";
|
||||
assertEquals(new String(StringUtils.encodeHex(input.getBytes())),
|
||||
new String(output.getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tests 2 StringUtil methods - encodeBase64(String) and encodeBase64(byte[]).
|
||||
*/
|
||||
public void testEncodeBase64() {
|
||||
String input = "";
|
||||
String output = "";
|
||||
assertEquals(StringUtils.encodeBase64(input), output);
|
||||
|
||||
input = "foo bar 123";
|
||||
output = "Zm9vIGJhciAxMjM=";
|
||||
assertEquals(StringUtils.encodeBase64(input), output);
|
||||
|
||||
input = "=";
|
||||
output = "PQ==";
|
||||
assertEquals(StringUtils.encodeBase64(input), output);
|
||||
|
||||
input = "abcdefghijklmnopqrstuvwxyz0123456789\n\t\"?!.@{}[]();',./<>#$%^&*";
|
||||
output = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5CgkiPyEuQHt9W10oKTsnLC4vPD4jJCVeJio=";
|
||||
assertEquals(StringUtils.encodeBase64(input), output);
|
||||
}
|
||||
|
||||
/***
|
||||
* This method tests 2 StringUtil methods - decodeBase64(String) and decodeBase64(byte[]).
|
||||
*/
|
||||
/*
|
||||
public void testDecodeBase64() {
|
||||
String input = "";
|
||||
String output = "";
|
||||
assertEquals(StringUtils.decodeBase64(input), output);
|
||||
|
||||
input = "Zm9vIGJhciAxMjM=";
|
||||
output = "foo bar 123";
|
||||
assertEquals(StringUtils.decodeBase64(input), output);
|
||||
|
||||
input = "PQ==";
|
||||
output = "=";
|
||||
assertEquals(StringUtils.decodeBase64(input), output);
|
||||
|
||||
input = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU2Nzg5CgkiPyEuQHt9W10oKTsnLC4vPD4jJCVeJio=";
|
||||
output = "abcdefghijklmnopqrstuvwxyz0123456789\n\t\"?!.@{}[]();',./<>#$%^&*";
|
||||
assertEquals(StringUtils.decodeBase64(input), output);
|
||||
}
|
||||
*/
|
||||
|
||||
public void testRandomString() {
|
||||
// Boundary test
|
||||
String result = StringUtils.randomString(-1);
|
||||
assertNull(result);
|
||||
|
||||
// Zero length string test
|
||||
result = StringUtils.randomString(0);
|
||||
assertNull(result);
|
||||
|
||||
// Test various lengths - make sure the same length is returned
|
||||
result = StringUtils.randomString(4);
|
||||
assertTrue(result.length() == 4);
|
||||
result = StringUtils.randomString(16);
|
||||
assertTrue(result.length() == 16);
|
||||
result = StringUtils.randomString(128);
|
||||
assertTrue(result.length() == 128);
|
||||
}
|
||||
|
||||
public void testParsing() {
|
||||
String error = "Error parsing node name";
|
||||
assertEquals(error, "", StringUtils.parseName("yahoo.myjabber.net"));
|
||||
assertEquals(error, "", StringUtils.parseName("yahoo.myjabber.net/registred"));
|
||||
assertEquals(error, "user", StringUtils.parseName("user@yahoo.myjabber.net/registred"));
|
||||
assertEquals(error, "user", StringUtils.parseName("user@yahoo.myjabber.net"));
|
||||
|
||||
error = "Error parsing server name";
|
||||
String result = "yahoo.myjabber.net";
|
||||
assertEquals(error, result, StringUtils.parseServer("yahoo.myjabber.net"));
|
||||
assertEquals(error, result, StringUtils.parseServer("yahoo.myjabber.net/registred"));
|
||||
assertEquals(error, result, StringUtils.parseServer("user@yahoo.myjabber.net/registred"));
|
||||
assertEquals(error, result, StringUtils.parseServer("user@yahoo.myjabber.net"));
|
||||
}
|
||||
}
|
||||
182
CopyOftrunk/test/org/jivesoftware/smackx/FormTest.java
Normal file
182
CopyOftrunk/test/org/jivesoftware/smackx/FormTest.java
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
* Tests the DataForms extensions.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class FormTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for FormTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public FormTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Create a form to fill out and send it to the other user
|
||||
* 2. Retrieve the form to fill out, complete it and return it to the requestor
|
||||
* 3. Retrieve the completed form and check that everything is OK
|
||||
*/
|
||||
public void testFilloutForm() {
|
||||
Form formToSend = new Form(Form.TYPE_FORM);
|
||||
formToSend.setInstructions(
|
||||
"Fill out this form to report your case.\nThe case will be created automatically.");
|
||||
formToSend.setTitle("Case configurations");
|
||||
// Add a hidden variable
|
||||
FormField field = new FormField("hidden_var");
|
||||
field.setType(FormField.TYPE_HIDDEN);
|
||||
field.addValue("Some value for the hidden variable");
|
||||
formToSend.addField(field);
|
||||
// Add a fixed variable
|
||||
field = new FormField();
|
||||
field.addValue("Section 1: Case description");
|
||||
formToSend.addField(field);
|
||||
// Add a text-single variable
|
||||
field = new FormField("name");
|
||||
field.setLabel("Enter a name for the case");
|
||||
field.setType(FormField.TYPE_TEXT_SINGLE);
|
||||
formToSend.addField(field);
|
||||
// Add a text-multi variable
|
||||
field = new FormField("description");
|
||||
field.setLabel("Enter a description");
|
||||
field.setType(FormField.TYPE_TEXT_MULTI);
|
||||
formToSend.addField(field);
|
||||
// Add a boolean variable
|
||||
field = new FormField("time");
|
||||
field.setLabel("Is this your first case?");
|
||||
field.setType(FormField.TYPE_BOOLEAN);
|
||||
formToSend.addField(field);
|
||||
// Add a text variable where an int value is expected
|
||||
field = new FormField("age");
|
||||
field.setLabel("How old are you?");
|
||||
field.setType(FormField.TYPE_TEXT_SINGLE);
|
||||
formToSend.addField(field);
|
||||
|
||||
// Create the chats between the two participants
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat.getThreadID());
|
||||
|
||||
Message msg = chat.createMessage();
|
||||
msg.setBody("To enter a case please fill out this form and send it back to me");
|
||||
msg.addExtension(formToSend.getDataFormToSend());
|
||||
|
||||
try {
|
||||
// Send the message with the form to fill out
|
||||
chat.sendMessage(msg);
|
||||
|
||||
// Get the message with the form to fill out
|
||||
Message msg2 = chat2.nextMessage(2000);
|
||||
// Retrieve the form to fill out
|
||||
Form formToRespond = Form.getFormFrom(msg2);
|
||||
assertNotNull(formToRespond);
|
||||
assertNotNull(formToRespond.getField("name"));
|
||||
assertNotNull(formToRespond.getField("description"));
|
||||
// Obtain the form to send with the replies
|
||||
Form completedForm = formToRespond.createAnswerForm();
|
||||
assertNotNull(completedForm.getField("hidden_var"));
|
||||
// Check that a field of type String does not accept booleans
|
||||
try {
|
||||
completedForm.setAnswer("name", true);
|
||||
fail("A boolean value was set to a field of type String");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
}
|
||||
completedForm.setAnswer("name", "Credit card number invalid");
|
||||
completedForm.setAnswer(
|
||||
"description",
|
||||
"The ATM says that my credit card number is invalid. What's going on?");
|
||||
completedForm.setAnswer("time", true);
|
||||
completedForm.setAnswer("age", 20);
|
||||
// Create a new message to send with the completed form
|
||||
msg2 = chat2.createMessage();
|
||||
msg2.setBody("To enter a case please fill out this form and send it back to me");
|
||||
// Add the completed form to the message
|
||||
msg2.addExtension(completedForm.getDataFormToSend());
|
||||
// Send the message with the completed form
|
||||
chat2.sendMessage(msg2);
|
||||
|
||||
// Get the message with the completed form
|
||||
Message msg3 = chat.nextMessage(2000);
|
||||
// Retrieve the completed form
|
||||
completedForm = Form.getFormFrom(msg3);
|
||||
assertNotNull(completedForm);
|
||||
assertNotNull(completedForm.getField("name"));
|
||||
assertNotNull(completedForm.getField("description"));
|
||||
assertEquals(
|
||||
completedForm.getField("name").getValues().next(),
|
||||
"Credit card number invalid");
|
||||
assertNotNull(completedForm.getField("time"));
|
||||
assertNotNull(completedForm.getField("age"));
|
||||
assertEquals("The age is bad", "20", completedForm.getField("age").getValues().next());
|
||||
|
||||
}
|
||||
catch (XMPPException ex) {
|
||||
fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.filter.PacketFilter;
|
||||
import org.jivesoftware.smack.filter.PacketExtensionFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class GroupChatInvitationTest extends SmackTestCase {
|
||||
|
||||
private PacketCollector collector = null;
|
||||
|
||||
/**
|
||||
* Constructor for GroupChatInvitationTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public GroupChatInvitationTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testInvitation() {
|
||||
try {
|
||||
GroupChatInvitation invitation = new GroupChatInvitation("test@" + getChatDomain());
|
||||
Message message = new Message(getBareJID(1));
|
||||
message.setBody("Group chat invitation!");
|
||||
message.addExtension(invitation);
|
||||
getConnection(0).sendPacket(message);
|
||||
|
||||
Thread.sleep(250);
|
||||
|
||||
Message result = (Message)collector.pollResult();
|
||||
assertNotNull("Message not delivered correctly.", result);
|
||||
|
||||
GroupChatInvitation resultInvite = (GroupChatInvitation)result.getExtension("x",
|
||||
"jabber:x:conference");
|
||||
|
||||
assertEquals("Invitation not to correct room", "test@" + getChatDomain(),
|
||||
resultInvite.getRoomAddress());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// Register listener for groupchat invitations.
|
||||
PacketFilter filter = new PacketExtensionFilter("x", "jabber:x:conference");
|
||||
collector = getConnection(1).createPacketCollector(filter);
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
// Cancel the packet collector so that no more results are queued up
|
||||
collector.cancel();
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test the MessageEvent extension using the high level API.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MessageEventManagerTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for MessageEventManagerTest.
|
||||
* @param name
|
||||
*/
|
||||
public MessageEventManagerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives the
|
||||
* message
|
||||
* 1. User_1 will send a message to user_2 requesting to be notified when any of these events
|
||||
* occurs: offline, composing, displayed or delivered
|
||||
*/
|
||||
public void testSendMessageEventRequest() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Add to the message all the notifications requests (offline, delivered, displayed,
|
||||
// composing)
|
||||
MessageEventManager.addNotificationsRequests(msg, true, true, true, true);
|
||||
|
||||
// Send the message that contains the notifications request
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* This is a simple test to use with a XMPP client, check if the client receives the
|
||||
* message and display in the console any notification
|
||||
* 1. User_1 will send a message to user_2 requesting to be notified when any of these events
|
||||
* occurs: offline, composing, displayed or delivered
|
||||
* 2. User_2 will use a XMPP client (like Exodus) to display the message and compose a reply
|
||||
* 3. User_1 will display any notification that receives
|
||||
*/
|
||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
MessageEventManager messageEventManager = new MessageEventManager(getConnection(0));
|
||||
messageEventManager
|
||||
.addMessageEventNotificationListener(new MessageEventNotificationListener() {
|
||||
public void deliveredNotification(String from, String packetID) {
|
||||
System.out.println("From: " + from + " PacketID: " + packetID + "(delivered)");
|
||||
}
|
||||
|
||||
public void displayedNotification(String from, String packetID) {
|
||||
System.out.println("From: " + from + " PacketID: " + packetID + "(displayed)");
|
||||
}
|
||||
|
||||
public void composingNotification(String from, String packetID) {
|
||||
System.out.println("From: " + from + " PacketID: " + packetID + "(composing)");
|
||||
}
|
||||
|
||||
public void offlineNotification(String from, String packetID) {
|
||||
System.out.println("From: " + from + " PacketID: " + packetID + "(offline)");
|
||||
}
|
||||
|
||||
public void cancelledNotification(String from, String packetID) {
|
||||
System.out.println("From: " + from + " PacketID: " + packetID + "(cancelled)");
|
||||
}
|
||||
});
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Add to the message all the notifications requests (offline, delivered, displayed,
|
||||
// composing)
|
||||
MessageEventManager.addNotificationsRequests(msg, true, true, true, true);
|
||||
|
||||
// Send the message that contains the notifications request
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
// Wait a few seconds so that the XMPP client can send any event
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* 1. User_1 will send a message to user_2 requesting to be notified when any of these events
|
||||
* occurs: offline, composing, displayed or delivered
|
||||
* 2. User_2 will receive the message
|
||||
* 3. User_2 will simulate that the message was displayed
|
||||
* 4. User_2 will simulate that he/she is composing a reply
|
||||
* 5. User_2 will simulate that he/she has cancelled the reply
|
||||
*/
|
||||
public void testRequestsAndNotifications() {
|
||||
final ArrayList results = new ArrayList();
|
||||
ArrayList resultsExpected = new ArrayList();
|
||||
resultsExpected.add("deliveredNotificationRequested");
|
||||
resultsExpected.add("composingNotificationRequested");
|
||||
resultsExpected.add("displayedNotificationRequested");
|
||||
resultsExpected.add("offlineNotificationRequested");
|
||||
resultsExpected.add("deliveredNotification");
|
||||
resultsExpected.add("displayedNotification");
|
||||
resultsExpected.add("composingNotification");
|
||||
resultsExpected.add("cancelledNotification");
|
||||
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
MessageEventManager messageEventManager1 = new MessageEventManager(getConnection(0));
|
||||
messageEventManager1
|
||||
.addMessageEventNotificationListener(new MessageEventNotificationListener() {
|
||||
public void deliveredNotification(String from, String packetID) {
|
||||
results.add("deliveredNotification");
|
||||
}
|
||||
|
||||
public void displayedNotification(String from, String packetID) {
|
||||
results.add("displayedNotification");
|
||||
}
|
||||
|
||||
public void composingNotification(String from, String packetID) {
|
||||
results.add("composingNotification");
|
||||
}
|
||||
|
||||
public void offlineNotification(String from, String packetID) {
|
||||
results.add("offlineNotification");
|
||||
}
|
||||
|
||||
public void cancelledNotification(String from, String packetID) {
|
||||
results.add("cancelledNotification");
|
||||
}
|
||||
});
|
||||
|
||||
MessageEventManager messageEventManager2 = new MessageEventManager(getConnection(1));
|
||||
messageEventManager2
|
||||
.addMessageEventRequestListener(new DefaultMessageEventRequestListener() {
|
||||
public void deliveredNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.deliveredNotificationRequested(from, packetID, messageEventManager);
|
||||
results.add("deliveredNotificationRequested");
|
||||
}
|
||||
|
||||
public void displayedNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.displayedNotificationRequested(from, packetID, messageEventManager);
|
||||
results.add("displayedNotificationRequested");
|
||||
}
|
||||
|
||||
public void composingNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.composingNotificationRequested(from, packetID, messageEventManager);
|
||||
results.add("composingNotificationRequested");
|
||||
}
|
||||
|
||||
public void offlineNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.offlineNotificationRequested(from, packetID, messageEventManager);
|
||||
results.add("offlineNotificationRequested");
|
||||
}
|
||||
});
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Add to the message all the notifications requests (offline, delivered, displayed,
|
||||
// composing)
|
||||
MessageEventManager.addNotificationsRequests(msg, true, true, true, true);
|
||||
|
||||
// Send the message that contains the notifications request
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
messageEventManager2.sendDisplayedNotification(getBareJID(0), msg.getPacketID());
|
||||
messageEventManager2.sendComposingNotification(getBareJID(0), msg.getPacketID());
|
||||
messageEventManager2.sendCancelledNotification(getBareJID(0), msg.getPacketID());
|
||||
// Wait up to 2 seconds
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
(!results.containsAll(resultsExpected))) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
assertTrue(
|
||||
"Test failed due to bad results (1)" + resultsExpected,
|
||||
resultsExpected.containsAll(results));
|
||||
assertTrue(
|
||||
"Test failed due to bad results (2)" + results,
|
||||
results.containsAll(resultsExpected));
|
||||
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message");
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smackx.packet.MessageEventTest;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test suite that runs all the Message Event extension tests
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MessageEventTests {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("High and low level API tests for message event extension");
|
||||
//$JUnit-BEGIN$
|
||||
suite.addTest(new TestSuite(MessageEventManagerTest.class));
|
||||
suite.addTest(new TestSuite(MessageEventTest.class));
|
||||
//$JUnit-END$
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.Chat;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.MessageTypeFilter;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.packet.OfflineMessageInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests handling of offline messaging using OfflineMessageManager. This server requires the
|
||||
* server to support JEP-0013: Flexible Offline Message Retrieval.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class OfflineMessageManagerTest extends SmackTestCase {
|
||||
|
||||
public OfflineMessageManagerTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testDiscoverFlexibleRetrievalSupport() throws XMPPException {
|
||||
OfflineMessageManager offlineManager = new OfflineMessageManager(getConnection(1));
|
||||
assertTrue("Server does not support JEP-13", offlineManager.supportsFlexibleRetrieval());
|
||||
}
|
||||
|
||||
/**
|
||||
* While user2 is connected but unavailable, user1 sends 2 messages to user1. User2 then
|
||||
* performs some "Flexible Offline Message Retrieval" checking the number of offline messages,
|
||||
* retriving the headers, then the real messages of the headers and finally removing the
|
||||
* loaded messages.
|
||||
*/
|
||||
public void testReadAndDelete() {
|
||||
// Make user2 unavailable
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.UNAVAILABLE));
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
chat.sendMessage("Test 1");
|
||||
chat.sendMessage("Test 2");
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
// User2 checks the number of offline messages
|
||||
OfflineMessageManager offlineManager = new OfflineMessageManager(getConnection(1));
|
||||
assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());
|
||||
// Check the message headers
|
||||
Iterator headers = offlineManager.getHeaders();
|
||||
assertTrue("No message header was found", headers.hasNext());
|
||||
List stamps = new ArrayList();
|
||||
while (headers.hasNext()) {
|
||||
OfflineMessageHeader header = (OfflineMessageHeader) headers.next();
|
||||
assertEquals("Incorrect sender", getFullJID(0), header.getJid());
|
||||
assertNotNull("No stamp was found in the message header", header.getStamp());
|
||||
stamps.add(header.getStamp());
|
||||
}
|
||||
assertEquals("Wrong number of headers", 2, stamps.size());
|
||||
// Get the offline messages
|
||||
Iterator messages = offlineManager.getMessages(stamps);
|
||||
assertTrue("No message was found", messages.hasNext());
|
||||
stamps = new ArrayList();
|
||||
while (messages.hasNext()) {
|
||||
Message message = (Message) messages.next();
|
||||
OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
|
||||
"http://jabber.org/protocol/offline");
|
||||
assertNotNull("No offline information was included in the offline message", info);
|
||||
assertNotNull("No stamp was found in the message header", info.getNode());
|
||||
stamps.add(info.getNode());
|
||||
}
|
||||
assertEquals("Wrong number of messages", 2, stamps.size());
|
||||
// Check that the offline messages have not been deleted
|
||||
assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());
|
||||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.CHAT));
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
|
||||
|
||||
// Check that no offline messages was sent to the user
|
||||
Message message = (Message) collector.nextResult(2500);
|
||||
assertNull("An offline message was sent from the server", message);
|
||||
|
||||
// Delete the retrieved offline messages
|
||||
offlineManager.deleteMessages(stamps);
|
||||
// Check that there are no offline message for this user
|
||||
assertEquals("Wrong number of offline messages", 0, offlineManager.getMessageCount());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* While user2 is connected but unavailable, user1 sends 2 messages to user1. User2 then
|
||||
* performs some "Flexible Offline Message Retrieval" by fetching all the offline messages
|
||||
* and then removing all the offline messages.
|
||||
*/
|
||||
public void testFetchAndPurge() {
|
||||
// Make user2 unavailable
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.UNAVAILABLE));
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
|
||||
// User1 sends some messages to User2 which is not available at the moment
|
||||
Chat chat = getConnection(0).createChat(getBareJID(1));
|
||||
chat.sendMessage("Test 1");
|
||||
chat.sendMessage("Test 2");
|
||||
|
||||
Thread.sleep(500);
|
||||
|
||||
// User2 checks the number of offline messages
|
||||
OfflineMessageManager offlineManager = new OfflineMessageManager(getConnection(1));
|
||||
assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());
|
||||
// Get all offline messages
|
||||
Iterator messages = offlineManager.getMessages();
|
||||
assertTrue("No message was found", messages.hasNext());
|
||||
List stamps = new ArrayList();
|
||||
while (messages.hasNext()) {
|
||||
Message message = (Message) messages.next();
|
||||
OfflineMessageInfo info = (OfflineMessageInfo) message.getExtension("offline",
|
||||
"http://jabber.org/protocol/offline");
|
||||
assertNotNull("No offline information was included in the offline message", info);
|
||||
assertNotNull("No stamp was found in the message header", info.getNode());
|
||||
stamps.add(info.getNode());
|
||||
}
|
||||
assertEquals("Wrong number of messages", 2, stamps.size());
|
||||
// Check that the offline messages have not been deleted
|
||||
assertEquals("Wrong number of offline messages", 2, offlineManager.getMessageCount());
|
||||
|
||||
// User2 becomes available again
|
||||
PacketCollector collector = getConnection(1).createPacketCollector(
|
||||
new MessageTypeFilter(Message.Type.CHAT));
|
||||
getConnection(1).sendPacket(new Presence(Presence.Type.AVAILABLE));
|
||||
|
||||
// Check that no offline messages was sent to the user
|
||||
Message message = (Message) collector.nextResult(2500);
|
||||
assertNull("An offline message was sent from the server", message);
|
||||
|
||||
// Delete all offline messages
|
||||
offlineManager.deleteMessages();
|
||||
// Check that there are no offline message for this user
|
||||
assertEquals("Wrong number of offline messages", 0, offlineManager.getMessageCount());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,246 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test the Roster Exchange extension using the high level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class RosterExchangeManagerTest extends SmackTestCase {
|
||||
|
||||
private int entriesSent;
|
||||
private int entriesReceived;
|
||||
|
||||
/**
|
||||
* Constructor for RosterExchangeManagerTest.
|
||||
* @param name
|
||||
*/
|
||||
public RosterExchangeManagerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives user1's
|
||||
* roster
|
||||
* 1. User_1 will send his/her roster to user_2
|
||||
*/
|
||||
public void testSendRoster() {
|
||||
// Send user1's roster to user2
|
||||
try {
|
||||
RosterExchangeManager rosterExchangeManager =
|
||||
new RosterExchangeManager(getConnection(0));
|
||||
rosterExchangeManager.send(getConnection(0).getRoster(), getBareJID(1));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("An error occured sending the roster");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives user1's
|
||||
* roster groups
|
||||
* 1. User_1 will send his/her RosterGroups to user_2
|
||||
*/
|
||||
public void testSendRosterGroup() {
|
||||
// Send user1's RosterGroups to user2
|
||||
try {
|
||||
RosterExchangeManager rosterExchangeManager =
|
||||
new RosterExchangeManager(getConnection(0));
|
||||
for (Iterator it = getConnection(0).getRoster().getGroups(); it.hasNext();)
|
||||
rosterExchangeManager.send((RosterGroup) it.next(), getBareJID(1));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("An error occured sending the roster");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* 1. User_1 will send his/her roster to user_2
|
||||
* 2. User_2 will receive the entries and iterate over them to check if everything is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendAndReceiveRoster() {
|
||||
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(getConnection(0));
|
||||
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(getConnection(1));
|
||||
|
||||
// Create a RosterExchangeListener that will iterate over the received roster entries
|
||||
RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() {
|
||||
public void entriesReceived(String from, Iterator remoteRosterEntries) {
|
||||
int received = 0;
|
||||
assertNotNull("From is null", from);
|
||||
assertNotNull("rosterEntries is null", remoteRosterEntries);
|
||||
assertTrue("Roster without entries", remoteRosterEntries.hasNext());
|
||||
while (remoteRosterEntries.hasNext()) {
|
||||
received++;
|
||||
RemoteRosterEntry remoteEntry = (RemoteRosterEntry) remoteRosterEntries.next();
|
||||
System.out.println(remoteEntry);
|
||||
}
|
||||
entriesReceived = received;
|
||||
}
|
||||
};
|
||||
rosterExchangeManager2.addRosterListener(rosterExchangeListener);
|
||||
|
||||
// Send user1's roster to user2
|
||||
try {
|
||||
entriesSent = getConnection(0).getRoster().getEntryCount();
|
||||
entriesReceived = 0;
|
||||
rosterExchangeManager1.send(getConnection(0).getRoster(), getBareJID(1));
|
||||
// Wait up to 2 seconds
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
(entriesSent != entriesReceived)) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
assertEquals(
|
||||
"Number of sent and received entries does not match",
|
||||
entriesSent,
|
||||
entriesReceived);
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* 1. User_1 will send his/her roster to user_2
|
||||
* 2. User_2 will automatically add the entries that receives to his/her roster in the
|
||||
* corresponding group
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendAndAcceptRoster() {
|
||||
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(getConnection(0));
|
||||
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(getConnection(1));
|
||||
|
||||
// Create a RosterExchangeListener that will accept all the received roster entries
|
||||
RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() {
|
||||
public void entriesReceived(String from, Iterator remoteRosterEntries) {
|
||||
int received = 0;
|
||||
assertNotNull("From is null", from);
|
||||
assertNotNull("remoteRosterEntries is null", remoteRosterEntries);
|
||||
assertTrue("Roster without entries", remoteRosterEntries.hasNext());
|
||||
while (remoteRosterEntries.hasNext()) {
|
||||
received++;
|
||||
try {
|
||||
RemoteRosterEntry remoteRosterEntry =
|
||||
(RemoteRosterEntry) remoteRosterEntries.next();
|
||||
getConnection(1).getRoster().createEntry(
|
||||
remoteRosterEntry.getUser(),
|
||||
remoteRosterEntry.getName(),
|
||||
remoteRosterEntry.getGroupArrayNames());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
entriesReceived = received;
|
||||
}
|
||||
};
|
||||
rosterExchangeManager2.addRosterListener(rosterExchangeListener);
|
||||
|
||||
// Send user1's roster to user2
|
||||
try {
|
||||
entriesSent = getConnection(0).getRoster().getEntryCount();
|
||||
entriesReceived = 0;
|
||||
rosterExchangeManager1.send(getConnection(0).getRoster(), getBareJID(1));
|
||||
// Wait up to 2 seconds
|
||||
long initial = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - initial < 2000 &&
|
||||
(entriesSent != entriesReceived)) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
assertEquals(
|
||||
"Number of sent and received entries does not match",
|
||||
entriesSent,
|
||||
entriesReceived);
|
||||
assertTrue("Roster2 has no entries", getConnection(1).getRoster().getEntryCount() > 0);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
try {
|
||||
getConnection(0).getRoster().createEntry(
|
||||
getBareJID(2),
|
||||
"gato5",
|
||||
new String[] { "Friends, Coworker" });
|
||||
getConnection(0).getRoster().createEntry(getBareJID(3), "gato6", null);
|
||||
Thread.sleep(100);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smackx.packet.RosterExchangeTest;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test suite that runs all the Roster Exchange extension tests
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class RosterExchangeTests {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("High and low level API tests for roster exchange extension");
|
||||
//$JUnit-BEGIN$
|
||||
suite.addTest(new TestSuite(RosterExchangeManagerTest.class));
|
||||
suite.addTest(new TestSuite(RosterExchangeTest.class));
|
||||
//$JUnit-END$
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
|
||||
|
||||
/**
|
||||
* Tests the service discovery functionality.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class ServiceDiscoveryManagerTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for ServiceDiscoveryManagerTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public ServiceDiscoveryManagerTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests info discovery of a Smack client.
|
||||
*/
|
||||
public void testSmackInfo() {
|
||||
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager
|
||||
.getInstanceFor(getConnection(0));
|
||||
try {
|
||||
// Discover the information of another Smack client
|
||||
DiscoverInfo info = discoManager.discoverInfo(getFullJID(1));
|
||||
// Check the identity of the Smack client
|
||||
Iterator identities = info.getIdentities();
|
||||
assertTrue("No identities were found", identities.hasNext());
|
||||
DiscoverInfo.Identity identity = (DiscoverInfo.Identity)identities.next();
|
||||
assertEquals("Name in identity is wrong", ServiceDiscoveryManager.getIdentityName(),
|
||||
identity.getName());
|
||||
assertEquals("Category in identity is wrong", "client", identity.getCategory());
|
||||
assertEquals("Type in identity is wrong", ServiceDiscoveryManager.getIdentityType(),
|
||||
identity.getType());
|
||||
assertFalse("More identities were found", identities.hasNext());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests service discovery of XHTML support.
|
||||
*/
|
||||
public void testXHTMLFeature() {
|
||||
// Check for local XHTML service support
|
||||
// By default the XHTML service support is enabled in all the connections
|
||||
assertTrue(XHTMLManager.isServiceEnabled(getConnection(0)));
|
||||
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1)));
|
||||
// Check for XHTML support in connection1 from connection2
|
||||
// Must specify a full JID and not a bare JID. Ensure that the server is working ok.
|
||||
assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getBareJID(0)));
|
||||
// Using a full JID check that the other client supports XHTML.
|
||||
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0)));
|
||||
|
||||
// Disable the XHTML Message support in connection1
|
||||
XHTMLManager.setServiceEnabled(getConnection(0), false);
|
||||
// Check for local XHTML service support
|
||||
assertFalse(XHTMLManager.isServiceEnabled(getConnection(0)));
|
||||
assertTrue(XHTMLManager.isServiceEnabled(getConnection(1)));
|
||||
// Check for XHTML support in connection1 from connection2
|
||||
assertFalse(XHTMLManager.isServiceEnabled(getConnection(1), getFullJID(0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests support for publishing items to another entity.
|
||||
*/
|
||||
public void testDiscoverPublishItemsSupport() {
|
||||
try {
|
||||
boolean canPublish = ServiceDiscoveryManager.getInstanceFor(getConnection(0))
|
||||
.canPublishItems(getHost());
|
||||
assertFalse("Messenger does not support publishing...so far!!", canPublish);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests publishing items to another entity.
|
||||
*/
|
||||
/*public void testPublishItems() {
|
||||
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);
|
||||
|
||||
try {
|
||||
ServiceDiscoveryManager.getInstanceFor(getConnection(0)).publishItems(getHost(),
|
||||
itemsToPublish);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
60
CopyOftrunk/test/org/jivesoftware/smackx/VCardTest.java
Normal file
60
CopyOftrunk/test/org/jivesoftware/smackx/VCardTest.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.packet.VCard;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Gaston
|
||||
* Date: Jun 18, 2005
|
||||
* Time: 1:29:30 AM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class VCardTest extends SmackTestCase {
|
||||
|
||||
public VCardTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testBigFunctional() {
|
||||
VCard origVCard = new VCard();
|
||||
|
||||
origVCard.setFirstName("kir");
|
||||
origVCard.setLastName("max");
|
||||
origVCard.setEmailHome("foo@fee.bar");
|
||||
origVCard.setJabberId("jabber@id.org");
|
||||
origVCard.setOrganization("Jetbrains, s.r.o");
|
||||
origVCard.setNickName("KIR");
|
||||
|
||||
origVCard.setField("TITLE", "Mr");
|
||||
origVCard.setAddressFieldHome("STREET", "Some street");
|
||||
origVCard.setPhoneWork("FAX", "3443233");
|
||||
|
||||
origVCard.save(getConnection(0));
|
||||
|
||||
VCard loaded = new VCard();
|
||||
try {
|
||||
loaded.load(getConnection(0));
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals("Should load own VCard successfully", origVCard, loaded);
|
||||
|
||||
loaded = new VCard();
|
||||
try {
|
||||
loaded.load(getConnection(1), getBareJID(0));
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
assertEquals("Should load another user's VCard successfully", origVCard, loaded);
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
76
CopyOftrunk/test/org/jivesoftware/smackx/VersionTest.java
Normal file
76
CopyOftrunk/test/org/jivesoftware/smackx/VersionTest.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 Jive Software.
|
||||
*
|
||||
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.packet.Version;
|
||||
|
||||
/**
|
||||
* Test case to ensure that Smack is able to get and parse correctly iq:version packets.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class VersionTest extends SmackTestCase {
|
||||
|
||||
public VersionTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the version of the server and make sure that all the required data is present
|
||||
*
|
||||
* Note: This test expects the server to answer an iq:version packet.
|
||||
*/
|
||||
public void testGetServerVersion() {
|
||||
Version version = new Version();
|
||||
version.setType(IQ.Type.GET);
|
||||
version.setTo(getHost());
|
||||
|
||||
// Create a packet collector to listen for a response.
|
||||
PacketCollector collector = getConnection(0).createPacketCollector(new PacketIDFilter(version.getPacketID()));
|
||||
|
||||
getConnection(0).sendPacket(version);
|
||||
|
||||
// Wait up to 5 seconds for a result.
|
||||
IQ result = (IQ)collector.nextResult(5000);
|
||||
// Close the collector
|
||||
collector.cancel();
|
||||
|
||||
assertNotNull("No result from the server", result);
|
||||
|
||||
assertEquals("Incorrect result type", IQ.Type.RESULT, result.getType());
|
||||
assertNotNull("No name specified in the result", ((Version)result).getName());
|
||||
assertNotNull("No version specified in the result", ((Version)result).getVersion());
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
XMPPConnection.DEBUG_ENABLED = false;
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
284
CopyOftrunk/test/org/jivesoftware/smackx/XHTMLManagerTest.java
Normal file
284
CopyOftrunk/test/org/jivesoftware/smackx/XHTMLManagerTest.java
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
* Test the XHTML extension using the high level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class XHTMLManagerTest extends SmackTestCase {
|
||||
|
||||
private int bodiesSent;
|
||||
private int bodiesReceived;
|
||||
|
||||
/**
|
||||
* Constructor for XHTMLManagerTest.
|
||||
* @param name
|
||||
*/
|
||||
public XHTMLManagerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives the message
|
||||
* 1. User_1 will send a message with formatted text (XHTML) to user_2
|
||||
*/
|
||||
public void testSendSimpleXHTMLMessage() {
|
||||
// User1 creates a chat with user2
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
|
||||
// Create an XHTMLText to send with the message
|
||||
XHTMLText xhtmlText = new XHTMLText(null, null);
|
||||
xhtmlText.appendOpenParagraphTag("font-size:large");
|
||||
xhtmlText.append("Hey John, this is my new ");
|
||||
xhtmlText.appendOpenSpanTag("color:green");
|
||||
xhtmlText.append("green");
|
||||
xhtmlText.appendCloseSpanTag();
|
||||
xhtmlText.appendOpenEmTag();
|
||||
xhtmlText.append("!!!!");
|
||||
xhtmlText.appendCloseEmTag();
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
// Add the XHTML text to the message
|
||||
XHTMLManager.addBody(msg, xhtmlText.toString());
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* High level API test.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a listener for the chat that will check if the received message includes
|
||||
// an XHTML extension. Answer an ACK if everything is ok
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertTrue(
|
||||
"The received message is not an XHTML Message",
|
||||
XHTMLManager.isXHTMLMessage(message));
|
||||
try {
|
||||
assertTrue(
|
||||
"Message without XHTML bodies",
|
||||
XHTMLManager.getBodies(message).hasNext());
|
||||
for (Iterator it = XHTMLManager.getBodies(message); it.hasNext();) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
chat2.addMessageListener(packetListener);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
|
||||
// Create an XHTMLText to send with the message
|
||||
XHTMLText xhtmlText = new XHTMLText(null, null);
|
||||
xhtmlText.appendOpenParagraphTag("font-size:large");
|
||||
xhtmlText.append("Hey John, this is my new ");
|
||||
xhtmlText.appendOpenSpanTag("color:green");
|
||||
xhtmlText.append("green");
|
||||
xhtmlText.appendCloseSpanTag();
|
||||
xhtmlText.appendOpenEmTag();
|
||||
xhtmlText.append("!!!!");
|
||||
xhtmlText.appendCloseEmTag();
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
// Add the XHTML text to the message
|
||||
XHTMLManager.addBody(msg, xhtmlText.toString());
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait for 1 second for a reply
|
||||
msg = chat1.nextMessage(1000);
|
||||
assertNotNull("No reply received", msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test. Test a message with two XHTML bodies and several XHTML tags.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a listener for the chat that will check if the received message includes
|
||||
// an XHTML extension. Answer an ACK if everything is ok
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
int received = 0;
|
||||
Message message = (Message) packet;
|
||||
assertTrue(
|
||||
"The received message is not an XHTML Message",
|
||||
XHTMLManager.isXHTMLMessage(message));
|
||||
try {
|
||||
assertTrue(
|
||||
"Message without XHTML bodies",
|
||||
XHTMLManager.getBodies(message).hasNext());
|
||||
for (Iterator it = XHTMLManager.getBodies(message); it.hasNext();) {
|
||||
received++;
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
bodiesReceived = received;
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
};
|
||||
chat2.addMessageListener(packetListener);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody(
|
||||
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||
|
||||
// Create an XHTMLText to send with the message (in Spanish)
|
||||
XHTMLText xhtmlText = new XHTMLText(null, "es-ES");
|
||||
xhtmlText.appendOpenHeaderTag(1, null);
|
||||
xhtmlText.append("impresionante!");
|
||||
xhtmlText.appendCloseHeaderTag(1);
|
||||
xhtmlText.appendOpenParagraphTag(null);
|
||||
xhtmlText.append("Como Emerson dijo una vez:");
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
xhtmlText.appendOpenBlockQuoteTag(null);
|
||||
xhtmlText.appendOpenParagraphTag(null);
|
||||
xhtmlText.append("Una consistencia ridícula es el espantajo de mentes pequeñas.");
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
xhtmlText.appendCloseBlockQuoteTag();
|
||||
// Add the XHTML text to the message
|
||||
XHTMLManager.addBody(msg, xhtmlText.toString());
|
||||
|
||||
// Create an XHTMLText to send with the message (in English)
|
||||
xhtmlText = new XHTMLText(null, "en-US");
|
||||
xhtmlText.appendOpenHeaderTag(1, null);
|
||||
xhtmlText.append("awesome!");
|
||||
xhtmlText.appendCloseHeaderTag(1);
|
||||
xhtmlText.appendOpenParagraphTag(null);
|
||||
xhtmlText.append("As Emerson once said:");
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
xhtmlText.appendOpenBlockQuoteTag(null);
|
||||
xhtmlText.appendOpenParagraphTag(null);
|
||||
xhtmlText.append("A foolish consistency is the hobgoblin of little minds.");
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
xhtmlText.appendCloseBlockQuoteTag();
|
||||
// Add the XHTML text to the message
|
||||
XHTMLManager.addBody(msg, xhtmlText.toString());
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
bodiesSent = 2;
|
||||
bodiesReceived = 0;
|
||||
chat1.sendMessage(msg);
|
||||
// Wait half second so that the complete test can run
|
||||
Thread.sleep(300);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
assertEquals(
|
||||
"Number of sent and received XHTMP bodies does not match",
|
||||
bodiesSent,
|
||||
bodiesReceived);
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smackx.packet.XHTMLExtensionTest;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Test suite that runs all the XHTML support tests
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class XHTMLSupportTests {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("High and low level API tests for XHTML support");
|
||||
//$JUnit-BEGIN$
|
||||
suite.addTest(new TestSuite(XHTMLManagerTest.class));
|
||||
suite.addTest(new TestSuite(XHTMLExtensionTest.class));
|
||||
//$JUnit-END$
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jivesoftware.smackx.muc;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.*;
|
||||
|
||||
/**
|
||||
* Tests creating new MUC rooms.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MultiUserChatCreationTest extends SmackTestCase {
|
||||
|
||||
private String room;
|
||||
|
||||
/**
|
||||
* Constructor for MultiUserChatCreationTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public MultiUserChatCreationTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a new "Reserved Room".
|
||||
*/
|
||||
public void testCreateReservedRoom() {
|
||||
MultiUserChat muc = new MultiUserChat(getConnection(0), room);
|
||||
|
||||
try {
|
||||
// Create the room
|
||||
muc.create("testbot1");
|
||||
|
||||
// Get the the room's configuration form
|
||||
Form form = muc.getConfigurationForm();
|
||||
assertNotNull("No room configuration form", form);
|
||||
// Create a new form to submit based on the original form
|
||||
Form submitForm = form.createAnswerForm();
|
||||
// Add default answers to the form to submit
|
||||
for (Iterator fields = form.getFields(); fields.hasNext();) {
|
||||
FormField field = (FormField) fields.next();
|
||||
if (!FormField.TYPE_HIDDEN.equals(field.getType())
|
||||
&& field.getVariable() != null) {
|
||||
// Sets the default value as the answer
|
||||
submitForm.setDefaultAnswer(field.getVariable());
|
||||
}
|
||||
}
|
||||
List owners = new ArrayList();
|
||||
owners.add(getBareJID(0));
|
||||
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
|
||||
|
||||
// Update the new room's configuration
|
||||
muc.sendConfigurationForm(submitForm);
|
||||
|
||||
// Destroy the new room
|
||||
muc.destroy("The room has almost no activity...", null);
|
||||
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests creating a new "Instant Room".
|
||||
*/
|
||||
public void testCreateInstantRoom() {
|
||||
MultiUserChat muc = new MultiUserChat(getConnection(0), room);
|
||||
|
||||
try {
|
||||
// Create the room
|
||||
muc.create("testbot");
|
||||
|
||||
// Send an empty room configuration form which indicates that we want
|
||||
// an instant room
|
||||
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
|
||||
|
||||
// Destroy the new room
|
||||
muc.destroy("The room has almost no activity...", null);
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
room = "fruta124@" + getMUCDomain();
|
||||
}
|
||||
}
|
||||
1810
CopyOftrunk/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java
Normal file
1810
CopyOftrunk/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,171 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.packet;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test the MessageEvent extension using the low level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MessageEventTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for MessageEventTest.
|
||||
* @param name
|
||||
*/
|
||||
public MessageEventTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives the
|
||||
* message
|
||||
* 1. User_1 will send a message to user_2 requesting to be notified when any of these events
|
||||
* occurs: offline, composing, displayed or delivered
|
||||
*/
|
||||
public void testSendMessageEventRequest() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Create a MessageEvent Package and add it to the message
|
||||
MessageEvent messageEvent = new MessageEvent();
|
||||
messageEvent.setComposing(true);
|
||||
messageEvent.setDelivered(true);
|
||||
messageEvent.setDisplayed(true);
|
||||
messageEvent.setOffline(true);
|
||||
msg.addExtension(messageEvent);
|
||||
|
||||
// Send the message that contains the notifications request
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
// Wait half second so that the complete test can run
|
||||
Thread.sleep(200);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* This is a simple test to use with a XMPP client, check if the client receives the
|
||||
* message and display in the console any notification
|
||||
* 1. User_1 will send a message to user_2 requesting to be notified when any of these events
|
||||
* occurs: offline, composing, displayed or delivered
|
||||
* 2. User_2 will use a XMPP client (like Exodus) to display the message and compose a reply
|
||||
* 3. User_1 will display any notification that receives
|
||||
*/
|
||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:event");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
try {
|
||||
MessageEvent messageEvent =
|
||||
(MessageEvent) message.getExtension("x", "jabber:x:event");
|
||||
assertNotNull("Message without extension \"jabber:x:event\"", messageEvent);
|
||||
assertTrue(
|
||||
"Message event is a request not a notification",
|
||||
!messageEvent.isMessageEventRequest());
|
||||
System.out.println(messageEvent.toXML());
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(0).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("An interesting body comes here...");
|
||||
// Create a MessageEvent Package and add it to the message
|
||||
MessageEvent messageEvent = new MessageEvent();
|
||||
messageEvent.setComposing(true);
|
||||
messageEvent.setDelivered(true);
|
||||
messageEvent.setDisplayed(true);
|
||||
messageEvent.setOffline(true);
|
||||
msg.addExtension(messageEvent);
|
||||
|
||||
// Send the message that contains the notifications request
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
// Wait half second so that the complete test can run
|
||||
Thread.sleep(200);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message");
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
/*
|
||||
* Created on 01/08/2003
|
||||
*
|
||||
*/
|
||||
package org.jivesoftware.smackx.packet;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test the Roster Exchange extension using the low level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class RosterExchangeTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for RosterExchangeTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public RosterExchangeTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives the message
|
||||
* 1. User_1 will send his/her roster entries to user_2
|
||||
*/
|
||||
public void testSendRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
assertTrue("Roster has no entries", getConnection(0).getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(getConnection(0).getRoster());
|
||||
msg.addExtension(rosterExchange);
|
||||
|
||||
// Send the message that contains the roster
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* 1. User_1 will send his/her roster entries to user_2
|
||||
* 2. User_2 will receive the entries and iterate over them to check if everything is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
||||
*/
|
||||
public void testSendAndReceiveRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:roster");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
RosterExchange rosterExchange =
|
||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||
assertTrue(
|
||||
"Roster without entries",
|
||||
rosterExchange.getRosterEntries().hasNext());
|
||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
assertTrue("Roster has no entries", getConnection(0).getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(getConnection(0).getRoster());
|
||||
msg.addExtension(rosterExchange);
|
||||
|
||||
// Send the message that contains the roster
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
// Wait for 2 seconds for a reply
|
||||
msg = chat1.nextMessage(2000);
|
||||
assertNotNull("No reply received", msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* 1. User_1 will send his/her roster entries to user_2
|
||||
* 2. User_2 will automatically add the entries that receives to his/her roster in the corresponding group
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
||||
*/
|
||||
public void testSendAndAcceptRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2, save the roster entries and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter = new PacketExtensionFilter("x", "jabber:x:roster");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
RosterExchange rosterExchange =
|
||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||
assertTrue(
|
||||
"Roster without entries",
|
||||
rosterExchange.getRosterEntries().hasNext());
|
||||
// Add the roster entries to user2's roster
|
||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||
getConnection(1).getRoster().createEntry(
|
||||
remoteRosterEntry.getUser(),
|
||||
remoteRosterEntry.getName(),
|
||||
remoteRosterEntry.getGroupArrayNames());
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
assertTrue("Roster has no entries", getConnection(0).getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(getConnection(0).getRoster());
|
||||
msg.addExtension(rosterExchange);
|
||||
|
||||
// Send the message that contains the roster
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
} catch (Exception e) {
|
||||
fail("An error occured sending the message with the roster");
|
||||
}
|
||||
// Wait for 10 seconds for a reply
|
||||
msg = chat1.nextMessage(5000);
|
||||
assertNotNull("No reply received", msg);
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
assertTrue("Roster2 has no entries", getConnection(1).getRoster().getEntryCount() > 0);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
try {
|
||||
getConnection(0).getRoster().createEntry(
|
||||
getBareJID(2),
|
||||
"gato5",
|
||||
new String[] { "Friends, Coworker" });
|
||||
getConnection(0).getRoster().createEntry(getBareJID(3), "gato6", null);
|
||||
Thread.sleep(300);
|
||||
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,259 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright (C) 2002-2003 Jive Software. All rights reserved.
|
||||
* ====================================================================
|
||||
* The Jive Software License (based on Apache Software License, Version 1.1)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by
|
||||
* Jive Software (http://www.jivesoftware.com)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Smack" and "Jive Software" must not be used to
|
||||
* endorse or promote products derived from this software without
|
||||
* prior written permission. For written permission, please
|
||||
* contact webmaster@jivesoftware.com.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Smack",
|
||||
* nor may "Smack" appear in their name, without prior written
|
||||
* permission of Jive Software.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx.packet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
* Test the XHTML extension using the low level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class XHTMLExtensionTest extends SmackTestCase {
|
||||
|
||||
private int bodiesSent;
|
||||
private int bodiesReceived;
|
||||
|
||||
/**
|
||||
* Constructor for XHTMLExtensionTest.
|
||||
* @param name
|
||||
*/
|
||||
public XHTMLExtensionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* This is a simple test to use with a XMPP client and check if the client receives the message
|
||||
* 1. User_1 will send a message with formatted text (XHTML) to user_2
|
||||
*/
|
||||
public void testSendSimpleXHTMLMessage() {
|
||||
// User1 creates a chat with user2
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
// Create a XHTMLExtension Package and add it to the message
|
||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||
xhtmlExtension.addBody(
|
||||
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
|
||||
msg.addExtension(xhtmlExtension);
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(200);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension
|
||||
//"http://jabber.org/protocol/xhtml-im"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter =
|
||||
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
XHTMLExtension xhtmlExtension =
|
||||
(XHTMLExtension) message.getExtension(
|
||||
"html",
|
||||
"http://jabber.org/protocol/xhtml-im");
|
||||
assertNotNull(
|
||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||
xhtmlExtension);
|
||||
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("Hey John, this is my new green!!!!");
|
||||
// Create a XHTMLExtension Package and add it to the message
|
||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||
xhtmlExtension.addBody(
|
||||
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
|
||||
msg.addExtension(xhtmlExtension);
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait for 2 seconds for a reply
|
||||
msg = chat1.nextMessage(1000);
|
||||
assertNotNull("No reply received", msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low level API test. Test a message with two XHTML bodies and several XHTML tags.
|
||||
* 1. User_1 will send a message with XHTML to user_2
|
||||
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
|
||||
* is fine
|
||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
|
||||
* something is wrong
|
||||
*/
|
||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension
|
||||
//"http://jabber.org/protocol/xhtml-im"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
PacketFilter packetFilter =
|
||||
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
int received = 0;
|
||||
Message message = (Message) packet;
|
||||
assertNotNull("Body is null", message.getBody());
|
||||
try {
|
||||
XHTMLExtension xhtmlExtension =
|
||||
(XHTMLExtension) message.getExtension(
|
||||
"html",
|
||||
"http://jabber.org/protocol/xhtml-im");
|
||||
assertNotNull(
|
||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||
xhtmlExtension);
|
||||
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||
received++;
|
||||
System.out.println((String) it.next());
|
||||
}
|
||||
bodiesReceived = received;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
};
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody(
|
||||
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||
// Create an XHTMLExtension and add it to the message
|
||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||
xhtmlExtension.addBody(
|
||||
"<body xml:lang=\"es-ES\"><h1>impresionante!</h1><p>Como Emerson dijo una vez:</p><blockquote><p>Una consistencia ridícula es el espantajo de mentes pequeñas.</p></blockquote></body>");
|
||||
xhtmlExtension.addBody(
|
||||
"<body xml:lang=\"en-US\"><h1>awesome!</h1><p>As Emerson once said:</p><blockquote><p>A foolish consistency is the hobgoblin of little minds.</p></blockquote></body>");
|
||||
msg.addExtension(xhtmlExtension);
|
||||
|
||||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
bodiesSent = xhtmlExtension.getBodiesCount();
|
||||
bodiesReceived = 0;
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(300);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait half second so that the complete test can run
|
||||
assertEquals(
|
||||
"Number of sent and received XHTMP bodies does not match",
|
||||
bodiesSent,
|
||||
bodiesReceived);
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue