Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
 Tue Jan 27 15:00:13 2015
@@ -18,9 +18,7 @@
 package org.apache.qpid.test.utils;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -28,7 +26,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
@@ -48,8 +45,10 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.log4j.xml.DOMConfigurator;
 
 import org.apache.qpid.AMQException;
 import org.apache.qpid.client.AMQConnectionFactory;
@@ -60,7 +59,6 @@ import org.apache.qpid.exchange.Exchange
 import org.apache.qpid.framing.AMQShortString;
 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.configuration.BrokerProperties;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
@@ -83,19 +81,11 @@ public class QpidBrokerTestCase extends
 {
     private TaskExecutor _taskExecutor;
 
-    public enum BrokerType
-    {
-        EXTERNAL /** Test case relies on a Broker started independently of the 
test-suite */,
-        INTERNAL /** Test case starts an embedded broker within this JVM */,
-        SPAWNED /** Test case spawns a new broker as a separate process */
-    }
-
     public static final String GUEST_USERNAME = "guest";
     public static final String GUEST_PASSWORD = "guest";
 
-    protected final static String QpidHome = System.getProperty("QPID_HOME");
     private final File _configFile = new 
File(System.getProperty("broker.config"));
-    private File _logConfigFile;
+    private File _spawnedBrokerLogConfigFile;
     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;
@@ -128,11 +118,7 @@ public class QpidBrokerTestCase extends
     private static final String BROKER_COMMAND_PLATFORM = "broker.command." + 
SystemUtils.getOSConfigSuffix();
     private static final String BROKER_CLEAN_BETWEEN_TESTS = 
"broker.clean.between.tests";
     private static final String BROKER_VERSION = "broker.version";
-    protected static final String BROKER_READY = "broker.ready";
-    private static final String BROKER_STOPPED = "broker.stopped";
     private static final String TEST_OUTPUT = "test.output";
-    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 PROFILE_USE_SSL = "profile.use_ssl";
 
@@ -141,41 +127,30 @@ public class QpidBrokerTestCase extends
     public static final int DEFAULT_JMXPORT_REGISTRYSERVER = 8999;
     public static final int JMXPORT_CONNECTORSERVER_OFFSET = 100;
     public static final int DEFAULT_HTTP_MANAGEMENT_PORT_VALUE = 8080;
-    public static final int DEFAULT_HTTPS_MANAGEMENT_PORT_VALUE = 8443;
 
     public static final String 
TEST_AMQP_PORT_PROTOCOLS_PROPERTY="test.amqp_port_protocols";
 
     // 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_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", DEFAULT_JMXPORT_REGISTRYSERVER);
     public static final int DEFAULT_HTTP_MANAGEMENT_PORT = 
Integer.getInteger("test.hport", DEFAULT_HTTP_MANAGEMENT_PORT_VALUE);
-    public static final int DEFAULT_HTTPS_MANAGEMENT_PORT = 
Integer.getInteger("test.hsport", DEFAULT_HTTPS_MANAGEMENT_PORT_VALUE);
     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());
+    protected BrokerHolder.BrokerType _brokerType = 
BrokerHolder.BrokerType.valueOf(System.getProperty(BROKER_TYPE, 
"").toUpperCase());
 
     private static final String BROKER_COMMAND_TEMPLATE = 
System.getProperty(BROKER_COMMAND_PLATFORM, System.getProperty(BROKER_COMMAND));
-    protected BrokerCommandHelper _brokerCommandHelper = new 
BrokerCommandHelper(BROKER_COMMAND_TEMPLATE);
 
     private Boolean _brokerCleanBetweenTests = 
Boolean.getBoolean(BROKER_CLEAN_BETWEEN_TESTS);
     private final Protocol _brokerProtocol = Protocol.valueOf("AMQP_" + 
System.getProperty(BROKER_VERSION, " ").substring(1));
     protected String _output = System.getProperty(TEST_OUTPUT, 
System.getProperty("java.io.tmpdir"));
     protected Boolean _brokerPersistent = Boolean.getBoolean(BROKER_PERSITENT);
 
-    protected static String _brokerLogPrefix = 
System.getProperty(BROKER_LOG_PREFIX,"BROKER: ");
-    protected static boolean _interleaveBrokerLog = 
Boolean.valueOf(System.getProperty(BROKER_LOG_INTERLEAVE,"true"));
-
     protected File _outputFile;
 
-    protected PrintStream _testcaseOutputStream;
-
     protected Map<Integer, BrokerHolder> _brokers = new HashMap<Integer, 
BrokerHolder>();
 
     protected InitialContext _initialContext;
@@ -195,6 +170,8 @@ public class QpidBrokerTestCase extends
 
     /** Size to create our message*/
     private int _messageSize = DEFAULT_MESSAGE_SIZE;
+    private String _brokerCommandTemplate;
+
     /** Type of message*/
     protected enum MessageType
     {
@@ -210,7 +187,8 @@ public class QpidBrokerTestCase extends
     {
         super();
         _brokerConfigurations = new HashMap<Integer, 
TestBrokerConfiguration>();
-        initialiseLogConfigFile();
+        initialiseSpawnedBrokerLogConfigFile();
+        _brokerCommandTemplate = BROKER_COMMAND_TEMPLATE;
     }
 
     public TestBrokerConfiguration getBrokerConfiguration(int port)
@@ -259,12 +237,12 @@ public class QpidBrokerTestCase extends
         return configuration;
     }
 
-    private void initialiseLogConfigFile()
+    private void initialiseSpawnedBrokerLogConfigFile()
     {
-        _logConfigFile = new File(LOG4J_CONFIG_FILE_PATH);
-        if(!_logConfigFile.exists())
+        _spawnedBrokerLogConfigFile = new 
File(SPAWNED_BROKER_LOG4J_CONFIG_FILE_PATH);
+        if(!_spawnedBrokerLogConfigFile.exists())
         {
-            throw new RuntimeException("Log config file " + 
_logConfigFile.getAbsolutePath() + " does not exist");
+            throw new RuntimeException("Log config file " + 
_spawnedBrokerLogConfigFile.getAbsolutePath() + " does not exist");
         }
     }
 
