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/01/29 23:05:37 UTC
qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP] Add
REST model create tests
Repository: qpid-broker-j
Updated Branches:
refs/heads/master 575d2762e -> 06e577da4
QPID-8083 [System Tests] [REST/HTTP] Add REST model create tests
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/06e577da
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/06e577da
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/06e577da
Branch: refs/heads/master
Commit: 06e577da412fcb0444116f1a436bdcd6e50ebc68
Parents: 575d276
Author: Keith Wall <kw...@apache.org>
Authored: Mon Jan 29 10:49:24 2018 +0000
Committer: Keith Wall <kw...@apache.org>
Committed: Mon Jan 29 23:05:15 2018 +0000
----------------------------------------------------------------------
.../qpid/tests/http/HttpRequestConfig.java | 31 ++
.../apache/qpid/tests/http/HttpTestBase.java | 61 +++
.../apache/qpid/tests/http/HttpTestHelper.java | 384 +++++++++++++++++
.../apache/qpid/tests/rest/RestTestHelper.java | 375 -----------------
.../resources/config-http-management-tests.json | 9 +-
.../qpid/tests/authentication/SaslRestTest.java | 408 -------------------
.../CompressedResponsesRestTest.java | 141 -------
.../tests/http/authentication/SaslTest.java | 405 ++++++++++++++++++
.../compression/CompressedResponsesTest.java | 131 ++++++
.../qpid/tests/http/rest/model/CreateTest.java | 142 +++++++
.../apache/qpid/tests/rest/BrokerRestTest.java | 51 ---
11 files changed, 1161 insertions(+), 977 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpRequestConfig.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpRequestConfig.java b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpRequestConfig.java
new file mode 100644
index 0000000..b0897f6
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpRequestConfig.java
@@ -0,0 +1,31 @@
+/*
+ *
+ * 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;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface HttpRequestConfig
+{
+ boolean useVirtualHostAsHost() default true;
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/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
new file mode 100644
index 0000000..b33e579
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestBase.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
+
+public abstract class HttpTestBase extends BrokerAdminUsingTestBase
+{
+ @Rule
+ public final TestName _testName = new TestName();
+ private HttpTestHelper _helper;
+
+ @Before
+ public void setUpTestBase()
+ {
+ System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
+
+ HttpRequestConfig config = getClass().getAnnotation(HttpRequestConfig.class);
+ _helper = new HttpTestHelper(getBrokerAdmin(),
+ config != null && config.useVirtualHostAsHost() ? getVirtualHost() : null);
+ }
+
+ @After
+ public void tearDownTestBase()
+ {
+ System.clearProperty("sun.net.http.allowRestrictedHeaders");
+ }
+
+ private String getVirtualHost()
+ {
+ return getClass().getSimpleName() + "_" + _testName.getMethodName();
+ }
+
+ public HttpTestHelper getHelper()
+ {
+ return _helper;
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/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
new file mode 100644
index 0000000..b305d34
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
@@ -0,0 +1,384 @@
+/*
+ *
+ * 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;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.DatatypeConverter;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Assert;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.qpid.tests.utils.BrokerAdmin;
+
+public class HttpTestHelper
+{
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpTestHelper.class);
+
+ 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>>()
+ {
+ };
+
+ private static final String API_BASE = "/api/latest/";
+ private final BrokerAdmin _admin;
+ private final int _httpPort;
+ private final String _username;
+ private final String _password;
+ private final String _requestHostName;
+
+ private final int _connectTimeout = Integer.getInteger("qpid.resttest_connection_timeout", 30000);
+
+ private String _acceptEncoding;
+ private boolean _useSsl = false;
+
+ public HttpTestHelper(final BrokerAdmin admin)
+ {
+ this(admin, null);
+ }
+
+ public HttpTestHelper(BrokerAdmin admin, final String requestHostName)
+ {
+ _admin = admin;
+ _httpPort = _admin.getBrokerAddress(BrokerAdmin.PortType.HTTP).getPort();
+ _username = admin.getValidUsername();
+ _password = admin.getValidPassword();
+ _requestHostName = requestHostName;
+ }
+
+ public int getHttpPort()
+ {
+ return _httpPort;
+ }
+
+ private String getHostName()
+ {
+ return "localhost";
+ }
+
+ private String getProtocol()
+ {
+ return _useSsl ? "https" : "http";
+ }
+
+ public String getManagementURL()
+ {
+ return getProtocol() + "://" + getHostName() + ":" + getHttpPort();
+ }
+
+ public URL getManagementURL(String path) throws MalformedURLException
+ {
+ return new URL(getManagementURL() + path);
+ }
+
+ public HttpURLConnection openManagementConnection(String path, String method) throws IOException
+ {
+ if (!path.startsWith("/"))
+ {
+ path = API_BASE + path;
+ }
+ URL url = getManagementURL(path);
+ HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
+ httpCon.setConnectTimeout(_connectTimeout);
+ if (_requestHostName != null)
+ {
+ httpCon.setRequestProperty("Host", _requestHostName);
+ }
+
+ if(_username != null)
+ {
+ String encoded = DatatypeConverter.printBase64Binary((_username + ":" + _password).getBytes(UTF_8));
+ httpCon.setRequestProperty("Authorization", "Basic " + encoded);
+ }
+
+ if (_acceptEncoding != null && !"".equals(_acceptEncoding))
+ {
+ httpCon.setRequestProperty("Accept-Encoding", _acceptEncoding);
+ }
+
+ httpCon.setDoOutput(true);
+ httpCon.setRequestMethod(method);
+ return httpCon;
+ }
+
+ public List<Map<String, Object>> readJsonResponseAsList(HttpURLConnection connection) throws IOException
+ {
+ byte[] data = readConnectionInputStream(connection);
+ ObjectMapper mapper = new ObjectMapper();
+ List<Map<String, Object>> providedObject = mapper.readValue(new ByteArrayInputStream(data), TYPE_LIST_OF_LINKED_HASH_MAPS);
+ return providedObject;
+ }
+
+ public Map<String, Object> readJsonResponseAsMap(HttpURLConnection connection) throws IOException
+ {
+ byte[] data = readConnectionInputStream(connection);
+
+ ObjectMapper mapper = new ObjectMapper();
+ Map<String, Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), TYPE_LINKED_HASH_MAPS);
+ return providedObject;
+ }
+
+ public <T> T readJsonResponse(HttpURLConnection connection, Class<T> valueType) throws IOException
+ {
+ byte[] data = readConnectionInputStream(connection);
+
+ ObjectMapper mapper = new ObjectMapper();
+
+ return mapper.readValue(new ByteArrayInputStream(data), valueType);
+ }
+
+ private byte[] readConnectionInputStream(HttpURLConnection connection) throws IOException
+ {
+ InputStream is = connection.getInputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int len = -1;
+ while ((len = is.read(buffer)) != -1)
+ {
+ baos.write(buffer, 0, len);
+ }
+ if (LOGGER.isTraceEnabled())
+ {
+ LOGGER.trace("RESPONSE:" + new String(baos.toByteArray(), UTF_8));
+ }
+ return baos.toByteArray();
+ }
+
+ private void writeJsonRequest(HttpURLConnection connection, Object data) throws IOException
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.writeValue(connection.getOutputStream(), data);
+ }
+
+ public Map<String, Object> find(String name, Object value, List<Map<String, Object>> data)
+ {
+ if (data == null)
+ {
+ return null;
+ }
+
+ for (Map<String, Object> map : data)
+ {
+ Object mapValue = map.get(name);
+ if (value.equals(mapValue))
+ {
+ return map;
+ }
+ }
+ return null;
+ }
+
+ public Map<String, Object> find(Map<String, Object> searchAttributes, List<Map<String, Object>> data)
+ {
+ for (Map<String, Object> map : data)
+ {
+ boolean equals = true;
+ for (Map.Entry<String, Object> entry : searchAttributes.entrySet())
+ {
+ Object mapValue = map.get(entry.getKey());
+ if (!entry.getValue().equals(mapValue))
+ {
+ equals = false;
+ break;
+ }
+ }
+ if (equals)
+ {
+ return map;
+ }
+ }
+ return null;
+ }
+
+ public Map<String, Object> getJsonAsSingletonList(String path) throws IOException
+ {
+ List<Map<String, Object>> response = getJsonAsList(path);
+
+ Assert.assertNotNull("Response cannot be null", response);
+ Assert.assertEquals("Unexpected response from " + path, 1, response.size());
+ return response.get(0);
+ }
+
+ public Map<String, Object> postDataToPathAndGetObject(String path, Map<String, Object> data) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "POST");
+ connection.connect();
+ writeJsonRequest(connection, data);
+ Map<String, Object> response = readJsonResponseAsMap(connection);
+ return response;
+ }
+
+ public List<Map<String, Object>> getJsonAsList(String path) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ connection.connect();
+ List<Map<String, Object>> response = readJsonResponseAsList(connection);
+ return response;
+ }
+
+ public List<Object> getJsonAsSimpleList(String path) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ connection.connect();
+ byte[] data = readConnectionInputStream(connection);
+ ObjectMapper mapper = new ObjectMapper();
+ List<Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), new TypeReference<List<Object>>()
+ {
+ });
+ return providedObject;
+ }
+
+ public Map<String, Object> getJsonAsMap(String path) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ try
+ {
+ connection.connect();
+ Map<String, Object> response = readJsonResponseAsMap(connection);
+ return response;
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ public <T> T getJson(String path, final Class<T> valueType) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ connection.connect();
+ return readJsonResponse(connection, valueType);
+ }
+
+ public <T> T postJson(String path, final Object data , final Class<T> valueType) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "POST");
+ connection.connect();
+ writeJsonRequest(connection, data);
+ return readJsonResponse(connection, valueType);
+ }
+
+
+ public int submitRequest(String url, String method, Object data) throws IOException
+ {
+ return submitRequest(url, method, data, null);
+ }
+
+ public int submitRequest(String url, String method, Object data, Map<String, List<String>> responseHeadersToCapture) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(url, method);
+ try
+ {
+ if (data != null)
+ {
+ writeJsonRequest(connection, data);
+ }
+ int responseCode = connection.getResponseCode();
+ if (responseHeadersToCapture != null)
+ {
+ responseHeadersToCapture.putAll(connection.getHeaderFields());
+ }
+ return responseCode;
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ public int submitRequest(String url, String method) throws IOException
+ {
+ return submitRequest(url, method, (byte[])null);
+ }
+
+ public void submitRequest(String url, String method, Object data, int expectedResponseCode) throws IOException
+ {
+ Map<String, List<String>> headers = new HashMap<>();
+ int responseCode = submitRequest(url, method, data, headers);
+ Assert.assertEquals("Unexpected response code from " + method + " " + url , expectedResponseCode, responseCode);
+ if (expectedResponseCode == 201)
+ {
+ List<String> location = headers.get("Location");
+ Assert.assertTrue("Location is not returned by REST create request", location != null && location.size() == 1);
+ }
+ }
+
+ public void submitRequest(String url, String method, int expectedResponseCode) throws IOException
+ {
+ submitRequest(url, method, null, expectedResponseCode);
+ }
+
+ public int submitRequest(String url, String method, byte[] parameters) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(url, method);
+ if (parameters != null)
+ {
+ OutputStream os = connection.getOutputStream();
+ os.write(parameters);
+ os.flush();
+ }
+ int responseCode = connection.getResponseCode();
+ connection.disconnect();
+ return responseCode;
+ }
+
+ public byte[] getBytes(String path) throws IOException
+ {
+ HttpURLConnection connection = openManagementConnection(path, "GET");
+ connection.connect();
+ return readConnectionInputStream(connection);
+ }
+
+ public String encode(String value, String encoding) throws UnsupportedEncodingException
+ {
+ return URLEncoder.encode(value, encoding).replace("+", "%20");
+ }
+
+ public String getAcceptEncoding()
+ {
+ return _acceptEncoding;
+ }
+
+ public void setAcceptEncoding(String acceptEncoding)
+ {
+ _acceptEncoding = acceptEncoding;
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/rest/RestTestHelper.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/rest/RestTestHelper.java b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/rest/RestTestHelper.java
deleted file mode 100644
index 2a5e514..0000000
--- a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/rest/RestTestHelper.java
+++ /dev/null
@@ -1,375 +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.tests.rest;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.bind.DatatypeConverter;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.tests.utils.BrokerAdmin;
-
-public class RestTestHelper
-{
- private static final Logger LOGGER = LoggerFactory.getLogger(RestTestHelper.class);
-
- 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>>()
- {
- };
-
- private static final String API_BASE = "/api/latest/";
- private final BrokerAdmin _admin;
- private final int _httpPort;
- private final String _username;
- private final String _password;
-
- private final int _connectTimeout = Integer.getInteger("qpid.resttest_connection_timeout", 30000);
-
- private String _acceptEncoding;
- private boolean _useSsl = false;
-
- public RestTestHelper(BrokerAdmin admin)
- {
- _admin = admin;
- _httpPort = _admin.getBrokerAddress(BrokerAdmin.PortType.HTTP).getPort();
- _username = admin.getValidUsername();
- _password = admin.getValidPassword();
- }
-
- public int getHttpPort()
- {
- return _httpPort;
- }
-
- private String getHostName()
- {
- return "localhost";
- }
-
- private String getProtocol()
- {
- return _useSsl ? "https" : "http";
- }
-
- public String getManagementURL()
- {
- return getProtocol() + "://" + getHostName() + ":" + getHttpPort();
- }
-
- public URL getManagementURL(String path) throws MalformedURLException
- {
- return new URL(getManagementURL() + path);
- }
-
- public HttpURLConnection openManagementConnection(String path, String method) throws IOException
- {
- if (!path.startsWith("/"))
- {
- path = API_BASE + path;
- }
- URL url = getManagementURL(path);
- HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
- httpCon.setConnectTimeout(_connectTimeout);
-
-
- if(_username != null)
- {
- String encoded = DatatypeConverter.printBase64Binary((_username + ":" + _password).getBytes(UTF_8));
- httpCon.setRequestProperty("Authorization", "Basic " + encoded);
- }
-
- if (_acceptEncoding != null && !"".equals(_acceptEncoding))
- {
- httpCon.setRequestProperty("Accept-Encoding", _acceptEncoding);
- }
-
- httpCon.setDoOutput(true);
- httpCon.setRequestMethod(method);
- return httpCon;
- }
-
- public List<Map<String, Object>> readJsonResponseAsList(HttpURLConnection connection) throws IOException
- {
- byte[] data = readConnectionInputStream(connection);
- ObjectMapper mapper = new ObjectMapper();
- List<Map<String, Object>> providedObject = mapper.readValue(new ByteArrayInputStream(data), TYPE_LIST_OF_LINKED_HASH_MAPS);
- return providedObject;
- }
-
- public Map<String, Object> readJsonResponseAsMap(HttpURLConnection connection) throws IOException
- {
- byte[] data = readConnectionInputStream(connection);
-
- ObjectMapper mapper = new ObjectMapper();
- Map<String, Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), TYPE_LINKED_HASH_MAPS);
- return providedObject;
- }
-
- public <T> T readJsonResponse(HttpURLConnection connection, Class<T> valueType) throws IOException
- {
- byte[] data = readConnectionInputStream(connection);
-
- ObjectMapper mapper = new ObjectMapper();
-
- return mapper.readValue(new ByteArrayInputStream(data), valueType);
- }
-
- private byte[] readConnectionInputStream(HttpURLConnection connection) throws IOException
- {
- InputStream is = connection.getInputStream();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int len = -1;
- while ((len = is.read(buffer)) != -1)
- {
- baos.write(buffer, 0, len);
- }
- if (LOGGER.isTraceEnabled())
- {
- LOGGER.trace("RESPONSE:" + new String(baos.toByteArray(), UTF_8));
- }
- return baos.toByteArray();
- }
-
- private void writeJsonRequest(HttpURLConnection connection, Object data) throws IOException
- {
- ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(connection.getOutputStream(), data);
- }
-
- public Map<String, Object> find(String name, Object value, List<Map<String, Object>> data)
- {
- if (data == null)
- {
- return null;
- }
-
- for (Map<String, Object> map : data)
- {
- Object mapValue = map.get(name);
- if (value.equals(mapValue))
- {
- return map;
- }
- }
- return null;
- }
-
- public Map<String, Object> find(Map<String, Object> searchAttributes, List<Map<String, Object>> data)
- {
- for (Map<String, Object> map : data)
- {
- boolean equals = true;
- for (Map.Entry<String, Object> entry : searchAttributes.entrySet())
- {
- Object mapValue = map.get(entry.getKey());
- if (!entry.getValue().equals(mapValue))
- {
- equals = false;
- break;
- }
- }
- if (equals)
- {
- return map;
- }
- }
- return null;
- }
-
- public Map<String, Object> getJsonAsSingletonList(String path) throws IOException
- {
- List<Map<String, Object>> response = getJsonAsList(path);
-
- Assert.assertNotNull("Response cannot be null", response);
- Assert.assertEquals("Unexpected response from " + path, 1, response.size());
- return response.get(0);
- }
-
- public Map<String, Object> postDataToPathAndGetObject(String path, Map<String, Object> data) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "POST");
- connection.connect();
- writeJsonRequest(connection, data);
- Map<String, Object> response = readJsonResponseAsMap(connection);
- return response;
- }
-
- public List<Map<String, Object>> getJsonAsList(String path) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "GET");
- connection.connect();
- List<Map<String, Object>> response = readJsonResponseAsList(connection);
- return response;
- }
-
- public List<Object> getJsonAsSimpleList(String path) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "GET");
- connection.connect();
- byte[] data = readConnectionInputStream(connection);
- ObjectMapper mapper = new ObjectMapper();
- List<Object> providedObject = mapper.readValue(new ByteArrayInputStream(data), new TypeReference<List<Object>>()
- {
- });
- return providedObject;
- }
-
- public Map<String, Object> getJsonAsMap(String path) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "GET");
- try
- {
- connection.connect();
- Map<String, Object> response = readJsonResponseAsMap(connection);
- return response;
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- public <T> T getJson(String path, final Class<T> valueType) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "GET");
- connection.connect();
- return readJsonResponse(connection, valueType);
- }
-
- public <T> T postJson(String path, final Object data , final Class<T> valueType) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "POST");
- connection.connect();
- writeJsonRequest(connection, data);
- return readJsonResponse(connection, valueType);
- }
-
-
- public int submitRequest(String url, String method, Object data) throws IOException
- {
- return submitRequest(url, method, data, null);
- }
-
- public int submitRequest(String url, String method, Object data, Map<String, List<String>> responseHeadersToCapture) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(url, method);
- try
- {
- if (data != null)
- {
- writeJsonRequest(connection, data);
- }
- int responseCode = connection.getResponseCode();
- if (responseHeadersToCapture != null)
- {
- responseHeadersToCapture.putAll(connection.getHeaderFields());
- }
- return responseCode;
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- public int submitRequest(String url, String method) throws IOException
- {
- return submitRequest(url, method, (byte[])null);
- }
-
- public void submitRequest(String url, String method, Object data, int expectedResponseCode) throws IOException
- {
- Map<String, List<String>> headers = new HashMap<>();
- int responseCode = submitRequest(url, method, data, headers);
- Assert.assertEquals("Unexpected response code from " + method + " " + url , expectedResponseCode, responseCode);
- if (expectedResponseCode == 201)
- {
- List<String> location = headers.get("Location");
- Assert.assertTrue("Location is not returned by REST create request", location != null && location.size() == 1);
- }
- }
-
- public void submitRequest(String url, String method, int expectedResponseCode) throws IOException
- {
- submitRequest(url, method, null, expectedResponseCode);
- }
-
- public int submitRequest(String url, String method, byte[] parameters) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(url, method);
- if (parameters != null)
- {
- OutputStream os = connection.getOutputStream();
- os.write(parameters);
- os.flush();
- }
- int responseCode = connection.getResponseCode();
- connection.disconnect();
- return responseCode;
- }
-
- public byte[] getBytes(String path) throws IOException
- {
- HttpURLConnection connection = openManagementConnection(path, "GET");
- connection.connect();
- return readConnectionInputStream(connection);
- }
-
- public String encode(String value, String encoding) throws UnsupportedEncodingException
- {
- return URLEncoder.encode(value, encoding).replace("+", "%20");
- }
-
- public String getAcceptEncoding()
- {
- return _acceptEncoding;
- }
-
- public void setAcceptEncoding(String acceptEncoding)
- {
- _acceptEncoding = acceptEncoding;
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/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 ca8922d..84310f9 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
@@ -77,8 +77,13 @@
"port": "0",
"protocols": [
"HTTP"
- ]
- }],
+ ],
+ "virtualhostaliases" : [ {
+ "name" : "nameAlias",
+ "type" : "nameAlias"
+ } ]
+
+ }],
"plugins" : [ {
"type" : "MANAGEMENT-HTTP",
"name" : "httpManagement",
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/authentication/SaslRestTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/authentication/SaslRestTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/authentication/SaslRestTest.java
deleted file mode 100644
index c2d51b4..0000000
--- a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/authentication/SaslRestTest.java
+++ /dev/null
@@ -1,408 +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.tests.authentication;
-
-import static javax.servlet.http.HttpServletResponse.SC_EXPECTATION_FAILED;
-import static javax.servlet.http.HttpServletResponse.SC_OK;
-import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
-import static org.apache.qpid.server.security.auth.sasl.SaslUtil.generateCramMD5ClientResponse;
-import static org.apache.qpid.server.security.auth.sasl.SaslUtil.generatePlainClientResponse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.xml.bind.DatatypeConverter;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.qpid.server.security.auth.manager.ScramSHA1AuthenticationManager;
-import org.apache.qpid.server.security.auth.manager.ScramSHA256AuthenticationManager;
-import org.apache.qpid.server.security.auth.sasl.crammd5.CramMd5Negotiator;
-import org.apache.qpid.server.security.auth.sasl.plain.PlainNegotiator;
-import org.apache.qpid.tests.rest.RestTestHelper;
-import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
-
-public class SaslRestTest extends BrokerAdminUsingTestBase
-{
- private static final String SASL_SERVICE = "/service/sasl";
- private static final String SET_COOKIE_HEADER = "Set-Cookie";
- private RestTestHelper _helper;
- private String _userName;
- private String _userPassword;
-
- @Before
- public void setUp()
- {
- _helper = new RestTestHelper(getBrokerAdmin());
- _userName = getBrokerAdmin().getValidUsername();
- _userPassword = getBrokerAdmin().getValidPassword();
- }
-
- @Test
- public void requestSASLMechanisms() throws Exception
- {
- Map<String, Object> saslData = _helper.getJsonAsMap(SASL_SERVICE);
- assertNotNull("mechanisms attribute is not found", saslData.get("mechanisms"));
-
- @SuppressWarnings("unchecked")
- List<String> mechanisms = (List<String>) saslData.get("mechanisms");
- String[] expectedMechanisms = {PlainNegotiator.MECHANISM,
- CramMd5Negotiator.MECHANISM,
- ScramSHA1AuthenticationManager.MECHANISM,
- ScramSHA256AuthenticationManager.MECHANISM};
- for (String mechanism : expectedMechanisms)
- {
- assertTrue(String.format("Mechanism '%s' is not found", mechanism), mechanisms.contains(mechanism));
- }
- assertNull(String.format("Unexpected user was returned: %s", saslData.get("user")), saslData.get("user"));
- }
-
- @Test
- public void requestUnsupportedSASLMechanism() throws Exception
- {
- HttpURLConnection connection = requestSASLAuthentication("UNSUPPORTED");
- try
- {
- assertEquals("Unexpected response", SC_EXPECTATION_FAILED, connection.getResponseCode());
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- @Test
- public void plainSASLAuthenticationWithoutInitialResponse() throws Exception
- {
- HttpURLConnection connection = requestSASLAuthentication(PlainNegotiator.MECHANISM);
- try
- {
- assertEquals("Unexpected response", SC_OK, connection.getResponseCode());
- handleChallengeAndSendResponse(connection, _userName, _userPassword, PlainNegotiator.MECHANISM, SC_OK);
-
- assertAuthenticatedUser(_userName, connection.getHeaderFields().get(SET_COOKIE_HEADER));
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- @Test
- public void plainSASLAuthenticationWithMalformedInitialResponse() throws Exception
- {
- byte[] responseBytes = "null".getBytes();
- String responseData = DatatypeConverter.printBase64Binary(responseBytes);
- String parameters = String.format("mechanism=%s&response=%s", PlainNegotiator.MECHANISM, responseData);
-
- HttpURLConnection connection = _helper.openManagementConnection(SASL_SERVICE, "POST");
- try
- {
- try (OutputStream os = connection.getOutputStream())
- {
- os.write(parameters.getBytes());
- os.flush();
-
- assertEquals("Unexpected response code", SC_UNAUTHORIZED, connection.getResponseCode());
-
- assertAuthenticatedUser(null, connection.getHeaderFields().get(SET_COOKIE_HEADER));
- }
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- @Test
- public void plainSASLAuthenticationWithValidCredentials() throws Exception
- {
- List<String> cookies = plainSASLAuthenticationWithInitialResponse(_userName, _userPassword, SC_OK);
-
- assertAuthenticatedUser(_userName, cookies);
- }
-
- @Test
- public void plainSASLAuthenticationWithIncorrectPassword() throws Exception
- {
- List<String> cookies = plainSASLAuthenticationWithInitialResponse(_userName, "incorrect", SC_UNAUTHORIZED);
-
- assertAuthenticatedUser(null, cookies);
- }
-
- @Test
- public void plainSASLAuthenticationWithUnknownUser() throws Exception
- {
- List<String> cookies = plainSASLAuthenticationWithInitialResponse("unknown", _userPassword, SC_UNAUTHORIZED);
-
- assertAuthenticatedUser(null, cookies);
- }
-
- @Test
- public void cramMD5SASLAuthenticationForValidCredentials() throws Exception
- {
- List<String> cookies =
- challengeResponseAuthentication(_userName, _userPassword, CramMd5Negotiator.MECHANISM, SC_OK);
- assertAuthenticatedUser(_userName, cookies);
- }
-
- @Test
- public void cramMD5SASLAuthenticationForIncorrectPassword() throws Exception
- {
- List<String> cookies =
- challengeResponseAuthentication(_userName, "incorrect", CramMd5Negotiator.MECHANISM, SC_UNAUTHORIZED);
- assertAuthenticatedUser(null, cookies);
- }
-
- @Test
- public void cramMD5SASLAuthenticationForNonExistingUser() throws Exception
- {
- List<String> cookies =
- challengeResponseAuthentication("unknown", _userPassword, CramMd5Negotiator.MECHANISM, SC_UNAUTHORIZED);
- assertAuthenticatedUser(null, cookies);
- }
-
- @Test
- public void cramMD5SASLAuthenticationResponseNotProvided() throws Exception
- {
- HttpURLConnection connection = requestSASLAuthentication(CramMd5Negotiator.MECHANISM);
- try
- {
- Map<String, Object> response = _helper.readJsonResponseAsMap(connection);
- String challenge = (String) response.get("challenge");
- assertNotNull("Challenge is not found", challenge);
-
- List<String> cookies = connection.getHeaderFields().get(SET_COOKIE_HEADER);
-
- String requestParameters = (String.format("id=%s", response.get("id")));
- postResponse(cookies, requestParameters, SC_UNAUTHORIZED);
-
- assertAuthenticatedUser(null, cookies);
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- @Test
- public void cramMD5SASLAuthenticationWithMalformedResponse() throws Exception
- {
- HttpURLConnection connection = requestSASLAuthentication(CramMd5Negotiator.MECHANISM);
- try
- {
- Map<String, Object> response = _helper.readJsonResponseAsMap(connection);
- String challenge = (String) response.get("challenge");
- assertNotNull("Challenge is not found", challenge);
-
- List<String> cookies = connection.getHeaderFields().get(SET_COOKIE_HEADER);
-
- String responseData = DatatypeConverter.printBase64Binary("null".getBytes());
- String requestParameters = String.format("id=%s&response=%s", response.get("id"), responseData);
-
- postResponse(cookies, requestParameters, SC_UNAUTHORIZED);
-
- assertAuthenticatedUser(null, cookies);
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- @Test
- public void cramMD5SASLAuthenticationWithInvalidId() throws Exception
- {
- HttpURLConnection connection = requestSASLAuthentication(CramMd5Negotiator.MECHANISM);
- try
- {
- Map<String, Object> response = _helper.readJsonResponseAsMap(connection);
- String challenge = (String) response.get("challenge");
- assertNotNull("Challenge is not found", challenge);
-
- List<String> cookies = connection.getHeaderFields().get(SET_COOKIE_HEADER);
-
- byte[] challengeBytes = DatatypeConverter.parseBase64Binary(challenge);
- byte[] responseBytes =
- generateClientResponse(CramMd5Negotiator.MECHANISM, _userName, _userPassword, challengeBytes);
- String responseData = DatatypeConverter.printBase64Binary(responseBytes);
- String requestParameters = (String.format("id=%s&response=%s", UUID.randomUUID().toString(), responseData));
-
- postResponse(cookies, requestParameters, SC_EXPECTATION_FAILED);
-
- assertAuthenticatedUser(null, cookies);
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- private List<String> plainSASLAuthenticationWithInitialResponse(final String userName,
- final String userPassword,
- final int expectedResponseCode) throws Exception
- {
- byte[] responseBytes = generatePlainClientResponse(userName, userPassword);
- String responseData = DatatypeConverter.printBase64Binary(responseBytes);
- String parameters = String.format("mechanism=%s&response=%s", PlainNegotiator.MECHANISM, responseData);
-
- HttpURLConnection connection = _helper.openManagementConnection(SASL_SERVICE, "POST");
- try
- {
- try (OutputStream os = connection.getOutputStream())
- {
- os.write(parameters.getBytes());
- os.flush();
-
- assertEquals("Unexpected response code", expectedResponseCode, connection.getResponseCode());
- }
- return connection.getHeaderFields().get(SET_COOKIE_HEADER);
- }
- finally
- {
- connection.disconnect();
- }
- }
-
- private List<String> challengeResponseAuthentication(final String userName,
- final String userPassword,
- final String mechanism,
- final int expectedResponseCode)
- throws Exception
- {
- HttpURLConnection connection = requestSASLAuthentication(mechanism);
- try
- {
- handleChallengeAndSendResponse(connection, userName, userPassword, mechanism, expectedResponseCode);
- return connection.getHeaderFields().get(SET_COOKIE_HEADER);
- }
- finally
- {
- connection.disconnect();
- }
- }
-
-
- private void handleChallengeAndSendResponse(HttpURLConnection requestChallengeConnection,
- String userName,
- String userPassword,
- String mechanism,
- final int expectedResponseCode)
- throws Exception
- {
- Map<String, Object> response = _helper.readJsonResponseAsMap(requestChallengeConnection);
- String challenge = (String) response.get("challenge");
- assertNotNull("Challenge is not found", challenge);
-
- byte[] challengeBytes = DatatypeConverter.parseBase64Binary(challenge);
- byte[] responseBytes = generateClientResponse(mechanism, userName, userPassword, challengeBytes);
- String responseData = DatatypeConverter.printBase64Binary(responseBytes);
- String requestParameters = (String.format("id=%s&response=%s", response.get("id"), responseData));
-
- postResponse(requestChallengeConnection.getHeaderFields().get(SET_COOKIE_HEADER),
- requestParameters,
- expectedResponseCode);
- }
-
- private void postResponse(final List<String> cookies,
- final String requestParameters,
- final int expectedResponseCode) throws IOException
- {
- HttpURLConnection authenticateConnection = _helper.openManagementConnection(SASL_SERVICE, "POST");
- try
- {
- applyCookiesToConnection(cookies, authenticateConnection);
- try (OutputStream os = authenticateConnection.getOutputStream())
- {
- os.write(requestParameters.getBytes());
- os.flush();
- assertEquals("Unexpected response code",
- expectedResponseCode,
- authenticateConnection.getResponseCode());
- }
- }
- finally
- {
- authenticateConnection.disconnect();
- }
- }
-
- private byte[] generateClientResponse(String mechanism, String userName, String userPassword, byte[] challengeBytes)
- throws Exception
- {
- byte[] responseBytes;
- if (PlainNegotiator.MECHANISM.equals(mechanism))
- {
- responseBytes = generatePlainClientResponse(_userName, _userPassword);
- }
- else if (CramMd5Negotiator.MECHANISM.equalsIgnoreCase(mechanism))
- {
- responseBytes = generateCramMD5ClientResponse(userName, userPassword, challengeBytes);
- }
- else
- {
- throw new RuntimeException("Not implemented test mechanism " + mechanism);
- }
- return responseBytes;
- }
-
-
- private void applyCookiesToConnection(List<String> cookies, HttpURLConnection connection)
- {
- for (String cookie : cookies)
- {
- connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
- }
- }
-
- private HttpURLConnection requestSASLAuthentication(String mechanism) throws IOException
- {
- HttpURLConnection connection = _helper.openManagementConnection(SASL_SERVICE, "POST");
- OutputStream os = connection.getOutputStream();
- os.write(String.format("mechanism=%s", mechanism).getBytes());
- os.flush();
- return connection;
- }
-
- private void assertAuthenticatedUser(final String userName, final List<String> cookies) throws IOException
- {
- HttpURLConnection connection = _helper.openManagementConnection(SASL_SERVICE, "GET");
- try
- {
- applyCookiesToConnection(cookies, connection);
- Map<String, Object> response = _helper.readJsonResponseAsMap(connection);
- assertEquals("Unexpected user", userName, response.get("user"));
- }
- finally
- {
- connection.disconnect();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/compression/CompressedResponsesRestTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/compression/CompressedResponsesRestTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/compression/CompressedResponsesRestTest.java
deleted file mode 100644
index f4d3c06..0000000
--- a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/compression/CompressedResponsesRestTest.java
+++ /dev/null
@@ -1,141 +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.tests.compression;
-
-import static javax.servlet.http.HttpServletResponse.SC_OK;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.zip.GZIPInputStream;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.io.ByteStreams;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.qpid.tests.rest.RestTestHelper;
-import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
-
-public class CompressedResponsesRestTest extends BrokerAdminUsingTestBase
-{
-
- private RestTestHelper _helper;
-
- @Before
- public void setUp()
- {
- _helper = new RestTestHelper(getBrokerAdmin());
- }
-
- @Test
- public void testCompressionOffAcceptOff() throws Exception
- {
- doCompressionTest(false, false);
- }
-
- @Test
- public void testCompressionOffAcceptOn() throws Exception
- {
- doCompressionTest(false, true);
- }
-
- @Test
- public void testCompressionOnAcceptOff() throws Exception
- {
- doCompressionTest(true, false);
- }
-
- @Test
- public void testCompressionOnAcceptOn() throws Exception
- {
- doCompressionTest(true, true);
-
- }
-
- private void doCompressionTest(final boolean allowCompression,
- final boolean acceptCompressed) throws Exception
- {
- final boolean expectCompression = allowCompression && acceptCompressed;
-
- _helper.submitRequest("plugin/httpManagement", "POST", Collections.singletonMap("compressResponses", expectCompression), SC_OK);
-
-
- HttpURLConnection conn = _helper.openManagementConnection("/service/metadata", "GET");
- try
- {
- if (acceptCompressed)
- {
- conn.setRequestProperty("Accept-Encoding", "gzip");
- }
-
- conn.connect();
-
- String contentEncoding = conn.getHeaderField("Content-Encoding");
-
- if (expectCompression)
- {
- assertEquals("gzip", contentEncoding);
- }
- else
- {
- if (contentEncoding != null)
- {
- assertEquals("identity", contentEncoding);
- }
- }
-
- byte[] bytes;
- try(ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream())
- {
- ByteStreams.copy(conn.getInputStream(), contentBuffer);
- bytes = contentBuffer.toByteArray();
- }
- try (InputStream jsonStream = expectCompression
- ? new GZIPInputStream(new ByteArrayInputStream(bytes))
- : new ByteArrayInputStream(bytes))
- {
- ObjectMapper mapper = new ObjectMapper();
- try
- {
- mapper.readValue(jsonStream, LinkedHashMap.class);
- }
- catch (JsonParseException | JsonMappingException e)
- {
- fail("Message was not in correct format");
- }
- }
- }
- finally
- {
- conn.disconnect();
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/authentication/SaslTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/authentication/SaslTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/authentication/SaslTest.java
new file mode 100644
index 0000000..9201793
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/authentication/SaslTest.java
@@ -0,0 +1,405 @@
+/*
+ *
+ * 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.authentication;
+
+import static javax.servlet.http.HttpServletResponse.SC_EXPECTATION_FAILED;
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
+import static org.apache.qpid.server.security.auth.sasl.SaslUtil.generateCramMD5ClientResponse;
+import static org.apache.qpid.server.security.auth.sasl.SaslUtil.generatePlainClientResponse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.xml.bind.DatatypeConverter;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.qpid.server.security.auth.manager.ScramSHA1AuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.ScramSHA256AuthenticationManager;
+import org.apache.qpid.server.security.auth.sasl.crammd5.CramMd5Negotiator;
+import org.apache.qpid.server.security.auth.sasl.plain.PlainNegotiator;
+import org.apache.qpid.tests.http.HttpTestBase;
+
+public class SaslTest extends HttpTestBase
+{
+ private static final String SASL_SERVICE = "/service/sasl";
+ private static final String SET_COOKIE_HEADER = "Set-Cookie";
+ private String _userName;
+ private String _userPassword;
+
+ @Before
+ public void setUp()
+ {
+ _userName = getBrokerAdmin().getValidUsername();
+ _userPassword = getBrokerAdmin().getValidPassword();
+ }
+
+ @Test
+ public void requestSASLMechanisms() throws Exception
+ {
+ Map<String, Object> saslData = getHelper().getJsonAsMap(SASL_SERVICE);
+ assertNotNull("mechanisms attribute is not found", saslData.get("mechanisms"));
+
+ @SuppressWarnings("unchecked")
+ List<String> mechanisms = (List<String>) saslData.get("mechanisms");
+ String[] expectedMechanisms = {PlainNegotiator.MECHANISM,
+ CramMd5Negotiator.MECHANISM,
+ ScramSHA1AuthenticationManager.MECHANISM,
+ ScramSHA256AuthenticationManager.MECHANISM};
+ for (String mechanism : expectedMechanisms)
+ {
+ assertTrue(String.format("Mechanism '%s' is not found", mechanism), mechanisms.contains(mechanism));
+ }
+ assertNull(String.format("Unexpected user was returned: %s", saslData.get("user")), saslData.get("user"));
+ }
+
+ @Test
+ public void requestUnsupportedSASLMechanism() throws Exception
+ {
+ HttpURLConnection connection = requestSASLAuthentication("UNSUPPORTED");
+ try
+ {
+ assertEquals("Unexpected response", SC_EXPECTATION_FAILED, connection.getResponseCode());
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ @Test
+ public void plainSASLAuthenticationWithoutInitialResponse() throws Exception
+ {
+ HttpURLConnection connection = requestSASLAuthentication(PlainNegotiator.MECHANISM);
+ try
+ {
+ assertEquals("Unexpected response", SC_OK, connection.getResponseCode());
+ handleChallengeAndSendResponse(connection, _userName, _userPassword, PlainNegotiator.MECHANISM, SC_OK);
+
+ assertAuthenticatedUser(_userName, connection.getHeaderFields().get(SET_COOKIE_HEADER));
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ @Test
+ public void plainSASLAuthenticationWithMalformedInitialResponse() throws Exception
+ {
+ byte[] responseBytes = "null".getBytes();
+ String responseData = DatatypeConverter.printBase64Binary(responseBytes);
+ String parameters = String.format("mechanism=%s&response=%s", PlainNegotiator.MECHANISM, responseData);
+
+ HttpURLConnection connection = getHelper().openManagementConnection(SASL_SERVICE, "POST");
+ try
+ {
+ try (OutputStream os = connection.getOutputStream())
+ {
+ os.write(parameters.getBytes());
+ os.flush();
+
+ assertEquals("Unexpected response code", SC_UNAUTHORIZED, connection.getResponseCode());
+
+ assertAuthenticatedUser(null, connection.getHeaderFields().get(SET_COOKIE_HEADER));
+ }
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ @Test
+ public void plainSASLAuthenticationWithValidCredentials() throws Exception
+ {
+ List<String> cookies = plainSASLAuthenticationWithInitialResponse(_userName, _userPassword, SC_OK);
+
+ assertAuthenticatedUser(_userName, cookies);
+ }
+
+ @Test
+ public void plainSASLAuthenticationWithIncorrectPassword() throws Exception
+ {
+ List<String> cookies = plainSASLAuthenticationWithInitialResponse(_userName, "incorrect", SC_UNAUTHORIZED);
+
+ assertAuthenticatedUser(null, cookies);
+ }
+
+ @Test
+ public void plainSASLAuthenticationWithUnknownUser() throws Exception
+ {
+ List<String> cookies = plainSASLAuthenticationWithInitialResponse("unknown", _userPassword, SC_UNAUTHORIZED);
+
+ assertAuthenticatedUser(null, cookies);
+ }
+
+ @Test
+ public void cramMD5SASLAuthenticationForValidCredentials() throws Exception
+ {
+ List<String> cookies =
+ challengeResponseAuthentication(_userName, _userPassword, CramMd5Negotiator.MECHANISM, SC_OK);
+ assertAuthenticatedUser(_userName, cookies);
+ }
+
+ @Test
+ public void cramMD5SASLAuthenticationForIncorrectPassword() throws Exception
+ {
+ List<String> cookies =
+ challengeResponseAuthentication(_userName, "incorrect", CramMd5Negotiator.MECHANISM, SC_UNAUTHORIZED);
+ assertAuthenticatedUser(null, cookies);
+ }
+
+ @Test
+ public void cramMD5SASLAuthenticationForNonExistingUser() throws Exception
+ {
+ List<String> cookies =
+ challengeResponseAuthentication("unknown", _userPassword, CramMd5Negotiator.MECHANISM, SC_UNAUTHORIZED);
+ assertAuthenticatedUser(null, cookies);
+ }
+
+ @Test
+ public void cramMD5SASLAuthenticationResponseNotProvided() throws Exception
+ {
+ HttpURLConnection connection = requestSASLAuthentication(CramMd5Negotiator.MECHANISM);
+ try
+ {
+ Map<String, Object> response = getHelper().readJsonResponseAsMap(connection);
+ String challenge = (String) response.get("challenge");
+ assertNotNull("Challenge is not found", challenge);
+
+ List<String> cookies = connection.getHeaderFields().get(SET_COOKIE_HEADER);
+
+ String requestParameters = (String.format("id=%s", response.get("id")));
+ postResponse(cookies, requestParameters, SC_UNAUTHORIZED);
+
+ assertAuthenticatedUser(null, cookies);
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ @Test
+ public void cramMD5SASLAuthenticationWithMalformedResponse() throws Exception
+ {
+ HttpURLConnection connection = requestSASLAuthentication(CramMd5Negotiator.MECHANISM);
+ try
+ {
+ Map<String, Object> response = getHelper().readJsonResponseAsMap(connection);
+ String challenge = (String) response.get("challenge");
+ assertNotNull("Challenge is not found", challenge);
+
+ List<String> cookies = connection.getHeaderFields().get(SET_COOKIE_HEADER);
+
+ String responseData = DatatypeConverter.printBase64Binary("null".getBytes());
+ String requestParameters = String.format("id=%s&response=%s", response.get("id"), responseData);
+
+ postResponse(cookies, requestParameters, SC_UNAUTHORIZED);
+
+ assertAuthenticatedUser(null, cookies);
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ @Test
+ public void cramMD5SASLAuthenticationWithInvalidId() throws Exception
+ {
+ HttpURLConnection connection = requestSASLAuthentication(CramMd5Negotiator.MECHANISM);
+ try
+ {
+ Map<String, Object> response = getHelper().readJsonResponseAsMap(connection);
+ String challenge = (String) response.get("challenge");
+ assertNotNull("Challenge is not found", challenge);
+
+ List<String> cookies = connection.getHeaderFields().get(SET_COOKIE_HEADER);
+
+ byte[] challengeBytes = DatatypeConverter.parseBase64Binary(challenge);
+ byte[] responseBytes =
+ generateClientResponse(CramMd5Negotiator.MECHANISM, _userName, _userPassword, challengeBytes);
+ String responseData = DatatypeConverter.printBase64Binary(responseBytes);
+ String requestParameters = (String.format("id=%s&response=%s", UUID.randomUUID().toString(), responseData));
+
+ postResponse(cookies, requestParameters, SC_EXPECTATION_FAILED);
+
+ assertAuthenticatedUser(null, cookies);
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ private List<String> plainSASLAuthenticationWithInitialResponse(final String userName,
+ final String userPassword,
+ final int expectedResponseCode) throws Exception
+ {
+ byte[] responseBytes = generatePlainClientResponse(userName, userPassword);
+ String responseData = DatatypeConverter.printBase64Binary(responseBytes);
+ String parameters = String.format("mechanism=%s&response=%s", PlainNegotiator.MECHANISM, responseData);
+
+ HttpURLConnection connection = getHelper().openManagementConnection(SASL_SERVICE, "POST");
+ try
+ {
+ try (OutputStream os = connection.getOutputStream())
+ {
+ os.write(parameters.getBytes());
+ os.flush();
+
+ assertEquals("Unexpected response code", expectedResponseCode, connection.getResponseCode());
+ }
+ return connection.getHeaderFields().get(SET_COOKIE_HEADER);
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+ private List<String> challengeResponseAuthentication(final String userName,
+ final String userPassword,
+ final String mechanism,
+ final int expectedResponseCode)
+ throws Exception
+ {
+ HttpURLConnection connection = requestSASLAuthentication(mechanism);
+ try
+ {
+ handleChallengeAndSendResponse(connection, userName, userPassword, mechanism, expectedResponseCode);
+ return connection.getHeaderFields().get(SET_COOKIE_HEADER);
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+
+
+ private void handleChallengeAndSendResponse(HttpURLConnection requestChallengeConnection,
+ String userName,
+ String userPassword,
+ String mechanism,
+ final int expectedResponseCode)
+ throws Exception
+ {
+ Map<String, Object> response = getHelper().readJsonResponseAsMap(requestChallengeConnection);
+ String challenge = (String) response.get("challenge");
+ assertNotNull("Challenge is not found", challenge);
+
+ byte[] challengeBytes = DatatypeConverter.parseBase64Binary(challenge);
+ byte[] responseBytes = generateClientResponse(mechanism, userName, userPassword, challengeBytes);
+ String responseData = DatatypeConverter.printBase64Binary(responseBytes);
+ String requestParameters = (String.format("id=%s&response=%s", response.get("id"), responseData));
+
+ postResponse(requestChallengeConnection.getHeaderFields().get(SET_COOKIE_HEADER),
+ requestParameters,
+ expectedResponseCode);
+ }
+
+ private void postResponse(final List<String> cookies,
+ final String requestParameters,
+ final int expectedResponseCode) throws IOException
+ {
+ HttpURLConnection authenticateConnection = getHelper().openManagementConnection(SASL_SERVICE, "POST");
+ try
+ {
+ applyCookiesToConnection(cookies, authenticateConnection);
+ try (OutputStream os = authenticateConnection.getOutputStream())
+ {
+ os.write(requestParameters.getBytes());
+ os.flush();
+ assertEquals("Unexpected response code",
+ expectedResponseCode,
+ authenticateConnection.getResponseCode());
+ }
+ }
+ finally
+ {
+ authenticateConnection.disconnect();
+ }
+ }
+
+ private byte[] generateClientResponse(String mechanism, String userName, String userPassword, byte[] challengeBytes)
+ throws Exception
+ {
+ byte[] responseBytes;
+ if (PlainNegotiator.MECHANISM.equals(mechanism))
+ {
+ responseBytes = generatePlainClientResponse(_userName, _userPassword);
+ }
+ else if (CramMd5Negotiator.MECHANISM.equalsIgnoreCase(mechanism))
+ {
+ responseBytes = generateCramMD5ClientResponse(userName, userPassword, challengeBytes);
+ }
+ else
+ {
+ throw new RuntimeException("Not implemented test mechanism " + mechanism);
+ }
+ return responseBytes;
+ }
+
+
+ private void applyCookiesToConnection(List<String> cookies, HttpURLConnection connection)
+ {
+ for (String cookie : cookies)
+ {
+ connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
+ }
+ }
+
+ private HttpURLConnection requestSASLAuthentication(String mechanism) throws IOException
+ {
+ HttpURLConnection connection = getHelper().openManagementConnection(SASL_SERVICE, "POST");
+ OutputStream os = connection.getOutputStream();
+ os.write(String.format("mechanism=%s", mechanism).getBytes());
+ os.flush();
+ return connection;
+ }
+
+ private void assertAuthenticatedUser(final String userName, final List<String> cookies) throws IOException
+ {
+ HttpURLConnection connection = getHelper().openManagementConnection(SASL_SERVICE, "GET");
+ try
+ {
+ applyCookiesToConnection(cookies, connection);
+ Map<String, Object> response = getHelper().readJsonResponseAsMap(connection);
+ assertEquals("Unexpected user", userName, response.get("user"));
+ }
+ finally
+ {
+ connection.disconnect();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
new file mode 100644
index 0000000..5c411e5
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
@@ -0,0 +1,131 @@
+/*
+ *
+ * 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.compression;
+
+import static javax.servlet.http.HttpServletResponse.SC_OK;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.zip.GZIPInputStream;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.io.ByteStreams;
+import org.junit.Test;
+
+import org.apache.qpid.tests.http.HttpTestBase;
+
+public class CompressedResponsesTest extends HttpTestBase
+{
+
+ @Test
+ public void compressionOffAcceptOff() throws Exception
+ {
+ doCompressionTest(false, false);
+ }
+
+ @Test
+ public void compressionOffAcceptOn() throws Exception
+ {
+ doCompressionTest(false, true);
+ }
+
+ @Test
+ public void compressionOnAcceptOff() throws Exception
+ {
+ doCompressionTest(true, false);
+ }
+
+ @Test
+ public void compressionOnAcceptOn() throws Exception
+ {
+ doCompressionTest(true, true);
+
+ }
+
+ private void doCompressionTest(final boolean allowCompression,
+ final boolean acceptCompressed) throws Exception
+ {
+ final boolean expectCompression = allowCompression && acceptCompressed;
+
+ getHelper().submitRequest("plugin/httpManagement", "POST", Collections.singletonMap("compressResponses", expectCompression), SC_OK);
+
+
+ HttpURLConnection conn = getHelper().openManagementConnection("/service/metadata", "GET");
+ try
+ {
+ if (acceptCompressed)
+ {
+ conn.setRequestProperty("Accept-Encoding", "gzip");
+ }
+
+ conn.connect();
+
+ String contentEncoding = conn.getHeaderField("Content-Encoding");
+
+ if (expectCompression)
+ {
+ assertEquals("gzip", contentEncoding);
+ }
+ else
+ {
+ if (contentEncoding != null)
+ {
+ assertEquals("identity", contentEncoding);
+ }
+ }
+
+ byte[] bytes;
+ try(ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream())
+ {
+ ByteStreams.copy(conn.getInputStream(), contentBuffer);
+ bytes = contentBuffer.toByteArray();
+ }
+ try (InputStream jsonStream = expectCompression
+ ? new GZIPInputStream(new ByteArrayInputStream(bytes))
+ : new ByteArrayInputStream(bytes))
+ {
+ ObjectMapper mapper = new ObjectMapper();
+ try
+ {
+ mapper.readValue(jsonStream, LinkedHashMap.class);
+ }
+ catch (JsonParseException | JsonMappingException e)
+ {
+ fail("Message was not in correct format");
+ }
+ }
+ }
+ finally
+ {
+ conn.disconnect();
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
new file mode 100644
index 0000000..a09d9ad
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/rest/model/CreateTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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_CREATED;
+import static javax.servlet.http.HttpServletResponse.SC_METHOD_NOT_ALLOWED;
+import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
+import static org.apache.qpid.server.management.plugin.servlet.rest.AbstractServlet.SC_UNPROCESSABLE_ENTITY;
+import static org.hamcrest.CoreMatchers.endsWith;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+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.HttpTestBase;
+import org.apache.qpid.tests.http.HttpRequestConfig;
+
+@HttpRequestConfig
+public class CreateTest extends HttpTestBase
+{
+ @Test
+ public void create() throws Exception
+ {
+ final String queueUrl = "queue/myqueue";
+ getHelper().submitRequest(queueUrl, "PUT", Collections.emptyMap(), SC_CREATED);
+ final Map<String, Object> queue = getHelper().getJsonAsMap(queueUrl);
+
+ assertThat(queue.get(ConfiguredObject.NAME), is(equalTo("myqueue")));
+ }
+
+ @Test
+ public void locationHeader() throws Exception
+ {
+ final String queueUrl = "queue/myqueue";
+ Map<String, List<String>> headers = new HashMap<>();
+ int responseCode = getHelper().submitRequest(queueUrl, "PUT", Collections.emptyMap(), headers);
+ assertThat(responseCode, is(equalTo(SC_CREATED)));
+ List<String> location = headers.get("Location");
+ assertThat(location.size(), is(equalTo(1)));
+ assertThat(location.get(0), endsWith(queueUrl));
+ }
+
+ @Test
+ public void createSubtype() throws Exception
+ {
+ final String queueUrl = "queue/myqueue";
+ final Map<String, Object> attrs = Collections.singletonMap(ConfiguredObject.TYPE, "priority");
+ getHelper().submitRequest(queueUrl, "PUT", attrs, SC_CREATED);
+ final Map<String, Object> queue = getHelper().getJsonAsMap(queueUrl);
+
+ assertThat(queue.get(ConfiguredObject.NAME), is(equalTo("myqueue")));
+ assertThat(queue.get(ConfiguredObject.TYPE), is(equalTo("priority")));
+ }
+
+ @Test
+ public void createPutToParent() throws Exception
+ {
+ createToParent("PUT");
+ }
+
+ @Test
+ public void createPostToParent() throws Exception
+ {
+ createToParent("POST");
+ }
+
+ @Test
+ public void unknownSubtype() throws Exception
+ {
+ final String queueUrl = "queue/myqueue";
+ final Map<String, Object> attrs = Collections.singletonMap(ConfiguredObject.TYPE, "unknown");
+ getHelper().submitRequest(queueUrl, "PUT", attrs, SC_UNPROCESSABLE_ENTITY);
+ getHelper().submitRequest(queueUrl, "GET", SC_NOT_FOUND);
+ }
+
+ @Test
+ public void unknownCategory() throws Exception
+ {
+ final String queueUrl = "unknown/myobj";
+ final Map<Object, Object> attrs = Collections.singletonMap(ConfiguredObject.TYPE, "unknown");
+ getHelper().submitRequest(queueUrl, "PUT", attrs, SC_METHOD_NOT_ALLOWED);
+ getHelper().submitRequest(queueUrl, "GET", SC_NOT_FOUND);
+ }
+
+ @Test
+ public void createChild() throws Exception
+ {
+ final String parentUrl = "virtualhostlogger/mylogger";
+ Map<String, Object> parentAttrs = Collections.singletonMap(ConfiguredObject.TYPE, VirtualHostFileLogger.TYPE);
+
+ getHelper().submitRequest(parentUrl, "PUT", parentAttrs, SC_CREATED);
+
+ final String childUrl = "virtualhostloginclusionrule/mylogger/myrule";
+ Map<String, Object> childAttrs = Collections.singletonMap(ConfiguredObject.TYPE, VirtualHostNameAndLevelLogInclusionRule.TYPE);
+ getHelper().submitRequest(childUrl, "PUT", childAttrs, SC_CREATED);
+ }
+
+ @Test
+ public void unknownParent() throws Exception
+ {
+ final String childUrl = "virtualhostloginclusionrule/unknown/myrule";
+ Map<String, Object> childAttrs = Collections.singletonMap(ConfiguredObject.TYPE, VirtualHostNameAndLevelLogInclusionRule.TYPE);
+ getHelper().submitRequest(childUrl, "PUT", childAttrs, SC_UNPROCESSABLE_ENTITY);
+ }
+
+ private void createToParent(final String method) throws Exception
+ {
+ final String parentUrl = "queue";
+ final String queueName = "myqueue";
+ final Map<Object, Object> attrs = Collections.singletonMap(ConfiguredObject.NAME, queueName);
+ getHelper().submitRequest(parentUrl, method, attrs, SC_CREATED);
+ final Map<String, Object> queue = getHelper().getJsonAsMap(String.format("%s/%s", parentUrl, queueName));
+
+ assertThat(queue.get(ConfiguredObject.NAME), is(equalTo(queueName)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/06e577da/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/rest/BrokerRestTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/rest/BrokerRestTest.java b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/rest/BrokerRestTest.java
deleted file mode 100644
index 91d88c0..0000000
--- a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/rest/BrokerRestTest.java
+++ /dev/null
@@ -1,51 +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.tests.rest;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-import java.util.Map;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.tests.utils.BrokerAdminUsingTestBase;
-
-public class BrokerRestTest extends BrokerAdminUsingTestBase
-{
- private RestTestHelper _helper;
-
- @Before
- public void setUp()
- {
- _helper = new RestTestHelper(getBrokerAdmin());
- }
-
- @Test
- public void get() throws Exception
- {
- Map<String, Object> brokerDetails = _helper.getJsonAsMap("broker");
- assertThat("Unexpected value of attribute " + Broker.NAME, brokerDetails.get(Broker.NAME), is(equalTo("Broker")));
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org