diff options
| author | Alex Rudyy <orudyy@apache.org> | 2013-02-19 09:35:28 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2013-02-19 09:35:28 +0000 |
| commit | a973713561140fe7395368ae53def8f7edfa18a3 (patch) | |
| tree | 7bda80afada592df681fb73908400e7a189f015f /qpid/java/systests/src | |
| parent | 1b0f1d06188e73e9440dc1789c28ee65e24d539d (diff) | |
| download | qpid-python-a973713561140fe7395368ae53def8f7edfa18a3.tar.gz | |
QPID-4390: Introduce a configuration store in java broker allowing runtime modifications and replace existing xml file configuration with json configuration store
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1447646 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/systests/src')
51 files changed, 995 insertions, 790 deletions
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java index 0e55557806..a0fd093bfe 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java @@ -20,7 +20,6 @@ */ package org.apache.qpid.client.failover; -import java.net.InetSocketAddress; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -33,16 +32,12 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; -import org.apache.commons.configuration.XMLConfiguration; import org.apache.log4j.Logger; -import org.apache.qpid.client.AMQBrokerDetails; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.jms.ConnectionListener; -import org.apache.qpid.server.store.MessageStoreConstants; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestUtils; -import org.apache.qpid.transport.network.NetworkConnection; import org.apache.qpid.util.FileUtils; public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements ConnectionListener @@ -90,10 +85,7 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C } _brokerPorts[i] = port; - XMLConfiguration testConfiguration = new XMLConfiguration(); - testConfiguration.addProperty("management.enabled", "false"); - - XMLConfiguration testVirtualhosts = new XMLConfiguration(); + createBrokerConfiguration(port); String host = null; if (i == 1 || i == _brokerPorts.length - 1) { @@ -103,13 +95,9 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C { host = NON_FAILOVER_VIRTUAL_HOST; } - testVirtualhosts.addProperty("virtualhost.name", host); - testVirtualhosts.addProperty("virtualhost." + host + ".store.class", getTestProfileMessageStoreClassName()); - testVirtualhosts.addProperty( - "virtualhost." + host + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, "${QPID_WORK}/" - + host); + createTestVirtualHost(port, host); - startBroker(port, testConfiguration, testVirtualhosts); + startBroker(port); revertSystemProperties(); } @@ -121,6 +109,11 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C _failoverStarted = new CountDownLatch(1); } + public void startBroker() throws Exception + { + // noop, prevent the broker startup in super.setUp() + } + private String generateUrlString(int numBrokers) { String baseString = "amqp://guest:guest@test/" + FAILOVER_VIRTUAL_HOST @@ -163,10 +156,6 @@ public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements C } } - public void startBroker() throws Exception - { - // noop, stop starting broker in super.tearDown() - } public void testFailoverOnBrokerKill() throws Exception { diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java index 4fafcb3504..884e89fb65 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java @@ -29,13 +29,19 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.client.AMQTestConnection_0_10; import org.apache.qpid.jms.ConnectionURL; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Transport; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import javax.jms.Connection; import javax.jms.JMSException; import javax.jms.Session; import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; public class SSLTest extends QpidBrokerTestCase { @@ -353,17 +359,13 @@ public class SSLTest extends QpidBrokerTestCase { if(isJavaBroker()) { - setConfigurationProperty("connector.ssl.enabled", String.valueOf(sslEnabled)); - setConfigurationProperty("connector.ssl.sslOnly", String.valueOf(sslOnly)); - setConfigurationProperty("connector.ssl.needClientAuth", String.valueOf(needClientAuth)); - setConfigurationProperty("connector.ssl.wantClientAuth", String.valueOf(wantClientAuth)); - - if(needClientAuth || wantClientAuth) - { - //TODO: make a broker trust store? - setConfigurationProperty("connector.ssl.trustStorePath", TRUSTSTORE); - setConfigurationProperty("connector.ssl.trustStorePassword", TRUSTSTORE_PASSWORD); - } + Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); + sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); + sslPortAttributes.put(Port.NEED_CLIENT_AUTH, needClientAuth); + sslPortAttributes.put(Port.WANT_CLIENT_AUTH, wantClientAuth); + sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); + getBrokerConfiguration().addPortConfiguration(sslPortAttributes); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java index e8d72c13bd..23a00431d1 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/SupportedProtocolVersionsTest.java @@ -23,13 +23,17 @@ package org.apache.qpid.server; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.configuration.ClientProperties; import org.apache.qpid.framing.ProtocolVersion; -import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.configuration.BrokerProperties; +import org.apache.qpid.server.model.Protocol; +import org.apache.qpid.server.model.adapter.PortFactoryTest; import org.apache.qpid.test.utils.QpidBrokerTestCase; /** * Tests to validate it is possible to disable support for particular protocol * versions entirely, rather than selectively excluding them on particular ports, * and it is possible to configure the reply to an unsupported protocol initiation. + *<p> + * Protocol exclusion/inclusion are unit tested as part of {@link PortFactoryTest} */ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase { @@ -41,8 +45,8 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase private void clearProtocolSupportManipulations() { //Remove the QBTC provided protocol manipulations, giving only the protocols which default to enabled - setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_EXCLUDES, null); - setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_INCLUDES, null); + setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, null); + setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES, null); } /** @@ -87,8 +91,8 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase clearProtocolSupportManipulations(); //disable 0-10 and 1-0 support - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false"); + setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, + Protocol.AMQP_1_0 + "," + Protocol.AMQP_0_10); super.setUp(); @@ -100,52 +104,14 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase connection.close(); } - public void testDisabling091and010and10() throws Exception - { - clearProtocolSupportManipulations(); - - //disable 0-91 and 0-10 and 1-0 support - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, "false"); - - super.setUp(); - - //Verify initially requesting a 0-10 connection now negotiates a 0-9 - //connection as the broker should reply with its highest supported protocol - setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10"); - AMQConnection connection = (AMQConnection) getConnection(); - assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_9, connection.getProtocolVersion()); - connection.close(); - } - - public void testDisabling09and091and010and10() throws Exception - { - clearProtocolSupportManipulations(); - - //disable 0-9, 0-91, 0-10 and 1-0 support - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP09ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP091ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false"); - - super.setUp(); - - //Verify initially requesting a 0-10 connection now negotiates a 0-8 - //connection as the broker should reply with its highest supported protocol - setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10"); - AMQConnection connection = (AMQConnection) getConnection(); - assertEquals("Unexpected protocol version in use", ProtocolVersion.v8_0, connection.getProtocolVersion()); - connection.close(); - } - public void testConfiguringReplyingToUnsupported010ProtocolInitiationWith09insteadOf091() throws Exception { clearProtocolSupportManipulations(); //disable 0-10 support, and set the default unsupported protocol initiation reply to 0-9 - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP_SUPPORTED_REPLY, "v0_9"); + setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES, + Protocol.AMQP_1_0 + "," + Protocol.AMQP_0_10); + setSystemProperty(BrokerProperties.PROPERTY_DEFAULT_SUPPORTED_PROTOCOL_REPLY, "v0_9"); super.setUp(); @@ -164,71 +130,5 @@ public class SupportedProtocolVersionsTest extends QpidBrokerTestCase connection.close(); } - public void testProtocolInclusionThroughQBTCSystemPropertiesOverridesProtocolExclusion() throws Exception - { - testProtocolInclusionOverridesProtocolExclusion(false); - } - - public void testProtocolInclusionThroughConfigOverridesProtocolExclusion() throws Exception - { - testProtocolInclusionOverridesProtocolExclusion(true); - } - - private void testProtocolInclusionOverridesProtocolExclusion(boolean useConfig) throws Exception - { - clearProtocolSupportManipulations(); - - //selectively exclude 0-10 and 1-0 on the test port - setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_EXCLUDES,"--exclude-0-10 @PORT --exclude-1-0 @PORT"); - - super.setUp(); - - //Verify initially requesting a 0-10 connection negotiates a 0-9-1 connection - setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10"); - AMQConnection connection = (AMQConnection) getConnection(); - assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_91, connection.getProtocolVersion()); - connection.close(); - - stopBroker(); - - if(useConfig) - { - //selectively include 0-10 support again on the test port through config - setConfigurationProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, String.valueOf(getPort())); - } - else - { - //selectively include 0-10 support again on the test port through QBTC sys props - setTestSystemProperty(QpidBrokerTestCase.BROKER_PROTOCOL_INCLUDES,"--include-0-10 @PORT"); - } - - startBroker(); - - //Verify requesting a 0-10 connection now returns one - setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10"); - connection = (AMQConnection) getConnection(); - assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_10, connection.getProtocolVersion()); - connection.close(); - } - - public void testProtocolInclusionOverridesProtocolDisabling() throws Exception - { - clearProtocolSupportManipulations(); - - //disable 0-10 and 1-0 - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP010ENABLED, "false"); - setConfigurationProperty(ServerConfiguration.CONNECTOR_AMQP10ENABLED, "false"); - - //selectively include 0-10 support again on the test port - setConfigurationProperty(ServerConfiguration.CONNECTOR_INCLUDE_010, String.valueOf(getPort())); - - super.setUp(); - - //Verify initially requesting a 0-10 connection still works - setTestClientSystemProperty(ClientProperties.AMQP_VERSION, "0-10"); - AMQConnection connection = (AMQConnection) getConnection(); - assertEquals("Unexpected protocol version in use", ProtocolVersion.v0_10, connection.getProtocolVersion()); - connection.close(); - } }
\ No newline at end of file diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java deleted file mode 100644 index 6f54a56e93..0000000000 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/configuration/ServerConfigurationFileTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.configuration; - -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.test.utils.QpidBrokerTestCase; - -/** - * This system test ensures that when loading our default system-test - * configuration file the configuration is correctly loaded. - * - * All configuration values should be set in the systest config file so that - * the ability to load them can be validated. - */ -public class ServerConfigurationFileTest extends QpidBrokerTestCase -{ - private ServerConfiguration _serverConfig; - - public void setUp() throws ConfigurationException - { - if (!_configFile.exists()) - { - fail("Unable to test without config file:" + _configFile); - } - - saveTestConfiguration(); - saveTestVirtualhosts(); - - _serverConfig = new ServerConfiguration(_configFile); - } - - /** - * This helper method ensures that when we attempt to read a value that is - * set in the configuration file we do actualy read a value and not - * simply get a defaulted value from the ServerConfiguration.get*() methods. - * - * @param property the propert to test - */ - private void validatePropertyDefinedInFile(String property) - { - //Verify that we are not just picking up the the default value from the getBoolean - assertNotNull("The value set in the configuration file is not being read for property:" + property, - _serverConfig.getConfig().getProperty(property)); - } - - public void testStatusUpdates() throws ConfigurationException - { - validatePropertyDefinedInFile(ServerConfiguration.STATUS_UPDATES); - } - - public void testLocale() throws ConfigurationException - { - validatePropertyDefinedInFile(ServerConfiguration.ADVANCED_LOCALE); - } - -} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java index b666b1f424..84017b6850 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AbstractTestLogging.java @@ -20,12 +20,7 @@ */ package org.apache.qpid.server.logging; -import org.apache.commons.configuration.ConfigurationException; - -import org.apache.qpid.server.configuration.ServerConfiguration; import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject; -import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.util.InternalBrokerBaseCase; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.util.LogMonitor; @@ -47,8 +42,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase public static final String TEST_LOG_PREFIX = "MESSAGE"; protected LogMonitor _monitor; - private InternalBrokerBaseCase _configLoader; - @Override public void setUp() throws Exception { @@ -58,32 +51,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase _monitor = new LogMonitor(_outputFile); } - protected ServerConfiguration getServerConfig() throws ConfigurationException - { - ServerConfiguration _serverConfiguration; - if (isExternalBroker()) - { - _serverConfiguration = new ServerConfiguration(_configFile) - { - @Override - public void initialise() throws ConfigurationException - { - //Overriding initialise to only setup the vhosts and not - //perform the ConfigurationPlugin setup, removing need for - //an ApplicationRegistry to be loaded. - setupVirtualHosts(getConfig()); - } - }; - _serverConfiguration.initialise(); - } - else - { - _serverConfiguration = ApplicationRegistry.getInstance().getConfiguration(); - } - - return _serverConfiguration; - } - protected void setLogMessagePrefix() { //set the message prefix to facilitate scraping from the munged test output. @@ -94,10 +61,6 @@ public class AbstractTestLogging extends QpidBrokerTestCase public void tearDown() throws Exception { _monitor.close(); - if (isExternalBroker() && _configLoader != null) - { - _configLoader.tearDown(); - } super.tearDown(); } @@ -159,7 +122,7 @@ public class AbstractTestLogging extends QpidBrokerTestCase } protected String fromMessage(String log) - { + {; int startSubject = log.indexOf("]") + 1; int start = log.indexOf("]", startSubject) + 1; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java index 7c676ad01d..68ec101245 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java @@ -42,8 +42,8 @@ public class AlertingTest extends AbstractTestLogging { _numMessages = 50; - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", String.valueOf(ALERT_LOG_WAIT_PERIOD)); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", String.valueOf(_numMessages)); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", String.valueOf(ALERT_LOG_WAIT_PERIOD)); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", String.valueOf(_numMessages)); // Then we do the normal setup stuff like starting the broker, getting a connection etc. super.setUp(); @@ -141,7 +141,7 @@ public class AlertingTest extends AbstractTestLogging _monitor.markDiscardPoint(); // Change max message count to 5, start broker and make sure that that's triggered at the right time - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", "5"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".queues.maximumMessageCount", "5"); startBroker(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java index 24c0aed611..c5f5e06ae1 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java @@ -23,12 +23,20 @@ package org.apache.qpid.server.logging; import junit.framework.AssertionFailedError; import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Transport; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.transport.ConnectionException; import org.apache.qpid.util.LogMonitor; import java.io.IOException; import java.net.Socket; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Broker Test Suite @@ -47,6 +55,8 @@ import java.util.List; */ public class BrokerLoggingTest extends AbstractTestLogging { + private static final String BROKER_MESSAGE_LOG_REG_EXP = ".*\\[\\w*\\] (BRK\\-\\d*) .*"; + private static final Pattern BROKER_MESSAGE_LOG_PATTERN = Pattern.compile(BROKER_MESSAGE_LOG_REG_EXP); private static final String BRK_LOG_PREFIX = "BRK-"; public void setUp() throws Exception @@ -95,7 +105,7 @@ public class BrokerLoggingTest extends AbstractTestLogging _monitor = new LogMonitor(_outputFile); - String configFilePath = _configFile.toString(); + String configFilePath = getConfigPath(); // Ensure we wait for TESTID to be logged waitAndFindMatches(TESTID); @@ -118,8 +128,9 @@ public class BrokerLoggingTest extends AbstractTestLogging 1, results.size()); //3 - assertTrue("Config file details not correctly logged", - log.endsWith(configFilePath)); + assertTrue("Config file details not correctly logged, got " + + log + " but expected it to end with " + configFilePath, + log.endsWith(configFilePath)); } catch (AssertionFailedError afe) { @@ -130,6 +141,11 @@ public class BrokerLoggingTest extends AbstractTestLogging } } + private String getConfigPath() + { + return getPathRelativeToWorkingDirectory(getTestConfigFile(DEFAULT_PORT)); + } + /** * Description: * On startup the broker must report correctly report the log4j file in use. This is important as it can help diagnose why logging messages are not being reported. @@ -242,6 +258,8 @@ public class BrokerLoggingTest extends AbstractTestLogging // This logging startup code only occurs when you run a Java broker if (isJavaBroker() && isExternalBroker()) { + String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath(); + String TESTID = "BRK-1007"; startBroker(); @@ -290,10 +308,9 @@ public class BrokerLoggingTest extends AbstractTestLogging //3 String messageString = getMessageString(log); - String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath(); - assertTrue("Log4j file details not correctly logged. Message '" + messageString - + "' should contain '" + customLog4j + "'", - messageString.contains(customLog4j)); + assertTrue("Log4j file details not correctly logged. Message '" + + messageString + "' should contain '" +customLog4j + "'", + messageString.endsWith(customLog4j)); validation = true; } @@ -441,10 +458,13 @@ public class BrokerLoggingTest extends AbstractTestLogging { String log = getLog(rawLog); + // using custom method to get id as getMessageId() fails to correctly identify id + // because of using brackets for protocols + String id = getBrokerLogId(log); // Ensure we do not have a BRK-1002 message - if (!getMessageID(log).equals(TESTID)) + if (!id.equals(TESTID)) { - if (getMessageID(log).equals("BRK-1001")) + if (id.equals("BRK-1001")) { foundBRK1001 = true; } @@ -454,7 +474,7 @@ public class BrokerLoggingTest extends AbstractTestLogging assertTrue("BRK-1001 not logged before this message", foundBRK1001); //1 - validateMessageID(TESTID, log); + assertEquals("Incorrect message", TESTID, id); //2 //There will be 2 copies of the startup message (one via SystemOut, and one via Log4J) @@ -464,7 +484,7 @@ public class BrokerLoggingTest extends AbstractTestLogging //3 String message = getMessageString(log); assertTrue("Expected Listen log not correct" + message, - message.endsWith("Listening on TCP port " + getPort())); + message.endsWith("Listening on [TCP] port " + getPort())); validation = true; } @@ -480,6 +500,16 @@ public class BrokerLoggingTest extends AbstractTestLogging } } + private String getBrokerLogId(String log) + { + Matcher m = BROKER_MESSAGE_LOG_PATTERN.matcher(log); + if (m.matches()) + { + return m.group(1); + } + return getMessageID(log); + } + /** * Description: * On startup the broker may listen on a number of ports and protocols. Each of these must be reported as they are made available. @@ -497,8 +527,8 @@ public class BrokerLoggingTest extends AbstractTestLogging * 1. The BRK ID is correct * 2. This occurs after the BRK-1001 startup message * 3. With SSL enabled in the configuration two BRK-1002 will be printed (order is not specified) - * 1. One showing values TCP / 5672 - * 2. One showing values TCP/SSL / 5672 + * 1. One showing values [TCP] 5672 + * 2. One showing values [SSL] 5671 * * @throws Exception caused by broker startup */ @@ -511,12 +541,11 @@ public class BrokerLoggingTest extends AbstractTestLogging String TESTID = "BRK-1002"; // Enable SSL on the connection - setConfigurationProperty("connector.ssl.enabled", "true"); - setConfigurationProperty("connector.ssl.sslOnly", "false"); - setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath")); - setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword")); - - Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port")); + Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); + sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); + sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); + getBrokerConfiguration().addPortConfiguration(sslPortAttributes); startBroker(); @@ -544,10 +573,11 @@ public class BrokerLoggingTest extends AbstractTestLogging { String log = getLog(rawLog); + String id = getBrokerLogId(log); // Ensure we do not have a BRK-1002 message - if (!getMessageID(log).equals(TESTID)) + if (!id.equals(TESTID)) { - if (getMessageID(log).equals("BRK-1001")) + if (id.equals("BRK-1001")) { foundBRK1001 = true; } @@ -557,7 +587,7 @@ public class BrokerLoggingTest extends AbstractTestLogging assertTrue("BRK-1001 not logged before this message", foundBRK1001); //1 - validateMessageID(TESTID, log); + assertEquals("Incorrect message", TESTID, id); //2 //There will be 4 copies of the startup message (two via SystemOut, and two via Log4J) @@ -569,16 +599,16 @@ public class BrokerLoggingTest extends AbstractTestLogging //Check the first String message = getMessageString(getLog(listenMessages .get(0))); assertTrue("Expected Listen log not correct" + message, - message.endsWith("Listening on TCP port " + getPort())); + message.endsWith("Listening on [TCP] port " + getPort())); // Check the third, ssl listen. message = getMessageString(getLog(listenMessages .get(2))); assertTrue("Expected Listen log not correct" + message, - message.endsWith("Listening on TCP/SSL port " + sslPort)); + message.endsWith("Listening on [SSL] port " + DEFAULT_SSL_PORT)); //4 Test ports open testSocketOpen(getPort()); - testSocketOpen(sslPort); + testSocketOpen(DEFAULT_SSL_PORT); validation = true; } @@ -802,11 +832,11 @@ public class BrokerLoggingTest extends AbstractTestLogging String TESTID = "BRK-1003"; // Enable SSL on the connection - setConfigurationProperty("connector.ssl.enabled", "true"); - setConfigurationProperty("connector.ssl.keyStorePath", getConfigurationStringProperty("management.ssl.keyStorePath")); - setConfigurationProperty("connector.ssl.keyStorePassword", getConfigurationStringProperty("management.ssl.keyStorePassword")); - - Integer sslPort = Integer.parseInt(getConfigurationStringProperty("connector.ssl.port")); + Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); + sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); + sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); + getBrokerConfiguration().addPortConfiguration(sslPortAttributes); startBroker(); @@ -847,13 +877,13 @@ public class BrokerLoggingTest extends AbstractTestLogging // Check second, ssl, listen. message = getMessageString(getLog(listenMessages.get(1))); assertTrue("Expected shutdown log not correct" + message, - message.endsWith("TCP/SSL port " + sslPort)); + message.endsWith("TCP/SSL port " + DEFAULT_SSL_PORT)); //4 //Test Port closed checkSocketClosed(getPort()); //Test SSL Port closed - checkSocketClosed(sslPort); + checkSocketClosed(DEFAULT_SSL_PORT); } catch (AssertionFailedError afe) { @@ -998,4 +1028,5 @@ public class BrokerLoggingTest extends AbstractTestLogging + ". Due to:" + e.getMessage()); } } + } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java index 5f96215269..1ea105ae1a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/VirtualHostLoggingTest.java @@ -23,7 +23,6 @@ package org.apache.qpid.server.logging; import junit.framework.AssertionFailedError; -import org.apache.qpid.server.configuration.ServerConfiguration; import java.util.Arrays; import java.util.List; @@ -68,7 +67,7 @@ public class VirtualHostLoggingTest extends AbstractTestLogging try { - List<String> vhosts = Arrays.asList(getServerConfig().getVirtualHosts()); + List<String> vhosts = Arrays.asList("test"); assertEquals("Each vhost did not create a store.", vhosts.size(), results.size()); @@ -110,23 +109,17 @@ public class VirtualHostLoggingTest extends AbstractTestLogging // Wait for the correct VHT message to arrive. waitForMessage(VHT_PREFIX + "1002"); - + // Validate each vhost logs a closure List<String> results = findMatches(VHT_PREFIX + "1002"); - + try { - // Load VirtualHost list from file. - ServerConfiguration configuration = new ServerConfiguration(_configFile); - configuration.initialise(); - List<String> vhosts = Arrays.asList(configuration.getVirtualHosts()); - - assertEquals("Each vhost did not close their store.", vhosts.size(), results.size()); + assertEquals("Each vhost did not close their store.", 1, results.size()); } catch (AssertionFailedError afe) { dumpLogs(results, _monitor); - throw afe; } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java index bcad59a1fa..82b421a531 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/persistent/NoLocalAfterRecoveryTest.java @@ -39,7 +39,7 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase; */ public class NoLocalAfterRecoveryTest extends QpidBrokerTestCase { - protected final String MY_TOPIC_SUBSCRIPTION_NAME = this.getName(); + protected final String MY_TOPIC_SUBSCRIPTION_NAME = getTestQueueName(); protected static final int SEND_COUNT = 10; public void testNoLocalNotQueued() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java index 8536651ffb..cbf4e032db 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/queue/MultipleTransactedBatchProducerTest.java @@ -30,6 +30,7 @@ import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; + import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -54,7 +55,9 @@ public class MultipleTransactedBatchProducerTest extends QpidBrokerTestCase //debug level logging often makes this test pass artificially, turn the level down to info. setSystemProperty("amqj.server.logging.level", "INFO"); _receivedLatch = new CountDownLatch(MESSAGE_COUNT * NUM_PRODUCERS); - setConfigurationProperty("management.enabled", "true"); + + getBrokerConfiguration().addJmxManagementConfiguration(); + super.setUp(); _queueName = getTestQueueName(); _failMsg = null; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java index 7b50749f5f..814936f342 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java @@ -26,6 +26,7 @@ import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.jms.ConnectionListener; import org.apache.qpid.protocol.AMQConstant; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.url.URLSyntaxException; @@ -58,25 +59,11 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements { /** Used to synchronise {@link #tearDown()} when exceptions are thrown */ protected CountDownLatch _exceptionReceived; - - /** Override this to return the name of the configuration XML file. */ - public String getConfig() - { - return "config-systests.xml"; - } - /** - * This setup method checks {@link #getConfig()} and {@link #getHostList()} to initialise the broker with specific - * ACL configurations and then runs an optional per-test setup method, which is simply a method with the same name - * as the test, but starting with {@code setUp} rather than {@code test}. - * - * @see org.apache.qpid.test.utils.QpidBrokerTestCase#setUp() - */ @Override public void setUp() throws Exception { - // Initialise ACLs. - _configFile = new File("build" + File.separator + "etc" + File.separator + getConfig()); + getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, System.getProperty(QPID_HOME) + "/etc/groups-systests"); // run test specific setup String testSetup = StringUtils.replace(getName(), "test", "setUp"); @@ -123,11 +110,11 @@ public abstract class AbstractACLTestCase extends QpidBrokerTestCase implements if (vhost == null) { - testcase.setConfigurationProperty("security.acl", aclFile.getAbsolutePath()); + testcase.getBrokerConfiguration().setBrokerAttribute(Broker.ACL_FILE, aclFile.getAbsolutePath()); } else { - testcase.setConfigurationProperty("virtualhosts.virtualhost." + vhost + ".security.acl", aclFile.getAbsolutePath()); + testcase.setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + vhost + ".security.acl", aclFile.getAbsolutePath()); } PrintWriter out = new PrintWriter(new FileWriter(aclFile)); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java index 52229316be..1830040007 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java @@ -43,8 +43,8 @@ public class ExternalACLJMXTest extends AbstractACLTestCase @Override public void setUp() throws Exception { - createTestVirtualHost(TEST_VHOST); - createTestVirtualHost(TEST2_VHOST); + createTestVirtualHost(0, TEST_VHOST); + createTestVirtualHost(0, TEST2_VHOST); _jmx = new JMXTestUtils(this); _jmx.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java index 295aac9f97..c7a43a292b 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java @@ -20,21 +20,30 @@ */ package org.apache.qpid.server.security.auth.manager; +import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE; +import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD; +import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE; +import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import javax.jms.Connection; import javax.jms.JMSException; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.client.AMQConnectionURL; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Transport; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class ExternalAuthenticationTest extends QpidBrokerTestCase { - private static final String EXTERNAL_AUTH_MANAGER = ExternalAuthenticationManager.class.getSimpleName(); - private static final String KEYSTORE = "test-profiles/test_resources/ssl/java_client_keystore.jks"; - private static final String KEYSTORE_PASSWORD = "password"; - private static final String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks"; - private static final String TRUSTSTORE_PASSWORD = "password"; - @Override protected void setUp() throws Exception { @@ -48,9 +57,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase public void testExternalAuthenticationManagerOnSSLPort() throws Exception { setCommonBrokerSSLProperties(true); - setConfigurationProperty("security.port-mappings.port-mapping.port", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT)); - setConfigurationProperty("security.port-mappings.port-mapping.auth-manager", EXTERNAL_AUTH_MANAGER); - setConfigurationProperty("security.default-auth-manager", PrincipalDatabaseAuthenticationManager.class.getSimpleName()); + getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_SSL_PORT, Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); super.setUp(); setClientKeystoreProperties(); @@ -83,7 +90,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase public void testExternalAuthenticationManagerAsDefault() throws Exception { setCommonBrokerSSLProperties(true); - setConfigurationProperty("security.default-auth-manager", EXTERNAL_AUTH_MANAGER); + getBrokerConfiguration().setBrokerAttribute(Broker.DEFAULT_AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); super.setUp(); setClientKeystoreProperties(); @@ -116,7 +123,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase public void testExternalAuthenticationManagerWithoutClientKeyStore() throws Exception { setCommonBrokerSSLProperties(false); - setConfigurationProperty("security.default-auth-manager", EXTERNAL_AUTH_MANAGER); + getBrokerConfiguration().setBrokerAttribute(Broker.DEFAULT_AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); super.setUp(); setClientTrustoreProperties(); @@ -148,12 +155,18 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase private void setCommonBrokerSSLProperties(boolean needClientAuth) throws ConfigurationException { - setConfigurationProperty("connector.ssl.enabled", "true"); - setConfigurationProperty("connector.ssl.sslOnly", "false"); - setConfigurationProperty("connector.ssl.trustStorePath", TRUSTSTORE); - setConfigurationProperty("connector.ssl.trustStorePassword", TRUSTSTORE_PASSWORD); - setConfigurationProperty("connector.ssl.needClientAuth", String.valueOf(needClientAuth)); - setConfigurationProperty("security.external-auth-manager", ""); + TestBrokerConfiguration config = getBrokerConfiguration(); + Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); + sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); + sslPortAttributes.put(Port.NEED_CLIENT_AUTH, String.valueOf(needClientAuth)); + sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); + config.addPortConfiguration(sslPortAttributes); + + Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>(); + externalAuthProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManagerFactory.PROVIDER_TYPE); + externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); + config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes); } private void setClientKeystoreProperties() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java index 34b62e0b92..f41f1159ab 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java @@ -25,23 +25,39 @@ import static org.apache.qpid.test.utils.TestSSLConstants.KEYSTORE_PASSWORD; import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE; import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import javax.jms.Connection; import javax.jms.JMSException; import org.apache.qpid.AMQException; import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Transport; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class MultipleAuthenticationManagersTest extends QpidBrokerTestCase { @Override protected void setUp() throws Exception { - setConfigurationProperty("connector.ssl.enabled", "true"); - setConfigurationProperty("connector.ssl.sslOnly", "false"); - setConfigurationProperty("security.anonymous-auth-manager", ""); - setConfigurationProperty("security.default-auth-manager", "PrincipalDatabaseAuthenticationManager"); - setConfigurationProperty("security.port-mappings.port-mapping.port", String.valueOf(QpidBrokerTestCase.DEFAULT_SSL_PORT)); - setConfigurationProperty("security.port-mappings.port-mapping.auth-manager", "AnonymousAuthenticationManager"); + TestBrokerConfiguration config = getBrokerConfiguration(); + + Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>(); + externalAuthProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE); + externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER); + config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes); + + Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); + sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + sslPortAttributes.put(Port.PORT, DEFAULT_SSL_PORT); + sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); + sslPortAttributes.put(Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER); + config.addPortConfiguration(sslPortAttributes); // set the ssl system properties setSystemProperty("javax.net.ssl.keyStore", KEYSTORE); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java index 1e61ff9382..6d53896371 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java @@ -27,10 +27,13 @@ import org.apache.qpid.client.AMQQueue; import org.apache.qpid.client.AMQSession; import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.util.LogMonitor; import java.util.List; +import java.util.Map; import javax.jms.Connection; import javax.jms.Destination; @@ -48,6 +51,7 @@ public class StatisticsReportingTest extends QpidBrokerTestCase private static final String VHOST_NAME1 = "vhost1"; private static final String VHOST_NAME2 = "vhost2"; private static final String VHOST_NAME3 = "vhost3"; + private static long STATISTICS_REPORTING_PERIOD_IN_SECONDS = 10l; protected LogMonitor _monitor; protected static final String USER = "admin"; @@ -56,23 +60,24 @@ public class StatisticsReportingTest extends QpidBrokerTestCase protected String _queueName = "statistics"; protected Destination _queue; protected String _brokerUrl; + private long _startTestTime; @Override public void setUp() throws Exception { - createTestVirtualHost(VHOST_NAME1); - createTestVirtualHost(VHOST_NAME2); - createTestVirtualHost(VHOST_NAME3); - - setConfigurationProperty("statistics.generation.broker", "true"); - setConfigurationProperty("statistics.generation.virtualhosts", "true"); + createTestVirtualHost(0, VHOST_NAME1); + createTestVirtualHost(0, VHOST_NAME2); + createTestVirtualHost(0, VHOST_NAME3); if (getName().equals("testEnabledStatisticsReporting")) { - setConfigurationProperty("statistics.reporting.period", "10"); + TestBrokerConfiguration config = getBrokerConfiguration(); + config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); + config.setBrokerAttribute(Broker.STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_PERIOD_IN_SECONDS); } _monitor = new LogMonitor(_outputFile); + _startTestTime = System.currentTimeMillis(); super.setUp(); @@ -105,17 +110,26 @@ public class StatisticsReportingTest extends QpidBrokerTestCase sendUsing(_conToVhost2, 20, 100); sendUsing(_conToVhost3, 15, 100); - Thread.sleep(10 * 1000); // 15s + Thread.sleep(STATISTICS_REPORTING_PERIOD_IN_SECONDS * 1000); - List<String> brokerStatsData = _monitor.findMatches("BRK-1008"); - List<String> brokerStatsMessages = _monitor.findMatches("BRK-1009"); - List<String> vhostStatsData = _monitor.findMatches("VHT-1003"); - List<String> vhostStatsMessages = _monitor.findMatches("VHT-1004"); + Map<String, List<String>> brokerStatsData = _monitor.findMatches("BRK-1008", "BRK-1009", "VHT-1003", "VHT-1004"); + long endTestTime = System.currentTimeMillis(); + + int maxNumberOfReports = (int)((endTestTime - _startTestTime)/STATISTICS_REPORTING_PERIOD_IN_SECONDS); + + int brk1008LinesNumber = brokerStatsData.get("BRK-1008").size(); + int brk1009LinesNumber = brokerStatsData.get("BRK-1009").size(); + int vht1003LinesNumber = brokerStatsData.get("VHT-1003").size(); + int vht1004LinesNumber = brokerStatsData.get("VHT-1004").size(); - assertEquals("Incorrect number of broker data stats log messages", 2, brokerStatsData.size()); - assertEquals("Incorrect number of broker message stats log messages", 2, brokerStatsMessages.size()); - assertEquals("Incorrect number of virtualhost data stats log messages", 6, vhostStatsData.size()); - assertEquals("Incorrect number of virtualhost message stats log messages", 6, vhostStatsMessages.size()); + assertTrue("Incorrect number of broker data stats log messages:" + brk1008LinesNumber, 2 <= brk1008LinesNumber + && brk1008LinesNumber <= maxNumberOfReports * 2); + assertTrue("Incorrect number of broker message stats log messages:" + brk1009LinesNumber, 2 <= brk1009LinesNumber + && brk1009LinesNumber <= maxNumberOfReports * 2); + assertTrue("Incorrect number of virtualhost data stats log messages:" + vht1003LinesNumber, 6 <= vht1003LinesNumber + && vht1003LinesNumber <= maxNumberOfReports * 6); + assertTrue("Incorrect number of virtualhost message stats log messages: " + vht1004LinesNumber, 6 <= vht1004LinesNumber + && vht1004LinesNumber <= maxNumberOfReports * 6); } /** @@ -142,7 +156,7 @@ public class StatisticsReportingTest extends QpidBrokerTestCase private void sendUsing(Connection con, int number, int size) throws Exception { - Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); + Session session = con.createSession(true, Session.SESSION_TRANSACTED); createQueue(session); MessageProducer producer = session.createProducer(_queue); String content = new String(new byte[size]); @@ -151,6 +165,8 @@ public class StatisticsReportingTest extends QpidBrokerTestCase { producer.send(msg); } + session.commit(); + session.close(); } private void createQueue(Session session) throws AMQException, JMSException diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java index 9fb1db3a4f..61ca6d9c28 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java @@ -60,9 +60,9 @@ public class StoreOverfullTest extends QpidBrokerTestCase public void setUp() throws Exception { - setConfigurationProperty("virtualhosts.virtualhost.test.store.class", QuotaMessageStore.class.getName()); - setConfigurationProperty("virtualhosts.virtualhost.test.store.overfull-size", String.valueOf(OVERFULL_SIZE)); - setConfigurationProperty("virtualhosts.virtualhost.test.store.underfull-size", String.valueOf(UNDERFULL_SIZE)); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.class", QuotaMessageStore.class.getName()); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.overfull-size", String.valueOf(OVERFULL_SIZE)); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.store.underfull-size", String.valueOf(UNDERFULL_SIZE)); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java index 7473a4d3e7..954208e78e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/BrokerManagementTest.java @@ -107,6 +107,8 @@ public class BrokerManagementTest extends QpidBrokerTestCase { String defaultExchangeName = ExchangeDefaults.DEFAULT_EXCHANGE_NAME.asString(); + ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName); + assertNotNull("Exchange should exist", defaultExchange); try { _managedBroker.unregisterExchange(defaultExchangeName); @@ -117,7 +119,7 @@ public class BrokerManagementTest extends QpidBrokerTestCase // PASS assertEquals("'<<default>>' is a reserved exchange and can't be deleted", e.getMessage()); } - final ManagedExchange defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName); + defaultExchange = _jmxUtils.getManagedExchange(defaultExchangeName); assertNotNull("Exchange should exist", defaultExchange); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java index 9fe043b23d..950b002b87 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java @@ -21,12 +21,16 @@ package org.apache.qpid.systest.management.jmx; -import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.configuration.BrokerProperties; import org.apache.qpid.server.logging.AbstractTestLogging; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Transport; import org.apache.qpid.test.utils.JMXTestUtils; +import org.apache.qpid.test.utils.TestBrokerConfiguration; +import org.apache.qpid.test.utils.TestSSLConstants; import org.apache.qpid.util.LogMonitor; -import java.io.File; +import java.util.Collections; import java.util.List; /** @@ -202,7 +206,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // We expect the RMI Registry port (the defined 'management port') to be // 100 lower than the JMX RMIConnector Server Port (the actual JMX server) - int jmxPort = mPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET; + int jmxPort = mPort + JMXPORT_CONNECTORSERVER_OFFSET; assertTrue("JMX RMIConnectorServer port not as expected(" + jmxPort + ").:" + getMessageString(log), getMessageString(log).endsWith(String.valueOf(jmxPort))); } @@ -245,7 +249,7 @@ public class ManagementLoggingTest extends AbstractTestLogging // Validate the keystore path is as expected assertTrue("SSL Keystore entry expected.:" + getMessageString(log), - getMessageString(log).endsWith(new File(getConfigurationStringProperty("management.ssl.keyStorePath")).getName())); + getMessageString(log).endsWith(TestSSLConstants.BROKER_KEYSTORE)); } } @@ -266,6 +270,7 @@ public class ManagementLoggingTest extends AbstractTestLogging { if (isJavaBroker()) { + setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false"); startBrokerAndCreateMonitor(true, false); final JMXTestUtils jmxUtils = new JMXTestUtils(this); @@ -301,13 +306,20 @@ public class ManagementLoggingTest extends AbstractTestLogging private void startBrokerAndCreateMonitor(boolean managementEnabled, boolean useManagementSSL) throws Exception { - //Ensure management is on - setConfigurationProperty("management.enabled", String.valueOf(managementEnabled)); + TestBrokerConfiguration config = getBrokerConfiguration(); + + if (managementEnabled) + { + config.addJmxManagementConfiguration(); + } if(useManagementSSL) { // This test requires we have an ssl connection - setConfigurationProperty("management.ssl.enabled", "true"); + config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + + setSystemProperty("javax.net.ssl.keyStore", "test-profiles/test_resources/ssl/java_broker_keystore.jks"); + setSystemProperty("javax.net.ssl.keyStorePassword", "password"); } startBroker(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java index 49207e2d7a..72fbd65acc 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/StatisticsTest.java @@ -53,8 +53,8 @@ public class StatisticsTest extends QpidBrokerTestCase @Override public void setUp() throws Exception { - createTestVirtualHost(TEST_VIRTUALHOST1); - createTestVirtualHost(TEST_VIRTUALHOST2); + createTestVirtualHost(0, TEST_VIRTUALHOST1); + createTestVirtualHost(0, TEST_VIRTUALHOST2); _jmxUtils = new JMXTestUtils(this, TEST_USER, TEST_PASSWORD); _jmxUtils.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java index 62b1b554a9..7eff1c89ee 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java @@ -23,15 +23,23 @@ import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.jms.Connection; import javax.jms.JMSException; import org.apache.qpid.management.common.mbeans.UserManagement; -import org.apache.qpid.server.security.auth.database.PlainPasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Protocol; +import org.apache.qpid.server.model.Transport; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory; +import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory; import org.apache.qpid.test.utils.JMXTestUtils; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.tools.security.Passwd; /** @@ -53,9 +61,10 @@ public class UserManagementTest extends QpidBrokerTestCase _passwd = createPasswordEncodingUtility(); _passwordFile = createTemporaryPasswordFileWithJmxAdminUser(); - setConfigurationProperty("security.pd-auth-manager.principal-database.class", getPrincipalDatabaseImplClass().getName()); - setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile"); - setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", _passwordFile.getAbsolutePath()); + Map<String, Object> newAttributes = new HashMap<String, Object>(); + newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, getAuthenticationManagerType()); + newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _passwordFile.getAbsolutePath()); + getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes); _jmxUtils = new JMXTestUtils(this); _jmxUtils.setUp(); @@ -163,9 +172,9 @@ public class UserManagementTest extends QpidBrokerTestCase }; } - protected Class<? extends PrincipalDatabase> getPrincipalDatabaseImplClass() + protected String getAuthenticationManagerType() { - return PlainPasswordFilePrincipalDatabase.class; + return PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE; } private File createTemporaryPasswordFileWithJmxAdminUser() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java index 84a66232ce..1423bc557e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementWithBase64MD5PasswordsTest.java @@ -18,8 +18,7 @@ */ package org.apache.qpid.systest.management.jmx; -import org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase; -import org.apache.qpid.server.security.auth.database.PrincipalDatabase; +import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory; import org.apache.qpid.tools.security.Passwd; public class UserManagementWithBase64MD5PasswordsTest extends UserManagementTest @@ -31,9 +30,8 @@ public class UserManagementWithBase64MD5PasswordsTest extends UserManagementTest } @Override - protected Class<? extends PrincipalDatabase> getPrincipalDatabaseImplClass() + protected String getAuthenticationManagerType() { - return Base64MD5PasswordFilePrincipalDatabase.class; + return Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE; } - } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java index 2991ba7890..16253139ce 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/Asserts.java @@ -37,6 +37,7 @@ import org.apache.qpid.server.model.Connection; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.VirtualHost; @@ -49,7 +50,7 @@ public class Asserts { assertNotNull("Virtualhost " + virtualHostName + " data are not found", virtualHost); assertAttributesPresent(virtualHost, VirtualHost.AVAILABLE_ATTRIBUTES, VirtualHost.TIME_TO_LIVE, - VirtualHost.CREATED, VirtualHost.UPDATED, VirtualHost.SUPPORTED_QUEUE_TYPES, VirtualHost.STORE_CONFIGURATION); + VirtualHost.CREATED, VirtualHost.UPDATED, VirtualHost.SUPPORTED_QUEUE_TYPES, VirtualHost.STORE_PATH, VirtualHost.CONFIG_PATH); assertEquals("Unexpected value of attribute " + VirtualHost.NAME, virtualHostName, virtualHost.get(VirtualHost.NAME)); assertNotNull("Unexpected value of attribute " + VirtualHost.ID, virtualHost.get(VirtualHost.ID)); @@ -180,7 +181,6 @@ public class Asserts public static void assertPortAttributes(Map<String, Object> port) { - assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED); assertNotNull("Unexpected value of attribute " + Port.ID, port.get(Port.ID)); assertEquals("Unexpected value of attribute " + Port.DURABLE, Boolean.FALSE, port.get(Port.DURABLE)); @@ -188,9 +188,30 @@ public class Asserts port.get(Broker.LIFETIME_POLICY)); assertEquals("Unexpected value of attribute " + Port.STATE, State.ACTIVE.name(), port.get(Port.STATE)); assertEquals("Unexpected value of attribute " + Port.TIME_TO_LIVE, 0, port.get(Port.TIME_TO_LIVE)); - assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS)); - assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, port.get(Port.PROTOCOLS)); - assertNotNull("Unexpected value of attribute " + Port.NAME, port.get(Port.NAME)); + + @SuppressWarnings("unchecked") + Collection<String> protocols = (Collection<String>) port.get(Port.PROTOCOLS); + assertNotNull("Unexpected value of attribute " + Port.PROTOCOLS, protocols); + boolean isAMQPPort = false; + for (String protocolName : protocols) + { + if (Protocol.valueOf(protocolName).isAMQP()) + { + isAMQPPort = true; + break; + } + } + if (isAMQPPort) + { + assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER); + assertNotNull("Unexpected value of attribute " + Port.BINDING_ADDRESS, port.get(Port.BINDING_ADDRESS)); + } + else + { + assertAttributesPresent(port, Port.AVAILABLE_ATTRIBUTES, Port.CREATED, Port.UPDATED, Port.AUTHENTICATION_MANAGER, + Port.BINDING_ADDRESS, Port.TCP_NO_DELAY, Port.SEND_BUFFER_SIZE, Port.RECEIVE_BUFFER_SIZE, + Port.NEED_CLIENT_AUTH, Port.WANT_CLIENT_AUTH); + } @SuppressWarnings("unchecked") Collection<String> transports = (Collection<String>) port.get(Port.TRANSPORTS); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java index 74b773c1fa..0574b6cc24 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java @@ -25,10 +25,14 @@ import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD; import java.io.IOException; import java.net.HttpURLConnection; +import java.util.Collections; import javax.servlet.http.HttpServletResponse; import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Protocol; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class BasicAuthRestTest extends QpidRestTestCase { @@ -51,11 +55,11 @@ public class BasicAuthRestTest extends QpidRestTestCase private void configure(boolean useSsl) throws ConfigurationException, IOException { getRestTestHelper().setUseSsl(useSsl); - setConfigurationProperty("management.http.enabled", String.valueOf(!useSsl)); - setConfigurationProperty("management.http.port", Integer.toString(getRestTestHelper().getHttpPort())); - setConfigurationProperty("management.https.enabled", String.valueOf(useSsl)); - setConfigurationProperty("management.https.port", Integer.toString(getRestTestHelper().getHttpPort())); - setConfigurationProperty("management.enabled", "false"); //JMX + if (useSsl) + { + getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PROTOCOLS, Collections.singleton(Protocol.HTTPS)); + } + super.customizeConfiguration(); } private void verifyGetBrokerAttempt(int responseCode) throws IOException @@ -91,7 +95,8 @@ public class BasicAuthRestTest extends QpidRestTestCase public void testEnablingForHttp() throws Exception { configure(false); - setConfigurationProperty("management.http.basic-auth", "true"); + + getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true); super.setUp(); // Try the attempt with authentication, it should succeed because @@ -103,7 +108,7 @@ public class BasicAuthRestTest extends QpidRestTestCase public void testDisablingForHttps() throws Exception { configure(true); - setConfigurationProperty("management.https.basic-auth", "false"); + getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpsBasicAuthenticationEnabled", false); super.setUp(); setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE); setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java index 7daac0eb46..372db8f560 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BindingRestTest.java @@ -34,7 +34,8 @@ public class BindingRestTest extends QpidRestTestCase { List<Map<String, Object>> bindings = getRestTestHelper().getJsonAsList("/rest/binding"); assertNotNull("Bindings cannot be null", bindings); - assertTrue("Unexpected number of bindings", bindings.size() >= EXPECTED_VIRTUALHOSTS.length * EXPECTED_QUEUES.length); + assertTrue("Unexpected number of bindings: " + bindings.size(), + bindings.size() >= EXPECTED_VIRTUALHOSTS.length * EXPECTED_QUEUES.length); for (Map<String, Object> binding : bindings) { Asserts.assertBinding((String) binding.get(Binding.NAME), (String) binding.get(Binding.EXCHANGE), binding); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java index c25f160ec8..13e0c1e819 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java @@ -24,10 +24,16 @@ import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE; import static org.apache.qpid.test.utils.TestSSLConstants.TRUSTSTORE_PASSWORD; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import org.apache.commons.configuration.ConfigurationException; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.Protocol; +import org.apache.qpid.server.model.Transport; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class BrokerRestHttpsTest extends QpidRestTestCase { @@ -43,11 +49,12 @@ public class BrokerRestHttpsTest extends QpidRestTestCase @Override protected void customizeConfiguration() throws ConfigurationException, IOException { + super.customizeConfiguration(); getRestTestHelper().setUseSsl(true); - setConfigurationProperty("management.enabled", "true"); - setConfigurationProperty("management.http.enabled", "false"); - setConfigurationProperty("management.https.enabled", "true"); - setConfigurationProperty("management.https.port", Integer.toString(getRestTestHelper().getHttpPort())); + Map<String, Object> newAttributes = new HashMap<String, Object>(); + newAttributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTPS)); + newAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT,newAttributes); } public void testGetWithHttps() throws Exception @@ -55,6 +62,8 @@ public class BrokerRestHttpsTest extends QpidRestTestCase Map<String, Object> brokerDetails = getRestTestHelper().getJsonAsSingletonList("/rest/broker"); Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES, Broker.BYTES_RETAINED, - Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED); + Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED, + Broker.ACL_FILE, Broker.KEY_STORE_CERT_ALIAS, Broker.TRUST_STORE_PATH, Broker.TRUST_STORE_PASSWORD, + Broker.GROUP_FILE); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java index e5b4ffb297..d479d39287 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestTest.java @@ -32,6 +32,7 @@ import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class BrokerRestTest extends QpidRestTestCase { @@ -61,18 +62,17 @@ public class BrokerRestTest extends QpidRestTestCase @SuppressWarnings("unchecked") List<Map<String, Object>> ports = (List<Map<String, Object>>) brokerDetails.get(BROKER_PORTS_ATTRIBUTE); - assertEquals("Unexpected number of ports", 2, ports.size()); + assertEquals("Unexpected number of ports", 4, ports.size()); for (Map<String, Object> port : ports) { Asserts.assertPortAttributes(port); } - String bindingAddress = (String)ports.get(0).get(Port.BINDING_ADDRESS); - - Map<String, Object> amqpPort = getRestTestHelper().find(Port.NAME, bindingAddress + ":" + getPort(), ports); - Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, bindingAddress + ":" + getRestTestHelper().getHttpPort(), ports); + Map<String, Object> amqpPort = getRestTestHelper().find(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, ports); + Map<String, Object> httpPort = getRestTestHelper().find(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, ports); + assertEquals("Unexpected binding address", "*", amqpPort.get(Port.BINDING_ADDRESS)); assertNotNull("Cannot find AMQP port", amqpPort); assertNotNull("Cannot find HTTP port", httpPort); @@ -90,7 +90,9 @@ public class BrokerRestTest extends QpidRestTestCase { Asserts.assertAttributesPresent(brokerDetails, Broker.AVAILABLE_ATTRIBUTES, Broker.BYTES_RETAINED, Broker.PROCESS_PID, Broker.SUPPORTED_STORE_TYPES, - Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED); + Broker.CREATED, Broker.TIME_TO_LIVE, Broker.UPDATED, Broker.ACL_FILE, + Broker.KEY_STORE_PATH, Broker.KEY_STORE_PASSWORD, Broker.KEY_STORE_CERT_ALIAS, + Broker.TRUST_STORE_PATH, Broker.TRUST_STORE_PASSWORD, Broker.GROUP_FILE); assertEquals("Unexpected value of attribute " + Broker.BUILD_VERSION, QpidProperties.getBuildVersion(), brokerDetails.get(Broker.BUILD_VERSION)); @@ -105,7 +107,7 @@ public class BrokerRestTest extends QpidRestTestCase assertEquals("Unexpected value of attribute " + Broker.DURABLE, Boolean.TRUE, brokerDetails.get(Broker.DURABLE)); assertEquals("Unexpected value of attribute " + Broker.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name(), brokerDetails.get(Broker.LIFETIME_POLICY)); - assertEquals("Unexpected value of attribute " + Broker.NAME, "Broker", brokerDetails.get(Broker.NAME)); + assertEquals("Unexpected value of attribute " + Broker.NAME, "QpidBroker", brokerDetails.get(Broker.NAME)); assertEquals("Unexpected value of attribute " + Broker.STATE, State.ACTIVE.name(), brokerDetails.get(Broker.STATE)); assertNotNull("Unexpected value of attribute " + Broker.ID, brokerDetails.get(Broker.ID)); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java index 2852de6fb3..861bf8cb71 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.Group; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.model.LifetimePolicy; @@ -42,8 +43,7 @@ public class GroupProviderRestTest extends QpidRestTestCase { _groupFile = createTemporaryGroupFile(); - setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile"); - setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath()); + getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath()); super.setUp(); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java index cbfd943f8f..d3f93cc0fe 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupRestTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.GroupMember; public class GroupRestTest extends QpidRestTestCase @@ -42,8 +43,7 @@ public class GroupRestTest extends QpidRestTestCase { _groupFile = createTemporaryGroupFile(); - setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile"); - setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath()); + getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath()); super.setUp(); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java index d5a8c31010..578565be05 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import org.apache.qpid.server.model.Port; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class PortRestTest extends QpidRestTestCase { @@ -32,22 +33,24 @@ public class PortRestTest extends QpidRestTestCase { List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/"); assertNotNull("Port data cannot be null", ports); - assertEquals("Unexpected number of ports", 2, ports.size()); - int[] expectedPorts = { getPort(), getRestTestHelper().getHttpPort() }; - for (int port : expectedPorts) - { - String portName = "0.0.0.0:" + port; - Map<String, Object> portData = getRestTestHelper().find(Port.NAME, portName, ports); - assertNotNull("Port " + portName + " is not found", portData); - Asserts.assertPortAttributes(portData); - } + assertEquals("Unexpected number of ports", 4, ports.size()); + + String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT; + Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports); + assertNotNull("Http port " + httpPortName + " is not found", portData); + Asserts.assertPortAttributes(portData); + + String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT; + Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports); + assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData); + Asserts.assertPortAttributes(amqpPortData); } public void testGetPort() throws Exception { List<Map<String, Object>> ports = getRestTestHelper().getJsonAsList("/rest/port/"); assertNotNull("Ports data cannot be null", ports); - assertEquals("Unexpected number of ports", 2, ports.size()); + assertEquals("Unexpected number of ports", 4, ports.size()); for (Map<String, Object> portMap : ports) { String portName = (String) portMap.get(Port.NAME); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java index d63d17f6e5..671bdd7eb8 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java @@ -23,6 +23,8 @@ package org.apache.qpid.systest.rest; import java.io.IOException; import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.QpidBrokerTestCase; public class QpidRestTestCase extends QpidBrokerTestCase @@ -43,11 +45,11 @@ public class QpidRestTestCase extends QpidBrokerTestCase // Set up virtualhost config with queues and bindings to the amq.direct for (String virtualhost : EXPECTED_VIRTUALHOSTS) { - createTestVirtualHost(virtualhost); + createTestVirtualHost(0, virtualhost); for (String queue : EXPECTED_QUEUES) { - setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.exchange", "amq.direct"); - setConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.queue(-1).name", queue); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.exchange", "amq.direct"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + virtualhost + ".queues.queue(-1).name", queue); } } @@ -70,10 +72,9 @@ public class QpidRestTestCase extends QpidBrokerTestCase protected void customizeConfiguration() throws ConfigurationException, IOException { - setConfigurationProperty("management.enabled", "false"); - setConfigurationProperty("management.http.enabled", "true"); - setConfigurationProperty("management.https.enabled", "false"); - setConfigurationProperty("management.http.port", Integer.toString(_restTestHelper.getHttpPort())); + TestBrokerConfiguration config = getBrokerConfiguration(); + config.addHttpManagementConfiguration(); + config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, _restTestHelper.getHttpPort()); } public RestTestHelper getRestTestHelper() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java index 4de603ae6e..0db1f7e50d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java @@ -51,8 +51,10 @@ import junit.framework.Assert; import org.apache.commons.codec.binary.Base64; import org.apache.commons.configuration.ConfigurationException; import org.apache.log4j.Logger; +import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory; import org.apache.qpid.ssl.SSLContextFactory; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; @@ -292,6 +294,7 @@ public class RestTestHelper public void assertNumberOfGroupMembers(Map<String, Object> data, int expectedNumberOfGroupMembers) { + @SuppressWarnings("unchecked") List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groupmembers"); if (groups == null) { @@ -327,7 +330,8 @@ public class RestTestHelper public void createOrUpdateUser(String username, String password, int responseCode) throws IOException { - HttpURLConnection connection = openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager/" + username, "PUT"); + HttpURLConnection connection = openManagementConnection("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username, "PUT"); Map<String, Object> data = new HashMap<String, Object>(); data.put("password", password); @@ -355,14 +359,16 @@ public class RestTestHelper public void removeUserById(String id) throws IOException { - HttpURLConnection connection = openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager?id=" + id, "DELETE"); + HttpURLConnection connection = openManagementConnection("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "?id=" + id, "DELETE"); Assert.assertEquals("Unexpected response code", HttpServletResponse.SC_OK, connection.getResponseCode()); connection.disconnect(); } public void removeUser(String username, int responseCode) throws IOException { - HttpURLConnection connection = openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager/" + username, "DELETE"); + HttpURLConnection connection = openManagementConnection("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username, "DELETE"); Assert.assertEquals("Unexpected response code", responseCode, connection.getResponseCode()); connection.disconnect(); } @@ -374,6 +380,7 @@ public class RestTestHelper public void assertNumberOfGroups(Map<String, Object> data, int expectedNumberOfGroups) { + @SuppressWarnings("unchecked") List<Map<String, Object>> groups = (List<Map<String, Object>>) data.get("groups"); if (groups == null) { @@ -400,8 +407,8 @@ public class RestTestHelper { _passwdFile = createTemporaryPasswdFile(users); - testCase.setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.name", "passwordFile"); - testCase.setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", _passwdFile.getAbsolutePath()); + testCase.getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, + AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, _passwdFile.getAbsolutePath()); } public void tearDown() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java index a775af5dcf..856fda9419 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java @@ -27,6 +27,7 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,6 +36,10 @@ import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.plugin.AuthenticationManagerFactory; +import org.apache.qpid.server.security.auth.manager.AbstractPrincipalDatabaseAuthManagerFactory; +import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.tools.security.Passwd; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; @@ -422,9 +427,9 @@ public class SaslRestTest extends QpidRestTestCase } // configure broker to use Base64MD5PasswordFilePrincipalDatabase - setConfigurationProperty("security.pd-auth-manager.principal-database.class", - "org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabase"); - setConfigurationProperty("security.pd-auth-manager.principal-database.attributes.attribute.value", passwordFile.getAbsolutePath()); - setConfigurationProperty("management.http.sasl-auth", "true"); + Map<String, Object> newAttributes = new HashMap<String, Object>(); + newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH, passwordFile.getAbsolutePath()); + newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE); + getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java index 30433fb40a..427934fac2 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/StructureRestTest.java @@ -23,6 +23,9 @@ package org.apache.qpid.systest.rest; import java.util.List; import java.util.Map; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.test.utils.TestBrokerConfiguration; + public class StructureRestTest extends QpidRestTestCase { @@ -30,7 +33,7 @@ public class StructureRestTest extends QpidRestTestCase { Map<String, Object> structure = getRestTestHelper().getJsonAsMap("/rest/structure"); assertNotNull("Structure data cannot be null", structure); - assertNode(structure, "Broker"); + assertNode(structure, "QpidBroker"); @SuppressWarnings("unchecked") List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) structure.get("virtualhosts"); @@ -38,7 +41,7 @@ public class StructureRestTest extends QpidRestTestCase @SuppressWarnings("unchecked") List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports"); - assertEquals("Unexpected number of ports", 2, ports.size()); + assertEquals("Unexpected number of ports", 4, ports.size()); @SuppressWarnings("unchecked") List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders"); @@ -89,22 +92,18 @@ public class StructureRestTest extends QpidRestTestCase } } } - - @SuppressWarnings("unchecked") - List<Map<String, Object>> aliases = (List<Map<String, Object>>) host.get("virtualhostaliases"); - assertNotNull("Host " + hostName + " aliaces are not found ", aliases); - assertEquals("Unexpected aliaces size", 1, aliases.size()); - assertNode(aliases.get(0), hostName); } - int[] expectedPorts = { getPort(), getRestTestHelper().getHttpPort() }; - for (int port : expectedPorts) - { - String portName = "0.0.0.0:" + port; - Map<String, Object> portData = getRestTestHelper().find("name", portName, ports); - assertNotNull("Port " + portName + " is not found ", portData); - assertNode(portData, portName); - } + + String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT; + Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports); + assertNotNull("Http Port " + httpPortName + " is not found", portData); + assertNode(portData, httpPortName); + + String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT; + Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports); + assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData); + assertNode(amqpPortData, amqpPortName); } private void assertNode(Map<String, Object> node, String name) diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java index 159cd8e52d..017467a8be 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/UserRestTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import org.apache.qpid.server.model.User; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class UserRestTest extends QpidRestTestCase { @@ -56,8 +57,8 @@ public class UserRestTest extends QpidRestTestCase assertNotNull("Attribute " + User.ID, user.get(User.ID)); String userName = (String) user.get(User.NAME); assertNotNull("Attribute " + User.NAME, userName); - Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/" - + userName); + Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName); assertUser(userDetails); assertEquals("Unexpected user name", userName, userDetails.get(User.NAME)); } @@ -68,8 +69,8 @@ public class UserRestTest extends QpidRestTestCase String userName = getTestName(); getRestTestHelper().createOrUpdateUser(userName, "newPassword"); - Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/" - + userName); + Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName); assertUser(userDetails); assertEquals("Unexpected user name", userName, userDetails.get(User.NAME)); } @@ -79,13 +80,14 @@ public class UserRestTest extends QpidRestTestCase String userName = getTestName(); getRestTestHelper().createOrUpdateUser(userName, "newPassword"); - Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/" - + userName); + Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName); String id = (String) userDetails.get(User.ID); getRestTestHelper().removeUserById(id); - List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user/PrincipalDatabaseAuthenticationManager/" + userName); + List<Map<String, Object>> users = getRestTestHelper().getJsonAsList("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + userName); assertEquals("User should be deleted", 0, users.size()); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java index 5b8c3fce33..fb2c941203 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java @@ -20,6 +20,7 @@ */ package org.apache.qpid.systest.rest; +import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.util.HashMap; @@ -29,11 +30,15 @@ import java.util.Map; import javax.jms.Session; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.XMLConfiguration; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.server.model.Exchange; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.queue.AMQQueueFactory; +import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.util.FileUtils; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; @@ -98,6 +103,72 @@ public class VirtualHostRestTest extends QpidRestTestCase Asserts.assertConnection(connections.get(0), _connection); } + public void testPutCreateVirtualHostUsingStoreType() throws Exception + { + String hostName = getTestName(); + String storeType = getTestProfileMessageStoreType(); + String storeLocation = createHost(hostName, storeType, null); + try + { + // make sure that the host is saved in the broker store + restartBroker(); + Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostName); + Asserts.assertVirtualHost(hostName, hostDetails); + assertEquals("Unexpected store type", storeType, hostDetails.get(VirtualHost.STORE_TYPE)); + + assertNewVirtualHost(hostDetails); + } + finally + { + if (storeLocation != null) + { + FileUtils.delete(new File(storeLocation), true); + } + } + } + + public void testPutCreateVirtualHostUsingConfigPath() throws Exception + { + String hostName = getTestName(); + File configFile = TestFileUtils.createTempFile(this, hostName + "-config.xml"); + String configPath = configFile.getAbsolutePath(); + String storeLocation = getStoreLocation(hostName); + createAndSaveVirtualHostConfiguration(hostName, configFile, storeLocation); + createHost(hostName, null, configPath); + try + { + // make sure that the host is saved in the broker store + restartBroker(); + Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostName); + Asserts.assertVirtualHost(hostName, hostDetails); + assertEquals("Unexpected config path", configPath, hostDetails.get(VirtualHost.CONFIG_PATH)); + + assertNewVirtualHost(hostDetails); + } + finally + { + if (storeLocation != null) + { + FileUtils.delete(new File(storeLocation), true); + } + configFile.delete(); + } + } + + public void testDeleteHost() throws Exception + { + String hostToDelete = TEST3_VIRTUALHOST; + HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/virtualhost/" + hostToDelete, "DELETE"); + connection.connect(); + assertEquals("Unexpected response code", 200, connection.getResponseCode()); + + // make sure that changes are saved in the broker store + restartBroker(); + + List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("/rest/virtualhost/" + hostToDelete); + assertEquals("Host should be deleted", 0, hosts.size()); + } + public void testPutCreateQueue() throws Exception { String queueName = getTestQueueName(); @@ -431,4 +502,75 @@ public class VirtualHostRestTest extends QpidRestTestCase return responseCode; } + private String createHost(String hostName, String storeType, String configPath) throws IOException, JsonGenerationException, + JsonMappingException + { + String storePath = getStoreLocation(hostName); + int responseCode = tryCreateVirtualHost(hostName, storeType, storePath, configPath); + assertEquals("Unexpected response code", 201, responseCode); + return storePath; + } + + private String getStoreLocation(String hostName) + { + return new File(TMP_FOLDER, "store-" + hostName + "-" + System.currentTimeMillis()).getAbsolutePath(); + } + + private int tryCreateVirtualHost(String hostName, String storeType, String storePath, String configPath) throws IOException, + JsonGenerationException, JsonMappingException + { + HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/virtualhost/" + hostName, "PUT"); + + Map<String, Object> hostData = new HashMap<String, Object>(); + hostData.put(VirtualHost.NAME, hostName); + if (storeType == null) + { + hostData.put(VirtualHost.CONFIG_PATH, configPath); + } + else + { + hostData.put(VirtualHost.STORE_PATH, storePath); + hostData.put(VirtualHost.STORE_TYPE, storeType); + } + + getRestTestHelper().writeJsonRequest(connection, hostData); + int responseCode = connection.getResponseCode(); + connection.disconnect(); + return responseCode; + } + + private XMLConfiguration createAndSaveVirtualHostConfiguration(String hostName, File configFile, String storeLocation) + throws ConfigurationException + { + XMLConfiguration testConfiguration = new XMLConfiguration(); + testConfiguration.setProperty("virtualhosts.virtualhost." + hostName + ".store.class", + getTestProfileMessageStoreClassName()); + testConfiguration.setProperty("virtualhosts.virtualhost." + hostName + ".store.environment-path", storeLocation); + testConfiguration.save(configFile); + return testConfiguration; + } + + private void assertNewVirtualHost(Map<String, Object> hostDetails) + { + @SuppressWarnings("unchecked") + Map<String, Object> statistics = (Map<String, Object>) hostDetails.get(Asserts.STATISTICS_ATTRIBUTE); + assertEquals("Unexpected number of exchanges in statistics", EXPECTED_EXCHANGES.length, + statistics.get(VirtualHost.EXCHANGE_COUNT)); + assertEquals("Unexpected number of queues in statistics", 0, statistics.get(VirtualHost.QUEUE_COUNT)); + assertEquals("Unexpected number of connections in statistics", 0, statistics.get(VirtualHost.CONNECTION_COUNT)); + + @SuppressWarnings("unchecked") + List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_EXCHANGES_ATTRIBUTE); + assertEquals("Unexpected number of exchanges", EXPECTED_EXCHANGES.length, exchanges.size()); + RestTestHelper restTestHelper = getRestTestHelper(); + Asserts.assertDurableExchange("amq.fanout", "fanout", restTestHelper.find(Exchange.NAME, "amq.fanout", exchanges)); + Asserts.assertDurableExchange("amq.topic", "topic", restTestHelper.find(Exchange.NAME, "amq.topic", exchanges)); + Asserts.assertDurableExchange("amq.direct", "direct", restTestHelper.find(Exchange.NAME, "amq.direct", exchanges)); + Asserts.assertDurableExchange("amq.match", "headers", restTestHelper.find(Exchange.NAME, "amq.match", exchanges)); + Asserts.assertDurableExchange("<<default>>", "direct", restTestHelper.find(Exchange.NAME, "<<default>>", exchanges)); + + assertNull("Unexpected queues", hostDetails.get(VIRTUALHOST_QUEUES_ATTRIBUTE)); + assertNull("Unexpected connections", hostDetails.get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE)); + } + } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java index 7b8ad9141c..40ea723b1e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java @@ -28,8 +28,11 @@ import java.util.Properties; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class GroupRestACLTest extends QpidRestTestCase { @@ -49,15 +52,19 @@ public class GroupRestACLTest extends QpidRestTestCase public void setUp() throws Exception { _groupFile = createTemporaryGroupFile(); - - setConfigurationProperty("management.http.basic-auth", "true"); - setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile"); - setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath()); + getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath()); //DONT call super.setUp(), the tests will start the broker after configuring it } @Override + protected void customizeConfiguration() throws ConfigurationException, IOException + { + super.customizeConfiguration(); + getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true); + } + + @Override public void tearDown() throws Exception { super.tearDown(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java index c02dc804db..12973113d8 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java @@ -28,8 +28,11 @@ import java.util.Properties; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.codehaus.jackson.JsonParseException; import org.codehaus.jackson.map.JsonMappingException; @@ -49,10 +52,7 @@ public class UserRestACLTest extends QpidRestTestCase public void setUp() throws Exception { _groupFile = createTemporaryGroupFile(); - - setConfigurationProperty("management.http.basic-auth", "true"); - setConfigurationProperty("security.file-group-manager.attributes.attribute.name", "groupFile"); - setConfigurationProperty("security.file-group-manager.attributes.attribute.value", _groupFile.getAbsolutePath()); + getBrokerConfiguration().setBrokerAttribute(Broker.GROUP_FILE, _groupFile.getAbsolutePath()); getRestTestHelper().configureTemporaryPasswordFile(this, ALLOWED_USER, DENIED_USER, OTHER_USER); @@ -60,6 +60,13 @@ public class UserRestACLTest extends QpidRestTestCase } @Override + protected void customizeConfiguration() throws ConfigurationException, IOException + { + super.customizeConfiguration(); + getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpBasicAuthenticationEnabled", true); + } + + @Override public void tearDown() throws Exception { super.tearDown(); @@ -163,7 +170,8 @@ public class UserRestACLTest extends QpidRestTestCase private void checkPassword(String username, String password, boolean passwordExpectedToBeCorrect) throws IOException { getRestTestHelper().setUsernameAndPassword(username, password); - HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/user/PrincipalDatabaseAuthenticationManager/", "GET"); + HttpURLConnection connection = getRestTestHelper().openManagementConnection("/rest/user/" + + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/", "GET"); boolean passwordIsCorrect = connection.getResponseCode() == HttpServletResponse.SC_OK; @@ -174,14 +182,14 @@ public class UserRestACLTest extends QpidRestTestCase private void assertUserDoesNotExist(String newUser) throws JsonParseException, JsonMappingException, IOException { - String path = "/rest/user/PrincipalDatabaseAuthenticationManager/" + newUser; + String path = "/rest/user/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + newUser; List<Map<String, Object>> userDetailsList = getRestTestHelper().getJsonAsList(path); assertTrue(userDetailsList.isEmpty()); } private void assertUserExists(String username) throws IOException { - String path = "/rest/user/PrincipalDatabaseAuthenticationManager/" + username; + String path = "/rest/user/" + TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "/" + username; Map<String, Object> userDetails = getRestTestHelper().getJsonAsSingletonList(path); assertEquals( diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java index 5b350d2d89..3cc15d5e9d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/message/JMSDestinationTest.java @@ -63,8 +63,7 @@ public class JMSDestinationTest extends QpidBrokerTestCase public void setUp() throws Exception { - //Ensure JMX management is enabled for MovedToQueue test - setConfigurationProperty("management.enabled", "true"); + getBrokerConfiguration().addJmxManagementConfiguration(); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java index ee81e7c372..9bf7dbd62a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java @@ -54,11 +54,9 @@ public class SyncWaitDelayTest extends QpidBrokerTestCase public void setUp() throws Exception { - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.class", "org.apache.qpid.server.store.SlowMessageStore"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.delays.commitTran.post", String.valueOf(POST_COMMIT_DELAY)); - setConfigurationProperty("management.enabled", "false"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.class", "org.apache.qpid.server.store.SlowMessageStore"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST+".store.delays.commitTran.post", String.valueOf(POST_COMMIT_DELAY)); - super.setUp(); //Set the syncWrite timeout to be just larger than the delay on the commitTran. diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java index 8c407d3def..40db17f799 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/MaxDeliveryCountTest.java @@ -74,14 +74,13 @@ public class MaxDeliveryCountTest extends QpidBrokerTestCase public void setUp() throws Exception { //enable DLQ/maximumDeliveryCount support for all queues at the vhost level - setConfigurationProperty("virtualhosts.virtualhost.test.queues.maximumDeliveryCount", + setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.queues.maximumDeliveryCount", String.valueOf(MAX_DELIVERY_COUNT)); - setConfigurationProperty("virtualhosts.virtualhost.test.queues.deadLetterQueues", + setVirtualHostConfigurationProperty("virtualhosts.virtualhost.test.queues.deadLetterQueues", String.valueOf(true)); //Ensure management is on - setConfigurationProperty("management.enabled", "true"); - setConfigurationProperty("management.ssl.enabled", "false"); + getBrokerConfiguration().addJmxManagementConfiguration(); // Set client-side flag to allow the server to determine if messages // dead-lettered or requeued. diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java index a07e531b98..a9ac028af6 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java @@ -73,7 +73,7 @@ public class DurableSubscriptionTest extends QpidBrokerTestCase public void setUp() throws Exception { - setConfigurationProperty("management.enabled", "true"); + getBrokerConfiguration().addJmxManagementConfiguration(); _jmxConnected=false; super.setUp(); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java index fd8beffbe6..d93c7a2e71 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutDisabledTest.java @@ -29,7 +29,7 @@ public class TransactionTimeoutDisabledTest extends TransactionTimeoutTestCase protected void configure() throws Exception { // Setup housekeeping every second - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100"); // No transaction timeout configuration. } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java index 1e8760dc33..4dc26847da 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/transacted/TransactionTimeoutTest.java @@ -40,28 +40,28 @@ public class TransactionTimeoutTest extends TransactionTimeoutTestCase protected void configure() throws Exception { // Setup housekeeping every 100ms - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".housekeeping.checkPeriod", "100"); if (getName().contains("ProducerIdle")) { - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "0"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "0"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1500"); } else if (getName().contains("ProducerOpen")) { - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "0"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "0"); } else { - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500"); - setConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openWarn", "1000"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.openClose", "2000"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleWarn", "500"); + setVirtualHostConfigurationProperty("virtualhosts.virtualhost." + VIRTUALHOST + ".transactionTimeout.idleClose", "1000"); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java index 4d5718f014..81b53e3dac 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelper.java @@ -17,14 +17,7 @@ */ package org.apache.qpid.test.utils; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; - import java.io.File; -import java.util.Arrays; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; /** * Generates the command to start a broker by substituting the tokens @@ -35,73 +28,25 @@ import java.util.List; */ public class BrokerCommandHelper { - private static final Logger _logger = Logger.getLogger(BrokerCommandHelper.class); - - /** use a LinkedList so we can call remove(int) */ - private final LinkedList<String> _brokerCommandTemplateAsList; + private String _brokerCommandTemplate; public BrokerCommandHelper(String brokerCommandTemplate) { - _brokerCommandTemplateAsList = new LinkedList(Arrays.asList(brokerCommandTemplate.split("\\s+"))); + _brokerCommandTemplate = brokerCommandTemplate; } - public List<String> getBrokerCommand( - int port, int sslPort, int managementPort, - File configFile, File logConfigFile, - String protocolIncludesList, String protocolExcludesList) + public String getBrokerCommand( int port, String storePath, String storeType, File logConfigFile) { - List<String> substitutedCommands = new ArrayList<String>(); - - // Replace the tokens in two passes. - // The first pass is for protocol include/exclude lists, each of which needs to be - // split into separate entries in the final list. - // The second pass is for the remaining options, which include file paths that - // are quoted in case they contain whitespace. - - for (String commandPart : _brokerCommandTemplateAsList) - { - String substitutedCommandPart = commandPart - .replace("@EXCLUDES", protocolExcludesList) - .replace("@INCLUDES", protocolIncludesList); - - String[] splitCommandPart = StringUtils.split(substitutedCommandPart); - substitutedCommands.addAll(Arrays.asList(splitCommandPart)); - } - - int i = 0; - for (String commandPart : substitutedCommands) - { - String substitutedCommandPart = commandPart + return _brokerCommandTemplate .replace("@PORT", "" + port) - .replace("@SSL_PORT", "" + sslPort) - .replace("@MPORT", "" + managementPort) - .replace("@CONFIG_FILE", '"' + configFile.getPath() + '"') + .replace("@STORE_PATH", storePath) + .replace("@STORE_TYPE", storeType) .replace("@LOG_CONFIG_FILE", '"' + logConfigFile.getAbsolutePath() + '"'); - - substitutedCommands.set(i, substitutedCommandPart); - i++; - } - - return substitutedCommands; - } - - private int getBrokerCommandLogOptionIndex() - { - String logOption = "-l"; - - int logOptionIndex = _brokerCommandTemplateAsList.indexOf(logOption); - if(logOptionIndex == -1) - { - throw new RuntimeException("Could not find option " + logOption + " in " + _brokerCommandTemplateAsList); - } - return logOptionIndex; } public void removeBrokerCommandLog4JFile() { - int logOptionIndex = getBrokerCommandLogOptionIndex(); - _brokerCommandTemplateAsList.remove(logOptionIndex); // removes the "-l" entry - _brokerCommandTemplateAsList.remove(logOptionIndex); // removes log file name that followed the -l - _logger.info("Removed broker command log4j config file"); + int logArgumentPosition = _brokerCommandTemplate.indexOf("-l"); + _brokerCommandTemplate = _brokerCommandTemplate.substring(0, logArgumentPosition - 1); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java index 332059dbc0..663e7d92b4 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/BrokerCommandHelperTest.java @@ -19,61 +19,32 @@ package org.apache.qpid.test.utils; import static org.mockito.Mockito.*; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; - import java.io.File; -import java.util.Arrays; -import java.util.List; public class BrokerCommandHelperTest extends QpidTestCase { - private BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper("qpid -p @PORT -s @SSL_PORT -m @MPORT @INCLUDES @EXCLUDES -c @CONFIG_FILE -l @LOG_CONFIG_FILE"); + private BrokerCommandHelper _brokerCommandHelper = new BrokerCommandHelper("qpid -p @PORT -sp @STORE_PATH -st @STORE_TYPE -l @LOG_CONFIG_FILE"); private File logConfigFile = mock(File.class); - private File configFile = mock(File.class); @Override public void setUp() { when(logConfigFile.getAbsolutePath()).thenReturn("logConfigFile"); - when(configFile.getPath()).thenReturn("configFile"); } public void testGetBrokerCommand() { - List<String> brokerCommand = _brokerCommandHelper.getBrokerCommand( - 1, 2, 3, configFile, logConfigFile, "includes", "excludes"); - - assertEquals(Arrays.asList("qpid", "-p", "1", "-s", "2", "-m", "3", - "includes", "excludes", - "-c", "\"configFile\"", "-l", "\"logConfigFile\""), - brokerCommand); - } - - public void testGetBrokerCommandForMultipleProtocolIncludesAndExcludes() - { - List<String> brokerCommand = _brokerCommandHelper.getBrokerCommand( - 1, 2, 3, configFile, logConfigFile, "includes1 includes2", "excludes1 excludes2"); - - assertEquals("The space-separated protocol include/exclude lists should be converted into separate entries in the returned list so that ProcessBuilder treats them as separate arguments", - Arrays.asList("qpid", "-p", "1", "-s", "2", "-m", "3", - "includes1", "includes2", "excludes1", "excludes2", - "-c", "\"configFile\"", "-l", "\"logConfigFile\""), - brokerCommand); + String brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile); + assertEquals("Unexpected broker command", "qpid -p 1 -sp configFile -st json -l \"logConfigFile\"", brokerCommand); } public void testRemoveBrokerCommandLog4JFile() { _brokerCommandHelper.removeBrokerCommandLog4JFile(); - - List<String> brokerCommand = _brokerCommandHelper.getBrokerCommand( - 1, 2, 3, configFile, logConfigFile, "includes", "excludes"); + String brokerCommand = _brokerCommandHelper.getBrokerCommand(1, "configFile", "json", logConfigFile); assertEquals("The broker command list should not contain a log4j config option", - Arrays.asList("qpid", "-p", "1", "-s", "2", "-m", "3", - "includes", "excludes", - "-c", "\"configFile\""), - brokerCommand); + "qpid -p 1 -sp configFile -st json", brokerCommand ); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java index c5e8a08ec6..8bad73d0ea 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/InternalBrokerHolder.java @@ -20,9 +20,6 @@ */ package org.apache.qpid.test.utils; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadInfo; -import java.lang.management.ThreadMXBean; import java.util.Set; import org.apache.log4j.Logger; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java index 826d00d0df..6e6e3271f0 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/JMXTestUtils.java @@ -31,6 +31,8 @@ import org.apache.qpid.management.common.mbeans.ManagedExchange; import org.apache.qpid.management.common.mbeans.ManagedQueue; import org.apache.qpid.management.common.mbeans.ServerInformation; import org.apache.qpid.management.common.mbeans.UserManagement; +import org.apache.qpid.server.model.Plugin; +import org.apache.qpid.server.plugin.PluginFactory; import javax.management.InstanceNotFoundException; import javax.management.JMException; @@ -45,7 +47,9 @@ import javax.management.ObjectName; import javax.management.remote.JMXConnector; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -77,7 +81,7 @@ public class JMXTestUtils public void setUp() throws IOException, ConfigurationException, Exception { - _test.setConfigurationProperty("management.enabled", "true"); + _test.getBrokerConfiguration().addJmxManagementConfiguration(); } public void open() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java index fe116f175b..4259254123 100755 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java @@ -23,6 +23,7 @@ import java.io.PrintStream; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -60,11 +61,14 @@ import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.jms.ConnectionURL; import org.apache.qpid.server.Broker; import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.ProtocolExclusion; -import org.apache.qpid.server.ProtocolInclusion; -import org.apache.qpid.server.configuration.ServerConfiguration; +import org.apache.qpid.server.configuration.BrokerProperties; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.protocol.AmqpProtocolVersion; +import org.apache.qpid.server.store.MemoryMessageStore; import org.apache.qpid.server.store.MessageStoreConstants; +import org.apache.qpid.server.store.MessageStoreCreator; +import org.apache.qpid.server.store.MessageStoreFactory; import org.apache.qpid.server.store.derby.DerbyMessageStore; import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.util.FileUtils; @@ -85,9 +89,9 @@ public class QpidBrokerTestCase extends QpidTestCase public static final String GUEST_PASSWORD = "guest"; protected final static String QpidHome = System.getProperty("QPID_HOME"); - protected File _configFile = new File(System.getProperty("broker.config")); + private final File _configFile = new File(System.getProperty("broker.config")); private File _logConfigFile; - + protected final String _brokerStoreType = System.getProperty("broker.config-store-type", "json"); protected static final Logger _logger = Logger.getLogger(QpidBrokerTestCase.class); protected static final int LOGMONITOR_TIMEOUT = 5000; @@ -95,7 +99,7 @@ public class QpidBrokerTestCase extends QpidTestCase private Map<String, String> _propertiesSetForBroker = new HashMap<String, String>(); - private XMLConfiguration _testConfiguration = new XMLConfiguration(); + private Map<Integer, TestBrokerConfiguration> _brokerConfigurations; private XMLConfiguration _testVirtualhosts = new XMLConfiguration(); protected static final String INDEX = "index"; @@ -103,6 +107,8 @@ public class QpidBrokerTestCase extends QpidTestCase private static final String DEFAULT_INITIAL_CONTEXT = "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"; + private static Map<String, String> supportedStoresClassToTypeMapping = new HashMap<String, String>(); + static { String initialContext = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); @@ -111,16 +117,21 @@ public class QpidBrokerTestCase extends QpidTestCase { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT); } + + MessageStoreCreator messageStoreCreator = new MessageStoreCreator(); + Collection<MessageStoreFactory> factories = messageStoreCreator.getFactories(); + for (MessageStoreFactory messageStoreFactory : factories) + { + supportedStoresClassToTypeMapping.put(messageStoreFactory.createMessageStore().getClass().getName(), messageStoreFactory.getType()); + } } // system properties private static final String TEST_VIRTUALHOSTS = "test.virtualhosts"; - private static final String TEST_CONFIG = "test.config"; private static final String BROKER_LANGUAGE = "broker.language"; protected static final String BROKER_TYPE = "broker.type"; private static final String BROKER_COMMAND = "broker.command"; private static final String BROKER_CLEAN_BETWEEN_TESTS = "broker.clean.between.tests"; - private static final String BROKER_EXISTING_QPID_WORK = "broker.existing.qpid.work"; private static final String BROKER_VERSION = "broker.version"; protected static final String BROKER_READY = "broker.ready"; private static final String BROKER_STOPPED = "broker.stopped"; @@ -128,21 +139,25 @@ public class QpidBrokerTestCase extends QpidTestCase private static final String BROKER_LOG_INTERLEAVE = "broker.log.interleave"; private static final String BROKER_LOG_PREFIX = "broker.log.prefix"; private static final String BROKER_PERSITENT = "broker.persistent"; - public static final String BROKER_PROTOCOL_EXCLUDES = "broker.protocol.excludes"; - public static final String BROKER_PROTOCOL_INCLUDES = "broker.protocol.includes"; public static final String PROFILE_USE_SSL = "profile.use_ssl"; + public static final int DEFAULT_PORT_VALUE = 5672; + public static final int DEFAULT_SSL_PORT_VALUE = 5671; + public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999; + public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100; + public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 8080; + public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 8443; + // values protected static final String JAVA = "java"; protected static final String CPP = "cpp"; protected static final String QPID_HOME = "QPID_HOME"; - public static final int DEFAULT_VM_PORT = 1; - public static final int DEFAULT_PORT = Integer.getInteger("test.port", ServerConfiguration.DEFAULT_PORT); + public static final int DEFAULT_PORT = Integer.getInteger("test.port", DEFAULT_PORT_VALUE); public static final int FAILING_PORT = Integer.parseInt(System.getProperty("test.port.alt")); - public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", ServerConfiguration.DEFAULT_JMXPORT_REGISTRYSERVER); - public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", ServerConfiguration.DEFAULT_SSL_PORT); + public static final int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", DEFAULT_JMXPORT_REGISTRYSERVER); + public static final int DEFAULT_SSL_PORT = Integer.getInteger("test.port.ssl", DEFAULT_SSL_PORT_VALUE); protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA); protected BrokerType _brokerType = BrokerType.valueOf(System.getProperty(BROKER_TYPE, "").toUpperCase()); @@ -189,16 +204,48 @@ public class QpidBrokerTestCase extends QpidTestCase } private MessageType _messageType = MessageType.TEXT; - public QpidBrokerTestCase(String name) + public QpidBrokerTestCase() { - super(name); + super(); + _brokerConfigurations = new HashMap<Integer, TestBrokerConfiguration>(); initialiseLogConfigFile(); } - public QpidBrokerTestCase() + public TestBrokerConfiguration getBrokerConfiguration(int port) { - super(); - initialiseLogConfigFile(); + int actualPort = getPort(port); + + synchronized (_brokerConfigurations) + { + TestBrokerConfiguration configuration = _brokerConfigurations.get(actualPort); + if (configuration == null) + { + configuration = createBrokerConfiguration(actualPort); + } + return configuration; + } + } + + public TestBrokerConfiguration getBrokerConfiguration() + { + return getBrokerConfiguration(DEFAULT_PORT); + } + + public TestBrokerConfiguration createBrokerConfiguration(int port) + { + int actualPort = getPort(port); + TestBrokerConfiguration configuration = new TestBrokerConfiguration(System.getProperty(_brokerStoreType), _configFile.getAbsolutePath()); + synchronized (_brokerConfigurations) + { + _brokerConfigurations.put(actualPort, configuration); + } + if (actualPort != DEFAULT_PORT) + { + configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.PORT, actualPort); + configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT, Port.PORT, getManagementPort(actualPort)); + configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.PORT, getManagementPort(actualPort) + JMXPORT_CONNECTORSERVER_OFFSET); + } + return configuration; } private void initialiseLogConfigFile() @@ -309,16 +356,6 @@ public class QpidBrokerTestCase extends QpidTestCase fail("Unable to test without config file:" + _configFile); } - String existingQpidWorkPath = System.getProperty(BROKER_EXISTING_QPID_WORK); - if(existingQpidWorkPath != null && !existingQpidWorkPath.equals("")) - { - - String qpidWork = getQpidWork(_brokerType, getPort()); - File existing = new File(existingQpidWorkPath); - cleanBrokerWork(qpidWork); - FileUtils.copyRecursive(existing, new File(qpidWork)); - } - startBroker(); } @@ -342,7 +379,7 @@ public class QpidBrokerTestCase extends QpidTestCase { Set<Integer> ports = new HashSet<Integer>(); int managementPort = getManagementPort(mainPort); - int connectorServerPort = managementPort + ServerConfiguration.JMXPORT_CONNECTORSERVER_OFFSET; + int connectorServerPort = managementPort + JMXPORT_CONNECTORSERVER_OFFSET; ports.add(mainPort); ports.add(managementPort); @@ -381,19 +418,11 @@ public class QpidBrokerTestCase extends QpidTestCase public void startBroker(int port) throws Exception { - startBroker(port, _testConfiguration, _testVirtualhosts); + int actualPort = getPort(port); + TestBrokerConfiguration configuration = getBrokerConfiguration(actualPort); + startBroker(actualPort, configuration, _testVirtualhosts); } - private List<String> getBrokerCommand(int port) - { - final int sslPort = port-1; - final String protocolExcludesList = getProtocolExcludesList(port, sslPort); - final String protocolIncludesList = getProtocolIncludesList(port, sslPort); - return _brokerCommandHelper.getBrokerCommand( - port, sslPort, getManagementPort(port), - _configFile, _logConfigFile, - protocolIncludesList, protocolExcludesList); - } protected File getBrokerCommandLog4JFile() { @@ -406,11 +435,10 @@ public class QpidBrokerTestCase extends QpidTestCase _logger.info("Modified log config file to: " + file); } - public void startBroker(int port, XMLConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception + public void startBroker(int port, TestBrokerConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception { port = getPort(port); - - // Save only virtual host configuration changes that have been made + String testConfig = saveTestConfiguration(port, testConfiguration); String virtualHostsConfig = saveTestVirtualhosts(port, virtualHosts); if(_brokers.get(port) != null) @@ -422,19 +450,13 @@ public class QpidBrokerTestCase extends QpidTestCase if (_brokerType.equals(BrokerType.INTERNAL) && !existingInternalBroker()) { - testConfiguration.setProperty(ServerConfiguration.MGMT_CUSTOM_REGISTRY_SOCKET, String.valueOf(false)); - String testConfig = saveTestConfiguration(port, testConfiguration); - setSystemProperty(TEST_CONFIG, testConfig); + _logger.info("Set test.virtualhosts property to: " + virtualHostsConfig); setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig); - + setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, "false"); BrokerOptions options = new BrokerOptions(); - options.setConfigFile(_configFile.getAbsolutePath()); - options.addPort(port); - addExcludedPorts(port, DEFAULT_SSL_PORT, options); - addIncludedPorts(port, DEFAULT_SSL_PORT, options); - - options.setJmxPortRegistryServer(getManagementPort(port)); + options.setConfigurationStoreType(_brokerStoreType); + options.setConfigurationStoreLocation(testConfig); //Set the log config file, relying on the log4j.configuration system property //set on the JVM by the JUnit runner task in module.xml. @@ -450,9 +472,10 @@ public class QpidBrokerTestCase extends QpidTestCase { // Add the port to QPID_WORK to ensure unique working dirs for multi broker tests final String qpidWork = getQpidWork(_brokerType, port); - List<String> cmd = getBrokerCommand(port); - _logger.info("Starting external broker using command: " + StringUtils.join(cmd, " ")); - ProcessBuilder pb = new ProcessBuilder(cmd); + + String cmd = _brokerCommandHelper.getBrokerCommand(port, testConfig, _brokerStoreType, _logConfigFile); + _logger.info("Starting spawn broker using command: " + cmd); + ProcessBuilder pb = new ProcessBuilder(cmd.split("\\s+")); pb.redirectErrorStream(true); Map<String, String> processEnv = pb.environment(); String qpidHome = System.getProperty(QPID_HOME); @@ -482,7 +505,6 @@ public class QpidBrokerTestCase extends QpidTestCase } } - String testConfig = saveTestConfiguration(port, testConfiguration); String qpidOpts = ""; // a synchronized hack to avoid adding into QPID_OPTS the values @@ -492,19 +514,11 @@ public class QpidBrokerTestCase extends QpidTestCase // Add default test logging levels that are used by the log4j-test // Use the convenience methods to push the current logging setting // in to the external broker's QPID_OPTS string. - if (System.getProperty("amqj.protocol.logging.level") != null) - { - setSystemProperty("amqj.protocol.logging.level"); - } - if (System.getProperty("root.logging.level") != null) - { - setSystemProperty("root.logging.level"); - } - - setSystemProperty(TEST_CONFIG, testConfig); + setSystemProperty("amqj.protocol.logging.level"); + setSystemProperty("root.logging.level"); + setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_EXCLUDES); + setSystemProperty(BrokerProperties.PROPERTY_BROKER_DEFAULT_AMQP_PROTOCOL_INCLUDES); setSystemProperty(TEST_VIRTUALHOSTS, virtualHostsConfig); - // set test.config and test.virtualhosts - qpidOpts += " -D" + TEST_CONFIG + "=" + testConfig + " -D" + TEST_VIRTUALHOSTS + "=" + virtualHostsConfig; // Add all the specified system properties to QPID_OPTS if (!_propertiesSetForBroker.isEmpty()) @@ -534,9 +548,15 @@ public class QpidBrokerTestCase extends QpidTestCase p.start(); + SpawnedBrokerHolder holder = new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker); if (!p.await(30, TimeUnit.SECONDS)) { _logger.info("broker failed to become ready (" + p.getReady() + "):" + p.getStopLine()); + String threadDump = holder.dumpThreads(); + if (!threadDump.isEmpty()) + { + _logger.info("the result of a try to capture thread dump:" + threadDump); + } //Ensure broker has stopped process.destroy(); cleanBrokerWork(qpidWork); @@ -557,65 +577,7 @@ public class QpidBrokerTestCase extends QpidTestCase // this is expect if the broker started successfully } - _brokers.put(port, new SpawnedBrokerHolder(process, qpidWork, portsUsedByBroker)); - } - } - - private void addExcludedPorts(int port, int sslPort, BrokerOptions options) - { - final String protocolExcludesList = getProtocolExcludesList(port, sslPort); - - if (protocolExcludesList.equals("")) - { - return; - } - final String[] toks = protocolExcludesList.split("\\s"); - - if(toks.length % 2 != 0) - { - throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolExcludesList + "'"); - } - for (int i = 0; i < toks.length; i=i+2) - { - String excludeArg = toks[i]; - final int excludedPort = Integer.parseInt(toks[i+1]); - options.addExcludedPort(ProtocolExclusion.lookup(excludeArg), excludedPort); - - _logger.info("Adding protocol exclusion " + excludeArg + " " + excludedPort); - } - } - - protected String getProtocolExcludesList(int port, int sslPort) - { - return System.getProperty(BROKER_PROTOCOL_EXCLUDES,"").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort); - } - - private String getProtocolIncludesList(int port, int sslPort) - { - return System.getProperty(BROKER_PROTOCOL_INCLUDES, "").replace("@PORT", "" + port).replace("@SSL_PORT", "" + sslPort); - } - - private void addIncludedPorts(int port, int sslPort, BrokerOptions options) - { - final String protocolIncludesList = getProtocolIncludesList(port, sslPort); - - if (protocolIncludesList.equals("")) - { - return; - } - final String[] toks = protocolIncludesList.split("\\s"); - - if(toks.length % 2 != 0) - { - throw new IllegalArgumentException("Must be an even number of tokens in '" + protocolIncludesList + "'"); - } - for (int i = 0; i < toks.length; i=i+2) - { - String includeArg = toks[i]; - final int includedPort = Integer.parseInt(toks[i+1]); - options.addIncludedPort(ProtocolInclusion.lookup(includeArg), includedPort); - - _logger.info("Adding protocol inclusion " + includeArg + " " + includedPort); + _brokers.put(port, holder); } } @@ -649,7 +611,7 @@ public class QpidBrokerTestCase extends QpidTestCase public String getTestConfigFile(int port) { - return _output + "/" + getTestQueueName() + "-" + port + "-config.xml"; + return _output + "/" + getTestQueueName() + "-" + port + "-config"; } public String getTestVirtualhostsFile(int port) @@ -662,35 +624,26 @@ public class QpidBrokerTestCase extends QpidTestCase return file.replace(System.getProperty(QPID_HOME,"QPID_HOME") + "/",""); } - protected void saveTestConfiguration() throws ConfigurationException + protected String getPathRelativeToWorkingDirectory(String file) { - String relative = saveTestConfiguration(getPort(), _testConfiguration); - setSystemProperty(TEST_CONFIG, relative); + File configLocation = new File(file); + File workingDirectory = new File(System.getProperty("user.dir")); + return configLocation.getAbsolutePath().replace(workingDirectory.getAbsolutePath(), "").substring(1); } - protected String saveTestConfiguration(int port, XMLConfiguration testConfiguration) throws ConfigurationException + protected String saveTestConfiguration(int port, TestBrokerConfiguration testConfiguration) { - // Specify the test config file String testConfig = getTestConfigFile(port); - String relative = relativeToQpidHome(testConfig); - - _logger.info("Saving test virtualhosts file at: " + testConfig); - - // Create the file if configuration does not exist - if (testConfiguration.isEmpty()) + String relative = getPathRelativeToWorkingDirectory(testConfig); + if (!testConfiguration.isSaved()) { - testConfiguration.addProperty("__ignore", "true"); + _logger.info("Saving test broker configuration at: " + testConfig); + testConfiguration.save(new File(testConfig)); + testConfiguration.setSaved(true); } - testConfiguration.save(testConfig); return relative; } - protected void saveTestVirtualhosts() throws ConfigurationException - { - String relative = saveTestVirtualhosts(getPort(), _testVirtualhosts); - setSystemProperty(TEST_VIRTUALHOSTS, relative); - } - protected String saveTestVirtualhosts(int port, XMLConfiguration virtualHostConfiguration) throws ConfigurationException { // Specify the test virtualhosts file @@ -846,11 +799,12 @@ public class QpidBrokerTestCase extends QpidTestCase /** * Creates a new virtual host within the test virtualhost file. - * + * @param brokerPort broker port * @param virtualHostName virtual host name + * * @throws ConfigurationException */ - protected void createTestVirtualHost(String virtualHostName) throws ConfigurationException + protected void createTestVirtualHost(int brokerPort, String virtualHostName) throws ConfigurationException { String storeClassName = getTestProfileMessageStoreClassName(); @@ -872,29 +826,13 @@ public class QpidBrokerTestCase extends QpidTestCase { _testVirtualhosts.setProperty("virtualhost." + virtualHostName + ".store." + MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY, storeDir); } - } - /** - * Get a property value from the current configuration file. - * - * @param property the property to lookup - * - * @return the requested String Value - * - * @throws org.apache.commons.configuration.ConfigurationException - * - */ - protected String getConfigurationStringProperty(String property) throws ConfigurationException - { - // Call save Configuration to be sure we have saved the test specific - // file. As the optional status - saveTestConfiguration(); - saveTestVirtualhosts(); - - ServerConfiguration configuration = new ServerConfiguration(_configFile); - // Don't need to configuration.configure() here as we are just pulling - // values directly by String. - return configuration.getConfig().getString(property); + // add new virtual host configuration to the broker store + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(VirtualHost.NAME, virtualHostName); + attributes.put(VirtualHost.CONFIG_PATH, System.getProperty("broker.virtualhosts-config")); + int port = getPort(brokerPort); + getBrokerConfiguration(port).addHostConfiguration(attributes); } /** @@ -911,7 +849,7 @@ public class QpidBrokerTestCase extends QpidTestCase * * @throws ConfigurationException when loading the current config file */ - public void setConfigurationProperty(String property, String value) throws ConfigurationException + public void setVirtualHostConfigurationProperty(String property, String value) throws ConfigurationException { // Choose which file to write the property to based on prefix. if (property.startsWith("virtualhosts")) @@ -920,7 +858,7 @@ public class QpidBrokerTestCase extends QpidTestCase } else { - _testConfiguration.setProperty(property, value); + throw new ConfigurationException("Cannot set broker configuration as property"); } } @@ -938,11 +876,13 @@ public class QpidBrokerTestCase extends QpidTestCase */ protected void setBrokerOnlySystemProperty(String property, String value) { - if (!_propertiesSetForBroker.containsKey(property)) + synchronized (_propertiesSetForBroker) { - _propertiesSetForBroker.put(property, value); + if (!_propertiesSetForBroker.containsKey(property)) + { + _propertiesSetForBroker.put(property, value); + } } - } /** @@ -955,7 +895,11 @@ public class QpidBrokerTestCase extends QpidTestCase */ protected void setSystemProperty(String property) { - setSystemProperty(property, System.getProperty(property)); + String value = System.getProperty(property); + if (value != null) + { + setSystemProperty(property, value); + } } /** @@ -974,9 +918,18 @@ public class QpidBrokerTestCase extends QpidTestCase */ protected void setSystemProperty(String property, String value) { - // Record the value for the external broker - _propertiesSetForBroker.put(property, value); - + synchronized(_propertiesSetForBroker) + { + // Record the value for the external broker + if (value == null) + { + _propertiesSetForBroker.remove(property); + } + else + { + _propertiesSetForBroker.put(property, value); + } + } //Set the value for the test client vm aswell. setTestClientSystemProperty(property, value); } @@ -1440,13 +1393,14 @@ public class QpidBrokerTestCase extends QpidTestCase _testVirtualhosts = testVirtualhosts; } - public XMLConfiguration getTestConfiguration() + public String getTestProfileMessageStoreType() { - return _testConfiguration; + final String storeClass = getTestProfileMessageStoreClassName(); + if (storeClass == null) + { + return MemoryMessageStore.TYPE; + } + return supportedStoresClassToTypeMapping.get(storeClass); } - public void setTestConfiguration(XMLConfiguration testConfiguration) - { - _testConfiguration = testConfiguration; - } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java new file mode 100644 index 0000000000..5f712f1127 --- /dev/null +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java @@ -0,0 +1,229 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.test.utils; + +import java.io.File; +import java.net.MalformedURLException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore; +import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Plugin; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.plugin.PluginFactory; + +public class TestBrokerConfiguration +{ + public static final String ENTRY_NAME_HTTP_PORT = "http"; + public static final String ENTRY_NAME_AMQP_PORT = "amqp"; + public static final String ENTRY_NAME_RMI_PORT = "rmi"; + public static final String ENTRY_NAME_JMX_PORT = "jmx"; + public static final String ENTRY_NAME_VIRTUAL_HOST = "test"; + public static final String ENTRY_NAME_AUTHENTICATION_PROVIDER = "plain"; + public static final String ENTRY_NAME_EXTERNAL_PROVIDER = "external"; + public static final String ENTRY_NAME_SSL_PORT = "sslPort"; + public static final String ENTRY_NAME_HTTP_MANAGEMENT = "MANAGEMENT-HTTP"; + public static final String MANAGEMENT_HTTP_PLUGIN_TYPE = "MANAGEMENT-HTTP"; + public static final String ENTRY_NAME_JMX_MANAGEMENT = "MANAGEMENT-JMX"; + public static final String MANAGEMENT_JMX_PLUGIN_TYPE = "MANAGEMENT-JMX"; + public static final String ENTRY_NAME_ANONYMOUS_PROVIDER = "anonymous"; + + private JsonConfigurationEntryStore _store; + private boolean _saved; + + public TestBrokerConfiguration(String storeType, String intialStoreLocation) + { + // TODO: add support for DERBY store + _store = new JsonConfigurationEntryStore(); + + try + { + // load the initial store data into our store + _store.load(new File(intialStoreLocation).toURI().toURL()); + } + catch (MalformedURLException e) + { + // ignore + } + } + + public boolean setBrokerAttribute(String name, Object value) + { + return setObjectAttribute(_store.getRootEntry(), name, value); + } + + public boolean setObjectAttribute(String objectName, String attributeName, Object value) + { + ConfigurationEntry entry = findObjectByName(objectName); + if (entry == null) + { + return false; + } + return setObjectAttribute(entry, attributeName, value); + } + + public boolean setObjectAttributes(String objectName, Map<String, Object> attributes) + { + ConfigurationEntry entry = findObjectByName(objectName); + if (entry == null) + { + return false; + } + return setObjectAttributes(entry, attributes); + } + + public boolean save(File configFile) + { + _store.saveTo(configFile); + return true; + } + + public UUID[] removeObjectConfiguration(String name) + { + ConfigurationEntry entry = findObjectByName(name); + if (entry != null) + { + return _store.remove(entry.getId()); + } + return null; + } + + public UUID addObjectConfiguration(String name, String type, Map<String, Object> attributes) + { + UUID id = UUIDGenerator.generateBrokerChildUUID(type, name); + addObjectConfiguration(id, type, attributes); + return id; + } + + public UUID addJmxManagementConfiguration() + { + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_JMX_PLUGIN_TYPE); + attributes.put(Plugin.NAME, ENTRY_NAME_JMX_MANAGEMENT); + return addObjectConfiguration(ENTRY_NAME_JMX_MANAGEMENT, Plugin.class.getSimpleName(), attributes); + } + + public UUID addHttpManagementConfiguration() + { + Map<String, Object> attributes = new HashMap<String, Object>(); + attributes.put(PluginFactory.PLUGIN_TYPE, MANAGEMENT_HTTP_PLUGIN_TYPE); + attributes.put(Plugin.NAME, ENTRY_NAME_HTTP_MANAGEMENT); + return addObjectConfiguration(ENTRY_NAME_HTTP_MANAGEMENT, Plugin.class.getSimpleName(), attributes); + } + + public UUID addPortConfiguration(Map<String, Object> attributes) + { + String name = (String) attributes.get(Port.NAME); + return addObjectConfiguration(name, Port.class.getSimpleName(), attributes); + } + + public UUID addHostConfiguration(Map<String, Object> attributes) + { + String name = (String) attributes.get(VirtualHost.NAME); + return addObjectConfiguration(name, VirtualHost.class.getSimpleName(), attributes); + } + + public UUID addAuthenticationProviderConfiguration(Map<String, Object> attributes) + { + String name = (String) attributes.get(AuthenticationProvider.NAME); + return addObjectConfiguration(name, AuthenticationProvider.class.getSimpleName(), attributes); + } + + private boolean setObjectAttributes(ConfigurationEntry entry, Map<String, Object> attributes) + { + Map<String, Object> newAttributes = new HashMap<String, Object>(entry.getAttributes()); + newAttributes.putAll(attributes); + ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), newAttributes, + entry.getChildrenIds(), _store); + _store.save(newEntry); + return true; + } + + private ConfigurationEntry findObjectByName(String objectName) + { + ConfigurationEntry root = _store.getRootEntry(); + return findObjectByName(root, objectName); + } + + private ConfigurationEntry findObjectByName(ConfigurationEntry entry, String objectName) + { + Map<String, Object> attributes = entry.getAttributes(); + if (attributes != null) + { + String name = (String) attributes.get("name"); + if (objectName.equals(name)) + { + return entry; + } + } + Set<UUID> childrenIds = entry.getChildrenIds(); + for (UUID uuid : childrenIds) + { + ConfigurationEntry child = _store.getEntry(uuid); + ConfigurationEntry result = findObjectByName(child, objectName); + if (result != null) + { + return result; + } + } + return null; + } + + private void addObjectConfiguration(UUID id, String type, Map<String, Object> attributes) + { + ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), _store); + ConfigurationEntry root = _store.getRootEntry(); + Set<UUID> childrenIds = new HashSet<UUID>(root.getChildrenIds()); + childrenIds.add(id); + ConfigurationEntry newRoot = new ConfigurationEntry(root.getId(), root.getType(), root.getAttributes(), childrenIds, + _store); + _store.save(newRoot, entry); + } + + private boolean setObjectAttribute(ConfigurationEntry entry, String attributeName, Object value) + { + Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); + attributes.put(attributeName, value); + ConfigurationEntry newEntry = new ConfigurationEntry(entry.getId(), entry.getType(), attributes, entry.getChildrenIds(), + _store); + _store.save(newEntry); + return true; + } + + public boolean isSaved() + { + return _saved; + } + + public void setSaved(boolean saved) + { + _saved = saved; + } + +} diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java index 19c9b9fb17..9d5be775dc 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestSSLConstants.java @@ -24,4 +24,7 @@ public interface TestSSLConstants String KEYSTORE_PASSWORD = "password"; String TRUSTSTORE = "test-profiles/test_resources/ssl/java_client_truststore.jks"; String TRUSTSTORE_PASSWORD = "password"; + + String BROKER_KEYSTORE = "test-profiles/test_resources/ssl/java_broker_keystore.jks"; + String BROKER_KEYSTORE_PASSWORD = "password"; } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java index d6b8a8400c..d77731d09f 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/util/LogMonitor.java @@ -30,8 +30,10 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * Utility to simplify the monitoring of Log4j file output @@ -160,6 +162,39 @@ public class LogMonitor return results; } + public Map<String, List<String>> findMatches(String... pattern) throws IOException + { + + Map<String, List<String>> results= new HashMap<String, List<String>>(); + for (String p : pattern) + { + results.put(p, new LinkedList<String>()); + } + LineNumberReader reader = new LineNumberReader(new FileReader(_logfile)); + try + { + while (reader.ready()) + { + String line = reader.readLine(); + if (reader.getLineNumber() > _linesToSkip) + { + for (String p : pattern) + { + if (line.contains(p)) + { + results.get(p).add(line); + } + } + } + } + } + finally + { + reader.close(); + } + + return results; + } /** * Checks the log file for a given message to appear. If the caller * has previously called {@link #markDiscardPoint()}, lines up until the discard |