@@ -276,36 +254,18 @@ public class QpidBrokerTestCase extends
     @Override
     public void runBare() throws Throwable
     {
-        String qname = getClass().getName() + "." + getName();
-
         // Initialize this for each test run
         _env = new HashMap<String, String>();
 
-        PrintStream oldOut = System.out;
-        PrintStream oldErr = System.err;
-        PrintStream out = null;
-        PrintStream err = null;
-
-        boolean redirected = _output != null && _output.length() > 0;
-        if (redirected)
-        {
-            _outputFile = new File(String.format("%s/TEST-%s.out", _output, 
qname));
-            out = new PrintStream(new FileOutputStream(_outputFile), true);
-            err = new PrintStream(String.format("%s/TEST-%s.err", _output, 
qname));
+        // Log4j properties expects this to be set
+        System.setProperty("qpid.testMethod", "-" + getName());
+        System.setProperty("qpid.testClass", getClass().getName());
 
-            System.setOut(out);
-            System.setErr(err);
+        String log4jConfigFile = 
System.getProperty("log4j.configuration.file");
+        DOMConfigurator.configure(log4jConfigFile);
 
-            if (_interleaveBrokerLog)
-            {
-                _testcaseOutputStream = out;
-            }
-            else
-            {
-                _testcaseOutputStream = new PrintStream(new 
FileOutputStream(String
-                        .format("%s/TEST-%s.broker.out", _output, qname)), 
true);
-            }
-        }
+        // get log file from file appender
+        _outputFile = new 
File(((FileAppender)LogManager.getRootLogger().getAllAppenders().nextElement()).getFile());
 
         try
         {
@@ -324,7 +284,7 @@ public class QpidBrokerTestCase extends
             revertSystemProperties();
             revertLoggingLevels();
 
-            if(_brokerCleanBetweenTests)
+            if (_brokerCleanBetweenTests)
             {
                 final String qpidWork = System.getProperty("QPID_WORK");
                 cleanBrokerWork(qpidWork);
@@ -333,17 +293,7 @@ public class QpidBrokerTestCase extends
 
             _logger.info("==========  stop " + getTestName() + " ==========");
 
-            if (redirected)
-            {
-                System.setErr(oldErr);
-                System.setOut(oldOut);
-                err.close();
-                out.close();
-                if (!_interleaveBrokerLog)
-                {
-                    _testcaseOutputStream.close();
-                }
-            }
+            LogManager.resetConfiguration();
         }
     }
 
@@ -403,7 +353,7 @@ public class QpidBrokerTestCase extends
 
     protected int getPort(int port)
     {
-        if (!_brokerType.equals(BrokerType.EXTERNAL))
+        if (!_brokerType.equals(BrokerHolder.BrokerType.EXTERNAL))
         {
             return port == 0 ? DEFAULT_PORT : port;
         }
@@ -425,28 +375,33 @@ public class QpidBrokerTestCase extends
 
     public void startBroker(int port, boolean managementMode) throws Exception
     {
+        startBroker(port, managementMode, null);
+    }
+
+    public void startBroker(int port, boolean managementMode, String 
log4jFile) throws Exception
+    {
         int actualPort = getPort(port);
         TestBrokerConfiguration configuration = 
getBrokerConfiguration(actualPort);
-        startBroker(actualPort, configuration, managementMode);
+        startBroker(actualPort, configuration, managementMode, log4jFile);
     }
 
     protected File getBrokerCommandLog4JFile()
     {
-        return _logConfigFile;
+        return _spawnedBrokerLogConfigFile;
     }
 
     protected void setBrokerCommandLog4JFile(File file)
     {
-        _logConfigFile = file;
+        _spawnedBrokerLogConfigFile = file;
         _logger.info("Modified log config file to: " + file);
     }
 
-    public void startBroker(int port, TestBrokerConfiguration 
testConfiguration) throws Exception
+    public void startBroker(int port, TestBrokerConfiguration 
testConfiguration, String log4jFile) throws Exception
     {
-        startBroker(port, testConfiguration, false);
+        startBroker(port, testConfiguration, false, log4jFile);
     }
 
-    public void startBroker(int port, TestBrokerConfiguration 
testConfiguration, boolean managementMode) throws Exception
+    protected void startBroker(int port, TestBrokerConfiguration 
testConfiguration, boolean managementMode, String log4jFile) throws Exception
     {
         port = getPort(port);
 
@@ -455,181 +410,12 @@ public class QpidBrokerTestCase extends
             throw new IllegalStateException("There is already an existing 
broker running on port " + port);
         }
 
-        Set<Integer> portsUsedByBroker = guessAllPortsUsedByBroker(port);
         String testConfig = saveTestConfiguration(port, testConfiguration);
-
-        if (_brokerType.equals(BrokerType.INTERNAL) && 
!existingInternalBroker())
-        {
-            
setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY, 
"false");
-            BrokerOptions options = new BrokerOptions();
-
-            options.setConfigurationStoreType(_brokerStoreType);
-            options.setConfigurationStoreLocation(testConfig);
-            options.setManagementMode(managementMode);
-            if (managementMode)
-            {
-                options.setManagementModePassword(MANAGEMENT_MODE_PASSWORD);
-            }
-
-            //Set the log config file, relying on the log4j.configuration 
system property
-            //set on the JVM by the JUnit runner task in module.xml.
-            options.setLogConfigFileLocation(_logConfigFile.getAbsolutePath());
-
-            Broker broker = new Broker();
-            _logger.info("Starting internal broker (same JVM)");
-            broker.startup(options);
-
-            _brokers.put(port, new InternalBrokerHolder(broker, 
System.getProperty("QPID_WORK"), portsUsedByBroker));
-        }
-        else if (!_brokerType.equals(BrokerType.EXTERNAL))
-        {
-            // Add the port to QPID_WORK to ensure unique working dirs for 
multi broker tests
-            final String qpidWork = getQpidWork(_brokerType, port);
-
-            String[] cmd = _brokerCommandHelper.getBrokerCommand(port, 
testConfig, _brokerStoreType, _logConfigFile);
-            if (managementMode)
-            {
-                String[] newCmd = new String[cmd.length + 3];
-                System.arraycopy(cmd, 0, newCmd, 0, cmd.length);
-                newCmd[cmd.length] = "-mm";
-                newCmd[cmd.length + 1] = "-mmpass";
-                newCmd[cmd.length + 2] = MANAGEMENT_MODE_PASSWORD;
-                cmd = newCmd;
-            }
-            _logger.info("Starting spawn broker using command: " + 
StringUtils.join(cmd, ' '));
-            ProcessBuilder pb = new ProcessBuilder(cmd);
-            pb.redirectErrorStream(true);
-            Map<String, String> processEnv = pb.environment();
-            String qpidHome = System.getProperty(QPID_HOME);
-            processEnv.put(QPID_HOME, qpidHome);
-            //Augment Path with bin directory in QPID_HOME.
-            boolean foundPath = false;
-            final String pathEntry = qpidHome + File.separator + "bin";
-            for(Map.Entry<String,String> entry : processEnv.entrySet())
-            {
-                if(entry.getKey().equalsIgnoreCase("path"))
-                {
-                    entry.setValue(entry.getValue().concat(File.pathSeparator 
+ pathEntry));
-                    foundPath = true;
-                }
-            }
-            if(!foundPath)
-            {
-                processEnv.put("PATH", pathEntry);
-
-            }
-            //Add the test name to the broker run.
-            // DON'T change PNAME, qpid.stop needs this value.
-            processEnv.put("QPID_PNAME", "-DPNAME=QPBRKR -DTNAME=\"" + 
getTestName() + "\"");
-            processEnv.put("QPID_WORK", qpidWork);
-
-            // Use the environment variable to set amqj.logging.level for the 
broker
-            // The value used is a 'server' value in the test configuration to
-            // allow a differentiation between the client and broker logging 
levels.
-            if (System.getProperty("amqj.server.logging.level") != null)
-            {
-                setBrokerEnvironment("AMQJ_LOGGING_LEVEL", 
System.getProperty("amqj.server.logging.level"));
-            }
-
-            // Add all the environment settings the test requested
-            if (!_env.isEmpty())
-            {
-                for (Map.Entry<String, String> entry : _env.entrySet())
-                {
-                    processEnv.put(entry.getKey(), entry.getValue());
-                }
-            }
-
-            String qpidOpts = "";
-
-            // a synchronized hack to avoid adding into QPID_OPTS the values
-            // of JVM properties "test.virtualhosts" and "test.config" set by 
a concurrent startup process
-            synchronized (_propertiesSetForBroker)
-            {
-                // 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.
-                setSystemProperty("amqj.protocol.logging.level");
-                setSystemProperty("root.logging.level");
-
-                setSystemProperty("test.port");
-                setSystemProperty("test.mport");
-                setSystemProperty("test.cport");
-                setSystemProperty("test.hport");
-                setSystemProperty("test.hsport");
-                setSystemProperty("test.port.ssl");
-                setSystemProperty("test.port.alt");
-                setSystemProperty("test.port.alt.ssl");
-                setSystemProperty("test.amqp_port_protocols");
-
-                setSystemProperty("virtualhostnode.type");
-                setSystemProperty("virtualhostnode.context.blueprint");
-
-                // Add all the specified system properties to QPID_OPTS
-                if (!_propertiesSetForBroker.isEmpty())
-                {
-                    for (String key : _propertiesSetForBroker.keySet())
-                    {
-                        qpidOpts += " -D" + key + "=" + 
_propertiesSetForBroker.get(key);
-                    }
-                }
-            }
-            if (processEnv.containsKey("QPID_OPTS"))
-            {
-                qpidOpts = processEnv.get("QPID_OPTS") + qpidOpts;
-            }
-            processEnv.put("QPID_OPTS", qpidOpts);
-
-            // cpp broker requires that the work directory is created
-            createBrokerWork(qpidWork);
-
-            Process process = pb.start();
-
-            Piper p = new Piper(process.getInputStream(),
-                                _testcaseOutputStream,
-                                System.getProperty(BROKER_READY),
-                                System.getProperty(BROKER_STOPPED),
-                                _interleaveBrokerLog ? _brokerLogPrefix : 
null);
-
-            p.start();
-            StringBuilder cmdLine = new StringBuilder(cmd[0]);
-            for(int i = 1; i< cmd.length; i++)
-            {
-                cmdLine.append(' ');
-                cmdLine.append(cmd[i]);
-            }
-
-            SpawnedBrokerHolder holder = new SpawnedBrokerHolder(process, 
qpidWork, portsUsedByBroker, cmdLine.toString());
-            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);
-                throw new RuntimeException("broker failed to become ready:"
-                                           + p.getStopLine());
-            }
-
-            try
-            {
-                //test that the broker is still running and hasn't exited 
unexpectedly
-                int exit = process.exitValue();
-                _logger.info("broker aborted: " + exit);
-                cleanBrokerWork(qpidWork);
-                throw new RuntimeException("broker aborted: " + exit);
-            }
-            catch (IllegalThreadStateException e)
-            {
-                // this is expect if the broker started successfully
-            }
-
-            _brokers.put(port, holder);
-        }
+        String log4jConfig = log4jFile == null ? 
getBrokerCommandLog4JFile().getAbsolutePath() : log4jFile;
+        BrokerOptions options = getBrokerOptions(managementMode, testConfig, 
log4jConfig, log4jFile == null);
+        BrokerHolder holder = new BrokerHolderFactory().create(_brokerType, 
port, this);
+        _brokers.put(port, holder);
+        holder.start(options);
     }
 
     private boolean existingInternalBroker()
@@ -645,21 +431,6 @@ public class QpidBrokerTestCase extends
         return false;
     }
 
-    private String getQpidWork(BrokerType broker, int port)
-    {
-        if (!broker.equals(BrokerType.EXTERNAL))
-        {
-            return System.getProperty("QPID_WORK")+ "/" + port;
-        }
-
-        return System.getProperty("QPID_WORK");
-    }
-
-    public String getTestConfigFile()
-    {
-        return getTestConfigFile(getPort());
-    }
-
     public String getTestConfigFile(int port)
     {
         return _output + File.separator + getTestQueueName() + "-" + port + 
"-config";
@@ -1035,7 +806,7 @@ public class QpidBrokerTestCase extends
 
     protected boolean isInternalBroker()
     {
-        return _brokerType.equals(BrokerType.INTERNAL);
+        return _brokerType.equals(BrokerHolder.BrokerType.INTERNAL);
     }
 
     protected boolean isBrokerStorePersistent()
@@ -1397,16 +1168,6 @@ public class QpidBrokerTestCase extends
         return message;
     }
 
