You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2011/08/15 13:26:57 UTC

svn commit: r1157780 [7/13] - in /qpid/branches/rg-amqp-1-0-sandbox/qpid/java: ./ broker-plugins/access-control/ broker-plugins/access-control/src/main/java/org/apache/qpid/server/security/access/config/ broker-plugins/access-control/src/main/java/org/...

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/management/AMQUserManagementMBeanTest.java Mon Aug 15 11:26:46 2011
@@ -21,22 +21,26 @@
 
 package org.apache.qpid.server.management;
 
-import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 
-import org.apache.commons.configuration.ConfigurationException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.qpid.management.common.mbeans.UserManagement;
 import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
 import org.apache.qpid.server.security.auth.management.AMQUserManagementMBean;
 
 import org.apache.qpid.server.util.InternalBrokerBaseCase;
 
-/* Note: The main purpose is to test the jmx access rights file manipulation 
- * within AMQUserManagementMBean. The Principal Databases are tested by their own tests, 
- * this test just exercises their usage in AMQUserManagementMBean. 
+/** 
+ * 
+ * Tests the AMQUserManagementMBean and its interaction with the PrincipalDatabase.
+ *
  */
 public class AMQUserManagementMBeanTest extends InternalBrokerBaseCase
 {
@@ -44,7 +48,6 @@ public class AMQUserManagementMBeanTest 
     private AMQUserManagementMBean _amqumMBean;
     
     private File _passwordFile;
-    private File _accessFile;
 
     private static final String TEST_USERNAME = "testuser";
     private static final String TEST_PASSWORD = "password";
@@ -57,7 +60,6 @@ public class AMQUserManagementMBeanTest 
         _database = new PlainPasswordFilePrincipalDatabase();
         _amqumMBean = new AMQUserManagementMBean();
         loadFreshTestPasswordFile();
-        loadFreshTestAccessFile();
     }
 
     @Override
@@ -65,142 +67,67 @@ public class AMQUserManagementMBeanTest 
     {
         //clean up test password/access files
         File _oldPasswordFile = new File(_passwordFile.getAbsolutePath() + ".old");
-        File _oldAccessFile = new File(_accessFile.getAbsolutePath() + ".old");
         _oldPasswordFile.delete();
-        _oldAccessFile.delete();
         _passwordFile.delete();
-        _accessFile.delete();
 
         super.tearDown();
     }
 
     public void testDeleteUser()
     {
-        loadFreshTestPasswordFile();
-        loadFreshTestAccessFile();
+        assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
+        assertTrue("Delete should return true to flag successful delete", _amqumMBean.deleteUser(TEST_USERNAME));
+        assertEquals("Unexpected number of users after test", 0,_amqumMBean.viewUsers().size());
+    }
+
+    public void testDeleteUserWhereUserDoesNotExist()
+    {
+        assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
+        assertFalse("Delete should return false to flag unsuccessful delete", _amqumMBean.deleteUser("made.up.username"));
+        assertEquals("Unexpected number of users after test", 1,_amqumMBean.viewUsers().size());
 
-        //try deleting a non existant user
-        assertFalse(_amqumMBean.deleteUser("made.up.username"));
-        
-        assertTrue(_amqumMBean.deleteUser(TEST_USERNAME));
     }
     
-    public void testDeleteUserIsSavedToAccessFile()
+    public void testCreateUser()
     {
-        loadFreshTestPasswordFile();
-        loadFreshTestAccessFile();
-
-        assertTrue(_amqumMBean.deleteUser(TEST_USERNAME));
-
-        //check the access rights were actually deleted from the file
-        try{
-            BufferedReader reader = new BufferedReader(new FileReader(_accessFile));
-
-            //check the 'generated by' comment line is present
-            assertTrue("File has no content", reader.ready());
-            assertTrue("'Generated by' comment line was missing",reader.readLine().contains("Generated by " +
-                                                      "AMQUserManagementMBean Console : Last edited by user:"));
-
-            //there should also be a modified date/time comment line
-            assertTrue("File has no modified date/time comment line", reader.ready());
-            assertTrue("Modification date/time comment line was missing",reader.readLine().startsWith("#"));
-            
-            //the access file should not contain any further data now as we just deleted the only user
-            assertFalse("User access data was present when it should have been deleted", reader.ready());
-        }
-        catch (IOException e)
-        {
-            fail("Unable to valdate file contents due to:" + e.getMessage());
-        }
-        
+        assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
+        assertTrue("Create should return true to flag successful create", _amqumMBean.createUser("newuser", "mypass"));
+        assertEquals("Unexpected number of users before test", 2,_amqumMBean.viewUsers().size());
     }
 
-    public void testSetRights()
+    public void testCreateUserWhereUserAlreadyExists()
     {
-        loadFreshTestPasswordFile();
-        loadFreshTestAccessFile();
-        
-        assertFalse(_amqumMBean.setRights("made.up.username", true, false, false));
-        
-        assertTrue(_amqumMBean.setRights(TEST_USERNAME, true, false, false));
-        assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, true, false));
-        assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, false, true));
+        assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
+        assertFalse("Create should return false to flag unsuccessful create", _amqumMBean.createUser(TEST_USERNAME, "mypass"));
+        assertEquals("Unexpected number of users before test", 1,_amqumMBean.viewUsers().size());
     }
-    
-    public void testSetRightsIsSavedToAccessFile()
+
+    public void testSetPassword()
     {
-        loadFreshTestPasswordFile();
-        loadFreshTestAccessFile();
-        
-        assertTrue(_amqumMBean.setRights(TEST_USERNAME, false, false, true));
-        
-        //check the access rights were actually updated in the file
-        try{
-            BufferedReader reader = new BufferedReader(new FileReader(_accessFile));
-
-            //check the 'generated by' comment line is present
-            assertTrue("File has no content", reader.ready());
-            assertTrue("'Generated by' comment line was missing",reader.readLine().contains("Generated by " +
-                                                      "AMQUserManagementMBean Console : Last edited by user:"));
-
-            //there should also be a modified date/time comment line
-            assertTrue("File has no modified date/time comment line", reader.ready());
-            assertTrue("Modification date/time comment line was missing",reader.readLine().startsWith("#"));
-            
-            //the access file should not contain any further data now as we just deleted the only user
-            assertTrue("User access data was not updated in the access file", 
-                    reader.readLine().equals(TEST_USERNAME + "=" + MBeanInvocationHandlerImpl.ADMIN));
-            
-            //the access file should not contain any further data now as we just deleted the only user
-            assertFalse("Additional user access data was present when there should be no more", reader.ready());
-        }
-        catch (IOException e)
-        {
-            fail("Unable to valdate file contents due to:" + e.getMessage());
-        }
+        assertTrue("Set password should return true to flag successful change", _amqumMBean.setPassword(TEST_USERNAME, "newpassword"));
     }
-
-    public void testSetAccessFileWithMissingFile()
+    
+    public void testSetPasswordWhereUserDoesNotExist()
     {
-        try
-        {
-            _amqumMBean.setAccessFile("made.up.filename");
-        }
-        catch (IOException e)
-        {
-            fail("Should not have been an IOE." + e.getMessage());
-        }
-        catch (ConfigurationException e)
-        {
-            assertTrue(e.getMessage(), e.getMessage().endsWith("does not exist"));
-        }
+        assertFalse("Set password should return false to flag successful change", _amqumMBean.setPassword("made.up.username", "newpassword"));
     }
 
