qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject [1/3] qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP] Add operations test
Date Mon, 05 Feb 2018 09:47:15 GMT
Repository: qpid-broker-j
Updated Branches:
  refs/heads/master d31e478a4 -> bd1f90985


QPID-8083 [System Tests] [REST/HTTP] Add operations test


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/792008b0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/792008b0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/792008b0

Branch: refs/heads/master
Commit: 792008b0796b41291554884cb0e4c97636f93662
Parents: d31e478
Author: Keith Wall <kwall@apache.org>
Authored: Sat Feb 3 00:02:58 2018 +0000
Committer: Keith Wall <kwall@apache.org>
Committed: Mon Feb 5 09:14:33 2018 +0000

----------------------------------------------------------------------
 .../apache/qpid/tests/http/HttpTestBase.java    | 19 +++-
 .../apache/qpid/tests/http/HttpTestHelper.java  | 15 +++-
 .../tests/http/rest/model/OperationTest.java    | 92 ++++++++++++++++++++
 .../qpid/tests/http/rest/model/ReadTest.java    | 84 +++++++++++++++++-
 4 files changed, 201 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/792008b0/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestBase.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestBase.java
b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestBase.java
index 01a19cf..32100fa 100644
--- a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestBase.java
+++ b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestBase.java
@@ -23,6 +23,8 @@ package org.apache.qpid.tests.http;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
+import org.junit.internal.runners.TestMethod;
+import org.junit.rules.MethodRule;
 import org.junit.rules.TestName;
 
 import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
@@ -31,14 +33,16 @@ public abstract class HttpTestBase extends BrokerAdminUsingTestBase
 {
     @Rule
     public final TestName _testName = new TestName();
+
     private HttpTestHelper _helper;
 
     @Before
-    public void setUpTestBase()
+    public void setUpTestBase() throws Exception
     {
         System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
 
-        HttpRequestConfig config = getClass().getAnnotation(HttpRequestConfig.class);
+        HttpRequestConfig config = getHttpRequestConfig();
+
         _helper = new HttpTestHelper(getBrokerAdmin(),
                                      config != null && config.useVirtualHostAsHost()
? getVirtualHost() : null);
     }
@@ -58,4 +62,15 @@ public abstract class HttpTestBase extends BrokerAdminUsingTestBase
     {
         return _helper;
     }
+
+    private HttpRequestConfig getHttpRequestConfig() throws Exception
+    {
+        HttpRequestConfig config = getClass().getMethod(_testName.getMethodName(), new Class[]{}).getAnnotation(HttpRequestConfig.class);
+        if (config == null)
+        {
+            config = getClass().getAnnotation(HttpRequestConfig.class);
+        }
+
+        return config;
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/792008b0/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
index b305d34..3fc6c78 100644
--- a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
+++ b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
@@ -54,6 +54,7 @@ public class HttpTestHelper
     private static final TypeReference<List<LinkedHashMap<String, Object>>>
TYPE_LIST_OF_LINKED_HASH_MAPS = new TypeReference<List<LinkedHashMap<String, Object>>>()
     {
     };
+
     private static final TypeReference<LinkedHashMap<String, Object>> TYPE_LINKED_HASH_MAPS
= new TypeReference<LinkedHashMap<String, Object>>()
     {
     };
@@ -281,19 +282,25 @@ public class HttpTestHelper
         }
     }
 
-    public <T> T getJson(String path, final Class<T> valueType) throws IOException
+    public <T> T getJson(String path, final TypeReference valueTypeRef, int expectedResponseCode)
throws IOException
     {
         HttpURLConnection connection = openManagementConnection(path, "GET");
         connection.connect();
-        return readJsonResponse(connection, valueType);
+        int responseCode = connection.getResponseCode();
+        Assert.assertEquals(String.format("Unexpected response code from : %s", path), expectedResponseCode,
responseCode);
+
+        return new ObjectMapper().readValue(new ByteArrayInputStream(readConnectionInputStream(connection)),
valueTypeRef);
     }
 
-    public <T> T postJson(String path, final Object data , final Class<T> valueType)
throws IOException
+    public <T> T postJson(String path, final Object data, final TypeReference valueTypeRef,
int expectedResponseCode) throws IOException
     {
         HttpURLConnection connection = openManagementConnection(path, "POST");
         connection.connect();
         writeJsonRequest(connection, data);
-        return readJsonResponse(connection, valueType);
+        int responseCode = connection.getResponseCode();
+        Assert.assertEquals(String.format("Unexpected response code from : %s", path), expectedResponseCode,
responseCode);
+
+        return new ObjectMapper().readValue(new ByteArrayInputStream(readConnectionInputStream(connection)),
valueTypeRef);
     }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/792008b0/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