-    protected int getMessageSize()
-    {
-        return _messageSize;
-    }
-
-    protected void setMessageSize(int byteSize)
-    {
-        _messageSize = byteSize;
-    }
-
     public BrokerDetails getBroker()
     {
         try
@@ -1453,4 +1214,91 @@ public class QpidBrokerTestCase extends
         session.commit();
         session.close();
     }
+
+    protected BrokerOptions getBrokerOptions( boolean managementMode, String 
testConfig, String log4jConfig, boolean skipLoggingConfiguration)
+    {
+        BrokerOptions options = new BrokerOptions();
+
+        options.setConfigurationStoreType(_brokerStoreType);
+        options.setConfigurationStoreLocation(testConfig);
+        options.setManagementMode(managementMode);
+        if (managementMode)
+        {
+            options.setManagementModePassword(MANAGEMENT_MODE_PASSWORD);
+        }
+        options.setSkipLoggingConfiguration(skipLoggingConfiguration);
+        options.setLogConfigFileLocation(log4jConfig);
+        options.setStartupLoggedToSystemOut(false);
+        return options;
+    }
+
+    private Map<String, String> getJvmProperties()
+    {
+        Map<String,String> jvmOptions = new HashMap();
+        synchronized (_propertiesSetForBroker)
+        {
+            jvmOptions.putAll(_propertiesSetForBroker);
+
+            copySystemProperty("amqj.protocol.logging.level", jvmOptions);
+            copySystemProperty("root.logging.level", jvmOptions);
+
+            copySystemProperty("test.port", jvmOptions);
+            copySystemProperty("test.mport", jvmOptions);
+            copySystemProperty("test.cport", jvmOptions);
+            copySystemProperty("test.hport", jvmOptions);
+            copySystemProperty("test.hsport", jvmOptions);
+            copySystemProperty("test.port.ssl", jvmOptions);
+            copySystemProperty("test.port.alt", jvmOptions);
+            copySystemProperty("test.port.alt.ssl", jvmOptions);
+            copySystemProperty("test.amqp_port_protocols", jvmOptions);
+
+            copySystemProperty("virtualhostnode.type", jvmOptions);
+            copySystemProperty("virtualhostnode.context.blueprint", 
jvmOptions);
+        }
+        return jvmOptions;
+    }
+
+    private void copySystemProperty(String name, Map<String, String> 
jvmOptions)
+    {
+        String value = System.getProperty(name);
+        if (value != null)
+        {
+            jvmOptions.put(name, value);
+        }
+    }
+
+    private Map<String, String> getEnvironmentProperties()
+    {
+        return new HashMap<>(_env);
+    }
+
+    private String getBrokerCommandTemplate()
+    {
+        return _brokerCommandTemplate;
+    }
+
+    public static class BrokerHolderFactory
+    {
+
+        public BrokerHolder create(BrokerHolder.BrokerType brokerType, int 
port, QpidBrokerTestCase testCase)
+        {
+            Set<Integer> portsUsedByBroker = 
testCase.guessAllPortsUsedByBroker(port);
+            BrokerHolder holder = null;
+            if (brokerType.equals(BrokerHolder.BrokerType.INTERNAL) && 
!testCase.existingInternalBroker())
+            {
+                
testCase.setSystemProperty(BrokerProperties.PROPERTY_USE_CUSTOM_RMI_SOCKET_FACTORY,
 "false");
+                holder = new InternalBrokerHolder(portsUsedByBroker);
+            }
+            else if (!brokerType.equals(BrokerHolder.BrokerType.EXTERNAL))
+            {
+
+                Map<String,String> jvmOptions = testCase.getJvmProperties();
+                Map<String,String> environmentProperties = 
testCase.getEnvironmentProperties();
+
+                holder = new 
SpawnedBrokerHolder(testCase.getBrokerCommandTemplate(), port, 
testCase.getTestName(), jvmOptions, environmentProperties, brokerType, 
portsUsedByBroker);
+            }
+            return holder;
+        }
+    }
+
 }

Propchange: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jan 27 15:00:13 2015
@@ -7,4 +7,5 @@
 
/qpid/branches/java-broker-vhost-refactor/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java:1493674-1494547
 
/qpid/branches/java-network-refactor/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java:805429-821809
 
/qpid/branches/qpid-2935/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java:1061302-1072333
+/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java:1643238-1655056
 
/qpid/trunk/qpid/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java:796646-796653

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/SpawnedBrokerHolder.java
 Tue Jan 27 15:00:13 2015