-    public void testSetAccessFileWithReadOnlyFile()
+    public void testViewUsers()
     {
-        File testFile = null;
-        try
-        {
-            testFile = File.createTempFile(this.getClass().getName(),".access.readonly");
-            BufferedWriter passwordWriter = new BufferedWriter(new FileWriter(testFile, false));
-            passwordWriter.write(TEST_USERNAME + ":" + TEST_PASSWORD);
-            passwordWriter.newLine();
-            passwordWriter.flush();
-            passwordWriter.close();
-
-            testFile.setReadOnly();
-            _amqumMBean.setAccessFile(testFile.getPath());
-        }
-        catch (IOException e)
-        {
-            fail("Access file was not created." + e.getMessage());
-        }
-        catch (ConfigurationException e)
-        {
-            fail("There should not have been a configuration exception." + e.getMessage());
-        }
+        TabularData userList = _amqumMBean.viewUsers();
 
-        testFile.delete();
+        assertNotNull(userList);
+        assertEquals("Unexpected number of users in user list", 1, userList.size());
+        assertTrue(userList.containsKey(new Object[]{TEST_USERNAME}));
+        
+        // Check the deprecated read, write and admin items continue to exist but return false.
+        CompositeData userRec = userList.get(new Object[]{TEST_USERNAME});
+        assertTrue(userRec.containsKey(UserManagement.RIGHTS_READ_ONLY));
+        assertEquals(false, userRec.get(UserManagement.RIGHTS_READ_ONLY));
+        assertEquals(false, userRec.get(UserManagement.RIGHTS_READ_WRITE));
+        assertTrue(userRec.containsKey(UserManagement.RIGHTS_READ_WRITE));
+        assertTrue(userRec.containsKey(UserManagement.RIGHTS_ADMIN));
+        assertEquals(false, userRec.get(UserManagement.RIGHTS_ADMIN));
     }
 
     // ============================ Utility methods =========================
@@ -227,37 +154,4 @@ public class AMQUserManagementMBeanTest 
             fail("Unable to create test password file: " + e.getMessage());
         }
     }
-
-    private void loadFreshTestAccessFile()
-    {
-        try
-        {
-            if(_accessFile == null)
-            {
-                _accessFile = File.createTempFile(this.getClass().getName(),".access");
-            }
-            
-            BufferedWriter accessWriter = new BufferedWriter(new FileWriter(_accessFile,false));
-            accessWriter.write("#Last Updated By comment");
-            accessWriter.newLine();
-            accessWriter.write("#Date/time comment");
-            accessWriter.newLine();
-            accessWriter.write(TEST_USERNAME + "=" + MBeanInvocationHandlerImpl.READONLY);
-            accessWriter.newLine();
-            accessWriter.flush();
-            accessWriter.close();
-        }
-        catch (IOException e)
-        {
-            fail("Unable to create test access file: " + e.getMessage());
-        }
-
-        try{
-            _amqumMBean.setAccessFile(_accessFile.toString());
-        }
-        catch (Exception e)
-        {
-            fail("Unable to set access file: " + e.getMessage());
-        }
-    }
 }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/protocol/InternalTestProtocolSession.java Mon Aug 15 11:26:46 2011
@@ -20,9 +20,16 @@
  */
 package org.apache.qpid.server.protocol;
 
-import java.security.Principal;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+import javax.security.auth.Subject;
 
 import org.apache.qpid.AMQException;
 import org.apache.qpid.framing.AMQShortString;
@@ -30,35 +37,31 @@ import org.apache.qpid.framing.ContentHe
 import org.apache.qpid.framing.abstraction.MessagePublishInfo;
 import org.apache.qpid.protocol.AMQConstant;
 import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.output.ProtocolOutputConverter;
 import org.apache.qpid.server.message.AMQMessage;
+import org.apache.qpid.server.message.MessageContentSource;
+import org.apache.qpid.server.output.ProtocolOutputConverter;
 import org.apache.qpid.server.queue.QueueEntry;
 import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.state.AMQState;
+import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
 import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.message.MessageContentSource;
-import org.apache.qpid.transport.TestNetworkDriver;
+import org.apache.qpid.transport.TestNetworkConnection;
 
 public class InternalTestProtocolSession extends AMQProtocolEngine implements ProtocolOutputConverter
 {
     // ChannelID(LIST)  -> LinkedList<Pair>
     final Map<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>> _channelDelivers;
     private AtomicInteger _deliveryCount = new AtomicInteger(0);
+    private static final AtomicLong ID_GENERATOR = new AtomicLong(0);
 
     public InternalTestProtocolSession(VirtualHost virtualHost) throws AMQException
     {
-        super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkDriver());
+        super(ApplicationRegistry.getInstance().getVirtualHostRegistry(), new TestNetworkConnection(), ID_GENERATOR.getAndIncrement());
 
         _channelDelivers = new HashMap<Integer, Map<AMQShortString, LinkedList<DeliveryPair>>>();
 
         // Need to authenticate session for it to be representative testing.
-        setAuthorizedID(new Principal()
-        {
-            public String getName()
-            {
-                return "InternalTestProtocolSession";
-            }
-        });
+        setAuthorizedSubject(new Subject(true, Collections.singleton(new UsernamePrincipal("InternalTestProtocolSession")),
+                Collections.EMPTY_SET, Collections.EMPTY_SET));
 
         setVirtualHost(virtualHost);
     }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java Mon Aug 15 11:26:46 2011
@@ -29,7 +29,7 @@ import org.apache.qpid.server.subscripti
 import org.apache.qpid.server.virtualhost.VirtualHost;
 import org.apache.qpid.server.management.ManagedObject;
 import org.apache.qpid.server.message.ServerMessage;
-import org.apache.qpid.server.security.PrincipalHolder;
+import org.apache.qpid.server.security.AuthorizationHolder;
 import org.apache.qpid.server.AMQChannel;
 import org.apache.qpid.server.protocol.AMQSessionModel;
 import org.apache.qpid.server.binding.Binding;
@@ -48,7 +48,7 @@ public class MockAMQQueue implements AMQ
     private AMQShortString _name;
     private VirtualHost _virtualhost;
 
-    private PrincipalHolder _principalHolder;
+    private AuthorizationHolder _authorizationHolder;
 
     private AMQSessionModel _exclusiveOwner;
     private AMQShortString _owner;
@@ -536,14 +536,14 @@ public class MockAMQQueue implements AMQ
         return null;  //To change body of implemented methods use File | Settings | File Templates.
     }
 
-    public PrincipalHolder getPrincipalHolder()
+    public AuthorizationHolder getAuthorizationHolder()
     {
-        return _principalHolder;
+        return _authorizationHolder;
     }
 
-    public void setPrincipalHolder(PrincipalHolder principalHolder)
+    public void setAuthorizationHolder(final AuthorizationHolder authorizationHolder)
     {
-        _principalHolder = principalHolder;
+        _authorizationHolder = authorizationHolder;
     }
 
     public AMQSessionModel getExclusiveOwningSession()

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/MockQueueEntry.java Mon Aug 15 11:26:46 2011
@@ -139,7 +139,7 @@ public class MockQueueEntry implements Q
     }
 
 
-    public boolean isRejectedBy(Subscription subscription)
+    public boolean isRejectedBy(long subscriptionId)
     {
 
         return false;
@@ -153,13 +153,6 @@ public class MockQueueEntry implements Q
     }
 
 
-    public void reject(Subscription subscription)
-    {
-
-
-    }
-
-
     public void release()
     {
 
@@ -231,4 +224,14 @@ public class MockQueueEntry implements Q
         _message = msg;
     }
 
+    public boolean isDequeued()
+    {
+        return false;
+    }
+
+    public boolean isDispensed()
+    {
+        return false;
+    }
+
 }

Copied: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java (from r1140000, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java)
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java?p2=qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java&r1=1140000&r2=1157780&rev=1157780&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/QueueEntryImplTest.java Mon Aug 15 11:26:46 2011
@@ -26,6 +26,7 @@ import org.apache.qpid.AMQException;
 import org.apache.qpid.server.message.AMQMessage;
 import org.apache.qpid.server.queue.QueueEntry.EntryState;
 import org.apache.qpid.server.subscription.MockSubscription;
