Replace GzipFilter and Tomcat compression with general purpose approach
Closes gh-3296
This commit is contained in:
@@ -16,16 +16,25 @@
|
||||
|
||||
package sample.tomcat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -33,6 +42,7 @@ import static org.junit.Assert.assertEquals;
|
||||
* Basic integration tests for demo application.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SampleTomcatApplication.class)
|
||||
@@ -51,4 +61,28 @@ public class SampleTomcatApplicationTests {
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompression() throws Exception {
|
||||
HttpHeaders requestHeaders = new HttpHeaders();
|
||||
requestHeaders.set("Accept-Encoding", "gzip");
|
||||
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
|
||||
|
||||
RestTemplate restTemplate = new TestRestTemplate();
|
||||
|
||||
ResponseEntity<byte[]> entity = restTemplate.exchange("http://localhost:"
|
||||
+ this.port, HttpMethod.GET, requestEntity, byte[].class);
|
||||
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
|
||||
GZIPInputStream inflater = new GZIPInputStream(new ByteArrayInputStream(
|
||||
entity.getBody()));
|
||||
try {
|
||||
assertEquals("Hello World",
|
||||
StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
|
||||
}
|
||||
finally {
|
||||
inflater.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user