You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2012/07/11 13:01:08 UTC

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

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QpidRestTestCase.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,232 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.type.TypeReference;
+
+public class QpidRestTestCase extends QpidBrokerTestCase
+{
+    private static final Logger LOGGER = Logger.getLogger(QpidRestTestCase.class);
+
+    public static final String[] EXPECTED_HOSTS = { "development", "test", "localhost" };
+    public static final String[] EXPECTED_QUEUES = { "queue", "ping" };
+    public static final String[] EXPECTED_EXCHANGES = { "amq.fanout", "amq.match", "amq.direct", "amq.topic",
+            "qpid.management", "<<default>>" };
+
+    private int _httpPort;
+    private String _hostName;
+    private List<HttpURLConnection> _httpConnections;
+
+    public void setUp() throws Exception
+    {
+        _httpConnections = new ArrayList<HttpURLConnection>();
+        _hostName = InetAddress.getLocalHost().getHostName();
+        _httpPort = findFreePort();
+        setConfigurationProperty("management.enabled", "true");
+        setConfigurationProperty("management.http.enabled", "true");
+        setConfigurationProperty("management.http.port", Integer.toString(_httpPort));
+        setConfigurationProperty("management.jmx.enabled", "false");
+        super.setUp();
+    }
+
+    public void teearDown() throws Exception
+    {
+        for (HttpURLConnection connection : _httpConnections)
+        {
+            try
+            {
+                connection.disconnect();
+            }
+            catch (Exception e)
+            {
+                // ignore
+            }
+        }
+        super.tearDown();
+    }
+
+    protected int getHttpPort()
+    {
+        return _httpPort;
+    }
+
+    protected String getHostName()
+    {
+        return _hostName;
+    }
+
+    protected String getManagementURL()
+    {
+        return "http://" + _hostName + ":" + _httpPort;
+    }
+
+    protected URL getManagementURL(String path) throws MalformedURLException
+    {
+        return new URL(getManagementURL() + path);
+    }
+
+    protected HttpURLConnection openManagementConection(String path) throws IOException
+    {
+        URL url = getManagementURL(path);
+        HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
+        httpCon.setDoOutput(true);
+        return httpCon;
+    }
+
+    protected HttpURLConnection openManagementConection(String path, String method) throws IOException
+    {
+        HttpURLConnection httpCon = openManagementConection(path);
+        httpCon.setRequestMethod(method);
+        return httpCon;
+    }
+
+    protected List<Map<String, Object>> readJsonResponseAsList(HttpURLConnection connection) throws IOException,
+            JsonParseException, JsonMappingException
+    {
+        byte[] data = readConnectionInputStream(connection);
+
+        ObjectMapper mapper = new ObjectMapper();
+
+        TypeReference<List<LinkedHashMap<String, Object>>> typeReference = new TypeReference<List<LinkedHashMap<String, Object>>>()
+        {
+        };
+        List<Map<String, Object>> providedObject = mapper.readValue(new ByteArrayInputStream(data), typeReference);
+        return providedObject;
+    }
+
+    protected Map<String, Object> readJsonResponseAsMap(HttpURLConnection connection) throws IOException,
+            JsonParseException, JsonMappingException
+    {
+        byte[] data = readConnectionInputStream(connection);
+
+        ObjectMapper mapper = new ObjectMapper();
+
+        TypeReference<LinkedHashMap<String, Object>> typeReference = new TypeReference<LinkedHashMap<String, Object>>()
+        {
+        };
+        Map<String, Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), typeReference);
+        return providedObject;
+    }
+
+    protected byte[] readConnectionInputStream(HttpURLConnection connection) throws IOException
+    {
+        InputStream is = connection.getInputStream();
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        byte[] buffer = new byte[1024];
+        int len = -1;
+        while ((len = is.read(buffer)) != -1)
+        {
+            baos.write(buffer, 0, len);
+        }
+        if (LOGGER.isTraceEnabled())
+        {
+            LOGGER.trace("RESPONSE:" + new String(baos.toByteArray()));
+        }
+        return baos.toByteArray();
+    }
+
+    protected void writeJsonRequest(HttpURLConnection connection, Map<String, Object> data) throws JsonGenerationException,
+            JsonMappingException, IOException
+    {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.writeValue(connection.getOutputStream(), data);
+    }
+
+    protected Map<String, Object> find(String name, Object value, List<Map<String, Object>> data)
+    {
+        for (Map<String, Object> map : data)
+        {
+            Object mapValue = map.get(name);
+            if (value.equals(mapValue))
+            {
+                return map;
+            }
+        }
+        return null;
+    }
+
+    protected Map<String, Object> find(Map<String, Object> searchAttributes, List<Map<String, Object>> data)
+    {
+        for (Map<String, Object> map : data)
+        {
+            boolean equals = true;
+            for (Map.Entry<String, Object> entry : searchAttributes.entrySet())
+            {
+                Object mapValue = map.get(entry.getKey());
+                if (!entry.getValue().equals(mapValue))
+                {
+                    equals = false;
+                    break;
+                }
+            }
+            if (equals)
+            {
+                return map;
+            }
+        }
+        return null;
+    }
+
+    protected Map<String, Object> getJsonAsSingletonList(String path) throws IOException
+    {
+        List<Map<String, Object>> response = getJsonAsList(path);
+
+        assertNotNull("Response cannot be null", response);
+        assertEquals("Unexpected response", 1, response.size());
+        return response.get(0);
+    }
+
+    protected List<Map<String, Object>> getJsonAsList(String path) throws IOException, JsonParseException,
+            JsonMappingException
+    {
+        HttpURLConnection connection = openManagementConection(path, "GET");
+        connection.connect();
+        List<Map<String, Object>> response = readJsonResponseAsList(connection);
+        return response;
+    }
+
+    protected Map<String, Object> getJsonAsMap(String path) throws IOException
+    {
+        HttpURLConnection connection = openManagementConection(path, "GET");
+        connection.connect();
+        Map<String, Object> response = readJsonResponseAsMap(connection);
+        return response;
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/QueueRestTest.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,225 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URLDecoder;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+
+import org.apache.qpid.server.model.Binding;
+import org.apache.qpid.server.model.Consumer;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.Queue;
+
+public class QueueRestTest extends QpidRestTestCase
+{
+    private static final String QUEUE_ATTRIBUTE_CONSUMERS = "consumers";
+    private static final String QUEUE_ATTRIBUTE_BINDINGS = "bindings";
+
+    /**
+     * Message number to publish into queue
+     */
+    private static final int MESSAGE_NUMBER = 2;
+    private static final int MESSAGE_PAYLOAD_SIZE = 6;
+    private static final int ENQUEUED_MESSAGES = 1;
+    private static final int DEQUEUED_MESSAGES = 1;
+    private static final int ENQUEUED_BYTES = MESSAGE_PAYLOAD_SIZE;
+    private static final int DEQUEUED_BYTES = MESSAGE_PAYLOAD_SIZE;
+
+    private Connection _connection;
+
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        _connection = getConnection();
+        Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
+        String queueName = getTestQueueName();
+        Destination queue = session.createQueue(queueName);
+        MessageConsumer consumer = session.createConsumer(queue);
+        MessageProducer producer = session.createProducer(queue);
+
+        for (int i = 0; i < MESSAGE_NUMBER; i++)
+        {
+            producer.send(session.createTextMessage("Test-" + i));
+        }
+        session.commit();
+        _connection.start();
+        Message m = consumer.receive(1000l);
+        assertNotNull("Message is not received", m);
+        session.commit();
+    }
+
+    public void testGetVirtualHostQueues() throws Exception
+    {
+        String queueName = getTestQueueName();
+        List<Map<String, Object>> queues = getJsonAsList("/rest/queue/test");
+        assertEquals("Unexpected number of queues", EXPECTED_QUEUES.length + 1, queues.size());
+        String[] expectedQueues = new String[EXPECTED_QUEUES.length + 1];
+        System.arraycopy(EXPECTED_QUEUES, 0, expectedQueues, 0, EXPECTED_QUEUES.length);
+        expectedQueues[EXPECTED_QUEUES.length] = queueName;
+
+        for (String name : expectedQueues)
+        {
+            Map<String, Object> queueDetails = find(Queue.NAME, name, queues);
+            Asserts.assertQueue(name, "standard", queueDetails);
+
+            @SuppressWarnings("unchecked")
+            List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
+            assertNotNull("Queue bindings are not found", bindings);
+            assertEquals("Unexpected number of bindings", 2, bindings.size());
+
+            Map<String, Object> defaultExchangeBinding = find(Binding.EXCHANGE, "<<default>>", bindings);
+            Map<String, Object> directExchangeBinding = find(Binding.EXCHANGE, "amq.direct", bindings);
+            Asserts.assertBinding(name, "<<default>>", defaultExchangeBinding);
+            Asserts.assertBinding(name, "amq.direct", directExchangeBinding);
+        }
+    }
+
+    public void testGetByName() throws Exception
+    {
+        String queueName = getTestQueueName();
+        Map<String, Object> queueDetails = getJsonAsSingletonList("/rest/queue/test/" + queueName);
+        Asserts.assertQueue(queueName, "standard", queueDetails);
+        assertStatistics(queueDetails);
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
+        assertNotNull("Queue bindings are not found", bindings);
+        assertEquals("Unexpected number of bindings", 2, bindings.size());
+
+        Map<String, Object> defaultExchangeBinding = find(Binding.EXCHANGE, "<<default>>", bindings);
+        Map<String, Object> directExchangeBinding = find(Binding.EXCHANGE, "amq.direct", bindings);
+        Asserts.assertBinding(queueName, "<<default>>", defaultExchangeBinding);
+        Asserts.assertBinding(queueName, "amq.direct", directExchangeBinding);
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> consumers = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_CONSUMERS);
+        assertNotNull("Queue consumers are not found", consumers);
+        assertEquals("Unexpected number of consumers", 1, consumers.size());
+        assertConsumer(consumers.get(0));
+    }
+
+    public void testPutCreateBinding() throws Exception
+    {
+        String queueName = getTestQueueName();
+        String bindingName = queueName + 2;
+        String[] exchanges = { "amq.direct", "amq.fanout", "amq.topic", "amq.match", "qpid.management", "<<default>>" };
+
+        for (int i = 0; i < exchanges.length; i++)
+        {
+            createBinding(bindingName, exchanges[i], queueName);
+        }
+
+        Map<String, Object> queueDetails = getJsonAsSingletonList("/rest/queue/test/" + queueName);
+        Asserts.assertQueue(queueName, "standard", queueDetails);
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> bindings = (List<Map<String, Object>>) queueDetails.get(QUEUE_ATTRIBUTE_BINDINGS);
+        assertNotNull("Queue bindings are not found", bindings);
+        assertEquals("Unexpected number of bindings", exchanges.length + 2, bindings.size());
+
+        Map<String, Object> searchAttributes = new HashMap<String, Object>();
+        searchAttributes.put(Binding.NAME, bindingName);
+
+        for (int i = 0; i < exchanges.length; i++)
+        {
+            searchAttributes.put(Binding.EXCHANGE, exchanges[i]);
+            Map<String, Object> binding = find(searchAttributes, bindings);
+            Asserts.assertBinding(bindingName, queueName, exchanges[i], binding);
+        }
+    }
+
+    private void createBinding(String bindingName, String exchangeName, String queueName) throws IOException
+    {
+        HttpURLConnection connection = openManagementConection(
+                "/rest/binding/test/" + URLDecoder.decode(exchangeName, "UTF-8") + "/" + queueName + "/" + bindingName,
+                "PUT");
+
+        Map<String, Object> bindingData = new HashMap<String, Object>();
+        bindingData.put(Binding.NAME, bindingName);
+        bindingData.put(Binding.EXCHANGE, exchangeName);
+        bindingData.put(Binding.QUEUE, queueName);
+
+        writeJsonRequest(connection, bindingData);
+        assertEquals("Unexpected response code", 201, connection.getResponseCode());
+
+        connection.disconnect();
+    }
+
+    private void assertConsumer(Map<String, Object> consumer)
+    {
+        assertNotNull("Consumer map should not be null", consumer);
+        Asserts.assertAttributesPresent(consumer, Consumer.AVAILABLE_ATTRIBUTES, Consumer.STATE, Consumer.TIME_TO_LIVE,
+                Consumer.CREATED, Consumer.UPDATED, Consumer.SETTLEMENT_MODE, Consumer.EXCLUSIVE, Consumer.SELECTOR,
+                Consumer.NO_LOCAL);
+
+        assertEquals("Unexpected binding attribute " + Consumer.NAME, "1", consumer.get(Consumer.NAME));
+        assertEquals("Unexpected binding attribute " + Consumer.DURABLE, Boolean.FALSE, consumer.get(Consumer.DURABLE));
+        assertEquals("Unexpected binding attribute " + Consumer.LIFETIME_POLICY, LifetimePolicy.AUTO_DELETE.name(),
+                consumer.get(Consumer.LIFETIME_POLICY));
+        assertEquals("Unexpected binding attribute " + Consumer.DISTRIBUTION_MODE, "MOVE",
+                consumer.get(Consumer.DISTRIBUTION_MODE));
+
+        @SuppressWarnings("unchecked")
+        Map<String, Object> statistics = (Map<String, Object>) consumer.get(Asserts.STATISTICS_ATTRIBUTE);
+        assertNotNull("Consumer statistics is not present", statistics);
+        Asserts.assertAttributesPresent(statistics, Consumer.AVAILABLE_STATISTICS, Consumer.STATE_CHANGED);
+    }
+
+    private void assertStatistics(Map<String, Object> queueDetails)
+    {
+        @SuppressWarnings("unchecked")
+        Map<String, Object> statistics = (Map<String, Object>) queueDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+        assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
+                statistics.get(Queue.PERSISTENT_DEQUEUED_MESSAGES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.QUEUE_DEPTH_MESSAGES, ENQUEUED_MESSAGES,
+                statistics.get(Queue.QUEUE_DEPTH_MESSAGES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.CONSUMER_COUNT, 1,
+                statistics.get(Queue.CONSUMER_COUNT));
+        assertEquals("Unexpected queue statistics attribute " + Queue.CONSUMER_COUNT_WITH_CREDIT, 1,
+                statistics.get(Queue.CONSUMER_COUNT_WITH_CREDIT));
+        assertEquals("Unexpected queue statistics attribute " + Queue.BINDING_COUNT, 2, statistics.get(Queue.BINDING_COUNT));
+        assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
+                statistics.get(Queue.PERSISTENT_DEQUEUED_MESSAGES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_DEQUEUED_MESSAGES, DEQUEUED_MESSAGES,
+                statistics.get(Queue.TOTAL_DEQUEUED_MESSAGES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_DEQUEUED_BYTES, DEQUEUED_BYTES,
+                statistics.get(Queue.TOTAL_DEQUEUED_BYTES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_DEQUEUED_BYTES, DEQUEUED_BYTES,
+                statistics.get(Queue.TOTAL_DEQUEUED_BYTES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.PERSISTENT_ENQUEUED_BYTES, ENQUEUED_BYTES
+                + DEQUEUED_BYTES, statistics.get(Queue.PERSISTENT_ENQUEUED_BYTES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.TOTAL_ENQUEUED_BYTES, ENQUEUED_BYTES + DEQUEUED_BYTES,
+                statistics.get(Queue.TOTAL_ENQUEUED_BYTES));
+        assertEquals("Unexpected queue statistics attribute " + Queue.QUEUE_DEPTH_BYTES, ENQUEUED_BYTES,
+                statistics.get(Queue.QUEUE_DEPTH_BYTES));
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslRestTest.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,22 @@
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.util.List;
+import java.util.Map;
+
+public class SaslRestTest extends QpidRestTestCase
+{
+    public void testGet() throws Exception
+    {
+        Map<String, Object> saslData = getJsonAsMap("/rest/sasl");
+        assertNotNull("mechanisms attribute is not found", saslData.get("mechanisms"));
+
+        @SuppressWarnings("unchecked")
+        List<String> mechanisms = (List<String>) saslData.get("mechanisms");
+        String[] expectedMechanisms = { "AMQPLAIN", "PLAIN", "CRAM-MD5" };
+        for (String mechanism : expectedMechanisms)
+        {
+            assertTrue("Mechanism " + mechanism + " is not found", mechanisms.contains(mechanism));
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureRestTest.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,115 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.util.List;
+import java.util.Map;
+
+public class StructureRestTest extends QpidRestTestCase
+{
+
+    public void testGet() throws Exception
+    {
+        Map<String, Object> structure = getJsonAsMap("/rest/structure");
+        assertNotNull("Structure data cannot be null", structure);
+        assertNode(structure, "Broker");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) structure.get("virtualhosts");
+        assertEquals("Unexpected number of virtual hosts", 3, virtualhosts.size());
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports");
+        assertEquals("Unexpected number of ports", 2, ports.size());
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders");
+        assertEquals("Unexpected number of authentication providers", 1, providers.size());
+
+        for (String hostName : EXPECTED_HOSTS)
+        {
+            Map<String, Object> host = find("name", hostName, virtualhosts);
+            assertNotNull("Host " + hostName + " is not found ", host);
+            assertNode(host, hostName);
+
+            @SuppressWarnings("unchecked")
+            List<Map<String, Object>> queues = (List<Map<String, Object>>) host.get("queues");
+            assertNotNull("Host " + hostName + " queues are not found ", queues);
+            for (String queueName : EXPECTED_QUEUES)
+            {
+                Map<String, Object> queue = find("name", queueName, queues);
+                assertNotNull(hostName + " queue " + queueName + " is not found ", queue);
+                assertNode(queue, queueName);
+
+                @SuppressWarnings("unchecked")
+                List<Map<String, Object>> bindings = (List<Map<String, Object>>) queue.get("bindings");
+                assertNotNull(hostName + " queue " + queueName + " bindings are not found ", queues);
+                for (Map<String, Object> binding : bindings)
+                {
+                    assertNode(binding, queueName);
+                }
+            }
+
+            @SuppressWarnings("unchecked")
+            List<Map<String, Object>> exchanges = (List<Map<String, Object>>) host.get("exchanges");
+            assertNotNull("Host " + hostName + " exchanges are not found ", exchanges);
+            for (String exchangeName : EXPECTED_EXCHANGES)
+            {
+                Map<String, Object> exchange = find("name", exchangeName, exchanges);
+                assertNotNull("Exchange " + exchangeName + " is not found ", exchange);
+                assertNode(exchange, exchangeName);
+                if ("amq.direct".equalsIgnoreCase(exchangeName) || "<<default>>".equalsIgnoreCase(exchangeName))
+                {
+                    @SuppressWarnings("unchecked")
+                    List<Map<String, Object>> bindings = (List<Map<String, Object>>) exchange.get("bindings");
+                    assertNotNull(hostName + " exchange " + exchangeName + " bindings are not found ", bindings);
+                    for (String queueName : EXPECTED_QUEUES)
+                    {
+                        Map<String, Object> binding = find("name", queueName, bindings);
+                        assertNotNull(hostName + " exchange " + exchangeName + " binding  " + queueName + " is not found", binding);
+                        assertNode(binding, queueName);
+                    }
+                }
+            }
+
+            @SuppressWarnings("unchecked")
+            List<Map<String, Object>> aliases = (List<Map<String, Object>>) host.get("virtualhostaliases");
+            assertNotNull("Host " + hostName + " aliaces are not found ", aliases);
+            assertEquals("Unexpected aliaces size", 1, aliases.size());
+            assertNode(aliases.get(0), hostName);
+        }
+
+        int[] expectedPorts = { getPort(), getHttpPort() };
+        for (int port : expectedPorts)
+        {
+            String portName = "0.0.0.0:" + port;
+            Map<String, Object> portData = find("name", portName, ports);
+            assertNotNull("Port " + portName + " is not found ", portData);
+            assertNode(portData, portName);
+        }
+    }
+
+    private void assertNode(Map<String, Object> node, String name)
+    {
+        assertEquals("Unexpected name", name, node.get("name"));
+        assertNotNull("Unexpected id", node.get("id"));
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/UserRestTest.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,92 @@
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.net.HttpURLConnection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.qpid.server.model.User;
+
+public class UserRestTest extends QpidRestTestCase
+{
+    public void testGet() throws Exception
+    {
+        List<Map<String, Object>> users = getJsonAsList("/rest/user");
+        assertNotNull("Users cannot be null", users);
+        assertTrue("Unexpected number of users", users.size() > 1);
+        for (Map<String, Object> user : users)
+        {
+            assertUser(user);
+        }
+    }
+
+    public void testGetUserByName() throws Exception
+    {
+        List<Map<String, Object>> users = getJsonAsList("/rest/user");
+        assertNotNull("Users cannot be null", users);
+        assertTrue("Unexpected number of users", users.size() > 1);
+        for (Map<String, Object> user : users)
+        {
+            assertNotNull("Attribute " + User.ID, user.get(User.ID));
+            String userName = (String) user.get(User.NAME);
+            assertNotNull("Attribute " + User.NAME, userName);
+            Map<String, Object> userDetails = getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
+                    + userName);
+            assertUser(userDetails);
+            assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
+        }
+    }
+
+    public void testPut() throws Exception
+    {
+        String userName = getTestName();
+        HttpURLConnection connection = openManagementConection("/rest/user/PrincipalDatabaseAuthenticationManager/"
+                + userName, "PUT");
+
+        Map<String, Object> userData = new HashMap<String, Object>();
+        userData.put(User.NAME, userName);
+        userData.put(User.PASSWORD, userName);
+
+        writeJsonRequest(connection, userData);
+        assertEquals("Unexpected response code", 201, connection.getResponseCode());
+
+        connection.disconnect();
+
+        Map<String, Object> userDetails = getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
+                + userName);
+        assertUser(userDetails);
+        assertEquals("Unexpected user name", userName, userDetails.get(User.NAME));
+    }
+
+    public void testDelete() throws Exception
+    {
+        // add user
+        String userName = getTestName();
+        HttpURLConnection connection = openManagementConection("/rest/user/PrincipalDatabaseAuthenticationManager/"
+                + userName, "PUT");
+
+        Map<String, Object> userData = new HashMap<String, Object>();
+        userData.put(User.NAME, userName);
+        userData.put(User.PASSWORD, userName);
+
+        writeJsonRequest(connection, userData);
+        assertEquals("Unexpected response code", 201, connection.getResponseCode());
+        connection.disconnect();
+
+        Map<String, Object> userDetails = getJsonAsSingletonList("/rest/user/PrincipalDatabaseAuthenticationManager/"
+                + userName);
+        String id = (String) userDetails.get(User.ID);
+
+        connection = openManagementConection("/rest/user/PrincipalDatabaseAuthenticationManager?id=" + id, "DELETE");
+        connection.connect();
+        assertEquals("Unexpected response code", 200, connection.getResponseCode());
+        List<Map<String, Object>> users = getJsonAsList("/rest/user/PrincipalDatabaseAuthenticationManager/" + userName);
+        assertEquals("User should be deleted", 0, users.size());
+    }
+
+    private void assertUser(Map<String, Object> user)
+    {
+        assertNotNull("Attribute " + User.ID, user.get(User.ID));
+        assertNotNull("Attribute " + User.NAME, user.get(User.NAME));
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/VirtualHostRestTest.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,294 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.jms.Session;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.server.model.Exchange;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+
+public class VirtualHostRestTest extends QpidRestTestCase
+{
+    private static final String VIRTUALHOST_EXCHANGES_ATTRIBUTE = "exchanges";
+    public static final String VIRTUALHOST_QUEUES_ATTRIBUTE = "queues";
+    public static final String VIRTUALHOST_CONNECTIONS_ATTRIBUTE = "connections";
+
+    private AMQConnection _connection;
+
+    public void testGet() throws Exception
+    {
+        List<Map<String, Object>> hosts = getJsonAsList("/rest/virtualhost/");
+        assertNotNull("Hosts data cannot be null", hosts);
+        assertEquals("Unexpected number of hosts", 3, hosts.size());
+        for (String hostName : EXPECTED_HOSTS)
+        {
+            Map<String, Object> host = find("name", hostName, hosts);
+            Asserts.assertVirtualHost(hostName, host);
+        }
+    }
+
+    public void testGetHost() throws Exception
+    {
+        // create AMQP connection to get connection JSON details
+        _connection = (AMQConnection) getConnection();
+        _connection.createSession(true, Session.SESSION_TRANSACTED);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+        Asserts.assertVirtualHost("test", hostDetails);
+
+        @SuppressWarnings("unchecked")
+        Map<String, Object> statistics = (Map<String, Object>) hostDetails.get(Asserts.STATISTICS_ATTRIBUTE);
+        assertEquals("Unexpected number of exchanges in statistics", 6, statistics.get(VirtualHost.EXCHANGE_COUNT));
+        assertEquals("Unexpected number of queues in statistics", 2, statistics.get(VirtualHost.QUEUE_COUNT));
+        assertEquals("Unexpected number of connections in statistics", 1, statistics.get(VirtualHost.CONNECTION_COUNT));
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+        assertEquals("Unexpected number of exchanges", 6, exchanges.size());
+        Asserts.assertDurableExchange("amq.fanout", "fanout", find(Exchange.NAME, "amq.fanout", exchanges));
+        Asserts.assertDurableExchange("qpid.management", "management", find(Exchange.NAME, "qpid.management", exchanges));
+        Asserts.assertDurableExchange("amq.topic", "topic", find(Exchange.NAME, "amq.topic", exchanges));
+        Asserts.assertDurableExchange("amq.direct", "direct", find(Exchange.NAME, "amq.direct", exchanges));
+        Asserts.assertDurableExchange("amq.match", "headers", find(Exchange.NAME, "amq.match", exchanges));
+        Asserts.assertDurableExchange("<<default>>", "direct", find(Exchange.NAME, "<<default>>", exchanges));
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VIRTUALHOST_QUEUES_ATTRIBUTE);
+        assertEquals("Unexpected number of queues", 2, queues.size());
+        Map<String, Object> queue = find(Queue.NAME,  "queue", queues);
+        Map<String, Object> ping = find(Queue.NAME, "ping", queues);
+        Asserts.assertQueue("queue", "standard", queue);
+        Asserts.assertQueue("ping", "standard", ping);
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.FALSE, queue.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.FALSE, ping.get(Queue.DURABLE));
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> connections = (List<Map<String, Object>>) hostDetails
+                .get(VIRTUALHOST_CONNECTIONS_ATTRIBUTE);
+        assertEquals("Unexpected number of connections", 1, connections.size());
+        Asserts.assertConnection(connections.get(0), _connection);
+    }
+
+    public void testPutCreateQueue() throws Exception
+    {
+        String queueName = getTestQueueName();
+
+        createQueue(queueName + "-standard", "standard", null);
+
+        Map<String, Object> sortedQueueAttributes = new HashMap<String, Object>();
+        sortedQueueAttributes.put(Queue.SORT_KEY, "sortme");
+        createQueue(queueName + "-sorted", "sorted", sortedQueueAttributes);
+
+        Map<String, Object> priorityQueueAttributes = new HashMap<String, Object>();
+        priorityQueueAttributes.put(Queue.PRIORITIES, 10);
+        createQueue(queueName + "-priority", "priority", priorityQueueAttributes);
+
+        Map<String, Object> lvqQueueAttributes = new HashMap<String, Object>();
+        lvqQueueAttributes.put(Queue.LVQ_KEY, "LVQ");
+        createQueue(queueName + "-lvq", "lvq", lvqQueueAttributes);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+        Map<String, Object> standardQueue = find(Queue.NAME, queueName + "-standard" , queues);
+        Map<String, Object> sortedQueue = find(Queue.NAME, queueName + "-sorted" , queues);
+        Map<String, Object> priorityQueue = find(Queue.NAME, queueName + "-priority" , queues);
+        Map<String, Object> lvqQueue = find(Queue.NAME, queueName + "-lvq" , queues);
+
+        Asserts.assertQueue(queueName + "-standard", "standard", standardQueue);
+        Asserts.assertQueue(queueName + "-sorted", "sorted", sortedQueue);
+        Asserts.assertQueue(queueName + "-priority", "priority", priorityQueue);
+        Asserts.assertQueue(queueName + "-lvq", "lvq", lvqQueue);
+
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, standardQueue.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, sortedQueue.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, priorityQueue.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, lvqQueue.get(Queue.DURABLE));
+
+        assertEquals("Unexpected sorted key attribute", "sortme", sortedQueue.get(Queue.SORT_KEY));
+        assertEquals("Unexpected lvq key attribute", "LVQ", lvqQueue.get(Queue.LVQ_KEY));
+        assertEquals("Unexpected priorities key attribute", 10, priorityQueue.get(Queue.PRIORITIES));
+    }
+
+    public void testPutCreateExchange() throws Exception
+    {
+        String exchangeName = getTestName();
+
+        createExchange(exchangeName + "-direct", "direct");
+        createExchange(exchangeName + "-topic", "topic");
+        createExchange(exchangeName + "-headers", "headers");
+        createExchange(exchangeName + "-fanout", "fanout");
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> exchanges = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_EXCHANGES_ATTRIBUTE);
+        Map<String, Object> directExchange = find(Queue.NAME, exchangeName + "-direct" , exchanges);
+        Map<String, Object> topicExchange = find(Queue.NAME, exchangeName + "-topic" , exchanges);
+        Map<String, Object> headersExchange = find(Queue.NAME, exchangeName + "-headers" , exchanges);
+        Map<String, Object> fanoutExchange = find(Queue.NAME, exchangeName + "-fanout" , exchanges);
+
+        Asserts.assertDurableExchange(exchangeName + "-direct", "direct", directExchange);
+        Asserts.assertDurableExchange(exchangeName + "-topic", "topic", topicExchange);
+        Asserts.assertDurableExchange(exchangeName + "-headers", "headers", headersExchange);
+        Asserts.assertDurableExchange(exchangeName + "-fanout", "fanout", fanoutExchange);
+
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, directExchange.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, topicExchange.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, headersExchange.get(Queue.DURABLE));
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, fanoutExchange.get(Queue.DURABLE));
+
+    }
+
+    public void testPutCreateLVQWithoutKey() throws Exception
+    {
+        String queueName = getTestQueueName()+ "-lvq";
+        createQueue(queueName, "lvq", null);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+        Map<String, Object> lvqQueue = find(Queue.NAME, queueName  , queues);
+
+        Asserts.assertQueue(queueName , "lvq", lvqQueue);
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, lvqQueue.get(Queue.DURABLE));
+        assertEquals("Unexpected lvq key attribute", AMQQueueFactory.QPID_LVQ_KEY, lvqQueue.get(Queue.LVQ_KEY));
+    }
+
+    public void testPutCreateSortedQueueWithoutKey() throws Exception
+    {
+        String queueName = getTestQueueName() + "-sorted";
+        int responseCode = tryCreateQueue(queueName, "sorted", null);
+        assertEquals("Unexpected response code", 409, responseCode);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+        Map<String, Object> testQueue = find(Queue.NAME, queueName  , queues);
+
+        assertNull("Sorted queue without a key was created ", testQueue);
+    }
+
+    public void testPutCreatePriorityQueueWithoutKey() throws Exception
+    {
+        String queueName = getTestQueueName()+ "-priority";
+        createQueue(queueName, "priority", null);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+        Map<String, Object> priorityQueue = find(Queue.NAME, queueName  , queues);
+
+        Asserts.assertQueue(queueName , "priority", priorityQueue);
+        assertEquals("Unexpected value of queue attribute " + Queue.DURABLE, Boolean.TRUE, priorityQueue.get(Queue.DURABLE));
+        assertEquals("Unexpected number of priorities", 10, priorityQueue.get(Queue.PRIORITIES));
+    }
+
+    public void testPutCreateStandardQueueWithoutType() throws Exception
+    {
+        String queueName = getTestQueueName();
+        createQueue(queueName, null, null);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+        Map<String, Object> queue = find(Queue.NAME, queueName  , queues);
+
+        Asserts.assertQueue(queueName , "standard", queue);
+    }
+
+    public void testPutCreateQueueOfUnsupportedType() throws Exception
+    {
+        String queueName = getTestQueueName();
+        int responseCode = tryCreateQueue(queueName, "unsupported", null);
+        assertEquals("Unexpected response code", 409, responseCode);
+
+        Map<String, Object> hostDetails = getJsonAsSingletonList("/rest/virtualhost/test");
+
+        @SuppressWarnings("unchecked")
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) hostDetails.get(VirtualHostRestTest.VIRTUALHOST_QUEUES_ATTRIBUTE);
+        Map<String, Object> queue = find(Queue.NAME, queueName  , queues);
+
+        assertNull("Queue of unsupported type was created", queue);
+    }
+
+    private void createExchange(String exchangeName, String exchangeType) throws IOException
+    {
+        HttpURLConnection connection = openManagementConection("/rest/exchange/test/" + exchangeName, "PUT");
+
+        Map<String, Object> queueData = new HashMap<String, Object>();
+        queueData.put(Exchange.NAME, exchangeName);
+        queueData.put(Exchange.DURABLE, Boolean.TRUE);
+        queueData.put(Exchange.TYPE, exchangeType);
+
+        writeJsonRequest(connection, queueData);
+        assertEquals("Unexpected response code", 201, connection.getResponseCode());
+
+        connection.disconnect();
+    }
+
+    private void createQueue(String queueName, String queueType, Map<String, Object> attributes) throws IOException,
+            JsonGenerationException, JsonMappingException
+    {
+        int responseCode = tryCreateQueue(queueName, queueType, attributes);
+        assertEquals("Unexpected response code", 201, responseCode);
+    }
+
+    private int tryCreateQueue(String queueName, String queueType, Map<String, Object> attributes) throws IOException,
+            JsonGenerationException, JsonMappingException
+    {
+        HttpURLConnection connection = openManagementConection("/rest/queue/test/" + queueName, "PUT");
+
+        Map<String, Object> queueData = new HashMap<String, Object>();
+        queueData.put(Queue.NAME, queueName);
+        queueData.put(Queue.DURABLE, Boolean.TRUE);
+        if (queueType != null)
+        {
+            queueData.put(Queue.TYPE, queueType);
+        }
+        if (attributes != null)
+        {
+            queueData.putAll(attributes);
+        }
+
+        writeJsonRequest(connection, queueData);
+        int responseCode = connection.getResponseCode();
+        connection.disconnect();
+        return responseCode;
+    }
+
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQChannel.java Wed Jul 11 11:01:06 2012
@@ -1686,4 +1686,10 @@ public class AMQChannel implements Sessi
     {
         return getQMFId().compareTo(session.getQMFId());
     }
+
+    @Override
+    public int getConsumerCount()
+    {
+        return _tag2SubscriptionMap.size();
+    }
 }

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Queue.java Wed Jul 11 11:01:06 2012
@@ -99,7 +99,7 @@ public interface Queue extends Configure
     public static final String QUEUE_FLOW_STOPPED = "queueFlowStopped";
     public static final String SORT_KEY = "sortKey";
     public static final String TYPE = "type";
-
+    public static final String PRIORITIES = "priorities";
 
 
 
@@ -132,7 +132,8 @@ public interface Queue extends Configure
                                   ALERT_THRESHOLD_MESSAGE_SIZE,
                                   ALERT_THRESHOLD_QUEUE_DEPTH_BYTES,
                                   ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES,
-                                  ALERT_REPEAT_GAP
+                                  ALERT_REPEAT_GAP,
+                                  PRIORITIES
                     ));
 
     //children