+import org.apache.qpid.server.subscription.Subscription;
 
 /**
  * Tests for {@link QueueEntryImpl}
@@ -210,4 +211,37 @@ public class QueueEntryImplTest extends 
         }
         return state;
     }
+
+    /**
+     * Tests rejecting a queue entry records the Subscription ID
+     * for later verification by isRejectedBy(subscriptionId).
+     */
+    public void testRejectAndRejectedBy()
+    {
+        Subscription sub = new MockSubscription();
+        long subId = sub.getSubscriptionID();
+
+        assertFalse("Queue entry should not yet have been rejected by the subscription", _queueEntry.isRejectedBy(subId));
+        assertFalse("Queue entry should not yet have been acquired by a subscription", _queueEntry.isAcquired());
+
+        //acquire, reject, and release the message using the subscription
+        assertTrue("Queue entry should have been able to be acquired", _queueEntry.acquire(sub));
+        _queueEntry.reject();
+        _queueEntry.release();
+
+        //verify the rejection is recorded
+        assertTrue("Queue entry should have been rejected by the subscription", _queueEntry.isRejectedBy(subId));
+
+        //repeat rejection using a second subscription
+        Subscription sub2 = new MockSubscription();
+        long sub2Id = sub2.getSubscriptionID();
+
+        assertFalse("Queue entry should not yet have been rejected by the subscription", _queueEntry.isRejectedBy(sub2Id));
+        assertTrue("Queue entry should have been able to be acquired", _queueEntry.acquire(sub2));
+        _queueEntry.reject();
+
+        //verify it still records being rejected by both subscriptions
+        assertTrue("Queue entry should have been rejected by the subscription", _queueEntry.isRejectedBy(subId));
+        assertTrue("Queue entry should have been rejected by the subscription", _queueEntry.isRejectedBy(sub2Id));
+    }
 }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java Mon Aug 15 11:26:46 2011
@@ -36,13 +36,16 @@ import org.apache.qpid.server.configurat
 import org.apache.qpid.server.exchange.DirectExchange;
 import org.apache.qpid.server.message.AMQMessage;
 import org.apache.qpid.server.message.MessageMetaData;
+import org.apache.qpid.server.message.ServerMessage;
 import org.apache.qpid.server.queue.BaseQueue.PostEnqueueAction;
+import org.apache.qpid.server.queue.SimpleAMQQueue.QueueEntryFilter;
 import org.apache.qpid.server.registry.ApplicationRegistry;
 import org.apache.qpid.server.store.StoredMessage;
 import org.apache.qpid.server.store.TestableMemoryMessageStore;
 import org.apache.qpid.server.subscription.MockSubscription;
 import org.apache.qpid.server.subscription.Subscription;
 import org.apache.qpid.server.txn.AutoCommitTransaction;
+import org.apache.qpid.server.txn.LocalTransaction;
 import org.apache.qpid.server.txn.ServerTransaction;
 import org.apache.qpid.server.util.InternalBrokerBaseCase;
 import org.apache.qpid.server.virtualhost.VirtualHost;
@@ -51,6 +54,8 @@ import org.apache.qpid.server.virtualhos
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 public class SimpleAMQQueueTest extends InternalBrokerBaseCase
 {
@@ -102,7 +107,7 @@ public class SimpleAMQQueueTest extends 
         ApplicationRegistry applicationRegistry = (ApplicationRegistry)ApplicationRegistry.getInstance();
 
         PropertiesConfiguration env = new PropertiesConfiguration();
-        _virtualHost = new VirtualHostImpl(new VirtualHostConfiguration(getClass().getName(), env), _store);
+        _virtualHost = new VirtualHostImpl(ApplicationRegistry.getInstance(), new VirtualHostConfiguration(getClass().getName(), env), _store);
         applicationRegistry.getVirtualHostRegistry().registerVirtualHost(_virtualHost);
 
         _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(_qname, false, _owner, false, false, _virtualHost, _arguments);
@@ -735,6 +740,530 @@ public class SimpleAMQQueueTest extends 
         verifyRecievedMessages(msgListSub3, sub3.getMessages());
     }
 
