You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2013/02/27 18:50:17 UTC

svn commit: r1450881 [2/2] - in /qpid/trunk/qpid/java: broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/ broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ broker-plu...

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java?rev=1450881&r1=1450880&r2=1450881&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PortRestTest.java Wed Feb 27 17:50:17 2013
@@ -21,10 +21,17 @@
 package org.apache.qpid.systest.rest;
 
 import java.net.URLDecoder;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.qpid.server.model.AuthenticationProvider;
 import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory;
 import org.apache.qpid.test.utils.TestBrokerConfiguration;
 
 public class PortRestTest extends QpidRestTestCase
@@ -61,4 +68,111 @@ public class PortRestTest extends QpidRe
         }
     }
 
+    public void testPutAmqpPortWithMinimumAttributes() throws Exception
+    {
+        String portName = "test-port";
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(Port.NAME, portName);
+        attributes.put(Port.PORT, findFreePort());
+
+        int responseCode = getRestTestHelper().submitRequest("/rest/port/" + portName, "PUT", attributes);
+        assertEquals("Unexpected response code", 201, responseCode);
+
+        List<Map<String, Object>> portDetails = getRestTestHelper().getJsonAsList("/rest/port/" + portName);
+        assertNotNull("Port details cannot be null", portDetails);
+        assertEquals("Unexpected number of ports with name " + portName, 1, portDetails.size());
+        Map<String, Object> port = portDetails.get(0);
+        Asserts.assertPortAttributes(port);
+
+        // make sure that port is there after broker restart
+        restartBroker();
+
+        portDetails = getRestTestHelper().getJsonAsList("/rest/port/" + portName);
+        assertNotNull("Port details cannot be null", portDetails);
+        assertEquals("Unexpected number of ports with name " + portName, 1, portDetails.size());
+    }
+
+    public void testPutRmiPortWithMinimumAttributes() throws Exception
+    {
+        String portName = "test-port";
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(Port.NAME, portName);
+        attributes.put(Port.PORT, findFreePort());
+        attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.RMI));
+
+        int responseCode = getRestTestHelper().submitRequest("/rest/port/" + portName, "PUT", attributes);
+        assertEquals("Unexpected response code", 201, responseCode);
+
+        List<Map<String, Object>> portDetails = getRestTestHelper().getJsonAsList("/rest/port/" + portName);
+        assertNotNull("Port details cannot be null", portDetails);
+        assertEquals("Unexpected number of ports with name " + portName, 1, portDetails.size());
+        Map<String, Object> port = portDetails.get(0);
+        Asserts.assertPortAttributes(port);
+
+        // make sure that port is there after broker restart
+        restartBroker();
+
+        portDetails = getRestTestHelper().getJsonAsList("/rest/port/" + portName);
+        assertNotNull("Port details cannot be null", portDetails);
+        assertEquals("Unexpected number of ports with name " + portName, 1, portDetails.size());
+    }
+
+    public void testPutCreateAndUpdateAmqpPort() throws Exception
+    {
+        String portName = "test-port";
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put(Port.NAME, portName);
+        attributes.put(Port.PORT, findFreePort());
+
+        int responseCode = getRestTestHelper().submitRequest("/rest/port/" + portName, "PUT", attributes);
+        assertEquals("Unexpected response code for port creation", 201, responseCode);
+
+        List<Map<String, Object>> portDetails = getRestTestHelper().getJsonAsList("/rest/port/" + portName);
+        assertNotNull("Port details cannot be null", portDetails);
+        assertEquals("Unexpected number of ports with name " + portName, 1, portDetails.size());
+        Map<String, Object> port = portDetails.get(0);
+        Asserts.assertPortAttributes(port);
+
+        Map<String, Object> authProviderAttributes = new HashMap<String, Object>();
+        authProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE);
+        authProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER);
+
+        responseCode = getRestTestHelper().submitRequest("/rest/authenticationprovider/" + TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER, "PUT", authProviderAttributes);
+        assertEquals("Unexpected response code for authentication provider creation", 201, responseCode);
+
+        attributes = new HashMap<String, Object>(port);
+        attributes.put(Port.AUTHENTICATION_MANAGER, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER);
+        attributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.AMQP_0_9_1));
+
+        responseCode = getRestTestHelper().submitRequest("/rest/port/" + portName, "PUT", attributes);
+        assertEquals("Unexpected response code for port update", 200, responseCode);
+
+        portDetails = getRestTestHelper().getJsonAsList("/rest/port/" + portName);
+        assertNotNull("Port details cannot be null", portDetails);
+        assertEquals("Unexpected number of ports with name " + portName, 1, portDetails.size());
+        port = portDetails.get(0);
+
+        assertEquals("Unexpected authentication provider", TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER, port.get(Port.AUTHENTICATION_MANAGER));
+        Object protocols = port.get(Port.PROTOCOLS);
+        assertNotNull("Protocols attribute is not found", protocols);
+        assertTrue("Protocol attribute value is not collection:" + protocols, protocols instanceof Collection);
+        @SuppressWarnings("unchecked")
+        Collection<String> protocolsCollection = ((Collection<String>)protocols);
+        assertEquals("Unexpected protocols size", 1, protocolsCollection.size());
+        assertEquals("Unexpected protocols", Protocol.AMQP_0_9_1.name(), protocolsCollection.iterator().next());
+    }
+
+    public void testPutUpdateOpenedAmqpPortFails() throws Exception
+    {
+        Map<String, Object> port = getRestTestHelper().getJsonAsSingletonList("/rest/port/" + TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT);
+        Integer portValue = (Integer)port.get(Port.PORT);
+
+        port.put(Port.PORT, findFreePort());
+
+        int responseCode = getRestTestHelper().submitRequest("/rest/port/" + TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, "PUT", port);
+        assertEquals("Unexpected response code for port update", 409, responseCode);
+
+        port = getRestTestHelper().getJsonAsSingletonList("/rest/port/" + TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT);
+        assertEquals("Port has been changed", portValue, port.get(Port.PORT));
+    }
 }

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java?rev=1450881&r1=1450880&r2=1450881&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java Wed Feb 27 17:50:17 2013
@@ -422,7 +422,7 @@ public class RestTestHelper
         }
     }
 
