-
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 CDI bean implementations of a …
…JaxRS interface
- Loading branch information
1 parent
4dd779e
commit a4559fe
Showing
10 changed files
with
823 additions
and
8 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
82 changes: 82 additions & 0 deletions
82
...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,82 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.cache; | ||
|
||
import io.restassured.RestAssured; | ||
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 java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
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"; | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../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,82 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.cache; | ||
|
||
import io.restassured.RestAssured; | ||
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 java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
|
||
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"; | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...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,82 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.cache; | ||
|
||
import io.restassured.RestAssured; | ||
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 java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
|
||
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.