You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2018/02/05 09:47:15 UTC
[1/3] qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP]
Add operations test
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 <kw...@apache.org>
Authored: Sat Feb 3 00:02:58 2018 +0000
Committer: Keith Wall <kw...@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
[2/3] qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP]
Move UserPreferencesRestTest to new module
Posted by kw...@apache.org.
QPID-8083 [System Tests] [REST/HTTP] Move UserPreferencesRestTest to new module
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/0bb035e1
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/0bb035e1
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/0bb035e1
Branch: refs/heads/master
Commit: 0bb035e1516f78d54ff9aa1fc6282cfe85eb6c7d
Parents: 792008b
Author: Keith Wall <kw...@apache.org>
Authored: Sat Feb 3 13:40:41 2018 +0000
Committer: Keith Wall <kw...@apache.org>
Committed: Mon Feb 5 09:14:42 2018 +0000
----------------------------------------------------------------------
.../http/userprefs/UserPreferencesRestTest.java | 428 +++++++++++++++
.../systest/rest/UserPreferencesRestTest.java | 533 -------------------
2 files changed, 428 insertions(+), 533 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/0bb035e1/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/userprefs/UserPreferencesRestTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/userprefs/UserPreferencesRestTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/userprefs/UserPreferencesRestTest.java
new file mode 100644
index 0000000..dfc5582
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/userprefs/UserPreferencesRestTest.java
@@ -0,0 +1,428 @@
+/*
+ *
+ * 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.userprefs;
+
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.common.collect.Lists;
+import org.junit.Test;
+
+import org.apache.qpid.server.management.plugin.preferences.QueryPreferenceValue;
+import org.apache.qpid.server.model.preferences.Preference;
+import org.apache.qpid.tests.http.HttpRequestConfig;
+import org.apache.qpid.tests.http.HttpTestBase;
+
+@HttpRequestConfig()
+public class UserPreferencesRestTest extends HttpTestBase
+{
+ private static final TypeReference<Map<String, List<Map<String, Object>>>>
+ MAP_TYPE_REF = new TypeReference<Map<String, List<Map<String, Object>>>>() {};
+
+ @Test
+ public void putSinglePreferenceRoundTrip() throws Exception
+ {
+ final String prefName = "mypref";
+ final String prefDescription = "mydesc";
+ final String prefType = "X-testtype";
+
+ Map<String, Object> prefAttributes = new HashMap<>();
+ prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
+
+ Map<String, Object> prefValueAttributes = new HashMap<>();
+ prefValueAttributes.put("valueAttrName", "valueAttrValue");
+ prefAttributes.put(Preference.VALUE_ATTRIBUTE, prefValueAttributes);
+
+ String fullUrl = String.format("virtualhost/userpreferences/%s/%s", prefType, prefName);
+ getHelper().submitRequest(fullUrl, "PUT", prefAttributes, SC_OK);
+
+ Map<String, Object> prefDetails = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected pref name", prefName, prefDetails.get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected pref description", prefDescription, prefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
+ assertEquals("Unexpected pref type", prefType, prefDetails.get(Preference.TYPE_ATTRIBUTE));
+ assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get(Preference.VALUE_ATTRIBUTE));
+ assertTrue("Unexpected pref owner", ((String) prefDetails.get(Preference.OWNER_ATTRIBUTE)).startsWith(getBrokerAdmin().getValidUsername() + "@"));
+
+ String typeUrl = String.format("virtualhost/userpreferences/%s", prefType);
+ assertEquals("Unexpected preference returned from type url",
+ prefDetails,
+ getHelper().getJsonAsSingletonList(typeUrl));
+
+ String allUrl = "virtualhost/userpreferences";
+ final Map<String, Object> allMap = getHelper().getJsonAsMap(allUrl);
+ assertEquals("Unexpected number of types in all url response", 1, allMap.size());
+ assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+ allMap.containsKey(prefType));
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
+ assertEquals("Unexpected number of preferences", 1, prefs.size());
+
+ assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
+ }
+
+ @Test
+ public void putQueryPreferenceRoundTrip() throws Exception
+ {
+ final String prefName = "myquery";
+ final String prefDescription = "myquerydesc";
+ final String prefType = "query";
+
+ Map<String, Object> prefAttributes = new HashMap<>();
+ prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
+
+ Map<String, Object> prefValueAttributes = new HashMap<>();
+ prefValueAttributes.put(QueryPreferenceValue.SCOPE_ATTRIBUTE, "");
+ prefValueAttributes.put(QueryPreferenceValue.CATEGORY_ATTRIBUTE, "queue");
+ prefValueAttributes.put(QueryPreferenceValue.SELECT_ATTRIBUTE, "id,name,queueDepthMessages");
+ prefAttributes.put(Preference.VALUE_ATTRIBUTE, prefValueAttributes);
+
+ String fullUrl = String.format("virtualhost/userpreferences/%s/%s", prefType, prefName);
+ getHelper().submitRequest(fullUrl, "PUT", prefAttributes, SC_OK);
+
+ Map<String, Object> prefDetails = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected pref name", prefName, prefDetails.get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected pref description", prefDescription, prefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
+ assertEquals("Unexpected pref type", prefType, prefDetails.get(Preference.TYPE_ATTRIBUTE));
+ assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get(Preference.VALUE_ATTRIBUTE));
+ assertTrue("Unexpected pref owner", ((String) prefDetails.get(Preference.OWNER_ATTRIBUTE)).startsWith(getBrokerAdmin().getValidUsername() + "@"));
+
+ String typeUrl = String.format("virtualhost/userpreferences/%s", prefType);
+ assertEquals("Unexpected preference returned from type url",
+ prefDetails,
+ getHelper().getJsonAsSingletonList(typeUrl));
+
+ String allUrl = "virtualhost/userpreferences";
+ final Map<String, Object> allMap = getHelper().getJsonAsMap(allUrl);
+ assertEquals("Unexpected number of types in all url response", 1, allMap.size());
+ assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+ allMap.containsKey(prefType));
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
+ assertEquals("Unexpected number of preferences", 1, prefs.size());
+
+ assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
+ }
+
+
+ @Test
+ public void postSinglePreferenceRoundTrip() throws Exception
+ {
+ final String prefName = "mypref";
+ final String prefDescription = "mydesc";
+ final String prefType = "X-testtype";
+
+ Map<String, Object> prefAttributes = new HashMap<>();
+ prefAttributes.put(Preference.NAME_ATTRIBUTE, prefName);
+ prefAttributes.put(Preference.TYPE_ATTRIBUTE, prefType);
+ prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
+
+ Map<String, Object> prefValueAttributes = new HashMap<>();
+ prefValueAttributes.put("valueAttrName", "valueAttrValue");
+ prefAttributes.put(Preference.VALUE_ATTRIBUTE, prefValueAttributes);
+
+ String rootUrl = "virtualhost/userpreferences";
+ Map<String, List<Map<String, Object>>> payload =
+ Collections.singletonMap(prefType, Collections.singletonList(prefAttributes));
+ getHelper().submitRequest(rootUrl, "POST", payload, SC_OK);
+
+ Map<String, List<Map<String, Object>>> allPrefs = getHelper().getJson(rootUrl, MAP_TYPE_REF, SC_OK);
+
+ Map<String, Object> prefDetails = allPrefs.get(prefType).get(0);
+ assertEquals("Unexpected pref name", prefName, prefDetails.get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected pref description", prefDescription, prefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
+ assertEquals("Unexpected pref type", prefType, prefDetails.get(Preference.TYPE_ATTRIBUTE));
+ assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get(Preference.VALUE_ATTRIBUTE));
+ assertTrue("Unexpected pref owner", ((String) prefDetails.get(Preference.OWNER_ATTRIBUTE)).startsWith(getBrokerAdmin().getValidUsername() + "@"));
+
+ String typeUrl = String.format("virtualhost/userpreferences/%s", prefType);
+ assertEquals("Unexpected preference returned from type url",
+ prefDetails,
+ getHelper().getJsonAsSingletonList(typeUrl));
+
+ String allUrl = "virtualhost/userpreferences";
+ final Map<String, Object> allMap = getHelper().getJsonAsMap(allUrl);
+ assertEquals("Unexpected number of types in all url response", 1, allMap.size());
+ assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+ allMap.containsKey(prefType));
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
+ assertEquals("Unexpected number of preferences", 1, prefs.size());
+
+ assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
+ }
+
+ @Test
+ public void postManyPreferences() throws Exception
+ {
+ final String pref1Name = "pref1";
+ final String pref2Name = "pref2Name";
+ final String pref3Name = "pref3";
+ final String prefType1 = "X-prefType1";
+ final String prefType2 = "X-prefType2";
+
+ Map<String, Object> pref1Attributes = new HashMap<>();
+ pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref1Name);
+ pref1Attributes.put(Preference.TYPE_ATTRIBUTE, prefType1);
+ pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+
+ Map<String, Object> pref2Attributes = new HashMap<>();
+ pref2Attributes.put(Preference.NAME_ATTRIBUTE, pref2Name);
+ pref2Attributes.put(Preference.TYPE_ATTRIBUTE, prefType2);
+ pref2Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+
+ Map<String, Object> payload = new HashMap<>();
+ payload.put(prefType1, Collections.singletonList(pref1Attributes));
+ payload.put(prefType2, Collections.singletonList(pref2Attributes));
+ String url = "virtualhost/userpreferences";
+ getHelper().submitRequest(url, "POST", payload, SC_OK);
+
+ Map<String, Object> pref3Attributes = new HashMap<>();
+ pref3Attributes.put(Preference.NAME_ATTRIBUTE, pref3Name);
+ pref3Attributes.put(Preference.TYPE_ATTRIBUTE, prefType2);
+ pref3Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+
+ String url2 = String.format("virtualhost/userpreferences/%s", prefType2);
+ getHelper().submitRequest(url2,
+ "POST",
+ Collections.singletonList(pref3Attributes),
+ SC_OK);
+
+ String allUrl = "virtualhost/userpreferences";
+ final Map<String, Object> allMap = getHelper().getJsonAsMap(allUrl);
+ assertEquals("Unexpected number of types in all url response", 2, allMap.size());
+ assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
+ allMap.containsKey(prefType1) && allMap.containsKey(prefType2));
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> pref1s = (List<Map<String, Object>>) allMap.get(prefType1);
+ assertEquals("Unexpected number of preferences", 1, pref1s.size());
+ @SuppressWarnings("unchecked")
+ List<Map<String, Object>> pref2s = (List<Map<String, Object>>) allMap.get(prefType2);
+ assertEquals("Unexpected number of preferences", 2, pref2s.size());
+
+ assertEquals("Unexpected preference returned from all url for type1. Found : " + pref1s.get(0).get(Preference.NAME_ATTRIBUTE),
+ pref1Name,
+ pref1s.get(0).get(Preference.NAME_ATTRIBUTE));
+ Set<String> pref2Names = new HashSet<>();
+ pref2Names.add((String) pref2s.get(0).get(Preference.NAME_ATTRIBUTE));
+ pref2Names.add((String) pref2s.get(1).get(Preference.NAME_ATTRIBUTE));
+ assertTrue("Unexpected preference returned from all url for type2. Found : " + pref2Names,
+ pref2Names.contains(pref2Name) && pref2Names.contains(pref3Name));
+ }
+
+ @Test
+ public void putReplaceOne() throws Exception
+ {
+ final String prefName = "mypref";
+ final String prefDescription = "mydesc";
+ final String prefType = "X-testtype";
+
+ Map<String, Object> prefAttributes = new HashMap<>();
+ prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
+
+ prefAttributes.put("value", Collections.emptyMap());
+ String fullUrl = String.format("virtualhost/userpreferences/%s/%s", prefType, prefName);
+ getHelper().submitRequest(fullUrl, "PUT", prefAttributes, SC_OK);
+
+ Map<String, Object> storedPreference = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected pref name", prefName, storedPreference.get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected pref description", prefDescription, storedPreference.get(Preference.DESCRIPTION_ATTRIBUTE));
+
+ Map<String, Object> updatePreference = new HashMap<>(storedPreference);
+ updatePreference.put(Preference.DESCRIPTION_ATTRIBUTE, "new description");
+ getHelper().submitRequest(fullUrl, "PUT", updatePreference, SC_OK);
+
+ Map<String, Object> rereadPrefDetails = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected id on updated pref", storedPreference.get(Preference.ID_ATTRIBUTE), rereadPrefDetails.get(Preference.ID_ATTRIBUTE));
+ assertEquals("Unexpected description on updated pref", "new description", rereadPrefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
+ }
+
+ @Test
+ public void putReplaceMany() throws Exception
+ {
+ final String pref1Name = "mypref1";
+ final String pref1Type = "X-testtype1";
+ final String pref2Name = "mypref2";
+ final String pref2Type = "X-testtype2";
+
+ String rootUrl = "virtualhost/userpreferences";
+
+ {
+ // Create two preferences (of different types)
+
+ Map<String, Object> pref1Attributes = new HashMap<>();
+ pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref1Name);
+ pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+ pref1Attributes.put(Preference.TYPE_ATTRIBUTE, pref1Type);
+
+ Map<String, Object> pref2Attributes = new HashMap<>();
+ pref2Attributes.put(Preference.NAME_ATTRIBUTE, pref2Name);
+ pref2Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+ pref2Attributes.put(Preference.TYPE_ATTRIBUTE, pref2Type);
+
+ final Map<String, List<Map<String, Object>>> payload = new HashMap<>();
+ payload.put(pref1Type, Lists.newArrayList(pref1Attributes));
+ payload.put(pref2Type, Lists.newArrayList(pref2Attributes));
+
+ getHelper().submitRequest(rootUrl, "PUT", payload, SC_OK);
+ }
+
+ Map<String, List<Map<String, Object>>> original = getHelper().getJson(rootUrl, MAP_TYPE_REF, SC_OK);
+ assertEquals("Unexpected number of types in root map", 2, original.size());
+
+ assertEquals("Unexpected number of " + pref1Type + " preferences", 1, original.get(pref1Type).size());
+ assertEquals(pref1Type + " preference has unexpected name", pref1Name, original.get(pref1Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
+
+ assertEquals("Unexpected number of " + pref2Type + " preferences", 1, original.get(pref2Type).size());
+ assertEquals(pref2Type + " preference has unexpected name", pref2Name, original.get(pref2Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
+
+ final String pref3Name = "mypref3";
+ final String pref4Name = "mypref4";
+ final String pref3Type = "X-testtype3";
+
+ {
+ // Replace all the preferences with ones that partially overlap the existing set:
+ // The preference of type X-testtype1 is replaced
+ // The preference of type X-testtype2 is removed
+ // A preference of type X-testtype3 is added
+
+ Map<String, Object> pref3Attributes = new HashMap<>();
+ pref3Attributes.put(Preference.NAME_ATTRIBUTE, pref3Name);
+ pref3Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+ pref3Attributes.put(Preference.TYPE_ATTRIBUTE, pref1Type);
+
+ Map<String, Object> pref4Attributes = new HashMap<>();
+ pref4Attributes.put(Preference.NAME_ATTRIBUTE, pref4Name);
+ pref4Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+ pref4Attributes.put(Preference.TYPE_ATTRIBUTE, pref3Type);
+
+ final Map<String, List<Map<String, Object>>> payload = new HashMap<>();
+ payload.put(pref1Type, Lists.newArrayList(pref3Attributes));
+ payload.put(pref3Type, Lists.newArrayList(pref4Attributes));
+
+ getHelper().submitRequest(rootUrl, "PUT", payload, SC_OK);
+ }
+
+ Map<String, List<Map<String, Object>>> reread = getHelper().getJson(rootUrl, MAP_TYPE_REF, SC_OK);
+ assertEquals("Unexpected number of types in root map after replacement", 2, reread.size());
+
+ assertEquals("Unexpected number of " + pref1Type + " preferences", 1, reread.get(pref1Type).size());
+ assertEquals(pref1Type + " preference has unexpected name", pref3Name, reread.get(pref1Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
+
+ assertEquals("Unexpected number of " + pref3Type + " preferences", 1, reread.get(pref3Type).size());
+ assertEquals(pref3Type + " preference has unexpected name", pref4Name, reread.get(pref3Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
+ }
+
+ @Test
+ public void postUpdate() throws Exception
+ {
+ final String prefName = "mypref";
+ final String prefDescription = "mydesc";
+ final String prefType = "X-testtype";
+
+ String fullUrl = String.format("virtualhost/userpreferences/%s/%s", prefType, prefName);
+ String typeUrl = String.format("virtualhost/userpreferences/%s", prefType);
+ String rootUrl = "virtualhost/userpreferences";
+
+ Map<String, Object> prefAttributes = new HashMap<>();
+ prefAttributes.put(Preference.NAME_ATTRIBUTE, prefName);
+ prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
+ prefAttributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+ final List<Map<String, Object>> payloadCreate = Collections.singletonList(prefAttributes);
+ getHelper().submitRequest(typeUrl, "POST", payloadCreate, SC_OK);
+
+ Map<String, Object> storedPreference = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected pref name", prefName, storedPreference.get(Preference.NAME_ATTRIBUTE));
+ assertEquals("Unexpected pref description", prefDescription, storedPreference.get(Preference.DESCRIPTION_ATTRIBUTE));
+
+ // Update via url to type
+ Map<String, Object> updatePreference = new HashMap<>(storedPreference);
+ updatePreference.put(Preference.DESCRIPTION_ATTRIBUTE, "update 1");
+ final List<Map<String, Object>> payloadUpdate1 = Collections.singletonList(updatePreference);
+ getHelper().submitRequest(typeUrl, "POST", payloadUpdate1, SC_OK);
+
+ Map<String, Object> rereadPrefDetails = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected id on updated pref, update 1",
+ storedPreference.get(Preference.ID_ATTRIBUTE),
+ rereadPrefDetails.get(Preference.ID_ATTRIBUTE));
+ assertEquals("Unexpected description on updated pref, update 1",
+ "update 1",
+ rereadPrefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
+
+ // Update via url to root
+ updatePreference = new HashMap<>(rereadPrefDetails);
+ updatePreference.put(Preference.DESCRIPTION_ATTRIBUTE, "update 2");
+ Map<String, List<Map<String, Object>>> payloadUpdate2 =
+ Collections.singletonMap(prefType, Collections.singletonList(updatePreference));
+ getHelper().submitRequest(rootUrl, "POST", payloadUpdate2, SC_OK);
+
+ rereadPrefDetails = getHelper().getJsonAsMap(fullUrl);
+
+ assertEquals("Unexpected description on updated pref, update 2",
+ "update 2",
+ rereadPrefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
+ }
+
+ @Test
+ public void delete() throws Exception
+ {
+ final String prefName = "mypref";
+ final String prefDescription = "mydesc";
+ final String prefType = "X-testtype";
+
+ Map<String, Object> prefAttributes = new HashMap<>();
+ prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
+ prefAttributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
+ String fullUrl = String.format("virtualhost/userpreferences/%s/%s", prefType, prefName);
+ getHelper().submitRequest(fullUrl, "PUT", prefAttributes, SC_OK);
+
+ getHelper().getJsonAsMap(fullUrl);
+
+ getHelper().submitRequest(fullUrl, "DELETE", SC_OK);
+
+ try
+ {
+ getHelper().getJsonAsMap(fullUrl);
+ fail();
+ }
+ catch (Exception e)
+ {
+ // pass
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/0bb035e1/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java b/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java
deleted file mode 100644
index d6e5cb1..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/UserPreferencesRestTest.java
+++ /dev/null
@@ -1,533 +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.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.servlet.http.HttpServletResponse;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-import org.apache.qpid.server.management.plugin.preferences.QueryPreferenceValue;
-import org.apache.qpid.server.model.preferences.Preference;
-
-public class UserPreferencesRestTest extends QpidRestTestCase
-{
-
- public void testPutSinglePreferenceRoundTrip() throws Exception
- {
- final String prefName = "mypref";
- final String prefDescription = "mydesc";
- final String prefType = "X-testtype";
-
- Map<String, Object> prefAttributes = new HashMap<>();
- prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
-
- Map<String, Object> prefValueAttributes = new HashMap<>();
- prefValueAttributes.put("valueAttrName", "valueAttrValue");
- prefAttributes.put(Preference.VALUE_ATTRIBUTE, prefValueAttributes);
-
- String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
- getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_OK);
-
- Map<String, Object> prefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected pref name", prefName, prefDetails.get(Preference.NAME_ATTRIBUTE));
- assertEquals("Unexpected pref description", prefDescription, prefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
- assertEquals("Unexpected pref type", prefType, prefDetails.get(Preference.TYPE_ATTRIBUTE));
- assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get(Preference.VALUE_ATTRIBUTE));
- assertTrue("Unexpected pref owner", ((String) prefDetails.get(Preference.OWNER_ATTRIBUTE)).startsWith(RestTestHelper.DEFAULT_USERNAME + "@"));
-
- String typeUrl = String.format("broker/userpreferences/%s", prefType);
- assertEquals("Unexpected preference returned from type url",
- prefDetails,
- getRestTestHelper().getJsonAsSingletonList(typeUrl));
-
- String allUrl = "broker/userpreferences";
- final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
- assertEquals("Unexpected number of types in all url response", 1, allMap.size());
- assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
- allMap.containsKey(prefType));
- List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
- assertEquals("Unexpected number of preferences", 1, prefs.size());
-
- assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
- }
-
- public void testPutQueryPreferenceRoundTrip() throws Exception
- {
- final String prefName = "myquery";
- final String prefDescription = "myquerydesc";
- final String prefType = "query";
-
- Map<String, Object> prefAttributes = new HashMap<>();
- prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
-
- Map<String, Object> prefValueAttributes = new HashMap<>();
- prefValueAttributes.put(QueryPreferenceValue.SCOPE_ATTRIBUTE, "");
- prefValueAttributes.put(QueryPreferenceValue.CATEGORY_ATTRIBUTE, "queue");
- prefValueAttributes.put(QueryPreferenceValue.SELECT_ATTRIBUTE, "id,name,queueDepthMessages");
- prefAttributes.put(Preference.VALUE_ATTRIBUTE, prefValueAttributes);
-
- String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
- getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_OK);
-
- Map<String, Object> prefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected pref name", prefName, prefDetails.get(Preference.NAME_ATTRIBUTE));
- assertEquals("Unexpected pref description", prefDescription, prefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
- assertEquals("Unexpected pref type", prefType, prefDetails.get(Preference.TYPE_ATTRIBUTE));
- assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get(Preference.VALUE_ATTRIBUTE));
- assertTrue("Unexpected pref owner", ((String) prefDetails.get(Preference.OWNER_ATTRIBUTE)).startsWith(RestTestHelper.DEFAULT_USERNAME + "@"));
-
- String typeUrl = String.format("broker/userpreferences/%s", prefType);
- assertEquals("Unexpected preference returned from type url",
- prefDetails,
- getRestTestHelper().getJsonAsSingletonList(typeUrl));
-
- String allUrl = "broker/userpreferences";
- final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
- assertEquals("Unexpected number of types in all url response", 1, allMap.size());
- assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
- allMap.containsKey(prefType));
- List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
- assertEquals("Unexpected number of preferences", 1, prefs.size());
-
- assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
- }
-
-
- public void testPostSinglePreferenceRoundTrip() throws Exception
- {
- final String prefName = "mypref";
- final String prefDescription = "mydesc";
- final String prefType = "X-testtype";
-
- Map<String, Object> prefAttributes = new HashMap<>();
- prefAttributes.put(Preference.NAME_ATTRIBUTE, prefName);
- prefAttributes.put(Preference.TYPE_ATTRIBUTE, prefType);
- prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
-
- Map<String, Object> prefValueAttributes = new HashMap<>();
- prefValueAttributes.put("valueAttrName", "valueAttrValue");
- prefAttributes.put(Preference.VALUE_ATTRIBUTE, prefValueAttributes);
-
- String rootUrl = "broker/userpreferences";
- Map<String, List<Map<String, Object>>> payload =
- Collections.singletonMap(prefType, Collections.singletonList(prefAttributes));
- getRestTestHelper().submitRequest(rootUrl, "POST", payload, HttpServletResponse.SC_OK);
-
- Map<String, List<Map<String, Object>>> allPrefs = (Map<String, List<Map<String, Object>>>) getRestTestHelper().getJson(rootUrl, Object.class);
-
- Map<String, Object> prefDetails = allPrefs.get(prefType).get(0);
- assertEquals("Unexpected pref name", prefName, prefDetails.get(Preference.NAME_ATTRIBUTE));
- assertEquals("Unexpected pref description", prefDescription, prefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
- assertEquals("Unexpected pref type", prefType, prefDetails.get(Preference.TYPE_ATTRIBUTE));
- assertEquals("Unexpected pref value", prefValueAttributes, prefDetails.get(Preference.VALUE_ATTRIBUTE));
- assertTrue("Unexpected pref owner", ((String) prefDetails.get(Preference.OWNER_ATTRIBUTE)).startsWith(RestTestHelper.DEFAULT_USERNAME + "@"));
-
- String typeUrl = String.format("broker/userpreferences/%s", prefType);
- assertEquals("Unexpected preference returned from type url",
- prefDetails,
- getRestTestHelper().getJsonAsSingletonList(typeUrl));
-
- String allUrl = "broker/userpreferences";
- final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
- assertEquals("Unexpected number of types in all url response", 1, allMap.size());
- assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
- allMap.containsKey(prefType));
- List<Map<String, Object>> prefs = (List<Map<String, Object>>) allMap.get(prefType);
- assertEquals("Unexpected number of preferences", 1, prefs.size());
-
- assertEquals("Unexpected preference returned from all url", prefDetails, prefs.get(0));
- }
-
- public void testPostManyPreferences() throws Exception
- {
- final String pref1Name = "pref1";
- final String pref2Name = "pref2Name";
- final String pref3Name = "pref3";
- final String prefType1 = "X-prefType1";
- final String prefType2 = "X-prefType2";
-
- Map<String, Object> pref1Attributes = new HashMap<>();
- pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref1Name);
- pref1Attributes.put(Preference.TYPE_ATTRIBUTE, prefType1);
- pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- Map<String, Object> pref2Attributes = new HashMap<>();
- pref2Attributes.put(Preference.NAME_ATTRIBUTE, pref2Name);
- pref2Attributes.put(Preference.TYPE_ATTRIBUTE, prefType2);
- pref2Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- Map<String, Object> payload = new HashMap<>();
- payload.put(prefType1, Collections.singletonList(pref1Attributes));
- payload.put(prefType2, Collections.singletonList(pref2Attributes));
- String url = "broker/userpreferences";
- getRestTestHelper().submitRequest(url, "POST", payload, HttpServletResponse.SC_OK);
-
- Map<String, Object> pref3Attributes = new HashMap<>();
- pref3Attributes.put(Preference.NAME_ATTRIBUTE, pref3Name);
- pref3Attributes.put(Preference.TYPE_ATTRIBUTE, prefType2);
- pref3Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- String url2 = String.format("broker/userpreferences/%s", prefType2);
- getRestTestHelper().submitRequest(url2,
- "POST",
- Collections.singletonList(pref3Attributes),
- HttpServletResponse.SC_OK);
-
- String allUrl = "broker/userpreferences";
- final Map<String, Object> allMap = getRestTestHelper().getJsonAsMap(allUrl);
- assertEquals("Unexpected number of types in all url response", 2, allMap.size());
- assertTrue("Expected type not found in all url response. Found : " + allMap.keySet(),
- allMap.containsKey(prefType1) && allMap.containsKey(prefType2));
- List<Map<String, Object>> pref1s = (List<Map<String, Object>>) allMap.get(prefType1);
- assertEquals("Unexpected number of preferences", 1, pref1s.size());
- List<Map<String, Object>> pref2s = (List<Map<String, Object>>) allMap.get(prefType2);
- assertEquals("Unexpected number of preferences", 2, pref2s.size());
-
- assertEquals("Unexpected preference returned from all url for type1. Found : " + pref1s.get(0).get(Preference.NAME_ATTRIBUTE),
- pref1Name,
- pref1s.get(0).get(Preference.NAME_ATTRIBUTE));
- Set<String> pref2Names = new HashSet<>();
- pref2Names.add((String) pref2s.get(0).get(Preference.NAME_ATTRIBUTE));
- pref2Names.add((String) pref2s.get(1).get(Preference.NAME_ATTRIBUTE));
- assertTrue("Unexpected preference returned from all url for type2. Found : " + pref2Names,
- pref2Names.contains(pref2Name) && pref2Names.contains(pref3Name));
- }
-
- public void testPutReplaceOne() throws Exception
- {
- final String prefName = "mypref";
- final String prefDescription = "mydesc";
- final String prefType = "X-testtype";
-
- Map<String, Object> prefAttributes = new HashMap<>();
- prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
-
- prefAttributes.put("value", Collections.emptyMap());
- String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
- getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_OK);
-
- Map<String, Object> storedPreference = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected pref name", prefName, storedPreference.get(Preference.NAME_ATTRIBUTE));
- assertEquals("Unexpected pref description", prefDescription, storedPreference.get(Preference.DESCRIPTION_ATTRIBUTE));
-
- Map<String, Object> updatePreference = new HashMap<>(storedPreference);
- updatePreference.put(Preference.DESCRIPTION_ATTRIBUTE, "new description");
- getRestTestHelper().submitRequest(fullUrl, "PUT", updatePreference, HttpServletResponse.SC_OK);
-
- Map<String, Object> rereadPrefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected id on updated pref", storedPreference.get(Preference.ID_ATTRIBUTE), rereadPrefDetails.get(Preference.ID_ATTRIBUTE));
- assertEquals("Unexpected description on updated pref", "new description", rereadPrefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
- }
-
- public void testPutReplaceMany() throws Exception
- {
- final String pref1Name = "mypref1";
- final String pref1Type = "X-testtype1";
- final String pref2Name = "mypref2";
- final String pref2Type = "X-testtype2";
-
- String rootUrl = "broker/userpreferences";
-
- {
- // Create two preferences (of different types)
-
- Map<String, Object> pref1Attributes = new HashMap<>();
- pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref1Name);
- pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
- pref1Attributes.put(Preference.TYPE_ATTRIBUTE, pref1Type);
-
- Map<String, Object> pref2Attributes = new HashMap<>();
- pref2Attributes.put(Preference.NAME_ATTRIBUTE, pref2Name);
- pref2Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
- pref2Attributes.put(Preference.TYPE_ATTRIBUTE, pref2Type);
-
- final Map<String, List<Map<String, Object>>> payload = new HashMap<>();
- payload.put(pref1Type, Lists.newArrayList(pref1Attributes));
- payload.put(pref2Type, Lists.newArrayList(pref2Attributes));
-
- getRestTestHelper().submitRequest(rootUrl, "PUT", payload, HttpServletResponse.SC_OK);
- }
-
- Map<String, List<Map<String, Object>>> original = getRestTestHelper().getJson(rootUrl, Map.class);
- assertEquals("Unexpected number of types in root map", 2, original.size());
-
- assertEquals("Unexpected number of " + pref1Type + " preferences", 1, original.get(pref1Type).size());
- assertEquals(pref1Type + " preference has unexpected name", pref1Name, original.get(pref1Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
-
- assertEquals("Unexpected number of " + pref2Type + " preferences", 1, original.get(pref2Type).size());
- assertEquals(pref2Type + " preference has unexpected name", pref2Name, original.get(pref2Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
-
- final String pref3Name = "mypref3";
- final String pref4Name = "mypref4";
- final String pref3Type = "X-testtype3";
-
- {
- // Replace all the preferences with ones that partially overlap the existing set:
- // The preference of type X-testtype1 is replaced
- // The preference of type X-testtype2 is removed
- // A preference of type X-testtype3 is added
-
- Map<String, Object> pref3Attributes = new HashMap<>();
- pref3Attributes.put(Preference.NAME_ATTRIBUTE, pref3Name);
- pref3Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
- pref3Attributes.put(Preference.TYPE_ATTRIBUTE, pref1Type);
-
- Map<String, Object> pref4Attributes = new HashMap<>();
- pref4Attributes.put(Preference.NAME_ATTRIBUTE, pref4Name);
- pref4Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
- pref4Attributes.put(Preference.TYPE_ATTRIBUTE, pref3Type);
-
- final Map<String, List<Map<String, Object>>> payload = new HashMap<>();
- payload.put(pref1Type, Lists.newArrayList(pref3Attributes));
- payload.put(pref3Type, Lists.newArrayList(pref4Attributes));
-
- getRestTestHelper().submitRequest(rootUrl, "PUT", payload, HttpServletResponse.SC_OK);
- }
-
- Map<String, List<Map<String, Object>>> reread = getRestTestHelper().getJson(rootUrl, Map.class);
- assertEquals("Unexpected number of types in root map after replacement", 2, reread.size());
-
- assertEquals("Unexpected number of " + pref1Type + " preferences", 1, reread.get(pref1Type).size());
- assertEquals(pref1Type + " preference has unexpected name", pref3Name, reread.get(pref1Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
-
- assertEquals("Unexpected number of " + pref3Type + " preferences", 1, reread.get(pref3Type).size());
- assertEquals(pref3Type + " preference has unexpected name", pref4Name, reread.get(pref3Type).iterator().next().get(Preference.NAME_ATTRIBUTE));
- }
-
- public void testPostUpdate() throws Exception
- {
- final String prefName = "mypref";
- final String prefDescription = "mydesc";
- final String prefType = "X-testtype";
-
- String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
- String typeUrl = String.format("broker/userpreferences/%s", prefType);
- String rootUrl = "broker/userpreferences";
-
- Map<String, Object> prefAttributes = new HashMap<>();
- prefAttributes.put(Preference.NAME_ATTRIBUTE, prefName);
- prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
- prefAttributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
- final List<Map<String, Object>> payloadCreate = Collections.singletonList(prefAttributes);
- getRestTestHelper().submitRequest(typeUrl, "POST", payloadCreate, HttpServletResponse.SC_OK);
-
- Map<String, Object> storedPreference = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected pref name", prefName, storedPreference.get(Preference.NAME_ATTRIBUTE));
- assertEquals("Unexpected pref description", prefDescription, storedPreference.get(Preference.DESCRIPTION_ATTRIBUTE));
-
- // Update via url to type
- Map<String, Object> updatePreference = new HashMap<>(storedPreference);
- updatePreference.put(Preference.DESCRIPTION_ATTRIBUTE, "update 1");
- final List<Map<String, Object>> payloadUpdate1 = Collections.singletonList(updatePreference);
- getRestTestHelper().submitRequest(typeUrl, "POST", payloadUpdate1, HttpServletResponse.SC_OK);
-
- Map<String, Object> rereadPrefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected id on updated pref, update 1",
- storedPreference.get(Preference.ID_ATTRIBUTE),
- rereadPrefDetails.get(Preference.ID_ATTRIBUTE));
- assertEquals("Unexpected description on updated pref, update 1",
- "update 1",
- rereadPrefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
-
- // Update via url to root
- updatePreference = new HashMap<>(rereadPrefDetails);
- updatePreference.put(Preference.DESCRIPTION_ATTRIBUTE, "update 2");
- Map<String, List<Map<String, Object>>> payloadUpdate2 =
- Collections.singletonMap(prefType, Collections.singletonList(updatePreference));
- getRestTestHelper().submitRequest(rootUrl, "POST", payloadUpdate2, HttpServletResponse.SC_OK);
-
- rereadPrefDetails = getRestTestHelper().getJsonAsMap(fullUrl);
-
- assertEquals("Unexpected description on updated pref, update 2",
- "update 2",
- rereadPrefDetails.get(Preference.DESCRIPTION_ATTRIBUTE));
- }
-
- public void testDelete() throws Exception
- {
- final String prefName = "mypref";
- final String prefDescription = "mydesc";
- final String prefType = "X-testtype";
-
- Map<String, Object> prefAttributes = new HashMap<>();
- prefAttributes.put(Preference.DESCRIPTION_ATTRIBUTE, prefDescription);
- prefAttributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
- String fullUrl = String.format("broker/userpreferences/%s/%s", prefType, prefName);
- getRestTestHelper().submitRequest(fullUrl, "PUT", prefAttributes, HttpServletResponse.SC_OK);
-
- getRestTestHelper().getJsonAsMap(fullUrl);
-
- getRestTestHelper().submitRequest(fullUrl, "DELETE", HttpServletResponse.SC_OK);
-
- try
- {
- getRestTestHelper().getJsonAsMap(fullUrl);
- fail();
- }
- catch (Exception e)
- {
- // pass
- }
- }
-
- public void testWildcards() throws Exception
- {
- final String pref1Name = "pref1Name";
- final String pref2Name = "pref2Name";
- final String pref3Name = "pref3Name";
- final String prefType1 = "X-prefType1";
- final String prefType2 = "X-prefType2";
-
- Map<String, Object> vh1Pref1Attributes = new HashMap<>();
- vh1Pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref1Name);
- vh1Pref1Attributes.put(Preference.TYPE_ATTRIBUTE, prefType1);
- vh1Pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- Map<String, Object> vh2Pref1Attributes = new HashMap<>();
- vh2Pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref2Name);
- vh2Pref1Attributes.put(Preference.TYPE_ATTRIBUTE, prefType1);
- vh2Pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- Map<String, Object> vh2Pref2Attributes = new HashMap<>();
- vh2Pref2Attributes.put(Preference.NAME_ATTRIBUTE, pref3Name);
- vh2Pref2Attributes.put(Preference.TYPE_ATTRIBUTE, prefType2);
- vh2Pref2Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- Map<String, Object> vh3Pref1Attributes = new HashMap<>();
- vh3Pref1Attributes.put(Preference.NAME_ATTRIBUTE, pref1Name);
- vh3Pref1Attributes.put(Preference.TYPE_ATTRIBUTE, prefType1);
- vh3Pref1Attributes.put(Preference.VALUE_ATTRIBUTE, Collections.emptyMap());
-
- String vh1PostUrl = String.format("virtualhost/%s/%s/userpreferences", QpidRestTestCase.TEST1_VIRTUALHOST, QpidRestTestCase.TEST1_VIRTUALHOST);
- String vh2PostUrl = String.format("virtualhost/%s/%s/userpreferences", QpidRestTestCase.TEST2_VIRTUALHOST, QpidRestTestCase.TEST2_VIRTUALHOST);
- String vh3PostUrl = String.format("virtualhost/%s/%s/userpreferences", QpidRestTestCase.TEST3_VIRTUALHOST, QpidRestTestCase.TEST3_VIRTUALHOST);
-
- Map<String, Object> payloadVh1 = new HashMap<>();
- payloadVh1.put(prefType1, Collections.singletonList(vh1Pref1Attributes));
- getRestTestHelper().submitRequest(vh1PostUrl, "POST", payloadVh1, HttpServletResponse.SC_OK);
-
- Map<String, Object> payloadVh2 = new HashMap<>();
- payloadVh2.put(prefType1, Lists.newArrayList(vh2Pref1Attributes));
- payloadVh2.put(prefType2, Lists.newArrayList(vh2Pref2Attributes));
- getRestTestHelper().submitRequest(vh2PostUrl, "POST", payloadVh2, HttpServletResponse.SC_OK);
-
- Map<String, Object> payloadVh3 = new HashMap<>();
- payloadVh3.put(prefType1, Lists.newArrayList(vh3Pref1Attributes));
- getRestTestHelper().submitRequest(vh3PostUrl, "POST", payloadVh3, HttpServletResponse.SC_OK);
-
- {
- String wildGetUrlAll = "virtualhost/*/*/userpreferences";
- final List<Map<String, List<Map<String, Object>>>> vhTypeMaps =
- getRestTestHelper().getJson(wildGetUrlAll, List.class);
- assertEquals("Unexpected number of virtualhost preference type maps", 3, vhTypeMaps.size());
-
- Set<Map<String, Object>> allPrefs = new HashSet<>();
- for (Map<String, List<Map<String, Object>>> vhTypeMap : vhTypeMaps)
- {
- for (List<Map<String, Object>> prefList : vhTypeMap.values())
- {
- allPrefs.addAll(prefList);
- }
- }
-
- assertEquals("Unexpected number of preferences in response", 4, allPrefs.size());
-
- assertContainsPreference(Preference.NAME_ATTRIBUTE, pref1Name, allPrefs, 2);
- assertContainsPreference(Preference.NAME_ATTRIBUTE, pref2Name, allPrefs, 1);
- assertContainsPreference(Preference.NAME_ATTRIBUTE, pref3Name, allPrefs, 1);
- }
-
- {
- String wildGetUrlByType = String.format("virtualhost/*/*/userpreferences/%s", prefType1);
-
- final List<List<Map<String, Object>>> vhListPrefs = getRestTestHelper().getJson(wildGetUrlByType, List.class);
- assertEquals("Unexpected number of virtualhost preference lists", 3, vhListPrefs.size());
-
- Set<Map<String, Object>> allPrefs = new HashSet<>();
- for (List<Map<String, Object>> prefList : vhListPrefs)
- {
- allPrefs.addAll(prefList);
- }
-
- assertEquals("Unexpected number of preferences in response", 3, allPrefs.size());
-
- assertContainsPreference(Preference.NAME_ATTRIBUTE, pref1Name, allPrefs, 2);
- assertContainsPreference(Preference.NAME_ATTRIBUTE, pref2Name, allPrefs, 1);
- }
-
- {
- String wildGetUrlByTypeAndName = String.format("virtualhost/*/*/userpreferences/%s/%s", prefType1, pref1Name);
-
- final List<Map<String, Object>> vhPrefs = getRestTestHelper().getJson(wildGetUrlByTypeAndName, List.class);
- assertEquals("Unexpected number of virtualhost preference lists", 2, vhPrefs.size());
-
- Set<Map<String, Object>> allPrefs = new HashSet<>();
- for (Map<String, Object> prefs : vhPrefs)
- {
- allPrefs.add(prefs);
- }
-
- assertEquals("Unexpected number of preferences in response", 2, allPrefs.size());
-
- assertContainsPreference(Preference.NAME_ATTRIBUTE, pref1Name, allPrefs, 2);
- }
- }
-
- private void assertContainsPreference(final String attribute, final String expected,
- final Set<Map<String, Object>> preferences, final int expectedCount)
- {
- Set<Map<String, Object>> found = Sets.filter(preferences, new AttributeMatchingPredicate(attribute, expected));
- assertEquals(String.format("Cannot find expected preference with attribute %s : %s", attribute, expected),
- expectedCount, found.size());
- }
-
- private static class AttributeMatchingPredicate implements Predicate<Map<String, Object>>
- {
- private final String _expectedName;
- private final String _attribute;
-
- public AttributeMatchingPredicate(String attribute, String expectedName)
- {
- _expectedName = expectedName;
- _attribute = attribute;
- }
-
- @Override
- public boolean apply(final Map<String, Object> input)
- {
- return _expectedName.equals(input.get(_attribute));
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[3/3] qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP]
Add end to end message test
Posted by kw...@apache.org.
QPID-8083 [System Tests] [REST/HTTP] Add end to end message 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/bd1f9098
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/bd1f9098
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/bd1f9098
Branch: refs/heads/master
Commit: bd1f90985703a5dedc37935ad833bece1f650ccd
Parents: 0bb035e
Author: Keith Wall <kw...@apache.org>
Authored: Mon Feb 5 07:09:00 2018 +0000
Committer: Keith Wall <kw...@apache.org>
Committed: Mon Feb 5 09:14:53 2018 +0000
----------------------------------------------------------------------
systests/qpid-systests-http-management/pom.xml | 56 +++++
.../apache/qpid/tests/http/HttpTestBase.java | 57 ++++-
.../apache/qpid/tests/http/HttpTestHelper.java | 66 +++++-
.../resources/config-http-management-tests.json | 174 ++++++++------
.../http/endtoend/message/MessageTest.java | 234 +++++++++++++++++++
5 files changed, 504 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/bd1f9098/systests/qpid-systests-http-management/pom.xml
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/pom.xml b/systests/qpid-systests-http-management/pom.xml
index 8ea2625..7135629 100644
--- a/systests/qpid-systests-http-management/pom.xml
+++ b/systests/qpid-systests-http-management/pom.xml
@@ -85,6 +85,11 @@
<dependency>
<groupId>org.apache.qpid</groupId>
+ <artifactId>qpid-systests-jms-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.qpid</groupId>
<artifactId>qpid-broker-plugins-derby-store</artifactId>
<optional>true</optional>
<scope>test</scope>
@@ -117,7 +122,58 @@
</dependencies>
+ <profiles>
+ <profile>
+ <id>addQpidJmsClientIfNecessary</id>
+ <activation>
+ <property>
+ <name>!enableAmqp0-x</name>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>qpid-jms-client</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>addJms11IfNecessary</id>
+ <activation>
+ <property>
+ <name>enableAmqp0-x</name>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.qpid</groupId>
+ <artifactId>qpid-client</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
<build>
+ <testResources>
+ <testResource>
+ <directory>${basedir}/src/test/java</directory>
+ <excludes>
+ <exclude>**/*.java/</exclude>
+ </excludes>
+ </testResource>
+ <testResource>
+ <directory>${basedir}/src/test/resources</directory>
+ </testResource>
+ <testResource>
+ <directory>${basedir}/../../test-profiles/test_resources/ssl</directory>
+ <includes>
+ <include>*.jks</include>
+ </includes>
+ </testResource>
+ </testResources>
+
+
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/bd1f9098/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 32100fa..7230400 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
@@ -20,13 +20,24 @@
package org.apache.qpid.tests.http;
+import java.net.InetSocketAddress;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.naming.NamingException;
+
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.server.model.Protocol;
+import org.apache.qpid.systests.AmqpManagementFacade;
+import org.apache.qpid.systests.ConnectionBuilder;
+import org.apache.qpid.systests.JmsProvider;
+import org.apache.qpid.systests.QpidJmsClient0xProvider;
+import org.apache.qpid.systests.QpidJmsClientProvider;
+import org.apache.qpid.tests.utils.BrokerAdmin;
import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
public abstract class HttpTestBase extends BrokerAdminUsingTestBase
@@ -36,6 +47,8 @@ public abstract class HttpTestBase extends BrokerAdminUsingTestBase
private HttpTestHelper _helper;
+ private JmsProvider _jmsProvider;
+
@Before
public void setUpTestBase() throws Exception
{
@@ -45,6 +58,18 @@ public abstract class HttpTestBase extends BrokerAdminUsingTestBase
_helper = new HttpTestHelper(getBrokerAdmin(),
config != null && config.useVirtualHostAsHost() ? getVirtualHost() : null);
+
+ Protocol protocol = getProtocol();
+ AmqpManagementFacade managementFacade = new AmqpManagementFacade(protocol);
+ if (protocol == Protocol.AMQP_1_0)
+ {
+ _jmsProvider = new QpidJmsClientProvider(managementFacade);
+ }
+ else
+ {
+ _jmsProvider = new QpidJmsClient0xProvider();
+ }
+
}
@After
@@ -63,6 +88,21 @@ public abstract class HttpTestBase extends BrokerAdminUsingTestBase
return _helper;
}
+ protected Connection getConnection() throws JMSException, NamingException
+ {
+ return getConnectionBuilder().build();
+ }
+
+ protected ConnectionBuilder getConnectionBuilder()
+ {
+ InetSocketAddress brokerAddress = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.AMQP);
+ return _jmsProvider.getConnectionBuilder()
+ .setHost(brokerAddress.getHostName())
+ .setPort(brokerAddress.getPort())
+ .setUsername(getBrokerAdmin().getValidUsername())
+ .setPassword(getBrokerAdmin().getValidPassword());
+ }
+
private HttpRequestConfig getHttpRequestConfig() throws Exception
{
HttpRequestConfig config = getClass().getMethod(_testName.getMethodName(), new Class[]{}).getAnnotation(HttpRequestConfig.class);
@@ -73,4 +113,17 @@ public abstract class HttpTestBase extends BrokerAdminUsingTestBase
return config;
}
+
+ protected static long getReceiveTimeout()
+ {
+ return Long.getLong("qpid.test_receive_timeout", 1000L);
+ }
+
+ protected static Protocol getProtocol()
+ {
+ return Protocol.valueOf("AMQP_" + System.getProperty("broker.version", "0-9-1")
+ .replace('-', '_')
+ .replace('.', '_'));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/bd1f9098/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 3fc6c78..5fcb62d 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
@@ -32,11 +32,20 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
import javax.xml.bind.DatatypeConverter;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -69,7 +78,7 @@ public class HttpTestHelper
private final int _connectTimeout = Integer.getInteger("qpid.resttest_connection_timeout", 30000);
private String _acceptEncoding;
- private boolean _useSsl = false;
+ private boolean _tls = false;
public HttpTestHelper(final BrokerAdmin admin)
{
@@ -85,27 +94,27 @@ public class HttpTestHelper
_requestHostName = requestHostName;
}
- public int getHttpPort()
+ public void setTls(final boolean tls)
{
- return _httpPort;
+ _tls = tls;
}
- private String getHostName()
+ private int getHttpPort()
{
- return "localhost";
+ return _httpPort;
}
- private String getProtocol()
+ private String getHostName()
{
- return _useSsl ? "https" : "http";
+ return "localhost";
}
- public String getManagementURL()
+ private String getManagementURL()
{
- return getProtocol() + "://" + getHostName() + ":" + getHttpPort();
+ return (_tls ? "https" : "http") + "://" + getHostName() + ":" + getHttpPort();
}
- public URL getManagementURL(String path) throws MalformedURLException
+ private URL getManagementURL(String path) throws MalformedURLException
{
return new URL(getManagementURL() + path);
}
@@ -118,6 +127,42 @@ public class HttpTestHelper
}
URL url = getManagementURL(path);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
+ if (httpCon instanceof HttpsURLConnection)
+ {
+ HttpsURLConnection httpsCon = (HttpsURLConnection) httpCon;
+ try
+ {
+ SSLContext sslContext = SSLContext.getInstance("TLS");
+ TrustManager[] trustAllCerts = new TrustManager[] {
+ new X509TrustManager()
+ {
+ public X509Certificate[] getAcceptedIssuers()
+ {
+ X509Certificate[] issuers = new X509Certificate[0];
+ return issuers;
+ }
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] certs, String authType)
+ {
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] certs, String authType)
+ {
+ }
+ }
+ };
+
+ sslContext.init(null, trustAllCerts, null);
+ httpsCon.setSSLSocketFactory(sslContext.getSocketFactory());
+ httpsCon.setHostnameVerifier((s, sslSession) -> true);
+ }
+ catch (KeyManagementException | NoSuchAlgorithmException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
httpCon.setConnectTimeout(_connectTimeout);
if (_requestHostName != null)
{
@@ -388,4 +433,5 @@ public class HttpTestHelper
{
_acceptEncoding = acceptEncoding;
}
+
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/bd1f9098/systests/qpid-systests-http-management/src/main/resources/config-http-management-tests.json
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/main/resources/config-http-management-tests.json b/systests/qpid-systests-http-management/src/main/resources/config-http-management-tests.json
index 84310f9..356c4bb 100644
--- a/systests/qpid-systests-http-management/src/main/resources/config-http-management-tests.json
+++ b/systests/qpid-systests-http-management/src/main/resources/config-http-management-tests.json
@@ -19,75 +19,107 @@
*
*/
{
- "name" : "${broker.name}",
- "modelVersion" : "7.0",
- "authenticationproviders" : [ {
- "name" : "anon",
- "type" : "Anonymous"
- }, {
- "name" : "plain",
- "type" : "Plain",
- "secureOnlyMechanisms" : [],
- "users" : [ {
- "name" : "admin",
- "type" : "managed",
- "password" : "admin"
- }, {
- "name" : "guest",
- "type" : "managed",
- "password" : "guest"
- } ]
- } ],
- "ports" : [ {
- "name" : "AMQP",
- "type" : "AMQP",
- "authenticationProvider" : "plain",
- "port" : "0",
- "virtualhostaliases" : [ {
- "name" : "defaultAlias",
- "type" : "defaultAlias"
- }, {
- "name" : "hostnameAlias",
- "type" : "hostnameAlias"
- }, {
- "name" : "nameAlias",
- "type" : "nameAlias"
- } ]
- }, {
- "name" : "ANONYMOUS_AMQP",
- "type" : "AMQP",
- "authenticationProvider" : "anon",
- "port" : "0",
- "virtualhostaliases" : [ {
- "name" : "defaultAlias",
- "type" : "defaultAlias",
- "durable" : true
- }, {
- "name" : "hostnameAlias",
- "type" : "hostnameAlias",
- "durable" : true
- }, {
- "name" : "nameAlias",
- "type" : "nameAlias",
- "durable" : true
- } ]
- }, {
- "name": "HTTP",
- "authenticationProvider": "plain",
- "port": "0",
- "protocols": [
- "HTTP"
- ],
- "virtualhostaliases" : [ {
- "name" : "nameAlias",
- "type" : "nameAlias"
- } ]
-
- }],
- "plugins" : [ {
- "type" : "MANAGEMENT-HTTP",
- "name" : "httpManagement",
- "httpBasicAuthenticationEnabled" : true
- } ],
- "virtualhostnodes" : []
+ "name": "${broker.name}",
+ "modelVersion": "7.0",
+ "keystores": [
+ {
+ "name": "systestsKeyStore",
+ "storeUrl": "classpath:java_broker_keystore.jks",
+ "password": "password"
+ }
+ ],
+ "authenticationproviders": [
+ {
+ "name": "anon",
+ "type": "Anonymous"
+ },
+ {
+ "name": "plain",
+ "type": "Plain",
+ "secureOnlyMechanisms": [],
+ "users": [
+ {
+ "name": "admin",
+ "type": "managed",
+ "password": "admin"
+ },
+ {
+ "name": "guest",
+ "type": "managed",
+ "password": "guest"
+ }
+ ]
+ }
+ ],
+ "ports": [
+ {
+ "name": "AMQP",
+ "type": "AMQP",
+ "authenticationProvider": "plain",
+ "port": "0",
+ "virtualhostaliases": [
+ {
+ "name": "defaultAlias",
+ "type": "defaultAlias"
+ },
+ {
+ "name": "hostnameAlias",
+ "type": "hostnameAlias"
+ },
+ {
+ "name": "nameAlias",
+ "type": "nameAlias"
+ }
+ ]
+ },
+ {
+ "name": "ANONYMOUS_AMQP",
+ "type": "AMQP",
+ "authenticationProvider": "anon",
+ "port": "0",
+ "virtualhostaliases": [
+ {
+ "name": "defaultAlias",
+ "type": "defaultAlias",
+ "durable": true
+ },
+ {
+ "name": "hostnameAlias",
+ "type": "hostnameAlias",
+ "durable": true
+ },
+ {
+ "name": "nameAlias",
+ "type": "nameAlias",
+ "durable": true
+ }
+ ]
+ },
+ {
+ "name": "HTTP",
+ "authenticationProvider": "plain",
+ "keyStore": "systestsKeyStore",
+ "port": "0",
+ "protocols": [
+ "HTTP"
+ ],
+ "transports": [
+ "TCP", "SSL"
+ ],
+ "virtualhostaliases": [
+ {
+ "name": "nameAlias",
+ "type": "nameAlias"
+ }
+ ]
+ }
+ ],
+ "plugins": [
+ {
+ "type": "MANAGEMENT-HTTP",
+ "name": "httpManagement",
+ "httpBasicAuthenticationEnabled": true
+ }
+ ],
+ "virtualhostnodes": []
}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/bd1f9098/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/message/MessageTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/message/MessageTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/message/MessageTest.java
new file mode 100644
index 0000000..cb92341
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/endtoend/message/MessageTest.java
@@ -0,0 +1,234 @@
+/*
+ *
+ * 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.endtoend.message;
+
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.IntStream;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.common.io.ByteStreams;
+import org.hamcrest.CoreMatchers;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.qpid.server.model.Protocol;
+import org.apache.qpid.tests.http.HttpRequestConfig;
+import org.apache.qpid.tests.http.HttpTestBase;
+
+@HttpRequestConfig
+public class MessageTest extends HttpTestBase
+{
+
+ private static final String QUEUE_NAME = "myqueue";
+ private static final TypeReference<List<Map<String, Object>>> LIST_MAP_TYPE_REF =
+ new TypeReference<List<Map<String, Object>>>() {};
+ private static final TypeReference<Map<String, Object>> MAP_TYPE_REF =
+ new TypeReference<Map<String, Object>>() {};
+ private static final TypeReference<List<Object>> LIST_TYPE_REF =
+ new TypeReference<List<Object>>() {};
+
+ @Before
+ public void setUp()
+ {
+ getBrokerAdmin().createQueue(QUEUE_NAME);
+ }
+
+ @Test
+ public void getJmsMessage() throws Exception
+ {
+ getHelper().setTls(true);
+
+ final String messageProperty = "myProp";
+ final String messagePropertyValue = "myValue";
+
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
+ Message message = session.createMessage();
+ message.setStringProperty(messageProperty, messagePropertyValue);
+ producer.send(message);
+ }
+ finally
+ {
+ connection.close();
+ }
+
+ List<Map<String, Object>> messages = getHelper().postJson("queue/myqueue/getMessageInfo",
+ Collections.singletonMap("includeHeaders", Boolean.TRUE),
+ LIST_MAP_TYPE_REF, SC_OK);
+ assertThat(messages.size(), is(equalTo(1)));
+
+ Map<String, Object> message = messages.get(0);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> headers = (Map<String, Object>) message.get("headers");
+ assertThat(headers.get(messageProperty), is(equalTo(messagePropertyValue)));
+ }
+
+ @Test
+ public void getJmsMapMessage() throws Exception
+ {
+ getHelper().setTls(true);
+ final String mapKey = "key";
+ final String mapKeyValue = "value";
+
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
+ MapMessage message = session.createMapMessage();
+ message.setString(mapKey, mapKeyValue);
+ producer.send(message);
+ }
+ finally
+ {
+ connection.close();
+ }
+
+ List<Map<String, Object>> messages = getHelper().postJson("queue/myqueue/getMessageInfo",
+ Collections.singletonMap("includeHeaders", Boolean.TRUE),
+ LIST_MAP_TYPE_REF, SC_OK);
+ assertThat(messages.size(), is(equalTo(1)));
+ Map<String, Object> message = messages.get(0);
+ int messageId = (int) message.get("id");
+
+ Map<String, Object> contentParams = new HashMap<>();
+ contentParams.put("messageId", messageId);
+ contentParams.put("returnJson", Boolean.TRUE);
+
+ Map<String, Object> content = getHelper().postJson("queue/myqueue/getMessageContent",
+ contentParams,
+ MAP_TYPE_REF, SC_OK);
+ assertThat(content.size(), is(equalTo(1)));
+ assertThat(content.get(mapKey), is(equalTo(mapKeyValue)));
+ }
+
+ @Test
+ public void getJmsStreamMessage() throws Exception
+ {
+ getHelper().setTls(true);
+
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
+ StreamMessage message = session.createStreamMessage();
+ message.writeLong(Long.MAX_VALUE);
+ message.writeBoolean(true);
+ message.writeString("Hello World");
+ producer.send(message);
+ }
+ finally
+ {
+ connection.close();
+ }
+
+ List<Map<String, Object>> messages = getHelper().postJson("queue/myqueue/getMessageInfo",
+ Collections.singletonMap("includeHeaders", Boolean.TRUE),
+ LIST_MAP_TYPE_REF, SC_OK);
+ assertThat(messages.size(), is(equalTo(1)));
+ Map<String, Object> message = messages.get(0);
+ int messageId = (int) message.get("id");
+
+ Map<String, Object> contentParams = new HashMap<>();
+ contentParams.put("messageId", messageId);
+ contentParams.put("returnJson", Boolean.TRUE);
+
+ List<Object> content = getHelper().postJson("queue/myqueue/getMessageContent",
+ contentParams,
+ LIST_TYPE_REF, SC_OK);
+ assertThat(content.size(), is(equalTo(3)));
+ assertThat(content.get(0), is(equalTo(Long.MAX_VALUE)));
+ assertThat(content.get(1), is(equalTo(Boolean.TRUE)));
+ assertThat(content.get(2), is(equalTo("Hello World")));
+ }
+
+ @Test
+ public void getJmsBytesMessage() throws Exception
+ {
+ getHelper().setTls(true);
+
+ final byte[] content = new byte[512];
+ IntStream.range(0, content.length).forEachOrdered(i -> content[i] = (byte) (i % 256));
+
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
+ BytesMessage message = session.createBytesMessage();
+ message.writeBytes(content);
+ producer.send(message);
+ }
+ finally
+ {
+ connection.close();
+ }
+
+ List<Map<String, Object>> messages = getHelper().postJson("queue/myqueue/getMessageInfo",
+ Collections.singletonMap("includeHeaders", Boolean.TRUE),
+ LIST_MAP_TYPE_REF, SC_OK);
+ assertThat(messages.size(), is(equalTo(1)));
+ Map<String, Object> message = messages.get(0);
+ int messageId = (int) message.get("id");
+
+ HttpURLConnection httpCon = getHelper().openManagementConnection(String.format(
+ "queue/myqueue/getMessageContent?messageId=%d", messageId), "GET");
+ httpCon.connect();
+
+ byte[] receivedContent;
+ try(InputStream is = httpCon.getInputStream())
+ {
+ receivedContent = ByteStreams.toByteArray(is);
+ }
+
+ assumeThat("AMQP1.0 messages return the AMQP type",
+ getProtocol(), is(not(equalTo(Protocol.AMQP_1_0))));
+
+ assertThat(receivedContent, is(equalTo(content)));
+ }
+
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org