Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Test gzip support in RESTEasy Reactive #16924

Closed
wants to merge 9 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.resteasy.reactive.server.test.GZip;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface DisableCompression {
// set default value of Transfer-Encoding as identity
// String TransferEncoding() default "identity";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.quarkus.resteasy.reactive.server.test.GZip;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.function.Supplier;

import javax.imageio.ImageIO;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class GZipTest {

private static final String APP_PROPS = "" +
"quarkus.http.enable-compression=true\n";

static long imageSize;
static String longString;
static File imageForTest;
static {

StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1000; ++i) {
sb.append("Hello RESTEasy Reactive;");
}
longString = sb.toString();
}

@RegisterExtension
static final QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addAsResource(new StringAsset(APP_PROPS), "application.properties")
.addClasses(TestCompression.class);
}
});

@Test
public void testServerCompression() throws Exception {

RestAssured.given().get("/test/compression").then().statusCode(200)
.header("content-encoding", "gzip")
.header("content-length", Matchers.not(Matchers.equalTo(Integer.toString(longString.length()))))
.body(Matchers.equalTo(longString));

RestAssured.given().get("/test/nocompression").then().statusCode(200)
.header("content-encoding", "identity")
.header("content-length", Matchers.equalTo(imageSize))
.body(Matchers.equalTo(imageForTest));
}

@Path("/test")
public static class TestCompression {

@Path("/compression")
@GET
public String registerCompression() {
return longString;
}

@Path("/nocompression")
@GET
@DisableCompression
public File registerNoCompression() throws IOException {
imageForTest = new File("src/test/resources/imageForTest.png");
imageSize = imageForTest.length();
return imageForTest;
}
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.