Added: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java?rev=1360121&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java (added)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/QueueType.java Wed Jul 11 11:01:06 2012
@@ -0,0 +1,29 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.server.model;
+
+public enum QueueType
+{
+    STANDARD,
+    PRIORITY,
+    LVQ,
+    SORTED
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/QueueAdapter.java Wed Jul 11 11:01:06 2012
@@ -58,9 +58,9 @@ final class QueueAdapter extends Abstrac
         QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.QUEUE_FLOW_CONTROL_SIZE_BYTES, "x-qpid-capacity");
         QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.QUEUE_FLOW_RESUME_SIZE_BYTES, "x-qpid-flow-resume-capacity");
 
-        QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.SORT_KEY, "qpid.sort_key");
-        QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.LVQ_KEY, "qpid.last_value_queue_key");
-
+        QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.SORT_KEY, AMQQueueFactory.QPID_QUEUE_SORT_KEY);
+        QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.LVQ_KEY, AMQQueueFactory.QPID_LAST_VALUE_QUEUE_KEY);
+        QueueAdapter.ATTRIBUTE_MAPPINGS.put(Queue.PRIORITIES, AMQQueueFactory.X_QPID_PRIORITIES);
     }
 
     private final AMQQueue _queue;
@@ -454,7 +454,13 @@ final class QueueAdapter extends Abstrac
         {
             return _queue.getDescription();
         }