@@ -22,6 +22,7 @@ package org.apache.qpid.test.utils;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -30,39 +31,215 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.log4j.Logger;
+import org.apache.qpid.server.BrokerOptions;
+import org.apache.qpid.server.configuration.BrokerProperties;
+import org.apache.qpid.server.logging.messages.BrokerMessages;
+import org.apache.qpid.util.FileUtils;
 import org.apache.qpid.util.SystemUtils;
 
 public class SpawnedBrokerHolder implements BrokerHolder
 {
     private static final Logger LOGGER = 
Logger.getLogger(SpawnedBrokerHolder.class);
+    protected static final String BROKER_READY = 
System.getProperty("broker.ready", BrokerMessages.READY().toString());
+    private static final String BROKER_STOPPED = 
System.getProperty("broker.stopped", BrokerMessages.STOPPED().toString());
 
-    private final Process _process;
-    private final Integer _pid;
-    private final String _workingDirectory;
+    private final BrokerType _type;
+    private final int _port;
+    private final String _name;
+    private final Map<String, String> _jvmOptions;
+    private final Map<String, String> _environmentSettings;
+    protected BrokerCommandHelper _brokerCommandHelper;
+
+    private  Process _process;
+    private  Integer _pid;
     private Set<Integer> _portsUsedByBroker;
-    private final String _brokerCommand;
+    private String _brokerCommand;
+
+    public SpawnedBrokerHolder(String brokerCommandTemplate, int port, String 
name, Map<String, String> jvmOptions, Map<String, String> environmentSettings, 
BrokerType type, Set<Integer> portsUsedByBroker)
+    {
+        _type = type;
+        _portsUsedByBroker = portsUsedByBroker;
+        _port = port;
+        _name = name;
+        _jvmOptions = jvmOptions;
+        _environmentSettings = environmentSettings;
+        _brokerCommandHelper = new BrokerCommandHelper(brokerCommandTemplate);
+    }
+
 
-    public SpawnedBrokerHolder(final Process process, final String 
workingDirectory, Set<Integer> portsUsedByBroker,
-                               String brokerCmd)
+    @Override
+    public void start(BrokerOptions brokerOptions) throws Exception
     {
-        if(process == null)
+        // Add the port to QPID_WORK to ensure unique working dirs for multi 
broker tests
+        final String qpidWork = getQpidWork(_type, _port);
+
+        String[] cmd = _brokerCommandHelper.getBrokerCommand(_port, 
brokerOptions.getConfigurationStoreLocation(), 
brokerOptions.getConfigurationStoreType(),
+                new File(brokerOptions.getLogConfigFileLocation()));
+        if (brokerOptions.isManagementMode())
         {
-            throw new IllegalArgumentException("Process must not be null");
+            String[] newCmd = new String[cmd.length + 3];
+            System.arraycopy(cmd, 0, newCmd, 0, cmd.length);
+            newCmd[cmd.length] = "-mm";
+            newCmd[cmd.length + 1] = "-mmpass";
+            newCmd[cmd.length + 2] = brokerOptions.getManagementModePassword();
+            cmd = newCmd;
         }
+        ProcessBuilder pb = new ProcessBuilder(cmd);
+        pb.redirectErrorStream(true);
+        Map<String, String> processEnv = pb.environment();
+        String qpidHome = 
System.getProperty(BrokerProperties.PROPERTY_QPID_HOME);
+        processEnv.put(BrokerProperties.PROPERTY_QPID_HOME, qpidHome);
+
+        //Augment Path with bin directory in QPID_HOME.
+        boolean foundPath = false;
+        final String pathEntry = qpidHome + File.separator + "bin";
+        for(Map.Entry<String,String> entry : processEnv.entrySet())
+        {
+            if(entry.getKey().equalsIgnoreCase("path"))
+            {
+                entry.setValue(entry.getValue().concat(File.pathSeparator + 
pathEntry));
+                foundPath = true;
+            }
+        }
+        if(!foundPath)
+        {
+            processEnv.put("PATH", pathEntry);
+        }
+        //Add the test name to the broker run.
+        // DON'T change PNAME, qpid.stop needs this value.
+        processEnv.put("QPID_PNAME", "-DPNAME=QPBRKR -DTNAME=\"" + _name + 
"\"");
+        processEnv.put("QPID_WORK", qpidWork);
+
+        // Use the environment variable to set amqj.logging.level for the 
broker
+        // The value used is a 'server' value in the test configuration to
+        // allow a differentiation between the client and broker logging 
levels.
+        if (System.getProperty("amqj.server.logging.level") != null)
+        {
+            processEnv.put("AMQJ_LOGGING_LEVEL", 
System.getProperty("amqj.server.logging.level"));
+        }
+
+        // Add all the environment settings the test requested
+        if (!_environmentSettings.isEmpty())
+        {
+            for (Map.Entry<String, String> entry : 
_environmentSettings.entrySet())
+            {
+                processEnv.put(entry.getKey(), entry.getValue());
+            }
+        }
+
+        String qpidOpts = "";
+
+        // Add all the specified system properties to QPID_OPTS
+        if (!_jvmOptions.isEmpty())
+        {
+            for (String key : _jvmOptions.keySet())
+            {
+                qpidOpts += " -D" + key + "=" + _jvmOptions.get(key);
+            }
+        }
+
+        if (processEnv.containsKey("QPID_OPTS"))
+        {
+            qpidOpts = processEnv.get("QPID_OPTS") + qpidOpts;
+        }
+        processEnv.put("QPID_OPTS", qpidOpts);
+
+        // cpp broker requires that the work directory is created
+        createBrokerWork(qpidWork);
+
+        _process = pb.start();
+
+        Piper standardOutputPiper = new Piper(_process.getInputStream(),
+                BROKER_READY,
+                BROKER_STOPPED,
+                "STD", "BROKER-" + _port);
+
+        standardOutputPiper.start();
+
+        new Piper(_process.getErrorStream(), null, null, "ERROR", "BROKER-" + 
_port).start();
 
-        _process = process;
+        StringBuilder cmdLine = new StringBuilder(cmd[0]);
+        for(int i = 1; i< cmd.length; i++)
+        {
+            cmdLine.append(' ');
+            cmdLine.append(cmd[i]);
+        }
+
+        _brokerCommand = cmdLine.toString();
         _pid = retrieveUnixPidIfPossible();
-        _workingDirectory = workingDirectory;
-        _portsUsedByBroker = portsUsedByBroker;
-        _brokerCommand = brokerCmd;
+
+        if (!standardOutputPiper.await(30, TimeUnit.SECONDS))
+        {
+            LOGGER.info("broker failed to become ready (" + 
standardOutputPiper.getReady() + "):" + standardOutputPiper.getStopLine());
+            String threadDump = dumpThreads();
+            if (!threadDump.isEmpty())
+            {
+                LOGGER.info("the result of a try to capture thread dump:" + 
threadDump);
+            }
+            //Ensure broker has stopped
+            _process.destroy();
+            cleanBrokerWork(qpidWork);
+            throw new RuntimeException("broker failed to become ready:"
+                    + standardOutputPiper.getStopLine());
+        }
+
+        try
+        {
+            //test that the broker is still running and hasn't exited 
unexpectedly
+            int exit = _process.exitValue();
+            LOGGER.info("broker aborted: " + exit);
+            cleanBrokerWork(qpidWork);
+            throw new RuntimeException("broker aborted: " + exit);
+        }
+        catch (IllegalThreadStateException e)
+        {
+            // this is expect if the broker started successfully
+        }
+
     }
 
-    @Override
-    public String getWorkingDirectory()
+    protected void createBrokerWork(final String qpidWork)
     {
-        return _workingDirectory;
+        if (qpidWork != null)
+        {
+            final File dir = new File(qpidWork);
+            dir.mkdirs();
+            if (!dir.isDirectory())
+            {
+                throw new RuntimeException("Failed to created Qpid work 
directory : " + qpidWork);
+            }
+        }
+    }
+
+    private String getQpidWork(BrokerType broker, int port)
+    {
+        if (!broker.equals(BrokerType.EXTERNAL))
+        {
+            return System.getProperty(BrokerProperties.PROPERTY_QPID_WORK) + 
File.separator + port;
+        }
+
+        return System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
+    }
+
+    private void cleanBrokerWork(final String qpidWork)
+    {
+        if (qpidWork != null)
+        {
+            LOGGER.info("Cleaning broker work dir: " + qpidWork);
+
+            File file = new File(qpidWork);
+            if (file.exists())
+            {
+                final boolean success = FileUtils.delete(file, true);
+                if(!success)
+                {
+                    throw new RuntimeException("Failed to recursively delete 
beneath : " + file);
+                }
+            }
+        }
     }
 
     public void shutdown()

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java
 Tue Jan 27 15:00:13 2015
@@ -44,21 +44,7 @@ import org.apache.qpid.server.BrokerOpti
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
 import org.apache.qpid.server.logging.EventLogger;
 import org.apache.qpid.server.logging.LogRecorder;
-import org.apache.qpid.server.model.AbstractSystemConfig;
-import org.apache.qpid.server.model.AccessControlProvider;
-import org.apache.qpid.server.model.AuthenticationProvider;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.BrokerModel;
-import org.apache.qpid.server.model.BrokerShutdownProvider;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.GroupProvider;
-import org.apache.qpid.server.model.JsonSystemConfigImpl;
-import org.apache.qpid.server.model.Plugin;
-import org.apache.qpid.server.model.PreferencesProvider;
-import org.apache.qpid.server.model.SystemConfig;
-import org.apache.qpid.server.model.UUIDGenerator;
-import org.apache.qpid.server.model.VirtualHostAlias;
-import org.apache.qpid.server.model.VirtualHostNode;
+import org.apache.qpid.server.model.*;
 import org.apache.qpid.server.model.adapter.FileBasedGroupProvider;
 import org.apache.qpid.server.model.adapter.FileBasedGroupProviderImpl;
 import org.apache.qpid.server.plugin.PluggableFactoryLoader;
@@ -108,7 +94,7 @@ public class TestBrokerConfiguration
         final AbstractSystemConfig parentObject = new 
JsonSystemConfigImpl(taskExecutor,
                                                                
mock(EventLogger.class),
                                                                
mock(LogRecorder.class),
-                                                               brokerOptions,
+                                                               
brokerOptions.convertToSystemConfigAttributes(),
                                                                
mock(BrokerShutdownProvider.class));
 
         ConfiguredObjectRecordConverter converter = new 
ConfiguredObjectRecordConverter(BrokerModel.getInstance());
@@ -216,10 +202,13 @@ public class TestBrokerConfiguration
         SystemConfigFactory configFactory =
                 (new 
PluggableFactoryLoader<>(SystemConfigFactory.class)).get(_storeType);
 
+        Map<String, Object> attributes = new 
HashMap<>(brokerOptions.convertToSystemConfigAttributes());
+        attributes.put(SystemConfig.STARTUP_LOGGED_TO_SYSTEM_OUT, false);
+        attributes.put(ConfiguredObject.DESIRED_STATE, State.QUIESCED);
         final SystemConfig parentObject = 
configFactory.newInstance(_taskExecutor,
                                                                    
mock(EventLogger.class),
                                                                    
mock(LogRecorder.class),
-                                                                   
brokerOptions,
+                                                                   attributes,
                                                                    
mock(BrokerShutdownProvider.class));
 
         parentObject.open();
@@ -252,6 +241,7 @@ public class TestBrokerConfiguration
 
         
configurationStore.openConfigurationStore(parentObject,true,initialRecords.toArray(new
 ConfiguredObjectRecord[initialRecords.size()]));
         configurationStore.closeConfigurationStore();
+        parentObject.close();
         return true;
     }
 

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/HeartbeatTest.java
 Tue Jan 27 15:00:13 2015
@@ -120,12 +120,15 @@ public class HeartbeatTest extends QpidB
         sendConn.setHeartbeatListener(sendListener);
         receiveConn.start();
 
+        // Start the flow of messages to the consumer
+        consumer.receiveNoWait();
+
         for(int i = 0; i < 5; i++)
         {
             producer.send(senderSession.createTextMessage("Msg " + i));
             Thread.sleep(500);
             assertNotNull("Expected to received message", 
consumer.receive(500));
-            // Consumer does not ack the message in  order to generate no 
bytes from consumer back to Broker
+            // Consumer does not ack the message in order that no bytes flow 
from consumer connection back to Broker
         }
 
         assertTrue("Too few heartbeats sent "+ 
receiveListener.getHeartbeatsSent() +" (expected at least 2)", 
receiveListener.getHeartbeatsSent()>=2);

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/failover/MultipleBrokersFailoverTest.java
 Tue Jan 27 15:00:13 2015
@@ -38,7 +38,6 @@ import org.apache.qpid.client.AMQConnect
 import org.apache.qpid.client.AMQConnectionURL;
 import org.apache.qpid.jms.ConnectionListener;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.apache.qpid.test.utils.TestUtils;
 import org.apache.qpid.util.FileUtils;
 
 public class MultipleBrokersFailoverTest extends QpidBrokerTestCase implements 
ConnectionListener
@@ -48,9 +47,10 @@ public class MultipleBrokersFailoverTest
     private static final String FAILOVER_VIRTUAL_HOST = "failover";
     private static final String NON_FAILOVER_VIRTUAL_HOST = "nonfailover";
     private static final String BROKER_PORTION_FORMAT = 
"tcp://localhost:%d?connectdelay='%d',retries='%d'";
-    private static final int FAILOVER_RETRIES = 1;
-    private static final int FAILOVER_CONNECTDELAY = 1000;
-    private static final int FAILOVER_FACTOR = 4;
+    private static final int FAILOVER_RETRIES = 0;
+    private static final int FAILOVER_CONNECTDELAY = 0;
+    private static final int FAILOVER_AWAIT_TIME = 10000;
+
 
     private int[] _brokerPorts;
     private AMQConnectionURL _connectionURL;
@@ -169,7 +169,7 @@ public class MultipleBrokersFailoverTest
 
         killBroker(_brokerPorts[1]);
 
-        awaitForFailoverCompletion(FAILOVER_CONNECTDELAY * _brokerPorts.length 
* FAILOVER_FACTOR);
+        awaitForFailoverCompletion(FAILOVER_AWAIT_TIME);
         assertEquals("Failover is not started as expected", 0, 
_failoverStarted.getCount());
 
         assertSendReceive(2);
@@ -185,7 +185,7 @@ public class MultipleBrokersFailoverTest
 
         stopBroker(_brokerPorts[1]);
 
-        awaitForFailoverCompletion(FAILOVER_CONNECTDELAY * _brokerPorts.length 
* FAILOVER_FACTOR);
+        awaitForFailoverCompletion(FAILOVER_AWAIT_TIME);
         assertEquals("Failover is not started as expected", 0, 
_failoverStarted.getCount());
 
         assertSendReceive(1);
@@ -214,20 +214,12 @@ public class MultipleBrokersFailoverTest
         }
     }
 
