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 2018/03/09 17:58:50 UTC

[2/2] qpid-broker-j git commit: QPID-8083: [Broker-J] Move structure test into module 'qpid-systests-http'

QPID-8083: [Broker-J] Move structure test into module 'qpid-systests-http'


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/39c228b5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/39c228b5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/39c228b5

Branch: refs/heads/master
Commit: 39c228b52c7e817d33b9c8ab393311fa6b3a6516
Parents: e776ae6
Author: Alex Rudyy <or...@apache.org>
Authored: Fri Mar 9 17:58:24 2018 +0000
Committer: Alex Rudyy <or...@apache.org>
Committed: Fri Mar 9 17:58:24 2018 +0000

----------------------------------------------------------------------
 .../qpid/tests/http/service/StructureTest.java  | 148 +++++++++++++++++++
 .../qpid/systest/rest/StructureRestTest.java    | 108 --------------
 2 files changed, 148 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/39c228b5/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/service/StructureTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/service/StructureTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/service/StructureTest.java
new file mode 100644
index 0000000..eeb6f99
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/service/StructureTest.java
@@ -0,0 +1,148 @@
+/*
+ *
+ * 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.tests.http.service;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+import org.apache.qpid.tests.http.HttpTestBase;
+import org.apache.qpid.tests.http.HttpTestHelper;
+
+public class StructureTest extends HttpTestBase
+{
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testGet() throws Exception
+    {
+        String nodeName = getVirtualHostNode();
+        String hostName = getVirtualHost();
+        HttpTestHelper helper = getHelper();
+        Map<String, Object> structure = helper.getJsonAsMap("/service/structure");
+
+        assertNotNull("Structure data cannot be null", structure);
+        assertEquals("Unexpected name", "Broker", structure.get("name"));
+        assertNotNull("Unexpected id", structure.get("id"));
+
+        List<Map<String, Object>>  virtualhostnodes = (List<Map<String, Object>>) structure.get("virtualhostnodes");
+        assertNotNull("Virtual host nodes not present", virtualhostnodes);
+
+        Map<String, Object> testNode = assertPresent(nodeName, virtualhostnodes);
+
+        List<Map<String, Object>>  virtualhosts = (List<Map<String, Object>>) testNode.get("virtualhosts");
+        assertNotNull("Virtual host not present", virtualhosts);
+        assertEquals(String.format("VH %s not found", hostName), 1, virtualhosts.size());
+
+        Map<String, Object> testHost = assertPresent(hostName, virtualhosts);
+
+        List<Map<String, Object>> exchanges = (List<Map<String, Object>>) testHost.get("exchanges");
+        assertNotNull("Exchanges not present", exchanges);
+        assertPresent("Exchange amq.direct is not found","amq.direct", exchanges);
+        assertPresent("Exchange amq.topic is not found","amq.topic", exchanges);
+        assertPresent("Exchange amq.fanout is not found","amq.fanout", exchanges);
+        assertPresent("Exchange amq.match is not found","amq.match", exchanges);
+
+        List<Map<String, Object>> queues = (List<Map<String, Object>>) testHost.get("queues");
+        assertNull("Unexpected queues", queues);
+
+        List<Map<String, Object>> ports = (List<Map<String, Object>>) structure.get("ports");
+        assertNotNull("Ports not present", ports);
+        Map<String, Object> amqpPort = assertPresent("AMQP", ports);
+        assertNotNull("Port AMQP is not found", amqpPort);
+        assertPresent("Port ANONYMOUS_AMQP is not found", "ANONYMOUS_AMQP", ports);
+        assertPresent("Port HTTP is not found", "HTTP", ports);
+
+        List<Map<String, Object>> aliases = (List<Map<String, Object>>) amqpPort.get("virtualhostaliases");
+        assertNotNull("Virtual host aliases not found", aliases);
+        assertPresent("Alias defaultAlias is not found","defaultAlias", aliases);
+        assertPresent("Alias hostnameAlias is not found","hostnameAlias", aliases);
+        assertPresent("Alias nameAlias is not found","nameAlias", aliases);
+
+        List<Map<String, Object>> providers = (List<Map<String, Object>>) structure.get("authenticationproviders");
+        assertNotNull("Authentication providers not present", providers);
+        assertPresent("Authentication provider 'anon' is not found", "anon", providers);
+        assertPresent("Authentication provider 'plain' is not found", "plain", providers);
+
+        Map<String, Object> plainProvider = assertPresent("plain", providers);
+        List<Map<String, Object>> users = (List<Map<String, Object>>) plainProvider.get("users");
+        assertNotNull("Authentication provider users not present", users);
+        assertPresent("User 'admin' not found","admin", users);
+        assertPresent("User 'guest' not found","guest", users);
+
+        List<Map<String, Object>> keystores = (List<Map<String, Object>>) structure.get("keystores");
+        assertNotNull("Key stores not present", keystores);
+        assertPresent("systestsKeyStore not found","systestsKeyStore", keystores);
+
+        List<Map<String, Object>> plugins = (List<Map<String, Object>>) structure.get("plugins");
+        assertNotNull("Plugins not present", plugins);
+        assertPresent("httpManagement not found","httpManagement", plugins);
+
+        String queueName = getTestName() + "Queue";
+        helper.submitRequest(String.format("queue/%s/%s/%s", nodeName, hostName, queueName),
+                             "PUT",
+                             Collections.singletonMap("name", queueName));
+
+        structure = helper.getJsonAsMap("/service/structure");
+
+        virtualhostnodes = (List<Map<String, Object>>) structure.get("virtualhostnodes");
+        assertNotNull("Virtual host nodes not present", virtualhostnodes);
+
+        testNode = assertPresent(hostName, virtualhostnodes);
+
+        virtualhosts = (List<Map<String, Object>>) testNode.get("virtualhosts");
+        assertNotNull("Virtual host not present", virtualhosts);
+        assertEquals(String.format("VH %s not found", hostName), 1, virtualhosts.size());
+
+        testHost = assertPresent(hostName, virtualhosts);
+
+        queues = (List<Map<String, Object>>) testHost.get("queues");
+        assertNotNull("Queues not present", queues);
+        assertPresent(String.format("Queue %s not found", queueName), queueName, queues);
+    }
+
+    private Map<String, Object> assertPresent(final String entryName,
+                                              final List<Map<String, Object>> entries)
+    {
+        return assertPresent(null, entryName, entries);
+    }
+
+    private Map<String, Object> assertPresent(final String notFoundErrorMessage,
+                                              final String entryName,
+                                              final List<Map<String, Object>> entries)
+    {
+        Iterator<Map<String, Object>> it = entries.stream().filter(e -> entryName.equals(e.get("name"))).iterator();
+        assertTrue(notFoundErrorMessage == null ? String.format("Entry with name '%s' is not found", entryName) : notFoundErrorMessage, it.hasNext());
+        Map<String, Object> data = it.next();
+        assertFalse(String.format("More than one entry found with name %s", entryName), it.hasNext());
+        return data;
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/39c228b5/systests/src/test/java/org/apache/qpid/systest/rest/StructureRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/StructureRestTest.java b/systests/src/test/java/org/apache/qpid/systest/rest/StructureRestTest.java
deleted file mode 100644
index 28ee1d0..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/StructureRestTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.systest.rest;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.qpid.exchange.ExchangeDefaults;
-import org.apache.qpid.server.model.Port;
-import org.apache.qpid.test.utils.TestBrokerConfiguration;
-
-public class StructureRestTest extends QpidRestTestCase
-{
-
-    @Override
-    public void setUp() throws Exception
-    {
-        super.setUp();
-        getRestTestHelper().createTestQueues();
-    }
-
-    public void testGet() throws Exception
-    {
-        Map<String, Object> structure = getRestTestHelper().getJsonAsMap("/service/structure");
-        assertNotNull("Structure data cannot be null", structure);
-        assertNode(structure, "Broker");
-
-        @SuppressWarnings("unchecked")
-        List<Map<String, Object>> virtualhostnodes = (List<Map<String, Object>>) structure.get("virtualhostnodes");
-        assertEquals("Unexpected number of virtual hosts", 3, virtualhostnodes.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 nodeName : EXPECTED_VIRTUALHOSTS)
-        {
-            Map<String, Object> node = getRestTestHelper().find("name", nodeName, virtualhostnodes);
-            assertNotNull("Node " + nodeName + " is not found ", node);
-            assertNode(node, nodeName);
-        }
-
-        String hostName = "test";
-        Map<String, Object> node = getRestTestHelper().find("name", hostName, virtualhostnodes);
-
-        @SuppressWarnings("unchecked")
-        List<Map<String, Object>> virtualhosts = (List<Map<String, Object>>) node.get("virtualhosts");
-
-        Map<String, Object> host = getRestTestHelper().find("name", hostName, virtualhosts);
-        @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 : RestTestHelper.EXPECTED_QUEUES)
-        {
-            Map<String, Object> queue = getRestTestHelper().find("name", queueName, queues);
-            assertNotNull(hostName + " queue " + queueName + " is not found ", queue);
-            assertNode(queue, 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 = getRestTestHelper().find("name", exchangeName, exchanges);
-            assertNotNull("Exchange " + exchangeName + " is not found ", exchange);
-            assertNode(exchange, exchangeName);
-        }
-
-        String httpPortName = TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT;
-        Map<String, Object> portData = getRestTestHelper().find(Port.NAME, httpPortName, ports);
-        assertNotNull("Http Port " + httpPortName + " is not found", portData);
-        assertNode(portData, httpPortName);
-
-        String amqpPortName = TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT;
-        Map<String, Object> amqpPortData = getRestTestHelper().find(Port.NAME, amqpPortName, ports);
-        assertNotNull("Amqp port " + amqpPortName + " is not found", amqpPortData);
-        assertNode(amqpPortData, amqpPortName);
-    }
-
-    private void assertNode(Map<String, Object> node, String name)
-    {
-        assertEquals("Unexpected name", name, node.get("name"));
-        assertNotNull("Unexpected id", node.get("id"));
-    }
-}


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