new file mode 100644
index 0000000..4ce88a4
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/OperationTest.java
@@ -0,0 +1,92 @@
+/*
+ *
+ * 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.rest.model;
+
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet.SC_UNPROCESSABLE_ENTITY;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.junit.Test;
+
+import org.apache.qpid.tests.http.HttpRequestConfig;
+import org.apache.qpid.tests.http.HttpTestBase;
+
+@HttpRequestConfig
+public class OperationTest extends HttpTestBase
+{
+    // TODO multipart posts
+
+    private static final TypeReference<LinkedHashMap<String, Object>> MAP_TYPE_REF
= new TypeReference<LinkedHashMap<String, Object>>()
+    {
+    };
+
+    @Test
+    public void invokeNoParameters() throws Exception
+    {
+        Map<String, Object> response = getHelper().postJson("virtualhost/getStatistics",
+                                                            Collections.emptyMap(),
+                                                            MAP_TYPE_REF, SC_OK);
+        assertThat(response.size(), is(greaterThan(1)));
+    }
+
+    @Test
+    public void invokeWithParameters() throws Exception
+    {
+        Map<Object, Object> params = Collections.singletonMap("statistics",
+                                                              Collections.singletonList("connectionCount"));
+
+        Map<String, Object> response = getHelper().postJson("virtualhost/getStatistics",
+                                                            params,
+                                                            MAP_TYPE_REF, SC_OK);
+        assertThat(response.size(), is(equalTo(1)));
+    }
+
+    @Test
+    public void invokeGetWithParameters() throws Exception
+    {
+        Map<String, Object> response = getHelper().getJson("virtualhost/getStatistics?statistics=bytesIn&statistics=bytesOut",
+                                                            MAP_TYPE_REF, SC_OK);
+        assertThat(response.size(), is(equalTo(2)));
+    }
+
+    @Test
+    public void invalidParameter() throws Exception
+    {
+        Map<String, Object> params = Collections.singletonMap("unknown", Collections.emptyMap());
+
+        getHelper().submitRequest("virtualhost/getStatistics", "POST", params, SC_UNPROCESSABLE_ENTITY);
+    }
+
+    @Test
+    public void operationNotFound() throws Exception
+    {
+        getHelper().submitRequest("virtualhost/notfound", "POST", Collections.emptyMap(),
SC_NOT_FOUND);
+    }
+}

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/792008b0/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/ReadTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/ReadTest.java
b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/ReadTest.java
index 90b44f5..447f062 100644
--- a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/ReadTest.java
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/ReadTest.java
@@ -21,6 +21,7 @@
 package org.apache.qpid.tests.http.rest.model;
 
 import static java.util.Collections.singletonMap;
+import static javax.servlet.http.HttpServletResponse.SC_CREATED;
 import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -29,7 +30,10 @@ import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.hamcrest.Matchers.isOneOf;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -39,11 +43,12 @@ import java.util.stream.Collectors;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.qpid.server.logging.logback.VirtualHostFileLogger;
+import org.apache.qpid.server.logging.logback.VirtualHostNameAndLevelLogInclusionRule;
 import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.tests.http.HttpRequestConfig;
 import org.apache.qpid.tests.http.HttpTestBase;
 
-/** KWTODO wildcards, actuals */
 @HttpRequestConfig
 public class ReadTest extends HttpTestBase
 {
@@ -132,13 +137,13 @@ public class ReadTest extends HttpTestBase
     {
         final String hostContextKey = "myvhcontextvar";
         final String hostContextValue = UUID.randomUUID().toString();
-        final Map<String, Object> hostUpdateAttrs = singletonMap("context",
+        final Map<String, Object> hostUpdateAttrs = singletonMap(ConfiguredObject.CONTEXT,
                                                                  singletonMap(hostContextKey,
hostContextValue));
         getHelper().submitRequest("virtualhost", "POST", hostUpdateAttrs, SC_OK);
 
         final String queueContextKey = "myqueuecontextvar";
         final String queueContextValue = UUID.randomUUID().toString();
-        final Map<String, Object> queueUpdateAttrs = singletonMap("context",
+        final Map<String, Object> queueUpdateAttrs = singletonMap(ConfiguredObject.CONTEXT,
                                                                   singletonMap(queueContextKey,
queueContextValue));
         getHelper().submitRequest(QUEUE1_URL, "POST", queueUpdateAttrs, SC_OK);
 
@@ -155,4 +160,77 @@ public class ReadTest extends HttpTestBase
         assertThat(context2.get(queueContextKey), is(equalTo(queueContextValue)));
         assertThat(context2.get(hostContextKey), is(equalTo(hostContextValue)));
     }
+
+    @Test
+    public void actuals() throws Exception
+    {
+        final String queueContextKey = "myqueuecontextvar";
+        final String queueContextValue = UUID.randomUUID().toString();
+
+        final Map<String, Object> queueUpdateAttrs = new HashMap<>();
+        queueUpdateAttrs.put(ConfiguredObject.DESCRIPTION, "${myqueuecontextvar}");
+        queueUpdateAttrs.put(ConfiguredObject.CONTEXT, singletonMap(queueContextKey, queueContextValue));
+        getHelper().submitRequest(QUEUE1_URL, "POST", queueUpdateAttrs, SC_OK);
+
+
+        final Map<String, Object> queue = getHelper().getJsonAsMap(QUEUE1_URL);
+        assertThat(queue.get(ConfiguredObject.DESCRIPTION), is(equalTo(queueContextValue)));
+
+        final Map<String, Object> queueActuals = getHelper().getJsonAsMap(QUEUE1_URL
+ "?actuals=true");
+        assertThat(queueActuals.get(ConfiguredObject.DESCRIPTION), is(equalTo("${myqueuecontextvar}")));
+    }
+
+    @Test
+    public void wildcards() throws Exception
+    {
+        String rule1A = createLoggerAndRule("mylogger1", "myinclusionruleA");
+        String rule1B = createLoggerAndRule("mylogger1", "myinclusionruleB");
+        String rule2A = createLoggerAndRule("mylogger2", "myinclusionruleA");
+
+        {
+            List<Map<String, Object>> rules = getHelper().getJsonAsList("virtualhostloginclusionrule/*");
+            assertThat(rules.size(), is(equalTo(3)));
+
+            Set<String> ids = rules.stream().map(ReadTest::getId).collect(Collectors.toSet());
+            assertThat(ids, containsInAnyOrder(rule1A, rule1B, rule2A));
+        }
+
+        {
+            List<Map<String, Object>> rules = getHelper().getJsonAsList("virtualhostloginclusionrule/mylogger1/*");
+            assertThat(rules.size(), is(equalTo(2)));
+
+            Set<String> ids = rules.stream().map(ReadTest::getId).collect(Collectors.toSet());
+            assertThat(ids, containsInAnyOrder(rule1A, rule1B));
+        }
+
+        {
+            List<Map<String, Object>> rules = getHelper().getJsonAsList("virtualhostloginclusionrule/*/myinclusionruleA");
+            assertThat(rules.size(), is(equalTo(2)));
+
+            Set<String> ids = rules.stream().map(ReadTest::getId).collect(Collectors.toSet());
+            assertThat(ids, containsInAnyOrder(rule1A, rule2A));
+        }
+    }
+
+    private String createLoggerAndRule(final String loggerName, final String inclusionRuleName)
throws Exception
+    {
+        final String parentUrl = String.format("virtualhostlogger/%s", loggerName);
+        Map<String, Object> parentAttrs = Collections.singletonMap(ConfiguredObject.TYPE,
VirtualHostFileLogger.TYPE);
+
+        int response = getHelper().submitRequest(parentUrl, "PUT", parentAttrs);
+        assertThat(response, is(isOneOf(SC_CREATED, SC_OK)));
+
+        final String childUrl = String.format("virtualhostloginclusionrule/%s/%s", loggerName,
inclusionRuleName);
+        Map<String, Object> childAttrs = Collections.singletonMap(ConfiguredObject.TYPE,
VirtualHostNameAndLevelLogInclusionRule.TYPE);
+        getHelper().submitRequest(childUrl, "PUT", childAttrs, SC_CREATED);
+
+        final Map<String, Object> child = getHelper().getJsonAsMap(childUrl);
+        return (String) child.get(ConfiguredObject.ID);
+
+    }
+
+    private static String getId(Map<String, Object> object)
+    {
+        return ((String) object.get(ConfiguredObject.ID));
+    }
 }


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


Mime
View raw message