+    /**
+     * Tests that dequeued message is not present in the list returned form
+     * {@link SimpleAMQQueue#getMessagesOnTheQueue()}
+     */
+    public void testGetMessagesOnTheQueueWithDequeuedEntry()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+
+        // send test messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        // get messages on the queue
+        List<QueueEntry> entries = _queue.getMessagesOnTheQueue();
+
+        // assert queue entries
+        assertEquals(messageNumber - 1, entries.size());
+        int expectedId = 0;
+        for (int i = 0; i < messageNumber - 1; i++)
+        {
+            Long id = ((AMQMessage) entries.get(i).getMessage()).getMessageId();
+            if (i == dequeueMessageIndex)
+            {
+                assertFalse("Message with id " + dequeueMessageIndex
+                        + " was dequeued and should not be returned by method getMessagesOnTheQueue!",
+                        new Long(expectedId).equals(id));
+                expectedId++;
+            }
+            assertEquals("Expected message with id " + expectedId + " but got message with id " + id,
+                    new Long(expectedId), id);
+            expectedId++;
+        }
+    }
+
+    /**
+     * Tests that dequeued message is not present in the list returned form
+     * {@link SimpleAMQQueue#getMessagesOnTheQueue(QueueEntryFilter)}
+     */
+    public void testGetMessagesOnTheQueueByQueueEntryFilterWithDequeuedEntry()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+
+        // send test messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        // get messages on the queue with filter accepting all available messages
+        List<QueueEntry> entries = _queue.getMessagesOnTheQueue(new QueueEntryFilter()
+        {
+            public boolean accept(QueueEntry entry)
+            {
+                return true;
+            }
+
+            public boolean filterComplete()
+            {
+                return false;
+            }
+        });
+
+        // assert entries on the queue
+        assertEquals(messageNumber - 1, entries.size());
+        int expectedId = 0;
+        for (int i = 0; i < messageNumber - 1; i++)
+        {
+            Long id = ((AMQMessage) entries.get(i).getMessage()).getMessageId();
+            if (i == dequeueMessageIndex)
+            {
+                assertFalse("Message with id " + dequeueMessageIndex
+                        + " was dequeued and should not be returned by method getMessagesOnTheQueue!",
+                        new Long(expectedId).equals(id));
+                expectedId++;
+            }
+            assertEquals("Expected message with id " + expectedId + " but got message with id " + id,
+                    new Long(expectedId), id);
+            expectedId++;
+        }
+    }
+
+    /**
+     * Tests that dequeued message is not copied as part of invocation of
+     * {@link SimpleAMQQueue#copyMessagesToAnotherQueue(long, long, String, StoreContext)}
+     */
+    public void testCopyMessagesWithDequeuedEntry()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+        String anotherQueueName = "testQueue2";
+
+        // put test messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        // create another queue
+        SimpleAMQQueue queue = createQueue(anotherQueueName);
+
+        // create transaction
+        ServerTransaction txn = new LocalTransaction(_queue.getVirtualHost().getTransactionLog());
+
+        // copy messages into another queue
+        _queue.copyMessagesToAnotherQueue(0, messageNumber, anotherQueueName, txn);
+
+        // commit transaction
+        txn.commit();
+
+        // get messages on another queue
+        List<QueueEntry> entries = queue.getMessagesOnTheQueue();
+
+        // assert another queue entries
+        assertEquals(messageNumber - 1, entries.size());
+        int expectedId = 0;
+        for (int i = 0; i < messageNumber - 1; i++)
+        {
+            Long id = ((AMQMessage)entries.get(i).getMessage()).getMessageId();
+            if (i == dequeueMessageIndex)
+            {
+                assertFalse("Message with id " + dequeueMessageIndex
+                        + " was dequeued and should not been copied into another queue!",
+                        new Long(expectedId).equals(id));
+                expectedId++;
+            }
+            assertEquals("Expected message with id " + expectedId + " but got message with id " + id,
+                    new Long(expectedId), id);
+            expectedId++;
+        }
+    }
+
+    /**
+     * Tests that dequeued message is not moved as part of invocation of
+     * {@link SimpleAMQQueue#moveMessagesToAnotherQueue(long, long, String, StoreContext)}
+     */
+    public void testMovedMessagesWithDequeuedEntry()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+        String anotherQueueName = "testQueue2";
+
+        // put messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        // create another queue
+        SimpleAMQQueue queue = createQueue(anotherQueueName);
+
+        // create transaction
+        ServerTransaction txn = new LocalTransaction(_queue.getVirtualHost().getTransactionLog());
+
+        // move messages into another queue
+        _queue.moveMessagesToAnotherQueue(0, messageNumber, anotherQueueName, txn);
+
+        // commit transaction
+        txn.commit();
+
+        // get messages on another queue
+        List<QueueEntry> entries = queue.getMessagesOnTheQueue();
+
+        // assert another queue entries
+        assertEquals(messageNumber - 1, entries.size());
+        int expectedId = 0;
+        for (int i = 0; i < messageNumber - 1; i++)
+        {
+            Long id = ((AMQMessage)entries.get(i).getMessage()).getMessageId();
+            if (i == dequeueMessageIndex)
+            {
+                assertFalse("Message with id " + dequeueMessageIndex
+                        + " was dequeued and should not been copied into another queue!",
+                        new Long(expectedId).equals(id));
+                expectedId++;
+            }
+            assertEquals("Expected message with id " + expectedId + " but got message with id " + id,
+                    new Long(expectedId), id);
+            expectedId++;
+        }
+    }
+
+    /**
+     * Tests that messages in given range including dequeued one are deleted
+     * from the queue on invocation of
+     * {@link SimpleAMQQueue#removeMessagesFromQueue(long, long, StoreContext)}
+     */
+    public void testRemoveMessagesFromQueueWithDequeuedEntry()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+
+        // put messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        // remove messages
+        _queue.removeMessagesFromQueue(0, messageNumber);
+
+        // get queue entries
+        List<QueueEntry> entries = _queue.getMessagesOnTheQueue();
+
+        // assert queue entries
+        assertNotNull("Null is returned from getMessagesOnTheQueue", entries);
+        assertEquals("Queue should be empty", 0, entries.size());
+    }
+
+    /**
+     * Tests that dequeued message on the top is not accounted and next message
+     * is deleted from the queue on invocation of
+     * {@link SimpleAMQQueue#deleteMessageFromTop(StoreContext)}
+     */
+    public void testDeleteMessageFromTopWithDequeuedEntryOnTop()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 0;
+
+        // put messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message on top
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        //delete message from top
+        _queue.deleteMessageFromTop();
+
+        //get queue netries
+        List<QueueEntry> entries = _queue.getMessagesOnTheQueue();
+
+        // assert queue entries
+        assertNotNull("Null is returned from getMessagesOnTheQueue", entries);
+        assertEquals("Expected " + (messageNumber - 2) + " number of messages  but recieved " + entries.size(),
+                messageNumber - 2, entries.size());
+        assertEquals("Expected first entry with id 2", new Long(2),
+                ((AMQMessage) entries.get(0).getMessage()).getMessageId());
+    }
+
+    /**
+     * Tests that all messages including dequeued one are deleted from the queue
+     * on invocation of {@link SimpleAMQQueue#clearQueue(StoreContext)}
+     */
+    public void testClearQueueWithDequeuedEntry()
+    {
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+
+        // put messages into a test queue
+        enqueueGivenNumberOfMessages(_queue, messageNumber);
+
+        // dequeue message on a test queue
+        dequeueMessage(_queue, dequeueMessageIndex);
+
+        // clean queue
+        try
+        {
+            _queue.clearQueue();
+        }
+        catch (AMQException e)
+        {
+            fail("Failure to clear queue:" + e.getMessage());
+        }
+
+        // get queue entries
+        List<QueueEntry> entries = _queue.getMessagesOnTheQueue();
+
+        // assert queue entries
+        assertNotNull(entries);
+        assertEquals(0, entries.size());
+    }
+
+    /**
+     * Tests whether dequeued entry is sent to subscriber in result of
+     * invocation of {@link SimpleAMQQueue#processQueue(QueueRunner)}
+     */
+    public void testProcessQueueWithDequeuedEntry()
+    {
+        // total number of messages to send
+        int messageNumber = 4;
+        int dequeueMessageIndex = 1;
+
+        // create queue with overridden method deliverAsync
+        SimpleAMQQueue testQueue = new SimpleAMQQueue(new AMQShortString("test"), false,
+                new AMQShortString("testOwner"), false, false, _virtualHost, null)
+        {
+            @Override
+            public void deliverAsync(Subscription sub)
+            {
+                // do nothing
+            }
+        };
+
+        // put messages
+        List<QueueEntry> entries = enqueueGivenNumberOfMessages(testQueue, messageNumber);
+
+        // dequeue message
+        dequeueMessage(testQueue, dequeueMessageIndex);
+
+        // latch to wait for message receipt
+        final CountDownLatch latch = new CountDownLatch(messageNumber -1);
+
+        // create a subscription
+        MockSubscription subscription = new MockSubscription()
+        {
+            /**
+             * Send a message and decrement latch
+             */
+            public void send(QueueEntry msg) throws AMQException
+            {
+                super.send(msg);
+                latch.countDown();
+            }
+        };
+
+        try
+        {
+            // subscribe
+            testQueue.registerSubscription(subscription, false);
+
+            // process queue
+            testQueue.processQueue(new QueueRunner(testQueue, 1)
+            {
+                public void run()
+                {
+                    // do nothing
+                }
+            });
+        }
+        catch (AMQException e)
+        {
+            fail("Failure to process queue:" + e.getMessage());
+        }
+        // wait up to 1 minute for message receipt
+        try
+        {
+            latch.await(1, TimeUnit.MINUTES);
+        }
+        catch (InterruptedException e1)
+        {
+            Thread.currentThread().interrupt();
+        }
+        List<QueueEntry> expected = createEntriesList(entries.get(0), entries.get(2), entries.get(3));
+        verifyRecievedMessages(expected, subscription.getMessages());
+    }
+
+    /**
+     * Tests that entry in dequeued state are not enqueued and not delivered to subscription
+     */
+    public void testEqueueDequeuedEntry()
+    {
+        // create a queue where each even entry is considered a dequeued
+        SimpleAMQQueue queue = new SimpleAMQQueue(new AMQShortString("test"), false, new AMQShortString("testOwner"),
+                false, false, _virtualHost, new QueueEntryListFactory()
+                {
+                    public QueueEntryList createQueueEntryList(AMQQueue queue)
+                    {
+                        /**
+                         * Override SimpleQueueEntryList to create a dequeued
+                         * entries for messages with even id
+                         */
+                        return new SimpleQueueEntryList(queue)
+                        {
+                            /**
+                             * Entries with even message id are considered
+                             * dequeued!
+                             */
+                            protected QueueEntryImpl createQueueEntry(final ServerMessage message)
+                            {
+                                return new QueueEntryImpl(this, message)
+                                {
+                                    public boolean isDequeued()
+                                    {
+                                        return (((AMQMessage) message).getMessageId().longValue() % 2 == 0);
+                                    }
+
+                                    public boolean isDispensed()
+                                    {
+                                        return (((AMQMessage) message).getMessageId().longValue() % 2 == 0);
+                                    }
+
+                                    public boolean isAvailable()
+                                    {
+                                        return !(((AMQMessage) message).getMessageId().longValue() % 2 == 0);
+                                    }
+                                };
+                            }
+                        };
+                    }
+                }, null);
+        // create a subscription
+        MockSubscription subscription = new MockSubscription();
+
+        // register subscription
+        try
+        {
+            queue.registerSubscription(subscription, false);
+        }
+        catch (AMQException e)
+        {
+            fail("Failure to register subscription:" + e.getMessage());
+        }
+
+        // put test messages into a queue
+        putGivenNumberOfMessages(queue, 4);
+
+        // assert received messages
+        List<QueueEntry> messages = subscription.getMessages();
+        assertEquals("Only 2 messages should be returned", 2, messages.size());
+        assertEquals("ID of first message should be 1", new Long(1),
+                ((AMQMessage) messages.get(0).getMessage()).getMessageId());
+        assertEquals("ID of second message should be 3", new Long(3),
+                ((AMQMessage) messages.get(1).getMessage()).getMessageId());
+    }
+
+    /**
+     * A helper method to create a queue with given name
+     *
+     * @param name
+     *            queue name
+     * @return queue
+     */
+    private SimpleAMQQueue createQueue(String name)
+    {
+        SimpleAMQQueue queue = null;
+        try
+        {
+            AMQShortString queueName = new AMQShortString(name);
+            AMQShortString ownerName = new AMQShortString(name + "Owner");
+            queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(queueName, false, ownerName, false, false,
+                    _virtualHost, _arguments);
+        }
+        catch (AMQException e)
+        {
+            fail("Failure to create a queue:" + e.getMessage());
+        }
+        assertNotNull("Queue was not created", queue);
+        return queue;
+    }
+
+    /**
+     * A helper method to put given number of messages into queue
+     * <p>
+     * All messages are asserted that they are present on queue
+     *
+     * @param queue
+     *            queue to put messages into
+     * @param messageNumber
+     *            number of messages to put into queue
+     */
+    private List<QueueEntry> enqueueGivenNumberOfMessages(AMQQueue queue, int messageNumber)
+    {
+        putGivenNumberOfMessages(queue, messageNumber);
+
+        // make sure that all enqueued messages are on the queue
+        List<QueueEntry> entries = queue.getMessagesOnTheQueue();
+        assertEquals(messageNumber, entries.size());
+        for (int i = 0; i < messageNumber; i++)
+        {
+            assertEquals(new Long(i), ((AMQMessage)entries.get(i).getMessage()).getMessageId());
+        }
+        return entries;
+    }
+
+    /**
+     * A helper method to put given number of messages into queue
+     * <p>
+     * Queue is not checked if messages are added into queue
+     *
+     * @param queue
+     *            queue to put messages into
+     * @param messageNumber
+     *            number of messages to put into queue
+     * @param queue
+     * @param messageNumber
+     */
+    private void putGivenNumberOfMessages(AMQQueue queue, int messageNumber)
+    {
+        for (int i = 0; i < messageNumber; i++)
+        {
+            // Create message
+            Long messageId = new Long(i);
+            AMQMessage message = null;
+            try
+            {
+                message = createMessage(messageId);
+            }
+            catch (AMQException e)
+            {
+                fail("Failure to create a test message:" + e.getMessage());
+            }
+            // Put message on queue
+            try
+            {
+                queue.enqueue(message);
+            }
+            catch (AMQException e)
+            {
+                fail("Failure to put message on queue:" + e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * A helper method to dequeue an entry on queue with given index
+     *
+     * @param queue
+     *            queue to dequeue message on
+     * @param dequeueMessageIndex
+     *            entry index to dequeue.
+     */
+    private QueueEntry dequeueMessage(AMQQueue queue, int dequeueMessageIndex)
+    {
+        List<QueueEntry> entries = queue.getMessagesOnTheQueue();
+        QueueEntry entry = entries.get(dequeueMessageIndex);
+        entry.acquire();
+        entry.dequeue();
+        assertTrue(entry.isDequeued());
+        return entry;
+    }
+
     private List<QueueEntry> createEntriesList(QueueEntry... entries)
     {
         ArrayList<QueueEntry> entriesList = new ArrayList<QueueEntry>();

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleQueueEntryListTest.java Mon Aug 15 11:26:46 2011
@@ -23,6 +23,7 @@ package org.apache.qpid.server.queue;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.qpid.AMQException;
 import org.apache.qpid.server.message.AMQMessage;
 
 import junit.framework.TestCase;
@@ -155,5 +156,55 @@ public class SimpleQueueEntryListTest ex
         
         assertEquals("Count should have been equal",count,remainingMessages.size());
     }
-    
+
+    public void testDequedMessagedNotPresentInIterator()
+    {
+        int numberOfMessages = 10;
+        SimpleQueueEntryList entryList = new SimpleQueueEntryList(new MockAMQQueue("test"));
+        QueueEntry[] entries = new QueueEntry[numberOfMessages];
+
+        for(int i = 0; i < numberOfMessages ; i++)
+        {
+            AMQMessage message = null;;
+            try
+            {
+                message = new MockAMQMessage(i);
+            }
+            catch (AMQException e)
+            {
+                fail("Failure to create a mock message:" + e.getMessage());
+            }
+            QueueEntry entry = entryList.add(message);
+            assertNotNull("QE should not be null", entry);
+            entries[i]= entry;
+        }
+
+        // dequeue all even messages
+        for (QueueEntry queueEntry : entries)
+        {
+            long i = ((AMQMessage)queueEntry.getMessage()).getMessageId().longValue();
+            if (i%2 == 0)
+            {
+                queueEntry.acquire();
+                queueEntry.dequeue();
+            }
+        }
+
+        // iterate and check that dequeued messages are not returned by iterator
+        QueueEntryIterator it = entryList.iterator();
+        int counter = 0;
+        int i = 1;
+        while (it.advance())
+        {
+            QueueEntry entry = it.getNode();
+            Long id = ((AMQMessage)entry.getMessage()).getMessageId();
+            assertEquals("Expected message with id " + i + " but got message with id "
+                    + id, new Long(i), id);
+            counter++;
+            i += 2;
+        }
+        int expectedNumber = numberOfMessages / 2;
+        assertEquals("Expected  " + expectedNumber + " number of entries in iterator but got " + counter,
+                expectedNumber, counter);
+    }
 }

Copied: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java (from r1140000, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java)
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java?p2=qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java&r1=1140000&r2=1157780&rev=1157780&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java Mon Aug 15 11:26:46 2011
@@ -20,6 +20,10 @@
  */
 package org.apache.qpid.server.security.auth.manager;
 
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
 import java.security.Provider;
 import java.security.Security;
 
@@ -27,8 +31,13 @@ import javax.security.auth.Subject;
 import javax.security.sasl.SaslException;
 import javax.security.sasl.SaslServer;
 
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
 import org.apache.qpid.server.security.auth.AuthenticationResult;
 import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
 import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
 import org.apache.qpid.server.util.InternalBrokerBaseCase;
 
@@ -39,8 +48,10 @@ import org.apache.qpid.server.util.Inter
  */
 public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase
 {
-    private PrincipalDatabaseAuthenticationManager _manager = null;
-    
+    private AuthenticationManager _manager = null; // Class under test
+    private String TEST_USERNAME = "guest";
+    private String TEST_PASSWORD = "guest";
+
     /**
      * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown()
      */
@@ -62,7 +73,79 @@ public class PrincipalDatabaseAuthentica
     {
         super.setUp();
         
-        _manager = new PrincipalDatabaseAuthenticationManager();
+        final String passwdFilename = createPasswordFile().getCanonicalPath();
+        final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(),
+                "passwordFile", passwdFilename);
+
+        _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config);
+    }
+
+    /**
+     * Tests where the case where the config specifies a PD implementation
+     * that is not found.
+     */
+    public void testPrincipalDatabaseImplementationNotFound() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig("not.Found", null, null));
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+        }
+    }
+
+    /**
+     * Tests where the case where the config specifies a PD implementation
+     * of the wrong type.
+     */
+    public void testPrincipalDatabaseImplementationWrongType() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(String.class.getName(), null, null)); // Not a PrincipalDatabase implementation
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+        }
+    }
+
+    /**
+     * Tests the case where a setter with the desired name cannot be found.
+     */
+    public void testPrincipalDatabaseSetterNotFound() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test")); 
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+        }
+    }
+
+    /**
+     * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file.
+     */
+    public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception
+    {
+        try
+        {
+            _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found")); 
+            fail("Exception not thrown");
+        }
+        catch (ConfigurationException ce)
+        {
+            // PASS
+            assertNotNull("Expected an underlying cause", ce.getCause());
+            assertEquals(FileNotFoundException.class, ce.getCause().getClass());
+        }
     }
 
     /**
@@ -72,8 +155,8 @@ public class PrincipalDatabaseAuthentica
     {
         assertNotNull(_manager.getMechanisms());
         // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager
-        assertEquals("PLAIN CRAM-MD5", _manager.getMechanisms());
-    
+        assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
+
         Provider qpidProvider = Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME);
         assertNotNull(qpidProvider);
     }
@@ -166,11 +249,11 @@ public class PrincipalDatabaseAuthentica
      */
     public void testClose() throws Exception
     {
-        assertEquals("PLAIN CRAM-MD5", _manager.getMechanisms());
+        assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
         assertNotNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
-        
+
         _manager.close();
-        
+
         // Check provider has been removed.
         assertNull(_manager.getMechanisms());
         assertNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
@@ -184,14 +267,11 @@ public class PrincipalDatabaseAuthentica
     {
         return new SaslServer()
         {
-
-            @Override
             public String getMechanismName()
             {
                 return null;
             }
 
-            @Override
             public byte[] evaluateResponse(byte[] response) throws SaslException
             {
                 if (throwSaslException)
@@ -201,40 +281,78 @@ public class PrincipalDatabaseAuthentica
                 return null;
             }
 
-            @Override
             public boolean isComplete()
             {
                 return complete;
             }
 
-            @Override
             public String getAuthorizationID()
             {
                 return complete ? "guest" : null;
             }
 
-            @Override
             public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
             {
                 return null;
             }
 
-            @Override
             public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
             {
                 return null;
             }
 
-            @Override
             public Object getNegotiatedProperty(String propName)
             {
                 return null;
             }
 
-            @Override
             public void dispose() throws SaslException
             {
             }
         };
     }
+
+    private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception
+    {
+        final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
+
+        XMLConfiguration xmlconfig = new XMLConfiguration();
+        xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz);
+
+        if (argName != null)
+        {
+            xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName);
+            xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue);
+        }
+
+        // Create a CompositeConfiguration as this is what the broker uses
+        CompositeConfiguration composite = new CompositeConfiguration();
+        composite.addConfiguration(xmlconfig);
+        config.setConfiguration("security", xmlconfig);
+        return config;
+    }
+
+    private File createPasswordFile() throws Exception
+    {
+        BufferedWriter writer = null;
+        try
+        {
+            File testFile = File.createTempFile(this.getClass().getName(),"tmp");
+            testFile.deleteOnExit();
+
+            writer = new BufferedWriter(new FileWriter(testFile));
+            writer.write(TEST_USERNAME + ":" + TEST_PASSWORD);
+            writer.newLine();
+ 
+            return testFile;
+
+        }
+        finally
+        {
+            if (writer != null)
+            {
+                writer.close();
+            }
+        }
+    }
 }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java Mon Aug 15 11:26:46 2011
