-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for @Cache and @nocache in RESTEasy Reactive
- Loading branch information
Showing
11 changed files
with
473 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../test/java/io/quarkus/resteasy/reactive/server/test/cache/CacheOnClassAndMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.resteasy.reactive.server.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.Cache; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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 CacheOnClassAndMethodsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ResourceWithCache.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testWith() { | ||
RestAssured.get("/test/with") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("with")) | ||
.header("Cache-Control", "no-store"); | ||
} | ||
|
||
@Test | ||
public void testWithout() { | ||
RestAssured.get("/test/without") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("without")) | ||
.header("Cache-Control", "no-cache, no-transform, proxy-revalidate, s-maxage=100"); | ||
} | ||
|
||
@Path("test") | ||
@Cache(sMaxAge = 100, noTransform = true, proxyRevalidate = true, noCache = true) | ||
public static class ResourceWithCache { | ||
|
||
@Path("with") | ||
@Cache(noStore = true) | ||
@GET | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Path("without") | ||
@GET | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ment/src/test/java/io/quarkus/resteasy/reactive/server/test/cache/CacheOnMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.resteasy.reactive.server.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.Cache; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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 CacheOnMethodsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest().setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class).addClasses(ResourceWithCache.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testWith() { | ||
RestAssured.get("/test/with") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("with")) | ||
.header("Cache-Control", "must-revalidate, no-store, max-age=100, private"); | ||
} | ||
|
||
@Test | ||
public void testWithout() { | ||
RestAssured.get("/test/without") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("without")) | ||
.header("Cache-Control", nullValue()); | ||
} | ||
|
||
@Path("test") | ||
public static class ResourceWithCache { | ||
|
||
@Path("with") | ||
@GET | ||
@Cache(maxAge = 100, noStore = true, mustRevalidate = true, isPrivate = true) | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Path("without") | ||
@GET | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...est/java/io/quarkus/resteasy/reactive/server/test/cache/NoCacheOnClassAndMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.resteasy.reactive.server.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.NoCache; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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 NoCacheOnClassAndMethodsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ResourceWithNoCache.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testWith() { | ||
RestAssured.get("/test/with") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("with")) | ||
.header("Cache-Control", "no-cache=\"f1\", no-cache=\"f2\""); | ||
} | ||
|
||
@Test | ||
public void testWithout() { | ||
RestAssured.get("/test/without") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("without")) | ||
.header("Cache-Control", "no-cache=\"f1\""); | ||
} | ||
|
||
@NoCache(fields = "f1") | ||
@Path("test") | ||
public static class ResourceWithNoCache { | ||
|
||
@Path("with") | ||
@GET | ||
@NoCache(fields = { "f1", "f2" }) | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Path("without") | ||
@GET | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...nt/src/test/java/io/quarkus/resteasy/reactive/server/test/cache/NoCacheOnMethodsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.resteasy.reactive.server.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.NoCache; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
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 NoCacheOnMethodsTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(new Supplier<JavaArchive>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ResourceWithNoCache.class); | ||
} | ||
}); | ||
|
||
@Test | ||
public void testWith() { | ||
RestAssured.get("/test/with") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("with")) | ||
.header("Cache-Control", "no-cache=\"f1\", no-cache=\"f2\""); | ||
} | ||
|
||
@Test | ||
public void testWithout() { | ||
RestAssured.get("/test/without") | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("without")) | ||
.header("Cache-Control", nullValue()); | ||
} | ||
|
||
@Path("test") | ||
public static class ResourceWithNoCache { | ||
|
||
@Path("with") | ||
@GET | ||
@NoCache(fields = { "f1", "f2" }) | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Path("without") | ||
@GET | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...cts/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/Cache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.jboss.resteasy.reactive; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Cache { | ||
|
||
int maxAge() default -1; | ||
|
||
int sMaxAge() default -1; | ||
|
||
boolean noStore() default false; | ||
|
||
boolean noTransform() default false; | ||
|
||
boolean mustRevalidate() default false; | ||
|
||
boolean proxyRevalidate() default false; | ||
|
||
boolean isPrivate() default false; | ||
|
||
boolean noCache() default false; | ||
} |
13 changes: 13 additions & 0 deletions
13
...s/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/NoCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jboss.resteasy.reactive; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface NoCache { | ||
|
||
String[] fields() default {}; | ||
} |
Oops, something went wrong.