You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2013/02/28 17:14:57 UTC
svn commit: r1451244 [33/45] - in /qpid/branches/asyncstore: ./ bin/ cpp/
cpp/bindings/ cpp/bindings/qmf/ cpp/bindings/qmf/python/
cpp/bindings/qmf/ruby/ cpp/bindings/qmf2/ cpp/bindings/qmf2/examples/cpp/
cpp/bindings/qmf2/python/ cpp/bindings/qmf2/rub...
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MaxChannelsTest.java Thu Feb 28 16:14:30 2013
@@ -23,20 +23,24 @@ package org.apache.qpid.server.protocol;
import org.apache.qpid.AMQException;
import org.apache.qpid.protocol.AMQConstant;
import org.apache.qpid.server.AMQChannel;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
-import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
/** Test class to test MBean operations for AMQMinaProtocolSession. */
-public class MaxChannelsTest extends InternalBrokerBaseCase
+public class MaxChannelsTest extends QpidTestCase
{
- private AMQProtocolEngine _session;
+ private AMQProtocolEngine _session;
- public void testChannels() throws Exception
+ @Override
+ public void setUp() throws Exception
{
- VirtualHost vhost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
- _session = new InternalTestProtocolSession(vhost);
+ super.setUp();
+ BrokerTestHelper.setUp();
+ _session = BrokerTestHelper.createSession();
+ }
+ public void testChannels() throws Exception
+ {
// check the channel count is correct
int channelCount = _session.getChannels().size();
assertEquals("Initial channel count wrong", 0, channelCount);
@@ -45,13 +49,15 @@ public class MaxChannelsTest extends Int
_session.setMaximumNumberOfChannels(maxChannels);
assertEquals("Number of channels not correctly set.", new Long(maxChannels), _session.getMaximumNumberOfChannels());
+ for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
+ {
+ _session.addChannel(new AMQChannel(_session, (int) currentChannel, null));
+ }
try
{
- for (long currentChannel = 0L; currentChannel < maxChannels; currentChannel++)
- {
- _session.addChannel(new AMQChannel(_session, (int) currentChannel, null));
- }
+ _session.addChannel(new AMQChannel(_session, (int) maxChannels, null));
+ fail("Cannot create more channels then maximum");
}
catch (AMQException e)
{
@@ -63,14 +69,14 @@ public class MaxChannelsTest extends Int
@Override
public void tearDown() throws Exception
{
- try {
- _session.closeSession();
- } catch (AMQException e) {
- // Yikes
- fail(e.getMessage());
- }
+ try
+ {
+ _session.getVirtualHost().close();
+ _session.closeSession();
+ }
finally
{
+ BrokerTestHelper.tearDown();
super.tearDown();
}
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/protocol/MultiVersionProtocolEngineFactoryTest.java Thu Feb 28 16:14:30 2013
@@ -20,36 +20,52 @@
*/
package org.apache.qpid.server.protocol;
-import org.apache.commons.configuration.XMLConfiguration;
-
-import org.apache.qpid.protocol.ServerProtocolEngine;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.TestApplicationRegistry;
-import org.apache.qpid.test.utils.QpidTestCase;
-import org.apache.qpid.transport.TestNetworkConnection;
+import static org.mockito.Mockito.when;
import java.nio.ByteBuffer;
import java.util.EnumSet;
import java.util.Set;
+import org.apache.qpid.protocol.ServerProtocolEngine;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.transport.TestNetworkConnection;
+
public class MultiVersionProtocolEngineFactoryTest extends QpidTestCase
{
+ private VirtualHost _virtualHost;
+ private Broker _broker;
+ @Override
protected void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
+ _broker = BrokerTestHelper.createBrokerMock();
+ VirtualHostRegistry virtualHostRegistry = _broker.getVirtualHostRegistry();
+ when(_broker.getAttribute(Broker.DEFAULT_VIRTUAL_HOST)).thenReturn("default");
- //the factory needs a registry instance
- ApplicationRegistry.initialise(new TestApplicationRegistry(new ServerConfiguration(new XMLConfiguration())));
+ // AMQP 1-0 connection needs default vhost to be present
+ _virtualHost = BrokerTestHelper.createVirtualHost("default", virtualHostRegistry);
}
- protected void tearDown()
+ @Override
+ protected void tearDown() throws Exception
{
- //the factory opens a registry instance
- ApplicationRegistry.remove();
+ try
+ {
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
-
+
private static final byte[] AMQP_0_8_HEADER =
new byte[] { (byte) 'A',
(byte) 'M',
@@ -108,6 +124,7 @@ public class MultiVersionProtocolEngineF
(byte) 0
};
+
private byte[] getAmqpHeader(final AmqpProtocolVersion version)
{
switch(version)
@@ -137,7 +154,7 @@ public class MultiVersionProtocolEngineF
Set<AmqpProtocolVersion> versions = EnumSet.allOf(AmqpProtocolVersion.class);
MultiVersionProtocolEngineFactory factory =
- new MultiVersionProtocolEngineFactory(versions, null);
+ new MultiVersionProtocolEngineFactory(_broker, versions, null);
//create a dummy to retrieve the 'current' ID number
long previousId = factory.newProtocolEngine().getConnectionId();
@@ -160,6 +177,7 @@ public class MultiVersionProtocolEngineF
assertEquals("ID was not as expected following receipt of the AMQP version header", expectedID, engine.getConnectionId());
previousId = expectedID;
+ engine.closed();
}
}
@@ -174,7 +192,7 @@ public class MultiVersionProtocolEngineF
try
{
- new MultiVersionProtocolEngineFactory(versions, AmqpProtocolVersion.v0_9);
+ new MultiVersionProtocolEngineFactory(_broker, versions, AmqpProtocolVersion.v0_9);
fail("should not have been allowed to create the factory");
}
catch(IllegalArgumentException iae)
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQPriorityQueueTest.java Thu Feb 28 16:14:30 2013
@@ -36,8 +36,9 @@ public class AMQPriorityQueueTest extend
@Override
public void setUp() throws Exception
{
- _arguments = new FieldTable();
- _arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 3);
+ FieldTable arguments = new FieldTable();
+ arguments.put(new AMQShortString(AMQQueueFactory.X_QPID_PRIORITIES), 3);
+ setArguments(arguments);
super.setUp();
}
@@ -45,25 +46,26 @@ public class AMQPriorityQueueTest extend
{
// Enqueue messages in order
- _queue.enqueue(createMessage(1L, (byte) 10));
- _queue.enqueue(createMessage(2L, (byte) 4));
- _queue.enqueue(createMessage(3L, (byte) 0));
+ SimpleAMQQueue queue = getQueue();
+ queue.enqueue(createMessage(1L, (byte) 10));
+ queue.enqueue(createMessage(2L, (byte) 4));
+ queue.enqueue(createMessage(3L, (byte) 0));
// Enqueue messages in reverse order
- _queue.enqueue(createMessage(4L, (byte) 0));
- _queue.enqueue(createMessage(5L, (byte) 4));
- _queue.enqueue(createMessage(6L, (byte) 10));
+ queue.enqueue(createMessage(4L, (byte) 0));
+ queue.enqueue(createMessage(5L, (byte) 4));
+ queue.enqueue(createMessage(6L, (byte) 10));
// Enqueue messages out of order
- _queue.enqueue(createMessage(7L, (byte) 4));
- _queue.enqueue(createMessage(8L, (byte) 10));
- _queue.enqueue(createMessage(9L, (byte) 0));
+ queue.enqueue(createMessage(7L, (byte) 4));
+ queue.enqueue(createMessage(8L, (byte) 10));
+ queue.enqueue(createMessage(9L, (byte) 0));
// Register subscriber
- _queue.registerSubscription(_subscription, false);
+ queue.registerSubscription(getSubscription(), false);
Thread.sleep(150);
- ArrayList<QueueEntry> msgs = _subscription.getMessages();
+ ArrayList<QueueEntry> msgs = getSubscription().getMessages();
try
{
assertEquals(1L, msgs.get(0).getMessage().getMessageNumber());
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AMQQueueFactoryTest.java Thu Feb 28 16:14:30 2013
@@ -20,23 +20,23 @@
*/
package org.apache.qpid.server.queue;
+import static org.mockito.Mockito.when;
+
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.qpid.AMQException;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.framing.FieldTable;
-import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DefaultExchangeFactory;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.logging.SystemOutMessageLogger;
-import org.apache.qpid.server.logging.actors.CurrentActor;
-import org.apache.qpid.server.logging.actors.TestLogActor;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.store.TestableMemoryMessageStore;
-import org.apache.qpid.server.util.TestApplicationRegistry;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -50,19 +50,19 @@ public class AMQQueueFactoryTest extends
{
super.setUp();
- CurrentActor.set(new TestLogActor(new SystemOutMessageLogger()));
-
+ BrokerTestHelper.setUp();
XMLConfiguration configXml = new XMLConfiguration();
- configXml.addProperty("virtualhosts.virtualhost(-1).name", getName());
- configXml.addProperty("virtualhosts.virtualhost(-1)."+getName()+".store.class", TestableMemoryMessageStore.class.getName());
+ configXml.addProperty("store.class", TestableMemoryMessageStore.class.getName());
- ServerConfiguration configuration = new ServerConfiguration(configXml);
- ApplicationRegistry registry = new TestApplicationRegistry(configuration);
- ApplicationRegistry.initialise(registry);
- registry.getVirtualHostRegistry().setDefaultVirtualHostName(getName());
+ Broker broker = BrokerTestHelper.createBrokerMock();
+ if (getName().equals("testDeadLetterQueueDoesNotInheritDLQorMDCSettings"))
+ {
+ when(broker.getAttribute(Broker.MAXIMUM_DELIVERY_ATTEMPTS)).thenReturn(5);
+ when(broker.getAttribute(Broker.DEAD_LETTER_QUEUE_ENABLED)).thenReturn(true);
+ }
- _virtualHost = registry.getVirtualHostRegistry().getVirtualHost(getName());
+ _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getName(), configXml, broker));
_queueRegistry = _virtualHost.getQueueRegistry();
@@ -73,11 +73,12 @@ public class AMQQueueFactoryTest extends
{
try
{
- super.tearDown();
+ _virtualHost.close();
}
finally
{
- ApplicationRegistry.remove();
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
}
@@ -172,11 +173,8 @@ public class AMQQueueFactoryTest extends
* are not applied to the DLQ itself.
* @throws AMQException
*/
- public void testDeadLetterQueueDoesNotInheritDLQorMDCSettings() throws AMQException
+ public void testDeadLetterQueueDoesNotInheritDLQorMDCSettings() throws Exception
{
- ApplicationRegistry.getInstance().getConfiguration().getConfig().addProperty("deadLetterQueues","true");
- ApplicationRegistry.getInstance().getConfiguration().getConfig().addProperty("maximumDeliveryCount","5");
-
String queueName = "testDeadLetterQueueEnabled";
AMQShortString dlExchangeName = new AMQShortString(queueName + DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
AMQShortString dlQueueName = new AMQShortString(queueName + AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
@@ -336,11 +334,8 @@ public class AMQQueueFactoryTest extends
try
{
// change DLQ name to make its length bigger than exchange name
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", "_DLE");
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", "_DLQUEUE");
-
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, "_DLE");
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, "_DLQUEUE");
FieldTable fieldTable = new FieldTable();
fieldTable.setBoolean(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, "owner",
@@ -353,13 +348,6 @@ public class AMQQueueFactoryTest extends
assertTrue("Unexpected exception message!", e.getMessage().contains("DLQ queue name")
&& e.getMessage().contains("length exceeds limit of 255"));
}
- finally
- {
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
}
/**
@@ -372,11 +360,8 @@ public class AMQQueueFactoryTest extends
try
{
// change DLQ name to make its length bigger than exchange name
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", "_DLEXCHANGE");
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", "_DLQ");
-
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_EXCHANGE_SUFFIX, "_DLEXCHANGE");
+ setTestSystemProperty(BrokerProperties.PROPERTY_DEAD_LETTER_QUEUE_SUFFIX, "_DLQ");
FieldTable fieldTable = new FieldTable();
fieldTable.setBoolean(AMQQueueFactory.X_QPID_DLQ_ENABLED, true);
AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), queueName, false, "owner",
@@ -389,13 +374,6 @@ public class AMQQueueFactoryTest extends
assertTrue("Unexpected exception message!", e.getMessage().contains("DL exchange name")
&& e.getMessage().contains("length exceeds limit of 255"));
}
- finally
- {
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterExchangeSuffix", DefaultExchangeFactory.DEFAULT_DLE_NAME_SUFFIX);
- ApplicationRegistry.getInstance().getConfiguration().getConfig()
- .addProperty("deadLetterQueueSuffix", AMQQueueFactory.DEFAULT_DLQ_NAME_SUFFIX);
- }
}
private String generateStringWithLength(char ch, int length)
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/AckTest.java Thu Feb 28 16:14:30 2013
@@ -32,18 +32,16 @@ import org.apache.qpid.server.flow.Limit
import org.apache.qpid.server.flow.Pre0_10CreditManager;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
-import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.protocol.AMQProtocolSession;
-import org.apache.qpid.server.protocol.InternalTestProtocolSession;
-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.Subscription;
import org.apache.qpid.server.subscription.SubscriptionFactoryImpl;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.ArrayList;
import java.util.Set;
@@ -51,7 +49,7 @@ import java.util.Set;
/**
* Tests that acknowledgements are handled correctly.
*/
-public class AckTest extends InternalBrokerBaseCase
+public class AckTest extends QpidTestCase
{
private Subscription _subscription;
@@ -70,15 +68,19 @@ public class AckTest extends InternalBro
public void setUp() throws Exception
{
super.setUp();
- _virtualHost = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
- _messageStore = new TestableMemoryMessageStore();
- _protocolSession = new InternalTestProtocolSession(_virtualHost);
- _channel = new AMQChannel(_protocolSession,5, _messageStore /*dont need exchange registry*/);
-
- _protocolSession.addChannel(_channel);
+ BrokerTestHelper.setUp();
+ _channel = BrokerTestHelper.createChannel(5);
+ _protocolSession = _channel.getProtocolSession();
+ _virtualHost = _protocolSession.getVirtualHost();
+ _queue = BrokerTestHelper.createQueue(getTestName(), _virtualHost);
+ _messageStore = (TestableMemoryMessageStore)_virtualHost.getMessageStore();
+ }
- _queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), "myQ", false, "guest", true, false,
- _virtualHost, null);
+ @Override
+ protected void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
}
private void publishMessages(int count) throws AMQException
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/MockAMQQueue.java Thu Feb 28 16:14:30 2013
@@ -23,10 +23,8 @@ package org.apache.qpid.server.queue;
import org.apache.qpid.AMQException;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.server.binding.Binding;
-import org.apache.qpid.server.configuration.ConfigStore;
-import org.apache.qpid.server.configuration.ConfiguredObject;
-import org.apache.qpid.server.configuration.QueueConfigType;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.configuration.QueueConfiguration;
+import org.apache.qpid.server.configuration.plugins.AbstractConfiguration;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.logging.LogSubject;
import org.apache.qpid.server.message.ServerMessage;
@@ -106,11 +104,6 @@ public class MockAMQQueue implements AMQ
return 0;
}
- public ConfigStore getConfigStore()
- {
- return getVirtualHost().getConfigStore();
- }
-
public long getMessageDequeueCount()
{
return 0;
@@ -186,22 +179,6 @@ public class MockAMQQueue implements AMQ
return null;
}
- @Override
- public UUID getQMFId()
- {
- return null;
- }
-
- public QueueConfigType getConfigType()
- {
- return null;
- }
-
- public ConfiguredObject getParent()
- {
- return null;
- }
-
public boolean isDurable()
{
return false;
@@ -532,16 +509,11 @@ public class MockAMQQueue implements AMQ
}
- public void configure(ConfigurationPlugin config)
+ public void configure(QueueConfiguration config)
{
}
- public ConfigurationPlugin getConfiguration()
- {
- return null;
- }
-
public AuthorizationHolder getAuthorizationHolder()
{
return _authorizationHolder;
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueTest.java Thu Feb 28 16:14:30 2013
@@ -28,8 +28,6 @@ import static org.mockito.Mockito.atLeas
import static org.mockito.Matchers.contains;
import static org.mockito.Matchers.eq;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQInternalException;
import org.apache.qpid.AMQSecurityException;
@@ -39,7 +37,6 @@ import org.apache.qpid.framing.BasicCont
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.FieldTable;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
-import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DirectExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
@@ -47,16 +44,15 @@ import org.apache.qpid.server.message.Se
import org.apache.qpid.server.model.UUIDGenerator;
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.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
-import org.apache.qpid.server.virtualhost.VirtualHostImpl;
+import org.apache.qpid.test.utils.QpidTestCase;
import java.util.ArrayList;
import java.util.Collections;
@@ -64,17 +60,17 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-public class SimpleAMQQueueTest extends InternalBrokerBaseCase
+public class SimpleAMQQueueTest extends QpidTestCase
{
- protected SimpleAMQQueue _queue;
- protected VirtualHost _virtualHost;
- protected AMQShortString _qname = new AMQShortString("qname");
- protected AMQShortString _owner = new AMQShortString("owner");
- protected AMQShortString _routingKey = new AMQShortString("routing key");
- protected DirectExchange _exchange;
- protected MockSubscription _subscription = new MockSubscription();
- protected FieldTable _arguments = null;
+ private SimpleAMQQueue _queue;
+ private VirtualHost _virtualHost;
+ private AMQShortString _qname = new AMQShortString("qname");
+ private AMQShortString _owner = new AMQShortString("owner");
+ private AMQShortString _routingKey = new AMQShortString("routing key");
+ private DirectExchange _exchange;
+ private MockSubscription _subscription = new MockSubscription();
+ private FieldTable _arguments = null;
private MessagePublishInfo info = new MessagePublishInfo()
{
@@ -108,25 +104,29 @@ public class SimpleAMQQueueTest extends
public void setUp() throws Exception
{
super.setUp();
- //Create Application Registry for test
- ApplicationRegistry applicationRegistry = (ApplicationRegistry)ApplicationRegistry.getInstance();
+ BrokerTestHelper.setUp();
- PropertiesConfiguration env = new PropertiesConfiguration();
- final VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration(getClass().getName(), env);
- vhostConfig.setMessageStoreClass(TestableMemoryMessageStore.class.getName());
- _virtualHost = new VirtualHostImpl(ApplicationRegistry.getInstance(), vhostConfig);
- applicationRegistry.getVirtualHostRegistry().registerVirtualHost(_virtualHost);
+ _virtualHost = BrokerTestHelper.createVirtualHost(getClass().getName());
- _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), _qname.asString(), false, _owner.asString(), false, false, _virtualHost, FieldTable.convertToMap(_arguments));
+ _queue = (SimpleAMQQueue) AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateRandomUUID(), _qname.asString(), false, _owner.asString(),
+ false, false, _virtualHost, FieldTable.convertToMap(_arguments));
- _exchange = (DirectExchange)_virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME);
+ _exchange = (DirectExchange) _virtualHost.getExchangeRegistry().getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME);
}
@Override
public void tearDown() throws Exception
{
- _queue.stop();
- super.tearDown();
+ try
+ {
+ _queue.stop();
+ _virtualHost.close();
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
}
public void testCreateQueue() throws AMQException
@@ -659,7 +659,7 @@ public class SimpleAMQQueueTest extends
public void onRollback()
{
}
- }, 0L);
+ });
// Check that it is enqueued
AMQQueue data = store.getMessages().get(1L);
@@ -1269,6 +1269,26 @@ public class SimpleAMQQueueTest extends
}
}
+ public SimpleAMQQueue getQueue()
+ {
+ return _queue;
+ }
+
+ public MockSubscription getSubscription()
+ {
+ return _subscription;
+ }
+
+ public FieldTable getArguments()
+ {
+ return _arguments;
+ }
+
+ public void setArguments(FieldTable arguments)
+ {
+ _arguments = arguments;
+ }
+
public class TestMessage extends AMQMessage
{
private final long _tag;
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/queue/SimpleAMQQueueThreadPoolTest.java Thu Feb 28 16:14:30 2013
@@ -20,20 +20,33 @@
*/
package org.apache.qpid.server.queue;
-import org.apache.qpid.AMQException;
import org.apache.qpid.pool.ReferenceCountingExecutorService;
import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class SimpleAMQQueueThreadPoolTest extends InternalBrokerBaseCase
+public class SimpleAMQQueueThreadPoolTest extends QpidTestCase
{
- public void test() throws AMQException
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ BrokerTestHelper.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+
+ public void test() throws Exception
{
int initialCount = ReferenceCountingExecutorService.getInstance().getReferenceCount();
- VirtualHost test = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHost("test");
+ VirtualHost test = BrokerTestHelper.createVirtualHost("test");
try
{
@@ -50,7 +63,7 @@ public class SimpleAMQQueueThreadPoolTes
}
finally
{
- ApplicationRegistry.remove();
+ test.close();
}
}
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/Base64MD5PasswordFilePrincipalDatabaseTest.java Thu Feb 28 16:14:30 2013
@@ -23,7 +23,7 @@ package org.apache.qpid.server.security.
import junit.framework.TestCase;
import org.apache.commons.codec.binary.Base64;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.login.AccountNotFoundException;
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/database/PlainPasswordFilePrincipalDatabaseTest.java Thu Feb 28 16:14:30 2013
@@ -22,7 +22,7 @@ package org.apache.qpid.server.security.
import junit.framework.TestCase;
-import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
import javax.security.auth.login.AccountNotFoundException;
import java.io.BufferedReader;
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/AnonymousAuthenticationManagerTest.java Thu Feb 28 16:14:30 2013
@@ -20,26 +20,17 @@
*/
package org.apache.qpid.server.security.auth.manager;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+
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.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class AnonymousAuthenticationManagerTest extends InternalBrokerBaseCase
+public class AnonymousAuthenticationManagerTest extends QpidTestCase
{
-
- private AuthenticationManager _manager = null;
-
- public void setUp() throws Exception
- {
- _manager = AnonymousAuthenticationManager.INSTANCE;
- }
-
+ private AuthenticationManager _manager = new AnonymousAuthenticationManager();
public void tearDown() throws Exception
{
@@ -49,29 +40,6 @@ public class AnonymousAuthenticationMana
}
}
- private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
-
- public void testConfiguration() throws Exception
- {
- AuthenticationManager authenticationManager =
- AnonymousAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
-
- assertNull("AnonymousAuthenticationManager unexpectedly created when not in config", authenticationManager);
- }
-
public void testGetMechanisms() throws Exception
{
assertEquals("ANONYMOUS", _manager.getMechanisms());
@@ -102,7 +70,8 @@ public class AnonymousAuthenticationMana
assertEquals("Expected authentication to be successful",
AuthenticationResult.AuthenticationStatus.SUCCESS,
result.getStatus());
- assertNotNull("Subject should not be null", result.getSubject());
+
+ assertOnlyContainsWrapped(AnonymousAuthenticationManager.ANONYMOUS_PRINCIPAL, result.getPrincipals());
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationManagerTest.java Thu Feb 28 16:14:30 2013
@@ -18,58 +18,18 @@
*/
package org.apache.qpid.server.security.auth.manager;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+
import javax.security.auth.x500.X500Principal;
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.database.PlainPasswordFilePrincipalDatabase;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.test.utils.QpidTestCase;
-public class ExternalAuthenticationManagerTest extends InternalBrokerBaseCase
+public class ExternalAuthenticationManagerTest extends QpidTestCase
{
-
- private AuthenticationManager _manager = null;
-
- public void setUp() throws Exception
- {
- _manager = ExternalAuthenticationManager.INSTANCE;
- }
-
-
- public void tearDown() throws Exception
- {
- if(_manager != null)
- {
- _manager = null;
- }
- }
-
- private ConfigurationPlugin getPlainDatabaseConfig() throws ConfigurationException
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
-
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", PlainPasswordFilePrincipalDatabase.class.getName());
-
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
- }
-
-
- public void testConfiguration() throws Exception
- {
- AuthenticationManager authenticationManager =
- ExternalAuthenticationManager.FACTORY.newInstance(getPlainDatabaseConfig());
-
- assertNull("ExternalAuthenticationManager unexpectedly created when not in config", authenticationManager);
- }
+ private AuthenticationManager _manager = new ExternalAuthenticationManager();
public void testGetMechanisms() throws Exception
{
@@ -103,12 +63,12 @@ public class ExternalAuthenticationManag
assertEquals("Expected authentication to be successful",
AuthenticationResult.AuthenticationStatus.SUCCESS,
result.getStatus());
- assertEquals("Expected principal to be unchanged",
- principal,
- result.getSubject().getPrincipals().iterator().next());
+
+ assertOnlyContainsWrapped(principal, result.getPrincipals());
saslServer = _manager.createSaslServer("EXTERNAL", "example.example.com", null);
result = _manager.authenticate(saslServer, new byte[0]);
+
assertNotNull(result);
assertEquals("Expected authentication to be unsuccessful",
AuthenticationResult.AuthenticationStatus.ERROR,
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManagerTest.java Thu Feb 28 16:14:30 2013
@@ -20,132 +20,92 @@
*/
package org.apache.qpid.server.security.auth.manager;
-import org.apache.commons.configuration.CompositeConfiguration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
+import static org.apache.qpid.server.security.auth.AuthenticatedPrincipalTestHelper.assertOnlyContainsWrapped;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-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;
+import java.security.Provider;
+import java.security.Security;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
-import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.security.Provider;
-import java.security.Security;
+import javax.security.sasl.SaslServerFactory;
+
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.AuthenticationResult.AuthenticationStatus;
+import org.apache.qpid.server.security.auth.UsernamePrincipal;
+import org.apache.qpid.server.security.auth.database.PrincipalDatabase;
+import org.apache.qpid.server.security.auth.sasl.AuthenticationProviderInitialiser;
+import org.apache.qpid.server.security.auth.sasl.UsernamePasswordInitialiser;
+import org.apache.qpid.test.utils.QpidTestCase;
/**
- *
* Tests the public methods of PrincipalDatabaseAuthenticationManager.
*
*/
-public class PrincipalDatabaseAuthenticationManagerTest extends InternalBrokerBaseCase
+public class PrincipalDatabaseAuthenticationManagerTest extends QpidTestCase
{
+ private static final String MOCK_MECH_NAME = "MOCK-MECH-NAME";
+ private static final UsernamePrincipal PRINCIPAL = new UsernamePrincipal("guest");
+
private AuthenticationManager _manager = null; // Class under test
- private String TEST_USERNAME = "guest";
- private String TEST_PASSWORD = "guest";
+ private PrincipalDatabase _principalDatabase;
- /**
- * @see org.apache.qpid.server.util.InternalBrokerBaseCase#tearDown()
- */
@Override
public void tearDown() throws Exception
{
- super.tearDown();
if (_manager != null)
{
_manager.close();
}
+ super.tearDown();
}
- /**
- * @see org.apache.qpid.server.util.InternalBrokerBaseCase#setUp()
- */
- @Override
- public void setUp() throws Exception
+ private void setupMocks() throws Exception
{
- super.setUp();
-
- final String passwdFilename = createPasswordFile().getCanonicalPath();
- final ConfigurationPlugin config = getConfig(PlainPasswordFilePrincipalDatabase.class.getName(),
- "passwordFile", passwdFilename);
+ _principalDatabase = mock(PrincipalDatabase.class);
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(config);
- }
+ AuthenticationProviderInitialiser _mockMechInitialiser = mock(AuthenticationProviderInitialiser.class);
+ Map<String, AuthenticationProviderInitialiser> _initialisers = Collections.singletonMap(MOCK_MECH_NAME, _mockMechInitialiser);
- /**
- * 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
- }
- }
+ when(_principalDatabase.getMechanisms()).thenReturn(_initialisers);
- /**
- * 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
- }
+ _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase);
+ _manager.initialise();
}
- /**
- * Tests the case where a setter with the desired name cannot be found.
- */
- public void testPrincipalDatabaseSetterNotFound() throws Exception
+ private void setupMocksWithInitialiser() throws Exception
{
- try
- {
- _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "noMethod", "test"));
- fail("Exception not thrown");
- }
- catch (ConfigurationException ce)
- {
- // PASS
- }
- }
+ _principalDatabase = mock(PrincipalDatabase.class);
- /**
- * 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)
+ UsernamePasswordInitialiser usernamePasswordInitialiser = new UsernamePasswordInitialiser()
{
- // PASS
- assertNotNull("Expected an underlying cause", ce.getCause());
- assertEquals(FileNotFoundException.class, ce.getCause().getClass());
- }
+ @Override
+ public Class<? extends SaslServerFactory> getServerFactoryClassForJCARegistration()
+ {
+ return MySaslServerFactory.class;
+ }
+
+ @Override
+ public String getMechanismName()
+ {
+ return MOCK_MECH_NAME;
+ }
+ };
+
+ Map<String,AuthenticationProviderInitialiser> initialisers = new HashMap<String, AuthenticationProviderInitialiser>();
+ initialisers.put(MOCK_MECH_NAME, usernamePasswordInitialiser);
+
+ when(_principalDatabase.getMechanisms()).thenReturn(initialisers);
+
+ usernamePasswordInitialiser.initialise(_principalDatabase);
+
+ _manager = new PrincipalDatabaseAuthenticationManager(_principalDatabase);
+ _manager.initialise();
}
/**
@@ -153,11 +113,16 @@ public class PrincipalDatabaseAuthentica
*/
public void testRegisteredMechanisms() throws Exception
{
+ //Ensure we haven't registered anything yet (though this would really indicate a prior test failure!)
+ Provider qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
+ assertNull(qpidProvider);
+
+ setupMocksWithInitialiser();
+
assertNotNull(_manager.getMechanisms());
- // relies on those mechanisms attached to PropertiesPrincipalDatabaseManager
- assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
+ assertEquals(MOCK_MECH_NAME, _manager.getMechanisms());
- Provider qpidProvider = Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME);
+ qpidProvider = Security.getProvider(AuthenticationManager.PROVIDER_NAME);
assertNotNull(qpidProvider);
}
@@ -167,96 +132,103 @@ public class PrincipalDatabaseAuthentica
*/
public void testSaslMechanismCreation() throws Exception
{
- SaslServer server = _manager.createSaslServer("CRAM-MD5", "localhost", null);
+ setupMocksWithInitialiser();
+
+ SaslServer server = _manager.createSaslServer(MOCK_MECH_NAME, "localhost", null);
assertNotNull(server);
// Merely tests the creation of the mechanism. Mechanisms themselves are tested
// by their own tests.
}
-
+
/**
* Tests that the authenticate method correctly interprets an
* authentication success.
- *
+ *
*/
public void testSaslAuthenticationSuccess() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(true, false);
-
+
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
- final Subject subject = result.getSubject();
- assertTrue(subject.getPrincipals().contains(new UsernamePrincipal("guest")));
+
+ assertOnlyContainsWrapped(PRINCIPAL, result.getPrincipals());
assertEquals(AuthenticationStatus.SUCCESS, result.getStatus());
}
/**
- *
+ *
* Tests that the authenticate method correctly interprets an
* authentication not complete.
- *
+ *
*/
public void testSaslAuthenticationNotCompleted() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(false, false);
-
+
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
- assertNull(result.getSubject());
+ assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
+
assertEquals(AuthenticationStatus.CONTINUE, result.getStatus());
}
/**
- *
+ *
* Tests that the authenticate method correctly interprets an
* authentication error.
- *
+ *
*/
public void testSaslAuthenticationError() throws Exception
{
+ setupMocks();
+
SaslServer testServer = createTestSaslServer(false, true);
-
+
AuthenticationResult result = _manager.authenticate(testServer, "12345".getBytes());
- assertNull(result.getSubject());
+ assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
- /**
- * Tests that the authenticate method correctly interprets an
- * authentication success.
- *
- */
public void testNonSaslAuthenticationSuccess() throws Exception
{
+ setupMocks();
+
+ when(_principalDatabase.verifyPassword("guest", "guest".toCharArray())).thenReturn(true);
+
AuthenticationResult result = _manager.authenticate("guest", "guest");
- final Subject subject = result.getSubject();
- assertFalse("Subject should not be set read-only", subject.isReadOnly());
- assertTrue(subject.getPrincipals().contains(new UsernamePrincipal("guest")));
+ assertOnlyContainsWrapped(PRINCIPAL, result.getPrincipals());
assertEquals(AuthenticationStatus.SUCCESS, result.getStatus());
}
- /**
- * Tests that the authenticate method correctly interprets an
- * authentication success.
- *
- */
public void testNonSaslAuthenticationNotCompleted() throws Exception
{
+ setupMocks();
+
+ when(_principalDatabase.verifyPassword("guest", "wrongpassword".toCharArray())).thenReturn(false);
+
AuthenticationResult result = _manager.authenticate("guest", "wrongpassword");
- assertNull(result.getSubject());
+ assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.CONTINUE, result.getStatus());
}
-
+
/**
* Tests the ability to de-register the provider.
*/
public void testClose() throws Exception
{
- assertEquals("AMQPLAIN PLAIN CRAM-MD5", _manager.getMechanisms());
- assertNotNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
+ setupMocksWithInitialiser();
+
+ assertEquals(MOCK_MECH_NAME, _manager.getMechanisms());
+ assertNotNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME));
_manager.close();
// Check provider has been removed.
assertNull(_manager.getMechanisms());
- assertNull(Security.getProvider(PrincipalDatabaseAuthenticationManager.PROVIDER_NAME));
+ assertNull(Security.getProvider(AuthenticationManager.PROVIDER_NAME));
_manager = null;
}
@@ -265,94 +237,90 @@ public class PrincipalDatabaseAuthentica
*/
private SaslServer createTestSaslServer(final boolean complete, final boolean throwSaslException)
{
- return new SaslServer()
- {
- public String getMechanismName()
- {
- return null;
- }
+ return new MySaslServer(throwSaslException, complete);
+ }
- public byte[] evaluateResponse(byte[] response) throws SaslException
- {
- if (throwSaslException)
- {
- throw new SaslException("Mocked exception");
- }
- return null;
- }
+ public static final class MySaslServer implements SaslServer
+ {
+ private final boolean _throwSaslException;
+ private final boolean _complete;
- public boolean isComplete()
- {
- return complete;
- }
+ public MySaslServer()
+ {
+ this(false, true);
+ }
- public String getAuthorizationID()
- {
- return complete ? "guest" : null;
- }
+ private MySaslServer(boolean throwSaslException, boolean complete)
+ {
+ _throwSaslException = throwSaslException;
+ _complete = complete;
+ }
- public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
- {
- return null;
- }
+ public String getMechanismName()
+ {
+ return null;
+ }
- public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
+ public byte[] evaluateResponse(byte[] response) throws SaslException
+ {
+ if (_throwSaslException)
{
- return null;
+ throw new SaslException("Mocked exception");
}
+ return null;
+ }
- public Object getNegotiatedProperty(String propName)
- {
- return null;
- }
+ public boolean isComplete()
+ {
+ return _complete;
+ }
- public void dispose() throws SaslException
- {
- }
- };
- }
+ public String getAuthorizationID()
+ {
+ return _complete ? "guest" : null;
+ }
- private ConfigurationPlugin getConfig(final String clazz, final String argName, final String argValue) throws Exception
- {
- final ConfigurationPlugin config = new PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration();
+ public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException
+ {
+ return null;
+ }
- XMLConfiguration xmlconfig = new XMLConfiguration();
- xmlconfig.addProperty("pd-auth-manager.principal-database.class", clazz);
+ public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException
+ {
+ return null;
+ }
- if (argName != null)
+ public Object getNegotiatedProperty(String propName)
{
- xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.name", argName);
- xmlconfig.addProperty("pd-auth-manager.principal-database.attributes.attribute.value", argValue);
+ return null;
}
- // Create a CompositeConfiguration as this is what the broker uses
- CompositeConfiguration composite = new CompositeConfiguration();
- composite.addConfiguration(xmlconfig);
- config.setConfiguration("security", xmlconfig);
- return config;
+ public void dispose() throws SaslException
+ {
+ }
}
- private File createPasswordFile() throws Exception
+ public static class MySaslServerFactory implements SaslServerFactory
{
- 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
+ @Override
+ public SaslServer createSaslServer(String mechanism, String protocol,
+ String serverName, Map<String, ?> props, CallbackHandler cbh)
+ throws SaslException
{
- if (writer != null)
+ if (MOCK_MECH_NAME.equals(mechanism))
{
- writer.close();
+ return new MySaslServer();
}
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public String[] getMechanismNames(Map<String, ?> props)
+ {
+ return new String[]{MOCK_MECH_NAME};
}
}
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/rmi/RMIPasswordAuthenticatorTest.java Thu Feb 28 16:14:30 2013
@@ -20,20 +20,26 @@
*/
package org.apache.qpid.server.security.auth.rmi;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.security.Principal;
+import java.util.regex.Pattern;
+
+import javax.security.auth.Subject;
+
import junit.framework.TestCase;
-import org.apache.qpid.server.configuration.plugins.ConfigurationPlugin;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.security.SubjectCreator;
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;
-
-import javax.management.remote.JMXPrincipal;
-import javax.security.auth.Subject;
-import javax.security.sasl.SaslException;
-import javax.security.sasl.SaslServer;
-import java.net.InetSocketAddress;
-import java.util.Collections;
+import org.apache.qpid.server.security.auth.SubjectAuthenticationResult;
+import org.apache.qpid.server.security.SecurityManager;
/**
* Tests the RMIPasswordAuthenticator and its collaboration with the AuthenticationManager.
@@ -41,36 +47,35 @@ import java.util.Collections;
*/
public class RMIPasswordAuthenticatorTest extends TestCase
{
- private final String USERNAME = "guest";
- private final String PASSWORD = "guest";
+ private static final String USERNAME = "guest";
+ private static final String PASSWORD = "password";
+
+ private final Broker _broker = mock(Broker.class);
+ private final SecurityManager _securityManager = mock(SecurityManager.class);
+ private final Subject _loginSubject = new Subject();
+ private final String[] _credentials = new String[] {USERNAME, PASSWORD};
+
private RMIPasswordAuthenticator _rmipa;
- private String[] _credentials;
+
+ private SubjectCreator _usernamePasswordOkaySuvjectCreator = createMockSubjectCreator(true, null);
+ private SubjectCreator _badPasswordSubjectCreator = createMockSubjectCreator(false, null);
protected void setUp() throws Exception
{
- _rmipa = new RMIPasswordAuthenticator(new InetSocketAddress(5672));
-
- _credentials = new String[] {USERNAME, PASSWORD};
+ when(_broker.getSecurityManager()).thenReturn(_securityManager);
+ _rmipa = new RMIPasswordAuthenticator(_broker, new InetSocketAddress(8999));
}
/**
- * Tests a successful authentication. Ensures that a populated read-only subject it returned.
+ * Tests a successful authentication. Ensures that the expected subject is returned.
*/
public void testAuthenticationSuccess()
{
- final Subject expectedSubject = new Subject(true,
- Collections.singleton(new JMXPrincipal(USERNAME)),
- Collections.EMPTY_SET,
- Collections.EMPTY_SET);
-
- _rmipa.setAuthenticationManager(createTestAuthenticationManager(true, null));
-
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_usernamePasswordOkaySuvjectCreator);
+ when(_securityManager.accessManagement()).thenReturn(true);
Subject newSubject = _rmipa.authenticate(_credentials);
- assertTrue("Subject must be readonly", newSubject.isReadOnly());
- assertTrue("Returned subject does not equal expected value",
- newSubject.equals(expectedSubject));
-
+ assertSame("Subject must be unchanged", _loginSubject, newSubject);
}
/**
@@ -78,7 +83,7 @@ public class RMIPasswordAuthenticatorTes
*/
public void testUsernameOrPasswordInvalid()
{
- _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, null));
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_badPasswordSubjectCreator);
try
{
@@ -89,17 +94,31 @@ public class RMIPasswordAuthenticatorTes
{
assertEquals("Unexpected exception message",
RMIPasswordAuthenticator.INVALID_CREDENTIALS, se.getMessage());
+ }
+ }
+ public void testAuthorisationFailure()
+ {
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(_usernamePasswordOkaySuvjectCreator);
+ when(_securityManager.accessManagement()).thenReturn(false);
+
+ try
+ {
+ _rmipa.authenticate(_credentials);
+ fail("Exception not thrown");
+ }
+ catch (SecurityException se)
+ {
+ assertEquals("Unexpected exception message",
+ RMIPasswordAuthenticator.USER_NOT_AUTHORISED_FOR_MANAGEMENT, se.getMessage());
}
}
- /**
- * Tests case where authentication system itself fails.
- */
- public void testAuthenticationFailure()
+ public void testSubjectCreatorInternalFailure()
{
final Exception mockAuthException = new Exception("Mock Auth system failure");
- _rmipa.setAuthenticationManager(createTestAuthenticationManager(false, mockAuthException));
+ SubjectCreator subjectCreator = createMockSubjectCreator(false, mockAuthException);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(subjectCreator);
try
{
@@ -112,13 +131,13 @@ public class RMIPasswordAuthenticatorTes
}
}
-
/**
* Tests case where authentication manager is not set.
*/
- public void testNullAuthenticationManager() throws Exception
+ public void testNullSubjectCreator() throws Exception
{
- _rmipa.setAuthenticationManager(null);
+ when(_broker.getSubjectCreator(any(SocketAddress.class))).thenReturn(null);
+
try
{
_rmipa.authenticate(_credentials);
@@ -126,8 +145,7 @@ public class RMIPasswordAuthenticatorTes
}
catch (SecurityException se)
{
- assertEquals("Unexpected exception message",
- RMIPasswordAuthenticator.UNABLE_TO_LOOKUP, se.getMessage());
+ assertTrue("Unexpected exception message", Pattern.matches("Can't get subject creator for .*:8999", se.getMessage()));
}
}
@@ -155,11 +173,13 @@ public class RMIPasswordAuthenticatorTes
*/
public void testWithIllegalNumberOfArguments()
{
+ String[] credentials;
+
// Test handling of incorrect number of credentials
try
{
- _credentials = new String[]{USERNAME, PASSWORD, PASSWORD};
- _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)
@@ -172,8 +192,8 @@ public class RMIPasswordAuthenticatorTes
try
{
//send a null array
- _credentials = null;
- _rmipa.authenticate(_credentials);
+ credentials = null;
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to not supplying an array of credentials");
}
catch (SecurityException se)
@@ -185,8 +205,8 @@ public class RMIPasswordAuthenticatorTes
try
{
//send a null password
- _credentials = new String[]{USERNAME, null};
- _rmipa.authenticate(_credentials);
+ credentials = new String[]{USERNAME, null};
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to sending a null password");
}
catch (SecurityException se)
@@ -198,8 +218,8 @@ public class RMIPasswordAuthenticatorTes
try
{
//send a null username
- _credentials = new String[]{null, PASSWORD};
- _rmipa.authenticate(_credentials);
+ credentials = new String[]{null, PASSWORD};
+ _rmipa.authenticate(credentials);
fail("SecurityException expected due to sending a null username");
}
catch (SecurityException se)
@@ -209,55 +229,30 @@ public class RMIPasswordAuthenticatorTes
}
}
- private AuthenticationManager createTestAuthenticationManager(final boolean successfulAuth, final Exception exception)
+ private SubjectCreator createMockSubjectCreator(final boolean successfulAuth, final Exception exception)
{
- return new AuthenticationManager()
+ SubjectCreator subjectCreator = mock(SubjectCreator.class);
+
+ SubjectAuthenticationResult subjectAuthenticationResult;
+
+ if (exception != null) {
+
+ subjectAuthenticationResult = new SubjectAuthenticationResult(
+ new AuthenticationResult(AuthenticationStatus.ERROR, exception));
+ }
+ else if (successfulAuth)
{
- 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, Principal externalPrincipal) 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);
- }
- }
- };
+ subjectAuthenticationResult = new SubjectAuthenticationResult(
+ new AuthenticationResult(mock(Principal.class)), _loginSubject);
+ }
+ else
+ {
+ subjectAuthenticationResult = new SubjectAuthenticationResult(new AuthenticationResult(AuthenticationStatus.CONTINUE));
+ }
+
+ when(subjectCreator.authenticate(anyString(), anyString())).thenReturn(subjectAuthenticationResult);
+
+ return subjectCreator;
}
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/security/auth/sasl/TestPrincipalDatabase.java Thu Feb 28 16:14:30 2013
@@ -86,4 +86,10 @@ public class TestPrincipalDatabase imple
// TODO Auto-generated method stub
}
+ @Override
+ public void setPasswordFile(String passwordFile) throws IOException
+ {
+ // TODO Auto-generated method stub
+ }
+
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/DurableConfigurationStoreTest.java Thu Feb 28 16:14:30 2013
@@ -51,10 +51,6 @@ import org.apache.qpid.server.message.En
import org.apache.qpid.server.model.UUIDGenerator;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.MockStoredMessage;
-import org.apache.qpid.server.store.ConfigurationRecoveryHandler;
-import org.apache.qpid.server.store.MessageStore;
-import org.apache.qpid.server.store.MessageStoreRecoveryHandler;
-import org.apache.qpid.server.store.TransactionLogRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.BindingRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.ExchangeRecoveryHandler;
import org.apache.qpid.server.store.ConfigurationRecoveryHandler.QueueRecoveryHandler;
@@ -76,7 +72,6 @@ public class DurableConfigurationStoreTe
private QueueRecoveryHandler _queueRecoveryHandler;
private ExchangeRecoveryHandler _exchangeRecoveryHandler;
private BindingRecoveryHandler _bindingRecoveryHandler;
- private ConfigurationRecoveryHandler.BrokerLinkRecoveryHandler _linkRecoveryHandler;
private MessageStoreRecoveryHandler _messageStoreRecoveryHandler;
private StoredMessageRecoveryHandler _storedMessageRecoveryHandler;
private TransactionLogRecoveryHandler _logRecoveryHandler;
@@ -116,7 +111,6 @@ public class DurableConfigurationStoreTe
when(_recoveryHandler.begin(isA(MessageStore.class))).thenReturn(_exchangeRecoveryHandler);
when(_exchangeRecoveryHandler.completeExchangeRecovery()).thenReturn(_queueRecoveryHandler);
when(_queueRecoveryHandler.completeQueueRecovery()).thenReturn(_bindingRecoveryHandler);
- when(_bindingRecoveryHandler.completeBindingRecovery()).thenReturn(_linkRecoveryHandler);
when(_logRecoveryHandler.begin(any(MessageStore.class))).thenReturn(_queueEntryRecoveryHandler);
when(_queueEntryRecoveryHandler.completeQueueEntryRecovery()).thenReturn(_dtxRecordRecoveryHandler);
when(_exchange.getNameShortString()).thenReturn(AMQShortString.valueOf(EXCHANGE_NAME));
@@ -161,7 +155,7 @@ public class DurableConfigurationStoreTe
public void testBindQueue() throws Exception
{
AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
- Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), null, ROUTING_KEY, queue,
+ Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), ROUTING_KEY, queue,
_exchange, FieldTable.convertToMap(_bindingArgs));
_store.bindQueue(binding);
@@ -175,7 +169,7 @@ public class DurableConfigurationStoreTe
public void testUnbindQueue() throws Exception
{
AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
- Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), null, ROUTING_KEY, queue,
+ Binding binding = new Binding(UUIDGenerator.generateRandomUUID(), ROUTING_KEY, queue,
_exchange, FieldTable.convertToMap(_bindingArgs));
_store.bindQueue(binding);
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java Thu Feb 28 16:14:30 2013
@@ -20,6 +20,7 @@
*/
package org.apache.qpid.server.store;
+
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.qpid.AMQException;
@@ -35,11 +36,12 @@ import org.apache.qpid.server.configurat
import org.apache.qpid.server.exchange.DirectExchange;
import org.apache.qpid.server.exchange.Exchange;
import org.apache.qpid.server.exchange.ExchangeRegistry;
-import org.apache.qpid.server.exchange.ExchangeType;
import org.apache.qpid.server.exchange.TopicExchange;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
+import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.server.plugin.ExchangeType;
import org.apache.qpid.server.queue.AMQPriorityQueue;
import org.apache.qpid.server.queue.AMQQueue;
import org.apache.qpid.server.queue.AMQQueueFactory;
@@ -48,11 +50,11 @@ import org.apache.qpid.server.queue.Conf
import org.apache.qpid.server.queue.IncomingMessage;
import org.apache.qpid.server.queue.QueueRegistry;
import org.apache.qpid.server.queue.SimpleAMQQueue;
-import org.apache.qpid.server.registry.ApplicationRegistry;
import org.apache.qpid.server.txn.AutoCommitTransaction;
import org.apache.qpid.server.txn.ServerTransaction;
-import org.apache.qpid.server.util.InternalBrokerBaseCase;
+import org.apache.qpid.server.util.BrokerTestHelper;
import org.apache.qpid.server.virtualhost.VirtualHost;
+import org.apache.qpid.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
import java.io.File;
@@ -66,7 +68,7 @@ import java.util.Map;
* For persistent stores, it validates that Exchanges, Queues, Bindings and
* Messages are persisted and recovered correctly.
*/
-public class MessageStoreTest extends InternalBrokerBaseCase
+public class MessageStoreTest extends QpidTestCase
{
public static final int DEFAULT_PRIORTY_LEVEL = 5;
public static final String SELECTOR_VALUE = "Test = 'MST'";
@@ -93,11 +95,15 @@ public class MessageStoreTest extends In
private AMQShortString queueOwner = new AMQShortString("MST");
- protected PropertiesConfiguration _config;
+ private PropertiesConfiguration _config;
+
+ private VirtualHost _virtualHost;
+ private Broker _broker;
public void setUp() throws Exception
{
super.setUp();
+ BrokerTestHelper.setUp();
String storePath = System.getProperty("QPID_WORK") + File.separator + getName();
@@ -107,9 +113,38 @@ public class MessageStoreTest extends In
cleanup(new File(storePath));
+ _broker = BrokerTestHelper.createBrokerMock();
+
reloadVirtualHost();
}
+ @Override
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ if (_virtualHost != null)
+ {
+ _virtualHost.close();
+ }
+ }
+ finally
+ {
+ BrokerTestHelper.tearDown();
+ super.tearDown();
+ }
+ }
+
+ public VirtualHost getVirtualHost()
+ {
+ return _virtualHost;
+ }
+
+ public PropertiesConfiguration getConfig()
+ {
+ return _config;
+ }
+
protected void reloadVirtualHost()
{
VirtualHost original = getVirtualHost();
@@ -119,8 +154,6 @@ public class MessageStoreTest extends In
try
{
getVirtualHost().close();
- getVirtualHost().getApplicationRegistry().
- getVirtualHostRegistry().unregisterVirtualHost(getVirtualHost());
}
catch (Exception e)
{
@@ -131,7 +164,7 @@ public class MessageStoreTest extends In
try
{
- setVirtualHost(ApplicationRegistry.getInstance().createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config)));
+ _virtualHost = BrokerTestHelper.createVirtualHost(new VirtualHostConfiguration(getClass().getName(), _config, _broker));
}
catch (Exception e)
{
@@ -628,7 +661,7 @@ public class MessageStoreTest extends In
{
//To change body of implemented methods use File | Settings | File Templates.
}
- }, 0L);
+ });
}
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/store/ReferenceCountingTest.java Thu Feb 28 16:14:30 2013
@@ -27,6 +27,7 @@ import org.apache.qpid.framing.ContentHe
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
import org.apache.qpid.server.message.AMQMessage;
import org.apache.qpid.server.message.MessageMetaData;
+import org.apache.qpid.server.message.MessageReference;
import org.apache.qpid.test.utils.QpidTestCase;
/**
@@ -86,10 +87,12 @@ public class ReferenceCountingTest exten
AMQMessage message = new AMQMessage(storedMessage);
- message.incrementReference();
+ MessageReference ref = message.newReference();
assertEquals(1, _store.getMessageCount());
- message.decrementReference();
+
+ ref.release();
+
assertEquals(0, _store.getMessageCount());
}
@@ -142,13 +145,13 @@ public class ReferenceCountingTest exten
AMQMessage message = new AMQMessage(storedMessage);
- message.incrementReference();
+ MessageReference ref = message.newReference();
// we call routing complete to set up the handle
// message.routingComplete(_store, _storeContext, new MessageHandleFactory());
assertEquals(1, _store.getMessageCount());
- message.incrementReference();
- message.decrementReference();
+ MessageReference ref2 = message.newReference();
+ ref.release();
assertEquals(1, _store.getMessageCount());
}
Modified: qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java
URL: http://svn.apache.org/viewvc/qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java?rev=1451244&r1=1451243&r2=1451244&view=diff
==============================================================================
--- qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java (original)
+++ qpid/branches/asyncstore/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java Thu Feb 28 16:14:30 2013
@@ -294,17 +294,12 @@ public class MockSubscription implements
private static class MockSessionModel implements AMQSessionModel
{
+ private final UUID _id = UUID.randomUUID();
@Override
- public int compareTo(AMQSessionModel o)
- {
- return 0;
- }
-
- @Override
- public UUID getQMFId()
+ public UUID getId()
{
- return null;
+ return _id;
}
@Override
@@ -409,6 +404,12 @@ public class MockSubscription implements
{
return 0;
}
+
+ @Override
+ public int compareTo(AMQSessionModel o)
+ {
+ return getId().compareTo(o.getId());
+ }
}
private static class MockConnectionModel implements AMQConnectionModel
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org