@@ -20,188 +20,125 @@
  */
 package org.apache.qpid.server.security.auth.rmi;
 
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.util.Collections;
 
 import javax.management.remote.JMXPrincipal;
 import javax.security.auth.Subject;
-
-import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase;
-import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase;
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
 
 import junit.framework.TestCase;
 
+import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+
+/**
+ * Tests the RMIPasswordAuthenticator and its collaboration with the AuthenticationManager.
+ *
+ */
 public class RMIPasswordAuthenticatorTest extends TestCase
 {
     private final String USERNAME = "guest";
     private final String PASSWORD = "guest";
-    private final String B64_MD5HASHED_PASSWORD = "CE4DQ6BIb/BVMN9scFyLtA==";
     private RMIPasswordAuthenticator _rmipa;
-    
-    private Base64MD5PasswordFilePrincipalDatabase _md5Pd;
-    private File _md5PwdFile;
-    
-    private PlainPasswordFilePrincipalDatabase _plainPd;
-    private File _plainPwdFile;
-
-    private Subject testSubject;
+    private String[] _credentials;
 
     protected void setUp() throws Exception
     {
         _rmipa = new RMIPasswordAuthenticator();
         
-        _md5Pd = new Base64MD5PasswordFilePrincipalDatabase();
-        _md5PwdFile = createTempPasswordFile(this.getClass().getName()+"md5pwd", USERNAME, B64_MD5HASHED_PASSWORD);
-        _md5Pd.setPasswordFile(_md5PwdFile.getAbsolutePath());
-        
-        _plainPd = new PlainPasswordFilePrincipalDatabase();
-        _plainPwdFile = createTempPasswordFile(this.getClass().getName()+"plainpwd", USERNAME, PASSWORD);
-        _plainPd.setPasswordFile(_plainPwdFile.getAbsolutePath());
-        
-        testSubject = new Subject(true,
+        _credentials = new String[] {USERNAME, PASSWORD};
+    }
+
+    /**
+     * Tests a successful authentication.  Ensures that a populated read-only subject it returned.
+     */
+    public void testAuthenticationSuccess()
+    {
+        final Subject expectedSubject = new Subject(true,
                 Collections.singleton(new JMXPrincipal(USERNAME)),
                 Collections.EMPTY_SET,
                 Collections.EMPTY_SET);
-    }
-    
-    private File createTempPasswordFile(String filenamePrefix, String user, String password)
-    {
-        try
-        {
-            File testFile = File.createTempFile(filenamePrefix,"tmp");
-            testFile.deleteOnExit();
 
-            BufferedWriter writer = new BufferedWriter(new FileWriter(testFile));
+        _rmipa.setAuthenticationManager(createTestAuthenticationManager(true, null));
 
-            writer.write(user + ":" + password);
-            writer.newLine();
 
-            writer.flush();
-            writer.close();
-
-            return testFile;
-        }
-        catch (IOException e)
-        {
-            fail("Unable to create temporary test password file." + e.getMessage());
-        }
+        Subject newSubject = _rmipa.authenticate(_credentials);
+        assertTrue("Subject must be readonly", newSubject.isReadOnly());
+        assertTrue("Returned subject does not equal expected value",
+                newSubject.equals(expectedSubject));
 
-        return null;
     }
-
-    
-    //********** Test Methods *********//
-    
     
-    public void testAuthenticate()
+    /**
+     * Tests a unsuccessful authentication.
+     */
+    public void testUsernameOrPasswordInvalid()
     {
-        String[] credentials;
-        Subject newSubject;
-
-        // Test when no PD has been set
-        try
-        {
-            credentials = new String[]{USERNAME, PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
-            fail("SecurityException expected due to lack of principal database");
-        }
-        catch (SecurityException se)
-        {
-            assertEquals("Unexpected exception message",
-                    RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage());
-        }
-
-        //The PrincipalDatabase's are tested primarily by their own tests, but
-        //minimal tests are done here to exercise their usage in this area.
+        _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, null));
         
-        // Test correct passwords are verified with an MD5 PD
         try
         {
-            _rmipa.setPrincipalDatabase(_md5Pd);
-            credentials = new String[]{USERNAME, PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
-            assertTrue("Returned subject does not equal expected value", 
-                    newSubject.equals(testSubject));
-        }
-        catch (Exception e)
-        {
-            fail("Unexpected Exception:" + e.getMessage());
-        }
-
-        // Test incorrect passwords are not verified with an MD5 PD
-        try
-        {
-            credentials = new String[]{USERNAME, PASSWORD+"incorrect"};
-            newSubject = _rmipa.authenticate(credentials);
-            fail("SecurityException expected due to incorrect password");
-        }
-        catch (SecurityException se)
-        {
-            assertEquals("Unexpected exception message",
-                    RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage());
-        }
-        
-        // Test non-existent accounts are not verified with an MD5 PD
-        try
-        {
-            credentials = new String[]{USERNAME+"invalid", PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
-            fail("SecurityException expected due to non-existant account");
+            _rmipa.authenticate(_credentials);
+            fail("Exception not thrown");
         }
         catch (SecurityException se)
         {
             assertEquals("Unexpected exception message",
                     RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage());
-        }
 
-        // Test correct passwords are verified with a Plain PD
-        try
-        {
-            _rmipa.setPrincipalDatabase(_plainPd);
-            credentials = new String[]{USERNAME, PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
-            assertTrue("Returned subject does not equal expected value", 
-                    newSubject.equals(testSubject));
-        }
-        catch (Exception e)
-        {
-            fail("Unexpected Exception");
         }
+    }
+
+    /**
+     * Tests case where authentication system itself fails.
+     */
+    public void testAuthenticationFailure()
+    {
+        final Exception mockAuthException = new Exception("Mock Auth system failure");
+        _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, mockAuthException));
 
-        // Test incorrect passwords are not verified with a Plain PD
         try
         {
-            credentials = new String[]{USERNAME, PASSWORD+"incorrect"};
-            newSubject = _rmipa.authenticate(credentials);
-            fail("SecurityException expected due to incorrect password");
+            _rmipa.authenticate(_credentials);
+            fail("Exception not thrown");
         }
         catch (SecurityException se)
         {
-            assertEquals("Unexpected exception message",
-                    RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage());
+            assertEquals("Initial cause not found", mockAuthException, se.getCause());
         }
-        
-        // Test non-existent accounts are not verified with an Plain PD
+    }
+
+
+    /**
+     * Tests case where authentication manager is not set.
+     */
+    public void testNullAuthenticationManager()
+    {
         try
         {
-            credentials = new String[]{USERNAME+"invalid", PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
-            fail("SecurityException expected due to non existant account");
+            _rmipa.authenticate(_credentials);
+            fail("SecurityException expected due to lack of authentication manager");
         }
         catch (SecurityException se)
         {
             assertEquals("Unexpected exception message",
-                    RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage());
+                    RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage());
         }
+    }
 
+    /**
+     * Tests case where arguments are non-Strings..
+     */
+    public void testWithNonStringArrayArgument()
+    {
         // Test handling of non-string credential's
+        final Object[] objCredentials = new Object[]{USERNAME, PASSWORD};
         try
         {
-            Object[] objCredentials = new Object[]{USERNAME, PASSWORD};
-            newSubject = _rmipa.authenticate(objCredentials);
+             _rmipa.authenticate(objCredentials);
             fail("SecurityException expected due to non string[] credentials");
         }
         catch (SecurityException se)
@@ -209,12 +146,18 @@ public class RMIPasswordAuthenticatorTes
             assertEquals("Unexpected exception message",
                     RMIPasswordAuthenticator.SHOULD_BE_STRING_ARRAY, se.getMessage());
         }
-        
-        // Test handling of incorrect number of credential's
+    }
+
+    /**
+     * Tests case where there are too many, too few or null arguments.
+     */
+    public void testWithIllegalNumberOfArguments()
+    {
+        // Test handling of incorrect number of credentials
         try
         {
-            credentials = new String[]{USERNAME, PASSWORD, PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
+            _credentials = new String[]{USERNAME, PASSWORD, PASSWORD};
+            _rmipa.authenticate(_credentials);
             fail("SecurityException expected due to supplying wrong number of credentials");
         }
         catch (SecurityException se)
@@ -223,12 +166,12 @@ public class RMIPasswordAuthenticatorTes
                     RMIPasswordAuthenticator.SHOULD_HAVE_2_ELEMENTS, se.getMessage());
         }
         
-        // Test handling of null credential's
+        // Test handling of null credentials
         try
         {
             //send a null array
-            credentials = null;
-            newSubject = _rmipa.authenticate(credentials);
+            _credentials = null;
+            _rmipa.authenticate(_credentials);
             fail("SecurityException expected due to not supplying an array of credentials");
         }
         catch (SecurityException se)
@@ -240,8 +183,8 @@ public class RMIPasswordAuthenticatorTes
         try
         {
             //send a null password
-            credentials = new String[]{USERNAME, null};
-            newSubject = _rmipa.authenticate(credentials);
+            _credentials = new String[]{USERNAME, null};
+            _rmipa.authenticate(_credentials);
             fail("SecurityException expected due to sending a null password");
         }
         catch (SecurityException se)
@@ -253,8 +196,8 @@ public class RMIPasswordAuthenticatorTes
         try
         {
             //send a null username
-            credentials = new String[]{null, PASSWORD};
-            newSubject = _rmipa.authenticate(credentials);
+            _credentials = new String[]{null, PASSWORD};
+            _rmipa.authenticate(_credentials);
             fail("SecurityException expected due to sending a null username");
         }
         catch (SecurityException se)
@@ -264,4 +207,59 @@ public class RMIPasswordAuthenticatorTes
         }
     }
 