-    private void awaitForFailoverCompletion(long delay)
+    private void awaitForFailoverCompletion(long delay) throws Exception
     {
         _logger.info("Awaiting Failover completion..");
-        try
-        {
-            if (!_failoverComplete.await(delay, TimeUnit.MILLISECONDS))
-            {
-                _logger.warn("Test thread stack:\n\n" + 
TestUtils.dumpThreads());
-                fail("Failover did not complete");
-            }
-        }
-        catch (InterruptedException e)
+        if (!_failoverComplete.await(delay, TimeUnit.MILLISECONDS))
         {
-            fail("Test was interrupted:" + e.getMessage());
+            fail("Failover did not complete within " + delay + "ms.");
         }
     }
 
@@ -239,7 +231,7 @@ public class MultipleBrokersFailoverTest
                 receivedMessage instanceof TextMessage);
     }
 
-    private void init(int acknowledgeMode, boolean startConnection) throws 
JMSException
+    private void init(int acknowledgeMode, boolean startConnection) throws 
Exception
     {
         boolean isTransacted = acknowledgeMode == Session.SESSION_TRANSACTED ? 
true : false;
 

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/client/ssl/SSLTest.java
 Tue Jan 27 15:00:13 2015
@@ -94,6 +94,29 @@ public class SSLTest extends QpidBrokerT
         }
     }
 
