1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-10 07:01:07 +01:00

Deleting.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2656 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2005-08-15 23:22:14 +00:00 committed by matt
parent 37231ec646
commit d4550a6356
276 changed files with 0 additions and 40430 deletions

View file

@ -1,131 +0,0 @@
/**
* $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;
}
}

View file

@ -1,102 +0,0 @@
/**
* $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;
}
}

View file

@ -1,78 +0,0 @@
/**
* $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;
}
}

View file

@ -1,104 +0,0 @@
/**
* $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;
}
}

View file

@ -1,139 +0,0 @@
/**
* $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();
}
}

View file

@ -1,101 +0,0 @@
/**
* $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);*/
}
}
}

View file

@ -1,102 +0,0 @@
/**
* $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;
}
}

View file

@ -1,137 +0,0 @@
/**
* $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();
}
}

View file

@ -1,527 +0,0 @@
/**
* $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();
}
}

View file

@ -1,99 +0,0 @@
/**
* $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));
}
}

View file

@ -1,104 +0,0 @@
/**
* $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;
}
}
}

View file

@ -1,86 +0,0 @@
/**
* $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));
}
}

View file

@ -1,133 +0,0 @@
/**
* $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));
}
}

View file

@ -1,98 +0,0 @@
/**
* $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;
}
}
}

View file

@ -1,147 +0,0 @@
/**
* $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));
}
}

View file

@ -1,104 +0,0 @@
/**
* $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;
}
}
}

View file

@ -1,69 +0,0 @@
/**
* $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;
}
}

View file

@ -1,73 +0,0 @@
/**
* $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;
}
}

View file

@ -1,370 +0,0 @@
/**
* $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";
}
}

View file

@ -1,236 +0,0 @@
/**
* $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("&lt;b&gt;", StringUtils.escapeForXML(input));
input = "\"";
assertEquals("&quot;", StringUtils.escapeForXML(input));
input = "&";
assertEquals("&amp;", StringUtils.escapeForXML(input));
input = "<b>\n\t\r</b>";
assertEquals("&lt;b&gt;\n\t\r&lt;/b&gt;", StringUtils.escapeForXML(input));
input = " & ";
assertEquals(" &amp; ", StringUtils.escapeForXML(input));
input = " \" ";
assertEquals(" &quot; ", StringUtils.escapeForXML(input));
input = "> of me <";
assertEquals("&gt; of me &lt;", StringUtils.escapeForXML(input));
input = "> of me & you<";
assertEquals("&gt; of me &amp; you&lt;", StringUtils.escapeForXML(input));
input = "& <";
assertEquals("&amp; &lt;", StringUtils.escapeForXML(input));
input = "&";
assertEquals("&amp;", 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"));
}
}