+    private AuthenticationManager createTestAuthenticationManager(final boolean successfulAuth, final Exception exception)
+    {
+        return new AuthenticationManager()
+        {
+            public void configure(ConfigurationPlugin config)
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public void initialise()
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public void close()
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public String getMechanisms()
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public SaslServer createSaslServer(String mechanism, String localFQDN) throws SaslException
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public AuthenticationResult authenticate(SaslServer server, byte[] response)
+            {
+                throw new UnsupportedOperationException();
+            }
+
+            public AuthenticationResult authenticate(String username, String password)
+            {
+                if (exception != null) {
+                    return new AuthenticationResult(AuthenticationStatus.ERROR, exception);
+                }
+                else if (successfulAuth)
+                {
+                    return new AuthenticationResult(new Subject());
+                }
+                else
+                {
+                    return new AuthenticationResult(AuthenticationStatus.CONTINUE);
+                }
+            }
+     
+            public javax.security.auth.callback.CallbackHandler getHandler(String mechansim)
+            {
+                throw new UnsupportedOperationException();
+            }
+        };
+    }
 }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/CRAMMD5HexServerTest.java Mon Aug 15 11:26:46 2011
@@ -197,8 +197,6 @@ public class CRAMMD5HexServerTest extend
     {
         return new Principal()
         {
-
-            @Override
             public String getName()
             {
                 return name;

Copied: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java (from r1140000, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java)
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java?p2=qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java&r1=1140000&r2=1157780&rev=1157780&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/UsernamePrincipalTest.java Mon Aug 15 11:26:46 2011
@@ -75,8 +75,6 @@ public class UsernamePrincipalTest exten
         final UsernamePrincipal expected = new UsernamePrincipal("name");
         final Principal other = new Principal()
         {
-
-            @Override
             public String getName()
             {
                 return "otherprincipal";

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java Mon Aug 15 11:26:46 2011
@@ -122,6 +122,7 @@ public class MessageStoreTest extends In
             }
             catch (Exception e)
             {
+                e.printStackTrace();
                 fail(e.getMessage());
             }
         }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockAction.java Mon Aug 15 11:26:46 2011
@@ -32,13 +32,11 @@ class MockAction implements Action
     private boolean _rollbackFired = false;
     private boolean _postCommitFired = false;
 
-    @Override
     public void postCommit()
     {
         _postCommitFired = true;
     }
 
-    @Override
     public void onRollback()
     {
         _rollbackFired = true;

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockServerMessage.java Mon Aug 15 11:26:46 2011
@@ -46,25 +46,22 @@ class MockServerMessage implements Serve
         this.persistent = persistent;
     }
 
-
     public boolean isPersistent()
     {
         return persistent;
     }
 
-
-    public MessageReference<MockServerMessage> newReference()
+    public boolean isImmediate()
     {
-        throw new NotImplementedException();
+        return false;
     }
 
 
-    public boolean isImmediate()
+    public MessageReference<MockServerMessage> newReference()
     {
         throw new NotImplementedException();
     }
 
-
     public long getSize()
     {
         throw new NotImplementedException();
@@ -76,39 +73,33 @@ class MockServerMessage implements Serve
         throw new NotImplementedException();
     }
 
-
     public String getRoutingKey()
     {
         throw new NotImplementedException();
     }
 
-
     public AMQMessageHeader getMessageHeader()
     {
         throw new NotImplementedException();
     }
 
-
     public long getExpiration()
     {
         throw new NotImplementedException();
     }
 
-
     public int getContent(ByteBuffer buf, int offset)
     {
         throw new NotImplementedException();
     }
 
-
     public long getArrivalTime()
     {
         throw new NotImplementedException();
     }
 
-
     public Long getMessageNumber()
     {
         return 0L;
     }
-}
\ No newline at end of file
+}

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/txn/MockStoreTransaction.java Mon Aug 15 11:26:46 2011
@@ -61,7 +61,6 @@ class MockStoreTransaction implements Tr
         return _state;
     }
 