-    private File createTemporaryPasswdFile(String[] users) throws IOException
+    File createTemporaryPasswdFile(String[] users) throws IOException
     {
         BufferedWriter writer = null;
         try
@@ -449,4 +449,17 @@ public class RestTestHelper
             }
         }
     }
+
+    public int submitRequest(String url, String method, Map<String, Object> attributes) throws IOException,
+            JsonGenerationException, JsonMappingException
+    {
+        HttpURLConnection connection = openManagementConnection(url, method);
+        if (attributes != null)
+        {
+            writeJsonRequest(connection, attributes);
+        }
+        int responseCode = connection.getResponseCode();
+        connection.disconnect();
+        return responseCode;
+    }
 }

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java?rev=1450881&r1=1450880&r2=1450881&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/VirtualHostRestTest.java Wed Feb 27 17:50:17 2013
@@ -169,6 +169,112 @@ public class VirtualHostRestTest extends
         assertEquals("Host should be deleted", 0, hosts.size());
     }
 
+    public void testDeleteDefaultHostFails() throws Exception
+    {
+        String hostToDelete = TEST1_VIRTUALHOST;
+        int response = getRestTestHelper().submitRequest("/rest/virtualhost/" + hostToDelete, "DELETE", null);
+        assertEquals("Unexpected response code", 409, response);
+
+        restartBroker();
+
+        List<Map<String, Object>> hosts = getRestTestHelper().getJsonAsList("/rest/virtualhost/" + hostToDelete);
+        assertEquals("Host should be deleted", 1, hosts.size());
+    }
+
+    public void testUpdateActiveHostFails() throws Exception
+    {
+        String hostToUpdate = TEST3_VIRTUALHOST;
+        Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostToUpdate);
+        Asserts.assertVirtualHost(hostToUpdate, hostDetails);
+        String configPath = (String)hostDetails.get(VirtualHost.CONFIG_PATH);
+        assertNotNull("Unexpected host configuration", configPath);
+
+        String storeType = getTestProfileMessageStoreType();
+        String storeLocation = getStoreLocation(hostToUpdate);
+        Map<String, Object> newAttributes = new HashMap<String, Object>();
+        newAttributes.put(VirtualHost.NAME, hostToUpdate);
+        newAttributes.put(VirtualHost.STORE_TYPE, storeType);
+        newAttributes.put(VirtualHost.STORE_PATH, storeLocation);
+
+        int response = getRestTestHelper().submitRequest("/rest/virtualhost/" + hostToUpdate, "PUT", newAttributes);
+        assertEquals("Unexpected response code", 409, response);
+
+        restartBroker();
+
+        hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostToUpdate);
+        Asserts.assertVirtualHost(hostToUpdate, hostDetails);
+        assertEquals("Unexpected config path", configPath, hostDetails.get(VirtualHost.CONFIG_PATH));
+    }
+
+    public void testUpdateInManagementMode() throws Exception
+    {
+        String hostToUpdate = TEST3_VIRTUALHOST;
+        Map<String, Object> hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostToUpdate);
+        Asserts.assertVirtualHost(hostToUpdate, hostDetails);
+        String configPath = (String)hostDetails.get(VirtualHost.CONFIG_PATH);
+        String storeType = (String)hostDetails.get(VirtualHost.STORE_TYPE);
+        assertNotNull("Unexpected host configuration", configPath);
+        assertNotNull("Unexpected store type", storeType);
+
+        String queueName = getTestQueueName();
+        if (isBrokerStorePersistent())
+        {
+            String storePath = (String)hostDetails.get(VirtualHost.STORE_PATH);
+            assertNotNull("Unexpected store path", storePath);
+
+            // add a durable queue to the host
+            // in order to test whether host store is copied into a new location
+            Map<String, Object> queueData = new HashMap<String, Object>();
+            queueData.put(Queue.NAME, queueName);
+            queueData.put(Queue.DURABLE, Boolean.TRUE);
+            int response = getRestTestHelper().submitRequest("/rest/queue/" + hostToUpdate + "/" + queueName, "PUT", queueData);
+            assertEquals("Unexpected response code for queue creation", 201, response);
+        }
+
+        // stop broker as it is running not in management mode
+        stopBroker(0);
+
+        // start broker in management mode
+        startBroker(0, true);
+
+        String newStoreType = getTestProfileMessageStoreType();
+        String newStorePath = getStoreLocation(hostToUpdate);
+        Map<String, Object> newAttributes = new HashMap<String, Object>();
+        newAttributes.put(VirtualHost.NAME, hostToUpdate);
+        newAttributes.put(VirtualHost.STORE_TYPE, newStoreType);
+        newAttributes.put(VirtualHost.STORE_PATH, newStorePath);
+        newAttributes.put(VirtualHost.CONFIG_PATH, null);
+
+        try
+        {
+            int response = getRestTestHelper().submitRequest("/rest/virtualhost/" + hostToUpdate, "PUT", newAttributes);
+            assertEquals("Unexpected response code for virtual host update", 200, response);
+
+            restartBroker();
+
+            hostDetails = getRestTestHelper().getJsonAsSingletonList("/rest/virtualhost/" + hostToUpdate);
+            Asserts.assertVirtualHost(hostToUpdate, hostDetails);
+            assertEquals("Unexpected config type", newStoreType, hostDetails.get(VirtualHost.STORE_TYPE));
+
+            if (isBrokerStorePersistent())
+            {
+                assertEquals("Unexpected config path", newStorePath, hostDetails.get(VirtualHost.STORE_PATH));
+
+                // the virtual host store should be copied into a new location
+                // check existence of the queue
+                List<Map<String, Object>> queues = getRestTestHelper().getJsonAsList("/rest/queue/" + hostToUpdate + "/" + queueName);
+                assertEquals("Queue is not found. Looks like message store was not copied", 1, queues.size());
+            }
+        }
+        finally
+        {
+            if (newStorePath != null)
+            {
+                FileUtils.delete(new File(newStorePath), true);
+            }
+        }
+    }
+
     public void testPutCreateQueue() throws Exception
     {
         String queueName = getTestQueueName();
@@ -519,7 +625,6 @@ public class VirtualHostRestTest extends
     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);