+    public void testSSLConnectionToPlainPortRejected() throws Exception
+    {
+        if (shouldPerformTest())
+        {
+            super.setUp();
+
+            String url = 
"amqp://guest:guest@test/?brokerlist='tcp://localhost:%s" +
+                         "?ssl='true''";
+
+            url = String.format(url,QpidBrokerTestCase.DEFAULT_PORT);
+
+            try
+            {
+                getConnection(new AMQConnectionURL(url));
+                fail("Exception not thrown");
+            }
+            catch (JMSException e)
+            {
+                assertTrue("Unexpected exception message", 
e.getMessage().contains("Unrecognized SSL message, plaintext connection?"));
+            }
+        }
+    }
+
     public void testHostVerificationIsOnByDefault() throws Exception
     {
         if (shouldPerformTest())
@@ -116,6 +139,7 @@ public class SSLTest extends QpidBrokerT
             try
             {
                 getConnection(new AMQConnectionURL(url));
+                fail("Exception not thrown");
             }
             catch(JMSException e)
             {

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/BrokerStartupTest.java
 Tue Jan 27 15:00:13 2015
@@ -77,7 +77,7 @@ public class BrokerStartupTest extends A
                 brokerConfigFile.delete();
             }
 
-            startBroker(port, null);
+            startBroker(port, null, null);
 
             AMQConnectionURL url = new AMQConnectionURL(String.format("amqp://"
                                                                       + 
GUEST_USERNAME
@@ -209,7 +209,7 @@ public class BrokerStartupTest extends A
                 brokerConfigFile.delete();
             }
 
-            startBroker(port, null);
+            startBroker(port, null, null);
 
             AMQConnectionURL url = new AMQConnectionURL(String.format("amqp://"
                     + GUEST_USERNAME

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/logging/BrokerLoggingTest.java
 Tue Jan 27 15:00:13 2015
@@ -22,13 +22,15 @@ package org.apache.qpid.server.logging;
 
 import junit.framework.AssertionFailedError;
 
-import org.apache.qpid.server.BrokerOptions;
+import org.apache.log4j.FileAppender;
+import org.apache.log4j.LogManager;
 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.File;
 import java.io.IOException;
 import java.net.Socket;
 import java.util.Collections;
@@ -59,6 +61,7 @@ public class BrokerLoggingTest extends A
     private static final Pattern BROKER_MESSAGE_LOG_PATTERN = 
Pattern.compile(BROKER_MESSAGE_LOG_REG_EXP);
     private static final String BRK_LOG_PREFIX = "BRK-";
 
+    @Override
     public void setUp() throws Exception
     {
         setLogMessagePrefix();
@@ -146,94 +149,6 @@ public class BrokerLoggingTest extends A
 
     /**
      * 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.
-     * Input:
-     * No custom -l value should be provided on the command line so that the 
default value is correctly reported.
-     * Output:
-     *
-     * <date> MESSAGE BRK-1007 : Using logging configuration : 
<$QPID_HOME>/etc/log4j.xml
-     *
-     * Validation Steps:
-     *
-     * 1. The BRK ID is correct
-     * 2. This occurs before the BRK-1001 startup message.
-     * 3. The log4j file is the full path to the file specified on the 
commandline.
-     *
-     * @throws Exception caused by broker startup
-     */
-    public void testBrokerStartupDefaultLog4j() throws Exception
-    {
-        if (isJavaBroker() && isExternalBroker() && !isInternalBroker())
-        {
-            String TESTID = "BRK-1007";
-
-            _brokerCommandHelper.removeBrokerCommandLog4JFile();
-
-            startBroker();
-
-            // Now we can create the monitor as _outputFile will now be defined
-            _monitor = new LogMonitor(_outputFile);
-
-            // Ensure broker has fully started up.
-            getConnection();
-
-            // Ensure we wait for TESTID to be logged
-            waitAndFindMatches(TESTID);
-
-            List<String> results = waitAndFindMatches(BRK_LOG_PREFIX);
-            try
-            {
-                // Validation
-
-                assertTrue("BRKer message not logged", results.size() > 0);
-
-                boolean validation = false;
-                for (String rawLog : results)
-                {
-                    // We don't care about messages after we have our log 
config
-                    if (validation)
-                    {
-                        break;
-                    }
-
-                    String log = getLog(rawLog);
-
-                    // Ensure we do not have a BRK-1001 message before
-                    if (!getMessageID(log).equals(TESTID))
-                    {
-                        assertFalse(getMessageID(log).equals("BRK-1001"));
-                        continue;
-                    }
-
-                    //1
-                    validateMessageID(TESTID, log);
-
-                    //2
-                    //There will be 1 copy of this startup message (via 
SystemOut)
-                    assertEquals("Unexpected log4j configuration message 
count.",
-                                 1, findMatches(TESTID).size());
-
-                    //3
-                    String defaultLog4j = System.getProperty(QPID_HOME) + "/" 
+ BrokerOptions.DEFAULT_LOG_CONFIG_FILE;
-                    assertTrue("Log4j file(" + defaultLog4j + ") details not 
correctly logged:" + getMessageString(log),
-                               getMessageString(log).endsWith(defaultLog4j));
-
-                    validation = true;
-                }
-
-                assertTrue("Validation not performed: " + TESTID + " not 
logged", validation);
-            }
-            catch (AssertionFailedError afe)
-            {
-                dumpLogs(results, _monitor);
-
-                throw afe;
-            }
-        }
-    }
-
-    /**
-     * 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. The broker must also be capable of correctly recognising the 
command line property to specify the custom logging configuration.
      * Input:
      * The value of -l specified on the command line.
@@ -254,11 +169,17 @@ public class BrokerLoggingTest extends A
         // This logging startup code only occurs when you run a Java broker
         if (isJavaBroker())
         {
-            String customLog4j = getBrokerCommandLog4JFile().getAbsolutePath();
+            // Log4j properties expects this to be set
+            System.setProperty("qpid.testMethod", "-" + getName() + 
".customLog4j");
+            System.setProperty("qpid.testClass", getClass().getName() );
+
+            String customLog4j = 
System.getProperty("log4j.configuration.file");
 
             String TESTID = "BRK-1007";
 
-            startBroker();
+            startBroker(0, false, customLog4j);
+            _outputFile = new File(((FileAppender) 
LogManager.getRootLogger().getAllAppenders().nextElement()).getFile());
+
 
             // Now we can create the monitor as _outputFile will now be defined
             _monitor = new LogMonitor(_outputFile);
@@ -385,7 +306,7 @@ public class BrokerLoggingTest extends A
                     //2
                     //There will be 2 copies of the startup message (one via 
SystemOut, and one via Log4J)
                     assertEquals("Unexpected startup message count",
-                                 2, findMatches(TESTID).size());
+                                 1, findMatches(TESTID).size());
 
                     validation = true;
                 }
@@ -471,9 +392,8 @@ public class BrokerLoggingTest extends A
                     assertEquals("Incorrect message", TESTID, id);
 
                     //2
-                    //There will be 2 copies of the startup message (one via 
SystemOut, and one via Log4J)
                     assertEquals("Unexpected listen message count",
-                                 2, findMatches(TESTID).size());
+                                 1, findMatches(TESTID).size());
 
                     //3
                     String message = getMessageString(log);
@@ -587,7 +507,7 @@ public class BrokerLoggingTest extends A
                     //There will be 4 copies of the startup message (two via 
SystemOut, and two via Log4J)
                     List<String> listenMessages  = findMatches(TESTID);
                     assertEquals("Four listen messages should be found.",
-                                 4, listenMessages .size());
+                                 2, listenMessages .size());
 
                     int tcpStarted = 0;
                     int sslStarted = 0;
@@ -604,8 +524,8 @@ public class BrokerLoggingTest extends A
                         }
                     }
 
-                    assertEquals("Unexpected number of logs 'Listening on TCP 
port'", 2, tcpStarted);
-                    assertEquals("Unexpected number of logs 'Listening on SSL 
port'", 2, sslStarted);
+                    assertEquals("Unexpected number of logs 'Listening on TCP 
port'", 1, tcpStarted);
+                    assertEquals("Unexpected number of logs 'Listening on SSL 
port'", 1, sslStarted);
 
                     //4 Test ports open
                     testSocketOpen(getPort());
@@ -690,10 +610,9 @@ public class BrokerLoggingTest extends A
                     //2
                     assertEquals("Ready message not present", "Qpid Broker 
Ready", getMessageString(log));
                     
-                    //There will be 2 copies of the startup message (one via 
SystemOut, and one via Log4J)
                     assertEquals("Unexpected ready message count",
-                                 2, findMatches(TESTID).size());
-                    assertEquals("The ready messages should have been the last 
2 messages", results.size() - 2, i);
+                                 1, findMatches(TESTID).size());
+                    assertEquals("The ready messages should have been the last 
2 messages", results.size() - 1, i);
 
                     validationComplete = true;
                     break;

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/server/security/acl/AbstractACLTestCase.java
 Tue Jan 27 15:00:13 2015
@@ -59,7 +59,7 @@ public abstract class AbstractACLTestCas
     @Override
     public void setUp() throws Exception
     {
-        
getBrokerConfiguration().addGroupFileConfiguration(System.getProperty(QPID_HOME)
 + "/etc/groups-systests");
+        getBrokerConfiguration().addGroupFileConfiguration(QPID_HOME + 
"/etc/groups-systests");
 
         // run test specific setup
         String testSetup = StringUtils.replace(getName(), "test", "setUp");

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/LoggingManagementTest.java
 Tue Jan 27 15:00:13 2015
@@ -25,6 +25,7 @@ import javax.management.openmbean.Compos
 import javax.management.openmbean.TabularData;
 
 import org.apache.qpid.management.common.mbeans.LoggingManagement;
+import org.apache.qpid.server.configuration.BrokerProperties;
 import org.apache.qpid.server.logging.log4j.LoggingManagementFacadeTest;
 import org.apache.qpid.test.utils.JMXTestUtils;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
@@ -35,7 +36,6 @@ import org.apache.qpid.util.LogMonitor;
  * System test for Logging Management.  <b>These tests rely on value set within
  * test-profiles/log4j-test.xml</b>.
  *
- * @see LoggingManagementMBeanTest
  * @see LoggingManagementFacadeTest
  *
  */
@@ -44,7 +44,9 @@ public class LoggingManagementTest exten
     private JMXTestUtils _jmxUtils;
     private LoggingManagement _loggingManagement;
     private LogMonitor _monitor;
+    private File _logConfig;
 
+    @Override
     public void setUp() throws Exception
     {
         getBrokerConfiguration().addJmxManagementConfiguration();
@@ -56,8 +58,9 @@ public class LoggingManagementTest exten
 
         File tmpLogFile = File.createTempFile("log4j" + "." + getName(), 
".xml");
         tmpLogFile.deleteOnExit();
-        FileUtils.copy(getBrokerCommandLog4JFile(), tmpLogFile);
+        FileUtils.copy(new 
File(System.getProperty("log4j.configuration.file")), tmpLogFile);
         setBrokerCommandLog4JFile(tmpLogFile);
+        _logConfig = tmpLogFile;
 
         super.setUp();
         _jmxUtils.open();
@@ -66,6 +69,12 @@ public class LoggingManagementTest exten
         _monitor = new LogMonitor(_outputFile);
     }
 
+    public void startBroker() throws Exception
+    {
+        super.startBroker(0, false, _logConfig.getAbsolutePath());
+    }
+
+    @Override
     public void tearDown() throws Exception
     {
         try
@@ -74,6 +83,11 @@ public class LoggingManagementTest exten
             {
                 _jmxUtils.close();
             }
+
+            if (_logConfig != null)
+            {
+               _logConfig.delete();
+            }
         }
         finally
         {
@@ -122,7 +136,7 @@ public class LoggingManagementTest exten
         _loggingManagement.setConfigFileLoggerLevel(operationalLoggingLogger, 
"OFF");
 
         List<String> matches = _monitor.waitAndFindMatches("Setting level to 
OFF for logger 'qpid.message'", 5000);
-        assertEquals(1, matches.size());
+        assertTrue(matches.size()>=1);
 
         assertEffectiveLoggingLevel(operationalLoggingLogger, "INFO");
 

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java
 Tue Jan 27 15:00:13 2015
@@ -104,7 +104,7 @@ public class ManagementLoggingTest exten
             //There will be 2 copies of the startup message (one via 
SystemOut, and one via Log4J)
             results = findMatches("MNG-1001");
             assertEquals("Unexpected startup message count.",
-                         2, results.size());
+                         1, results.size());
 
             //3
             assertEquals("Startup log message is not 'Startup'.", "JMX 
Management Startup",
@@ -185,7 +185,7 @@ public class ManagementLoggingTest exten
             // Validation
 
             //There will be 4 startup messages (two via SystemOut, and two via 
Log4J)
-            assertEquals("Unexpected MNG-1002 message count", 4, 
results.size());
+            assertEquals("Unexpected MNG-1002 message count", 2, 
results.size());
 
             String log = getLogMessage(results, 0);
 
@@ -197,7 +197,7 @@ public class ManagementLoggingTest exten
             assertTrue("RMI Registry port not as expected(" + mPort + ").:" + 
getMessageString(log),
                        getMessageString(log).endsWith(String.valueOf(mPort)));
 
-            log = getLogMessage(results, 2);
+            log = getLogMessage(results, 1);
 
             //1
             validateMessageID("MNG-1002", log);
@@ -243,7 +243,7 @@ public class ManagementLoggingTest exten
             // Validate we only have two MNG-1002 (one via stdout, one via 
log4j)
             results = findMatches("MNG-1006");
             assertEquals("Upexpected SSL Keystore message count",
-                         2, results.size());
+                         1, results.size());
 
             // Validate the keystore path is as expected
             assertTrue("SSL Keystore entry expected.:" + getMessageString(log),

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java
 Tue Jan 27 15:00:13 2015
@@ -125,34 +125,28 @@ public class AccessControlProviderRestTe
 
     public void testReplaceAccessControlProvider() throws Exception
     {
-        String accessControlProviderName1 = getTestName() + "1";
 
-        //verify that the access control provider doesn't exist, and
-        //in doing so implicitly verify that the 'denied' user can
-        //actually currently connect because no ACL is in effect yet
-        getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
-        assertAccessControlProviderExistence(accessControlProviderName1, 
false);
 
         //create the access control provider using the 'allowed' user
         getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        int responseCode = 
createAccessControlProvider(accessControlProviderName1, _aclFileContent1);
+        int responseCode = createAccessControlProvider(getTestName(), 
_aclFileContent1);
         assertEquals("Access control provider creation should be allowed", 
201, responseCode);
 
         //verify it exists with the 'allowed' user
-        assertAccessControlProviderExistence(accessControlProviderName1, true);
+        assertAccessControlProviderExistence(getTestName(), true);
 
         //verify the 'denied' and 'other' user can no longer access the 
management
         //interface due to the just-created ACL file now preventing them
         getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
-        assertCanAccessManagementInterface(accessControlProviderName1, false);
+        assertCanAccessManagementInterface(getTestName(), false);
         getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER);
-        assertCanAccessManagementInterface(accessControlProviderName1, false);
+        assertCanAccessManagementInterface(getTestName(), false);
 
         //create the replacement access control provider using the 'allowed' 
user.
         String accessControlProviderName2 = getTestName() + "2";
         getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        responseCode = createAccessControlProvider(accessControlProviderName2, 
_aclFileContent2);
-        assertEquals("Access control provider creation should be allowed", 
201, responseCode);
+        responseCode = createAccessControlProvider(getTestName(), 
_aclFileContent2);
+        assertEquals("Access control provider creation should be allowed", 
200, responseCode);
 
         //Verify that it took effect immediately, replacing the first access 
control provider
 
@@ -162,11 +156,6 @@ public class AccessControlProviderRestTe
         getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER);
         assertCanAccessManagementInterface(accessControlProviderName2, true);
 
-        //remove the original access control provider using the 'allowed' user
-        getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        responseCode = 
getRestTestHelper().submitRequest("accesscontrolprovider/" + 
accessControlProviderName1, "DELETE");
-        assertEquals("Access control provider deletion should be allowed", 
200, responseCode);
-        assertAccessControlProviderExistence(accessControlProviderName1, 
false);
 
         //verify the 'denied' user still can't access the management 
interface, the 'other' user still can, thus
         //confirming that the second access control provider is still in effect
@@ -177,61 +166,6 @@ public class AccessControlProviderRestTe
     }
 
 
-    public void 
testAddAndRemoveSecondAccessControlProviderReinstatesOriginal() throws Exception
-    {
-        String accessControlProviderName1 = getTestName() + "1";
-
-        //verify that the access control provider doesn't exist, and
-        //in doing so implicitly verify that the 'denied' user can
-        //actually currently connect because no ACL is in effect yet
-        getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
-        assertAccessControlProviderExistence(accessControlProviderName1, 
false);
-
-        //create the access control provider using the 'allowed' user
-        getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        int responseCode = 
createAccessControlProvider(accessControlProviderName1, _aclFileContent1);
-        assertEquals("Access control provider creation should be allowed", 
201, responseCode);
-
-        //verify it exists with the 'allowed' user
-        assertAccessControlProviderExistence(accessControlProviderName1, true);
-
-        //verify the 'denied' and 'other' user can no longer access the 
management
-        //interface due to the just-created ACL file now preventing them
-        getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
-        assertCanAccessManagementInterface(accessControlProviderName1, false);
-        getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER);
-        assertCanAccessManagementInterface(accessControlProviderName1, false);
-
-        //create the replacement access control provider using the 'allowed' 
user.
-        String accessControlProviderName2 = getTestName() + "2";
-        getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        responseCode = createAccessControlProvider(accessControlProviderName2, 
_aclFileContent2);
-        assertEquals("Access control provider creation should be allowed", 
201, responseCode);
-
-        //Verify that it took effect immediately, replacing the first access 
control provider
-
-        //verify the 'denied' user still can't access the management 
interface, but the 'other' user now CAN.
-        getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
-        assertCanAccessManagementInterface(accessControlProviderName2, false);
-        getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER);
-        assertCanAccessManagementInterface(accessControlProviderName2, true);
-
-        //remove the second access control provider using the 'allowed' user
-        getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        responseCode = 
getRestTestHelper().submitRequest("accesscontrolprovider/" + 
accessControlProviderName2, "DELETE");
-        assertEquals("Access control provider deletion should be allowed", 
200, responseCode);
-        assertAccessControlProviderExistence(accessControlProviderName2, 
false);
-
-        //verify the 'denied' user still can't access the management 
interface, the
-        //'other' now CANT again, the 'allowed' still can, thus confirming 
that the
-        //first access control provider is now in effect once again
-        getRestTestHelper().setUsernameAndPassword(DENIED_USER, DENIED_USER);
-        assertCanAccessManagementInterface(accessControlProviderName2, false);
-        getRestTestHelper().setUsernameAndPassword(OTHER_USER, OTHER_USER);
-        assertCanAccessManagementInterface(accessControlProviderName2, false);
-        getRestTestHelper().setUsernameAndPassword(ALLOWED_USER, ALLOWED_USER);
-        assertCanAccessManagementInterface(accessControlProviderName2, true);
-    }
 
     public void 
