-
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.
Honor Cache and NoCache annotations on implementations of a JaxRS int…
…erface
- Loading branch information
1 parent
11d6830
commit 7bbc170
Showing
10 changed files
with
840 additions
and
10 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
84 changes: 84 additions & 0 deletions
84
...s/resteasy/reactive/server/vertx/test/cache/CacheOnClassAndMethodsImplementationTest.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,84 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.Cache; | ||
import org.jboss.resteasy.reactive.server.processor.ResteasyReactiveDeploymentManager; | ||
import org.jboss.resteasy.reactive.server.processor.scanning.CacheControlScanner; | ||
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; | ||
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.restassured.RestAssured; | ||
|
||
public class CacheOnClassAndMethodsImplementationTest { | ||
|
||
@RegisterExtension | ||
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() | ||
.addScanCustomizer(new Consumer<ResteasyReactiveDeploymentManager.ScanStep>() { | ||
@Override | ||
public void accept(ResteasyReactiveDeploymentManager.ScanStep scanStep) { | ||
scanStep.addMethodScanner(new CacheControlScanner()); | ||
} | ||
}) | ||
.setArchiveProducer(new Supplier<>() { | ||
@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") | ||
public interface IResourceWithCache { | ||
|
||
@Path("with") | ||
@GET | ||
String with(); | ||
|
||
@Path("without") | ||
@GET | ||
String without(); | ||
} | ||
|
||
@Cache(sMaxAge = 100, noTransform = true, proxyRevalidate = true, noCache = true) | ||
public static class ResourceWithCache implements IResourceWithCache { | ||
|
||
@Override | ||
@Cache(noStore = true) | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Override | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
.../jboss/resteasy/reactive/server/vertx/test/cache/CacheOnClassAndMethodsInterfaceTest.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,84 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.Cache; | ||
import org.jboss.resteasy.reactive.server.processor.ResteasyReactiveDeploymentManager; | ||
import org.jboss.resteasy.reactive.server.processor.scanning.CacheControlScanner; | ||
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; | ||
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.restassured.RestAssured; | ||
|
||
public class CacheOnClassAndMethodsInterfaceTest { | ||
|
||
@RegisterExtension | ||
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() | ||
.addScanCustomizer(new Consumer<ResteasyReactiveDeploymentManager.ScanStep>() { | ||
@Override | ||
public void accept(ResteasyReactiveDeploymentManager.ScanStep scanStep) { | ||
scanStep.addMethodScanner(new CacheControlScanner()); | ||
} | ||
}) | ||
.setArchiveProducer(new Supplier<>() { | ||
@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 interface IResourceWithCache { | ||
|
||
@Path("with") | ||
@Cache(noStore = true) | ||
@GET | ||
String with(); | ||
|
||
@Path("without") | ||
@GET | ||
String without(); | ||
} | ||
|
||
public static class ResourceWithCache implements IResourceWithCache { | ||
|
||
@Override | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Override | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...org/jboss/resteasy/reactive/server/vertx/test/cache/CacheOnMethodsImplementationTest.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,84 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.cache; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.Cache; | ||
import org.jboss.resteasy.reactive.server.processor.ResteasyReactiveDeploymentManager; | ||
import org.jboss.resteasy.reactive.server.processor.scanning.CacheControlScanner; | ||
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; | ||
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.restassured.RestAssured; | ||
|
||
public class CacheOnMethodsImplementationTest { | ||
|
||
@RegisterExtension | ||
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() | ||
.addScanCustomizer(new Consumer<ResteasyReactiveDeploymentManager.ScanStep>() { | ||
@Override | ||
public void accept(ResteasyReactiveDeploymentManager.ScanStep scanStep) { | ||
scanStep.addMethodScanner(new CacheControlScanner()); | ||
} | ||
}) | ||
.setArchiveProducer(new Supplier<>() { | ||
@Override | ||
public JavaArchive get() { | ||
return ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(IResourceWithCache.class, 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 interface IResourceWithCache { | ||
|
||
@Path("with") | ||
@GET | ||
String with(); | ||
|
||
@Path("without") | ||
@GET | ||
String without(); | ||
} | ||
|
||
public static class ResourceWithCache implements IResourceWithCache { | ||
|
||
@Override | ||
@Cache(maxAge = 100, noStore = true, mustRevalidate = true, isPrivate = true) | ||
public String with() { | ||
return "with"; | ||
} | ||
|
||
@Override | ||
public String without() { | ||
return "without"; | ||
} | ||
} | ||
} |
Oops, something went wrong.