@@ -533,10 +638,7 @@ public class VirtualHostRestTest extends
             hostData.put(VirtualHost.STORE_TYPE, storeType);
         }
 
-        getRestTestHelper().writeJsonRequest(connection, hostData);
-        int responseCode = connection.getResponseCode();
-        connection.disconnect();
-        return responseCode;
+        return getRestTestHelper().submitRequest("/rest/virtualhost/" + hostName, "PUT", hostData);
     }
 
     private XMLConfiguration createAndSaveVirtualHostConfiguration(String hostName, File configFile, String storeLocation)

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java?rev=1450881&r1=1450880&r2=1450881&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java Wed Feb 27 17:50:17 2013
@@ -418,12 +418,16 @@ public class QpidBrokerTestCase extends 
 
     public void startBroker(int port) throws Exception
     {
+        startBroker(port, false);
+    }
+
+    public void startBroker(int port, boolean managementMode) throws Exception
+    {
         int actualPort = getPort(port);
         TestBrokerConfiguration configuration = getBrokerConfiguration(actualPort);
-        startBroker(actualPort, configuration, _testVirtualhosts);
+        startBroker(actualPort, configuration, _testVirtualhosts, managementMode);
     }
 
-
     protected File getBrokerCommandLog4JFile()
     {
         return _logConfigFile;
@@ -437,6 +441,11 @@ public class QpidBrokerTestCase extends 
 
     public void startBroker(int port, TestBrokerConfiguration testConfiguration, XMLConfiguration virtualHosts) throws Exception
     {
+        startBroker(port, testConfiguration, virtualHosts, false);
+    }
+
+    public void startBroker(int port, TestBrokerConfiguration testConfiguration, XMLConfiguration virtualHosts, boolean managementMode) throws Exception
+    {
         port = getPort(port);
         String testConfig = saveTestConfiguration(port, testConfiguration);
         String virtualHostsConfig = saveTestVirtualhosts(port, virtualHosts);
@@ -457,6 +466,7 @@ public class QpidBrokerTestCase extends 
 
             options.setConfigurationStoreType(_brokerStoreType);
             options.setConfigurationStoreLocation(testConfig);
+            options.setManagementMode(managementMode);
 
             //Set the log config file, relying on the log4j.configuration system property
             //set on the JVM by the JUnit runner task in module.xml.
@@ -474,6 +484,13 @@ public class QpidBrokerTestCase extends 
             final String qpidWork = getQpidWork(_brokerType, port);
 
             String[] cmd = _brokerCommandHelper.getBrokerCommand(port, testConfig, _brokerStoreType, _logConfigFile);
+            if (managementMode)
+            {
+                String[] newCmd = new String[cmd.length + 1];
+                System.arraycopy(cmd, 0, newCmd, 0, cmd.length);
+                newCmd[cmd.length] = "-mm";
+                cmd = newCmd;
+            }
             _logger.info("Starting spawn broker using command: " + StringUtils.join(cmd, ' '));
             ProcessBuilder pb = new ProcessBuilder(cmd);
             pb.redirectErrorStream(true);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org