testRemovalOfAccessControlProviderInErrorStateUsingManagementMode() throws 
Exception
     {

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
 Tue Jan 27 15:00:13 2015
@@ -235,9 +235,6 @@ public class BrokerRestTest extends Qpid
         assertNotNull("Unexpected value of attribute ports", 
brokerDetails.get(BROKER_PORTS_ATTRIBUTE));
         assertNotNull("Unexpected value of attribute authenticationproviders", 
brokerDetails.get(BROKER_AUTHENTICATIONPROVIDERS_ATTRIBUTE));
 
-        assertNotNull("Unexpected value of attribute 
supportedVirtualHostTypes", 
brokerDetails.get(Broker.SUPPORTED_VIRTUALHOST_TYPES));
-        assertNotNull("Unexpected value of attribute 
supportedVirtualHostNodeTypes", 
brokerDetails.get(Broker.SUPPORTED_VIRTUALHOSTNODE_TYPES));
-
     }
 
 }

Modified: 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java
URL: 
http://svn.apache.org/viewvc/qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java?rev=1655057&r1=1655056&r2=1655057&view=diff
==============================================================================
--- 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java
 (original)
+++ 
qpid/branches/QPID-6262-JavaBrokerNIO/qpid/java/systests/src/test/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java
 Tue Jan 27 15:00:13 2015
@@ -20,23 +20,20 @@
  */
 package org.apache.qpid.systest.rest;
 
-import java.io.IOException;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
+import javax.servlet.http.HttpServletResponse;
+
 
 import org.apache.qpid.server.model.AbstractConfiguredObject;
 import org.apache.qpid.server.model.KeyStore;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.server.model.Transport;
 import org.apache.qpid.server.security.FileKeyStore;
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 import org.apache.qpid.test.utils.TestSSLConstants;
+import org.apache.qpid.util.DataUrlUtils;
+import org.apache.qpid.util.FileUtils;
 
 public class KeyStoreRestTest extends QpidRestTestCase
 {
@@ -56,7 +53,7 @@ public class KeyStoreRestTest extends Qp
 
         Map<String, Object> keystore = keyStores.get(0);
         assertKeyStoreAttributes(keystore, 
TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE,
-                System.getProperty(QPID_HOME) + "/../" + 
TestSSLConstants.BROKER_KEYSTORE, null);
+                QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null);
     }
 
     public void testCreate() throws Exception
@@ -67,7 +64,7 @@ public class KeyStoreRestTest extends Qp
         String certAlias = "app2";
 
         assertNumberOfKeyStores(1);
-        createKeyStore(name, certAlias);
+        createKeyStore(name, certAlias, TestSSLConstants.KEYSTORE, 
TestSSLConstants.KEYSTORE_PASSWORD);
         assertNumberOfKeyStores(2);
 
         List<Map<String, Object>> keyStores = 
getRestTestHelper().getJsonAsList("keystore/" + name);
@@ -76,161 +73,72 @@ public class KeyStoreRestTest extends Qp
         assertKeyStoreAttributes(keyStores.get(0), name, 
TestSSLConstants.KEYSTORE, certAlias);
     }
 
-    public void testDelete() throws Exception
+    public void testCreateWithDataUrl() throws Exception
     {
         super.setUp();
 
         String name = getTestName();
-        String certAlias = "app2";
+        byte[] keystoreAsBytes = 
FileUtils.readFileAsBytes(TestSSLConstants.KEYSTORE);
+        String dataUrlForKeyStore = 
DataUrlUtils.getDataUrlForBytes(keystoreAsBytes);
 
         assertNumberOfKeyStores(1);
-        createKeyStore(name, certAlias);
-        assertNumberOfKeyStores(2);
-
-        int responseCode = getRestTestHelper().submitRequest("keystore/" + 
name , "DELETE");
-        assertEquals("Unexpected response code for provider deletion", 200, 
responseCode);
-
-        List<Map<String, Object>> keyStore = 
getRestTestHelper().getJsonAsList("keystore/" + name);
-        assertNotNull("details should not be null", keyStore);
-        assertTrue("details should be empty as the keystore no longer exists", 
keyStore.isEmpty());
-
-        //check only the default systests key store remains
-        List<Map<String, Object>> keyStores = assertNumberOfKeyStores(1);
-        Map<String, Object> keystore = keyStores.get(0);
-        assertKeyStoreAttributes(keystore, 
TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE,
-                System.getProperty(QPID_HOME) + "/../" + 
TestSSLConstants.BROKER_KEYSTORE, null);
-    }
-
-    public void testDeleteFailsWhenKeyStoreInUse() throws Exception
-    {
-        String name = "testDeleteFailsWhenKeyStoreInUse";
-
-        //add a new key store config to use
-        Map<String, Object> sslKeyStoreAttributes = new HashMap<String, 
Object>();
-        sslKeyStoreAttributes.put(KeyStore.NAME, name);
-        sslKeyStoreAttributes.put(FileKeyStore.PATH, 
TestSSLConstants.BROKER_KEYSTORE);
-        sslKeyStoreAttributes.put(FileKeyStore.PASSWORD, 
TestSSLConstants.BROKER_KEYSTORE_PASSWORD);
-        
getBrokerConfiguration().addObjectConfiguration(KeyStore.class,sslKeyStoreAttributes);
-
-        //add the SSL port using it
-        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_PROVIDER, 
TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER);
-        sslPortAttributes.put(Port.KEY_STORE, name);
-        
getBrokerConfiguration().addObjectConfiguration(Port.class,sslPortAttributes);
-
-        super.setUp();
-
-        //verify the keystore is there
+        createKeyStore(name, null, dataUrlForKeyStore, 
TestSSLConstants.KEYSTORE_PASSWORD);
         assertNumberOfKeyStores(2);
 