-    @Override
     public void enqueueMessage(TransactionLogResource queue, Long messageId) throws AMQStoreException
     {
         if (_throwExceptionOnQueueOp)
@@ -83,8 +82,6 @@ class MockStoreTransaction implements Tr
         return _numberOfEnqueuedMessages;
     }
 
-
-    @Override
     public void dequeueMessage(TransactionLogResource queue, Long messageId) throws AMQStoreException
     {
         if (_throwExceptionOnQueueOp)
@@ -95,19 +92,16 @@ class MockStoreTransaction implements Tr
         _numberOfDequeuedMessages++;
     }
 
-    @Override
     public void commitTran() throws AMQStoreException
     {
         _state = TransactionState.COMMITTED;
     }
 
-    @Override
     public StoreFuture commitTranAsync() throws AMQStoreException
     {
         throw new NotImplementedException();
     }
 
-    @Override
     public void abortTran() throws AMQStoreException
     {
         _state = TransactionState.ABORTED;
@@ -117,14 +111,11 @@ class MockStoreTransaction implements Tr
     {
         return new TransactionLog()
         {
-    
-            @Override
             public void configureTransactionLog(String name, TransactionLogRecoveryHandler recoveryHandler,
                     Configuration storeConfiguration, LogSubject logSubject) throws Exception
             {
             }
-    
-            @Override
+
             public Transaction newTransaction()
             {
                 storeTransaction.setState(TransactionState.STARTED);

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/InternalBrokerBaseCase.java Mon Aug 15 11:26:46 2011
@@ -44,14 +44,13 @@ import org.apache.qpid.server.store.Mess
 import org.apache.qpid.server.store.TestableMemoryMessageStore;
 import org.apache.qpid.server.virtualhost.VirtualHost;
 import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.util.MockChannel;
 
 
 public class InternalBrokerBaseCase extends QpidTestCase
 {
     private IApplicationRegistry _registry;
     private MessageStore _messageStore;
-    private MockChannel _channel;
+    private AMQChannel _channel;
     private InternalTestProtocolSession _session;
     private VirtualHost _virtualHost;
     private AMQQueue _queue;
@@ -111,7 +110,7 @@ public class InternalBrokerBaseCase exte
         _session = new InternalTestProtocolSession(_virtualHost);
         CurrentActor.set(_session.getLogActor());
 
-        _channel = new MockChannel(_session, 1, _messageStore);
+        _channel = new AMQChannel(_session, 1, _messageStore);
 
         _session.addChannel(_channel);
     }
@@ -283,12 +282,12 @@ public class InternalBrokerBaseCase exte
         _messageStore = messageStore;
     }
 
-    public MockChannel getChannel()
+    public AMQChannel getChannel()
     {
         return _channel;
     }
 
-    public void setChannel(MockChannel channel)
+    public void setChannel(AMQChannel channel)
     {
         _channel = channel;
     }

Modified: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java?rev=1157780&r1=1157779&r2=1157780&view=diff
==============================================================================
--- qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java Mon Aug 15 11:26:46 2011
@@ -20,27 +20,72 @@
  */
 package org.apache.qpid.server.util;
 
+import java.util.Properties;
+
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.logging.NullRootMessageLogger;
+import org.apache.qpid.server.logging.actors.BrokerActor;
+import org.apache.qpid.server.logging.actors.CurrentActor;
+import org.apache.qpid.server.logging.actors.GenericActor;
+import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
 import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabaseManager;
-
-import java.util.Properties;
-
+import org.apache.qpid.server.security.auth.database.PropertiesPrincipalDatabase;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager;
 
 public class TestApplicationRegistry extends ApplicationRegistry
 {
+
     public TestApplicationRegistry(ServerConfiguration config) throws ConfigurationException
     {
         super(config);
     }
 
-    protected void createDatabaseManager(ServerConfiguration configuration) throws Exception
+    @Override
+    public void initialise() throws Exception
+    {
+        CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger()));
+        GenericActor.setDefaultMessageLogger(new NullRootMessageLogger());
+        super.initialise();
+    }
+
+    /**
+     * @see org.apache.qpid.server.registry.ApplicationRegistry#createAuthenticationManager()
+     */
+    @Override
+    protected AuthenticationManager createAuthenticationManager() throws ConfigurationException
     {
-        Properties users = new Properties();
+        final Properties users = new Properties();
         users.put("guest","guest");
         users.put("admin","admin");
-        _databaseManager = new PropertiesPrincipalDatabaseManager("testPasswordFile", users);
+
+        final PropertiesPrincipalDatabase ppd = new PropertiesPrincipalDatabase(users);
+
+        AuthenticationManager pdam =  new PrincipalDatabaseAuthenticationManager()
+        {
+
+            /**
+             * @see org.apache.qpid.server.security.auth.manager.PrincipalDatabaseAuthenticationManager#configure(org.apache.qpid.server.configuration.plugins.ConfigurationPlugin)
+             */
+            @Override
+            public void configure(ConfigurationPlugin config) throws ConfigurationException
+            {
+                // We don't pass configuration to this test instance.
+            }
+
+            @Override
+            public void initialise()
+            {
+                setPrincipalDatabase(ppd);
+
+                super.initialise();
+            }
+        };
+
+        pdam.initialise();
+
+        return pdam;
     }
 
 }

Copied: qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java (from r1140000, qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java)
URL: http://svn.apache.org/viewvc/qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java?p2=qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java&p1=qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java&r1=1140000&r2=1157780&rev=1157780&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java (original)
+++ qpid/branches/rg-amqp-1-0-sandbox/qpid/java/broker/src/test/java/org/apache/qpid/server/virtualhost/MockVirtualHost.java Mon Aug 15 11:26:46 2011
@@ -42,6 +42,8 @@ import org.apache.qpid.server.stats.Stat
 import org.apache.qpid.server.store.DurableConfigurationStore;
 import org.apache.qpid.server.store.MessageStore;
 import org.apache.qpid.server.store.TransactionLog;
+import org.apache.qpid.server.protocol.v1_0.LinkRegistry;
+
 
 public class MockVirtualHost implements VirtualHost
 {
@@ -239,6 +241,11 @@ public class MockVirtualHost implements 
         return null;
     }
 
+    public LinkRegistry getLinkRegistry(String name)
+    {
+        return null;
+    }
+
     public void initialiseStatistics()
     {
 
@@ -268,4 +275,4 @@ public class MockVirtualHost implements 
     {
 
     }
-}
\ No newline at end of file
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org