Commit e5abdee4 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Added a test for setting vCards, both read only and not read only. Note that...

Added a test for setting vCards, both read only and not read only. Note that this checkin contains a change to UserManager which will allow it to be mocked. JM-1026

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8477 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9af72ffb
No preview for this file type
......@@ -4,30 +4,37 @@ ant.jar | Jetty 6.1.0 (1.6.5)
ant-contrib.jar | 1.0b1
ant-subdirtask.jar | Revision 1.4 (CVS)
bouncycastle.jar | JDK 1.5, 135 (bcprov-jdk15-135.jar)
cglib.jar | 2.1.3 (JMock 2.1.0)
commons-logging.jar | Jetty 5.1.10
commons-el.jar | Jetty 6.0.1 (1.0)
commons-httpclient.jar | 3.0
commons-codec.jar | 1.3
dom4j.jar | 1.6.1
dbutil.jar | Jive Code, no release version.
hamcrest.jar | 1.0 (JMock 2.1.0)
hamcrest-api.jar | 1.0 (JMock 2.1.0)
hsqldb.jar | 1.8.0.5
jetty.jar | Jetty 6.1.0
jetty-util.jar | Jetty 6.1.0
jasper-compiler.jar | Jetty 6.1.0 (5.5.15)
jasper-runtime.jar | Jetty 6.1.0 (5.5.15)
jaxen.jar | 1.1 beta 4 (from DOM4J 1.6.1)
junit.jar | 3.8.1
jdic.jar | 0.9.1 (for windows only)
jstl.jar | Jakarta standard taglib 1.1.2
jmdns.jar | PRE 1.0, patched
jmock.jar | 2.1.0
jmock-junit4.jar | 2.1.0
jmock-legacy.jar | 2.1.0
jsp-api.jar | Jetty 6.0.1 (2.0)
jtds.jar | 1.2
junit.jar | 4.3.1
jzlib.jar | 1.0.7
mail.jar | 1.4.0 (JavaMail)
mina-core-1.2.0.jar | https://svn.apache.org/repos/asf/mina/branches/1.1
mina-filter-compression-1.2.0.jar | https://svn.apache.org/repos/asf/mina/branches/1.1
mina-filter-ssl-1.2.0.jar | https://svn.apache.org/repos/asf/mina/branches/1.1
mysql.jar | 3.1.13
objenesis | 1.0 (JMock 2.1.0)
pack200task.jar | August 5, 2004
postgres.jar | 8.1-404 JDBC 3
servlet.jar | Jetty 6.1.0 (2.5)
......
......@@ -34,18 +34,39 @@ import java.util.*;
*/
public class UserManager implements IQResultListener {
// Wrap this guy up so we can mock out the UserManager class.
private static class UserManagerContainer {
private static UserManager instance = new UserManager();
}
/**
* Cache of local users.
* Returns the currently-installed UserProvider. <b>Warning:</b> in virtually all
* cases the user provider should not be used directly. Instead, the appropriate
* methods in UserManager should be called. Direct access to the user provider is
* only provided for special-case logic.
*
* @return the current UserProvider.
*/
private static Cache<String, User> userCache;
public static UserProvider getUserProvider() {
return UserManagerContainer.instance.provider;
}
/**
* Cache if a local or remote user exists.
* Returns a singleton UserManager instance.
*
* @return a UserManager instance.
*/
private static Cache<String, Boolean> remoteUsersCache;
private static UserProvider provider;
private static UserManager instance = new UserManager();
public static UserManager getInstance() {
return UserManagerContainer.instance;
}
/** Cache of local users. */
private Cache<String, User> userCache;
/** Cache if a local or remote user exists. */
private Cache<String, Boolean> remoteUsersCache;
private UserProvider provider;
static {
private UserManager() {
// Initialize caches.
userCache = CacheFactory.createCache("User");
remoteUsersCache = CacheFactory.createCache("Remote Users Existence");
......@@ -93,30 +114,6 @@ public class UserManager implements IQResultListener {
UserEventDispatcher.addListener(userListener);
}
/**
* Returns the currently-installed UserProvider. <b>Warning:</b> in virtually all
* cases the user provider should not be used directly. Instead, the appropriate
* methods in UserManager should be called. Direct access to the user provider is
* only provided for special-case logic.
*
* @return the current UserProvider.
*/
public static UserProvider getUserProvider() {
return provider;
}
/**
* Returns a singleton UserManager instance.
*
* @return a UserManager instance.
*/
public static UserManager getInstance() {
return instance;
}
private UserManager() {
}
/**
* Creates a new User. Required values are username and password. The email address
* can optionally be <tt>null</tt>.
......@@ -394,7 +391,7 @@ public class UserManager implements IQResultListener {
}
}
private static void initProvider() {
private void initProvider() {
String className = JiveGlobals.getXMLProperty("provider.user.className",
"org.jivesoftware.openfire.user.DefaultUserProvider");
// Check if we need to reset the provider class
......
/**
* $Revision:$
* $Date:$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.handler;
import org.jmock.Mockery;
import org.jmock.Expectations;
import org.jmock.lib.legacy.ClassImposteriser;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.integration.junit4.JMock;
import org.junit.runner.RunWith;
import org.junit.BeforeClass;
import org.junit.Test;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.openfire.vcard.VCardManager;
import org.xmpp.packet.IQ;
import static org.junit.Assert.*;
import org.dom4j.Element;
/**
* Test for the IQvCardHandler.
*/
@RunWith(JMock.class)
public class IQvCardHandlerTest {
private static Mockery context = new JUnit4Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
private static XMPPServer xmppServer;
private static UserManager userManager;
private static PacketDeliverer packetDeliverer;
private static SessionManager sessionManager;
@BeforeClass
public static void doBeforeClass() {
xmppServer = context.mock(XMPPServer.class);
userManager = context.mock(UserManager.class);
packetDeliverer = context.mock(PacketDeliverer.class);
sessionManager = context.mock(SessionManager.class);
context.checking(new Expectations() {{
allowing(xmppServer).getUserManager();
will(returnValue(userManager));
allowing(xmppServer).getPacketDeliverer();
will(returnValue(packetDeliverer));
allowing(xmppServer).getSessionManager();
will(returnValue(sessionManager));
}});
}
@Test
public void testVCardHandlerSetReadOnly() throws UnauthorizedException {
IQ vCardSet = new IQ(IQ.Type.set);
vCardSet.setChildElement("vCard", "vcard-temp");
final VCardManager vCardManager = context.mock(VCardManager.class);
IQvCardHandler vCardHandler = new IQvCardHandler();
context.checking(new Expectations() {{
one(xmppServer).getVCardManager();
will(returnValue(vCardManager));
one(vCardManager).isReadOnly();
will(returnValue(true));
}});
vCardHandler.initialize(xmppServer);
IQ result = vCardHandler.handleIQ(vCardSet);
assertEquals(result.getType(), IQ.Type.error);
}
@Test
public void testVCardHandlerSet() throws UnauthorizedException {
IQ vCardSet = new IQ(IQ.Type.set);
vCardSet.setFrom("test@test.com");
vCardSet.setChildElement("vCard", "vcard-temp");
final Element vCardElement = vCardSet.getChildElement();
final VCardManager vCardManager = context.mock(VCardManager.class);
final User user = context.mock(User.class);
final IQvCardHandler vCardHandler = new IQvCardHandler();
context.checking(new Expectations() {{
one(xmppServer).getVCardManager();
will(returnValue(vCardManager));
one(vCardManager).isReadOnly();
will(returnValue(false));
try {
one(userManager).getUser(with(a(String.class)));
}
catch (UserNotFoundException e) {
fail("User not found");
}
will(returnValue(user));
one(user).getUsername();
will(returnValue("test"));
try {
one(vCardManager).setVCard("test", vCardElement);
}
catch (Exception e) {
fail("Vcard exception");
}
}});
vCardHandler.initialize(xmppServer);
IQ result = vCardHandler.handleIQ(vCardSet);
assertEquals(result.getType(), IQ.Type.result);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment