You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2018/01/29 15:02:49 UTC
qpid-broker-j git commit: QPID-8083 [System Tests] [REST/HTTP] Move
CompressedResponsesRestTest into http management system tests
Repository: qpid-broker-j
Updated Branches:
refs/heads/master e26dd3321 -> e30e86596
QPID-8083 [System Tests] [REST/HTTP] Move CompressedResponsesRestTest into http management system 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/e30e8659
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/e30e8659
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/e30e8659
Branch: refs/heads/master
Commit: e30e86596053cd1efdabf11bde3058b7e48eb55f
Parents: e26dd33
Author: Alex Rudyy <or...@apache.org>
Authored: Mon Jan 29 15:02:21 2018 +0000
Committer: Alex Rudyy <or...@apache.org>
Committed: Mon Jan 29 15:02:35 2018 +0000
----------------------------------------------------------------------
.../CompressedResponsesRestTest.java | 141 +++++++++++++++++++
.../rest/CompressedResponsesRestTest.java | 138 ------------------
2 files changed, 141 insertions(+), 138 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/e30e8659/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
new file mode 100644
index 0000000..f4d3c06
--- /dev/null
+++ b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/compression/CompressedResponsesRestTest.java
@@ -0,0 +1,141 @@
+/*
+ *
+ * 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/e30e8659/systests/src/test/java/org/apache/qpid/systest/rest/CompressedResponsesRestTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/systest/rest/CompressedResponsesRestTest.java b/systests/src/test/java/org/apache/qpid/systest/rest/CompressedResponsesRestTest.java
deleted file mode 100644
index 4388b1c..0000000
--- a/systests/src/test/java/org/apache/qpid/systest/rest/CompressedResponsesRestTest.java
+++ /dev/null
@@ -1,138 +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.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-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 org.apache.qpid.server.model.Plugin;
-import org.apache.qpid.test.utils.TestBrokerConfiguration;
-
-public class CompressedResponsesRestTest extends QpidRestTestCase
-{
- @Override
- public void startDefaultBroker() throws Exception
- {
- // noop
- }
-
- @Override
- protected void customizeConfiguration() throws Exception
- {
- // noop
- }
-
- public void testCompressionOffAcceptOff() throws Exception
- {
- doCompressionTest(false, false);
- }
-
- public void testCompressionOffAcceptOn() throws Exception
- {
- doCompressionTest(false, true);
- }
-
- public void testCompressionOnAcceptOff() throws Exception
- {
- doCompressionTest(true, false);
- }
-
- public void testCompressionOnAcceptOn() throws Exception
- {
- doCompressionTest(true, true);
-
- }
-
- private void doCompressionTest(final boolean allowCompression,
- final boolean acceptCompressed) throws Exception
- {
- final boolean expectCompression = allowCompression && acceptCompressed;
- super.customizeConfiguration();
- getDefaultBrokerConfiguration().setObjectAttribute(Plugin.class,
- TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT,
- "compressResponses",
- expectCompression);
- super.startDefaultBroker();
-
- HttpURLConnection conn = getRestTestHelper().openManagementConnection("/service/metadata", "GET");
- 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);
- }
- }
-
- ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream();
-
- InputStream connectionInputStream = conn.getInputStream();
- byte[] buf = new byte[1024];
- int read;
- while((read = connectionInputStream.read(buf))!= -1)
- {
- contentBuffer.write(buf,0,read);
- }
-
- InputStream jsonStream;
-
- if(expectCompression)
- {
- jsonStream = new GZIPInputStream(new ByteArrayInputStream(contentBuffer.toByteArray()));
- }
- else
- {
- jsonStream = new ByteArrayInputStream(contentBuffer.toByteArray());
- }
-
- ObjectMapper mapper = new ObjectMapper();
- try
- {
- mapper.readValue(jsonStream, LinkedHashMap.class);
- }
- catch (JsonParseException | JsonMappingException e)
- {
- fail("Message was not in correct format");
- }
- }
-
-
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org