-
+        else if(PRIORITIES.equals(name))
+        {
+            if(_queue instanceof AMQPriorityQueue)
+            {
+                return ((AMQPriorityQueue)_queue).getPriorities();
+            }
+        }
         return super.getAttribute(name);
     }
 

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/SessionAdapter.java Wed Jul 11 11:01:06 2012
@@ -198,8 +198,7 @@ final class SessionAdapter extends Abstr
             }
             else if(name.equals(CONSUMER_COUNT))
             {
-                final Collection<Consumer> subscriptions = getSubscriptions();
-                return subscriptions == null ? 0 : subscriptions.size();
+                return _session.getConsumerCount();
             }
             else if(name.equals(LOCAL_TRANSACTION_BEGINS))
             {
@@ -207,12 +206,12 @@ final class SessionAdapter extends Abstr
             }
             else if(name.equals(LOCAL_TRANSACTION_OPEN))
             {
-                long open = _session.getTxnCount() - (_session.getTxnCommits() + _session.getTxnRejects());
+                long open = _session.getTxnStart() - (_session.getTxnCommits() + _session.getTxnRejects());
                 return (Boolean) (open > 0l);
             }
             else if(name.equals(LOCAL_TRANSACTION_ROLLBACKS))
             {
-                return _session.getTxnCommits();
+                return _session.getTxnRejects();
             }
             else if(name.equals(STATE_CHANGED))
             {

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java Wed Jul 11 11:01:06 2012
@@ -43,6 +43,7 @@ import org.apache.qpid.server.model.Exch
 import org.apache.qpid.server.model.LifetimePolicy;
 import org.apache.qpid.server.model.Port;
 import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.QueueType;
 import org.apache.qpid.server.model.State;
 import org.apache.qpid.server.model.Statistics;
 import org.apache.qpid.server.model.UUIDGenerator;
@@ -252,6 +253,31 @@ final class VirtualHostAdapter extends A
     {
         attributes = new HashMap<String, Object>(attributes);
 
+        if (attributes.containsKey(Queue.TYPE))
+        {
+            String typeAttribute = getStringAttribute(Queue.TYPE, attributes, null);
+            QueueType queueType = null;
+            try
+            {
+                queueType = QueueType.valueOf(typeAttribute.toUpperCase());
+            }
+            catch(Exception e)
+            {
+                throw new IllegalArgumentException("Unsupported queue type :" + typeAttribute);
+            }
+            if (queueType == QueueType.LVQ && attributes.get(Queue.LVQ_KEY) == null)
+            {
+                attributes.put(Queue.LVQ_KEY, AMQQueueFactory.QPID_LVQ_KEY);
+            }
+            else if (queueType == QueueType.PRIORITY && attributes.get(Queue.PRIORITIES) == null)
+            {
+                attributes.put(Queue.PRIORITIES, 10);
+            }
+            else if (queueType == QueueType.SORTED && attributes.get(Queue.SORT_KEY) == null)
+            {
+                throw new IllegalArgumentException("Sort key is not specified for sorted queue");
+            }
+        }
         String         name     = getStringAttribute(Queue.NAME, attributes, null);
         State          state    = getEnumAttribute(State.class, Queue.STATE, attributes, State.ACTIVE);
         boolean        durable  = getBooleanAttribute(Queue.DURABLE, attributes, false);

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/protocol/AMQSessionModel.java Wed Jul 11 11:01:06 2012
@@ -84,4 +84,6 @@ public interface AMQSessionModel extends
     Long getTxnRejects();
 
     int getChannelId();
+
+    int getConsumerCount();
 }

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/ServerSession.java Wed Jul 11 11:01:06 2012
@@ -1070,4 +1070,10 @@ public class ServerSession extends Sessi
     {
         return getQMFId().compareTo(session.getQMFId());
     }
+
+    @Override
+    public int getConsumerCount()
+    {
+        return _subscriptions.values().size();
+    }
 }

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java (original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/subscription/MockSubscription.java Wed Jul 11 11:01:06 2012
@@ -403,6 +403,12 @@ public class MockSubscription implements
         {
             return 0;
         }
+
+        @Override
+        public int getConsumerCount()
+        {
+            return 0;
+        }
     }
 
     private static class MockConnectionModel implements AMQConnectionModel

Modified: qpid/trunk/qpid/java/test-profiles/CPPExcludes
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/CPPExcludes?rev=1360121&r1=1360120&r2=1360121&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/CPPExcludes (original)
+++ qpid/trunk/qpid/java/test-profiles/CPPExcludes Wed Jul 11 11:01:06 2012
@@ -181,3 +181,5 @@ org.apache.qpid.client.AsynchMessageList
 org.apache.qpid.systest.disttest.*
 org.apache.qpid.disttest.*
 
+// Exclude java broker REST API tests
+org.apache.qpid.server.management.plugin.servlet.rest.*



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