-        List<Map<String, Object>> keyStore = 
getRestTestHelper().getJsonAsList("keystore/" + name);
-        assertNotNull("details should not be null", keyStore);
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.BROKER_KEYSTORE, null);
-
-        //try to delete it, which should fail as it is in use
-        int responseCode = getRestTestHelper().submitRequest("keystore/" + 
name , "DELETE");
-        assertEquals("Unexpected response code for provider deletion", 409, 
responseCode);
+        List<Map<String, Object>> keyStores = 
getRestTestHelper().getJsonAsList("keystore/" + name);
+        assertNotNull("details cannot be null", keyStores);
 
-        //check its still there
-        assertNumberOfKeyStores(2);
-        keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
-        assertNotNull("details should not be null", keyStore);
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.BROKER_KEYSTORE, null);
+        assertKeyStoreAttributes(keyStores.get(0), name, dataUrlForKeyStore, 
null);
     }
 
-    public void testUpdateWithGoodPathSucceeds() throws Exception
+    public void testDelete() throws Exception
     {
         super.setUp();
 
         String name = getTestName();
+        String certAlias = "app2";
 
         assertNumberOfKeyStores(1);
-        createKeyStore(name, null);
+        createKeyStore(name, certAlias, TestSSLConstants.KEYSTORE, 
TestSSLConstants.KEYSTORE_PASSWORD);
         assertNumberOfKeyStores(2);
 
-        Map<String, Object> attributes = new HashMap<String, Object>();
-        attributes.put(KeyStore.NAME, name);
-        attributes.put(FileKeyStore.PATH, TestSSLConstants.UNTRUSTED_KEYSTORE);
-
-        int responseCode = getRestTestHelper().submitRequest("keystore/" + 
name , "PUT", attributes);
-        assertEquals("Unexpected response code for keystore update", 200, 
responseCode);
+        getRestTestHelper().submitRequest("keystore/" + name, "DELETE", 
HttpServletResponse.SC_OK);
 
         List<Map<String, Object>> keyStore = 
getRestTestHelper().getJsonAsList("keystore/" + name);
         assertNotNull("details should not be null", keyStore);
+        assertTrue("details should be empty as the keystore no longer exists", 
keyStore.isEmpty());
 
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.UNTRUSTED_KEYSTORE, null);
+        //check only the default systests key store remains
+        List<Map<String, Object>> keyStores = assertNumberOfKeyStores(1);
+        Map<String, Object> keystore = keyStores.get(0);
+        assertKeyStoreAttributes(keystore, 
TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE,
+                QPID_HOME + "/../" + TestSSLConstants.BROKER_KEYSTORE, null);
     }
 
-    public void testUpdateWithNonExistentPathFails() throws Exception
+    public void testUpdate() throws Exception
     {
         super.setUp();
 
         String name = getTestName();
 
         assertNumberOfKeyStores(1);
-        createKeyStore(name, null);
+        createKeyStore(name, null, TestSSLConstants.KEYSTORE, 
TestSSLConstants.KEYSTORE_PASSWORD);
         assertNumberOfKeyStores(2);
 
         Map<String, Object> attributes = new HashMap<String, Object>();
         attributes.put(KeyStore.NAME, name);
-        attributes.put(FileKeyStore.PATH, "does.not.exist");
+        attributes.put(FileKeyStore.PATH, TestSSLConstants.UNTRUSTED_KEYSTORE);
 
-        int responseCode = getRestTestHelper().submitRequest("keystore/" + 
name , "PUT", attributes);
-        assertEquals("Unexpected response code for keystore update", 409, 
responseCode);
+        getRestTestHelper().submitRequest("keystore/" + name, "PUT", 
attributes, HttpServletResponse.SC_OK);
 
         List<Map<String, Object>> keyStore = 
getRestTestHelper().getJsonAsList("keystore/" + name);
         assertNotNull("details should not be null", keyStore);
 
-        //verify the details remain unchanged
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.KEYSTORE, null);
+        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.UNTRUSTED_KEYSTORE, null);
     }
 
-    public void testUpdateCertificateAlias() throws Exception
-    {
-        super.setUp();
-
-        String name = getTestName();
 
-        assertNumberOfKeyStores(1);
-        createKeyStore(name, "app1");
-        assertNumberOfKeyStores(2);
-
-        List<Map<String, Object>> keyStore = 
getRestTestHelper().getJsonAsList("keystore/" + name);
-        assertNotNull("details should not be null", keyStore);
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.KEYSTORE, "app1");
-
-        //Update the certAlias from app1 to app2
-        Map<String, Object> attributes = new HashMap<String, Object>();
-        attributes.put(KeyStore.NAME, name);
-        attributes.put(FileKeyStore.CERTIFICATE_ALIAS, "app2");
-
-        int responseCode = getRestTestHelper().submitRequest("keystore/" + 
name , "PUT", attributes);
-        assertEquals("Unexpected response code for keystore update", 200, 
responseCode);
-
-        keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
-        assertNotNull("details should not be null", keyStore);
-
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.KEYSTORE, "app2");
-
-        //Update the certAlias to clear it (i.e go from from app1 to null)
-        attributes = new HashMap<String, Object>();
-        attributes.put(KeyStore.NAME, name);
-        attributes.put(FileKeyStore.CERTIFICATE_ALIAS, null);
-
-        responseCode = getRestTestHelper().submitRequest("keystore/" + name , 
"PUT", attributes);
-        assertEquals("Unexpected response code for keystore update", 200, 
responseCode);
-
-        keyStore = getRestTestHelper().getJsonAsList("keystore/" + name);
-        assertNotNull("details should not be null", keyStore);
-
-        assertKeyStoreAttributes(keyStore.get(0), name, 
TestSSLConstants.KEYSTORE, null);
-    }
-
-    private List<Map<String, Object>> assertNumberOfKeyStores(int 
numberOfKeystores) throws IOException,
-    JsonParseException, JsonMappingException
+    private List<Map<String, Object>> assertNumberOfKeyStores(int 
numberOfKeystores) throws Exception
     {
         List<Map<String, Object>> keyStores = 
getRestTestHelper().getJsonAsList("keystore");
         assertNotNull("keystores should not be null", keyStores);
@@ -239,16 +147,18 @@ public class KeyStoreRestTest extends Qp
         return keyStores;
     }
 
-    private void createKeyStore(String name, String certAlias) throws 
IOException, JsonGenerationException, JsonMappingException
+    private void createKeyStore(String name, String certAlias, final String 
keyStorePath, final String keystorePassword) throws Exception
     {
-        Map<String, Object> keyStoreAttributes = new HashMap<String, Object>();
+        Map<String, Object> keyStoreAttributes = new HashMap<>();
         keyStoreAttributes.put(KeyStore.NAME, name);
-        keyStoreAttributes.put(FileKeyStore.PATH, TestSSLConstants.KEYSTORE);
-        keyStoreAttributes.put(FileKeyStore.PASSWORD, 
TestSSLConstants.KEYSTORE_PASSWORD);
-        keyStoreAttributes.put(FileKeyStore.CERTIFICATE_ALIAS, certAlias);
+        keyStoreAttributes.put(FileKeyStore.PATH, keyStorePath);
+        keyStoreAttributes.put(FileKeyStore.PASSWORD, keystorePassword);
+        if (certAlias != null)
+        {
+            keyStoreAttributes.put(FileKeyStore.CERTIFICATE_ALIAS, certAlias);
+        }
 
-        int responseCode = getRestTestHelper().submitRequest("keystore/" + 
name, "PUT", keyStoreAttributes);
-        assertEquals("Unexpected response code", 201, responseCode);
+        getRestTestHelper().submitRequest("keystore/" + name, "PUT", 
keyStoreAttributes, HttpServletResponse.SC_CREATED);
     }
 
     private void assertKeyStoreAttributes(Map<String, Object> keystore, String 
name, String path, String certAlias)
@@ -261,12 +171,16 @@ public class KeyStoreRestTest extends Qp
                      AbstractConfiguredObject.SECURED_STRING_VALUE, 
keystore.get(FileKeyStore.PASSWORD));
         assertEquals("unexpected type of default systests key store",
                 java.security.KeyStore.getDefaultType(), 
keystore.get(FileKeyStore.KEY_STORE_TYPE));
-        assertEquals("unexpected certificateAlias value",
-                certAlias, keystore.get(FileKeyStore.CERTIFICATE_ALIAS));
         if(certAlias == null)
         {
             assertFalse("should not be a certificateAlias attribute",
                             
keystore.containsKey(FileKeyStore.CERTIFICATE_ALIAS));
         }
+        else
+        {
+            assertEquals("unexpected certificateAlias value",
+                         certAlias, 
keystore.get(FileKeyStore.CERTIFICATE_ALIAS));
+
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to