diff --git a/README.md b/README.md
index ba00b011d..1bd0503dd 100644
--- a/README.md
+++ b/README.md
@@ -613,3 +613,13 @@ It covers different usages:
2. from a request scoped service
3. from a blocking endpoint
4. from a reactive endpoint
+
+### `cache/spring`
+
+Verifies the `quarkus-spring-cache` extension using `@Cacheable`, `@CacheEvict` and `@CachePut`.
+It covers different usages:
+1. from an application scoped service
+2. from a request scoped service
+3. from a REST controller endpoint (using `@RestController)
+
+More information about this extension in https://quarkus.io/guides/spring-cache.
\ No newline at end of file
diff --git a/cache/caffeine/src/test/java/io/quarkus/ts/cache/caffeine/cache/caffeine/ServiceWithCacheResourceIT.java b/cache/caffeine/src/test/java/io/quarkus/ts/cache/caffeine/cache/caffeine/ServiceWithCacheResourceIT.java
index 1b4ca3bb5..3c34efc66 100644
--- a/cache/caffeine/src/test/java/io/quarkus/ts/cache/caffeine/cache/caffeine/ServiceWithCacheResourceIT.java
+++ b/cache/caffeine/src/test/java/io/quarkus/ts/cache/caffeine/cache/caffeine/ServiceWithCacheResourceIT.java
@@ -20,6 +20,9 @@ public class ServiceWithCacheResourceIT {
private static final String RESOURCE_BLOCKING_API_PATH = "/api/blocking";
private static final String RESOURCE_REACTIVE_API_PATH = "/api/reactive";
+ private static final String PREFIX_ONE = "prefix1";
+ private static final String PREFIX_TWO = "prefix2";
+
/**
* Check whether the `@CacheResult` annotation works when used in a service.
*/
@@ -59,13 +62,13 @@ public void shouldGetDifferentValueWhenInvalidateCacheFromPath(String path) {
RESOURCE_REACTIVE_API_PATH })
public void shouldGetTheSameValueForSamePrefixesWhenGettingValueFromPath(String path) {
// We call the service endpoint
- String value = getValueFromPathUsingPrefix(path, "prefix1");
+ String value = getValueFromPathUsingPrefix(path, PREFIX_ONE);
// At this point, the cache is populated and we should get the same value from the cache
- assertEquals(value, getValueFromPathUsingPrefix(path, "prefix1"),
+ assertEquals(value, getValueFromPathUsingPrefix(path, PREFIX_ONE),
"Value was different which means cache is not working");
// But different value using another prefix
- assertNotEquals(value, getValueFromPathUsingPrefix(path, "prefix2"),
+ assertNotEquals(value, getValueFromPathUsingPrefix(path, PREFIX_TWO),
"Value was equal which means @CacheKey didn't work");
}
@@ -77,16 +80,15 @@ public void shouldGetTheSameValueForSamePrefixesWhenGettingValueFromPath(String
RESOURCE_REACTIVE_API_PATH })
public void shouldGetTheSameValuesEvenAfterCallingToCacheInvalidateFromPath(String path) {
// We call the service endpoints
- String valueOfPrefix1 = getValueFromPathUsingPrefix(path, "prefix1");
- String valueOfPrefix2 = getValueFromPathUsingPrefix(path, "prefix2");
+ String valueOfPrefix1 = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+ String valueOfPrefix2 = getValueFromPathUsingPrefix(path, PREFIX_TWO);
// invalidate the cache: this should not invalidate all the keys
invalidateCacheFromPath(path);
- // At this point, the cache is populated and we should get the same value from the cache
- assertEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, "prefix1"));
- // But different value using another prefix
- assertEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, "prefix2"));
+ // At this point, the cache is populated and we should get the same value for both prefixes
+ assertEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, PREFIX_ONE));
+ assertEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, PREFIX_TWO));
}
/**
@@ -97,16 +99,16 @@ public void shouldGetTheSameValuesEvenAfterCallingToCacheInvalidateFromPath(Stri
RESOURCE_REACTIVE_API_PATH })
public void shouldGetDifferentValueWhenInvalidateCacheOnlyForOnePrefixFromPath(String path) {
// We call the service endpoints
- String valueOfPrefix1 = getValueFromPathUsingPrefix(path, "prefix1");
- String valueOfPrefix2 = getValueFromPathUsingPrefix(path, "prefix2");
+ String valueOfPrefix1 = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+ String valueOfPrefix2 = getValueFromPathUsingPrefix(path, PREFIX_TWO);
// invalidate the cache: this should not invalidate all the keys
- invalidateCacheWithPrefixFromPath(path, "prefix1");
+ invalidateCacheWithPrefixFromPath(path, PREFIX_ONE);
// The cache was invalidated only for prefix1, so the value should be different
- assertNotEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, "prefix1"));
+ assertNotEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, PREFIX_ONE));
// The cache was not invalidated for prefix2, so the value should be the same
- assertEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, "prefix2"));
+ assertEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, PREFIX_TWO));
}
/**
@@ -118,16 +120,16 @@ public void shouldGetDifferentValueWhenInvalidateCacheOnlyForOnePrefixFromPath(S
public void shouldGetDifferentValueWhenInvalidateAllTheCacheFromPath(String path) {
// We call the service endpoints
String value = getFromPath(path);
- String valueOfPrefix1 = getValueFromPathUsingPrefix(path, "prefix1");
- String valueOfPrefix2 = getValueFromPathUsingPrefix(path, "prefix2");
+ String valueOfPrefix1 = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+ String valueOfPrefix2 = getValueFromPathUsingPrefix(path, PREFIX_TWO);
// invalidate all the cache
invalidateCacheAllFromPath(path);
// Then, all the values should be different:
assertNotEquals(value, getFromPath(path));
- assertNotEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, "prefix1"));
- assertNotEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, "prefix2"));
+ assertNotEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, PREFIX_ONE));
+ assertNotEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, PREFIX_TWO));
}
private void invalidateCacheAllFromPath(String path) {
diff --git a/cache/spring/pom.xml b/cache/spring/pom.xml
new file mode 100644
index 000000000..825a1aea8
--- /dev/null
+++ b/cache/spring/pom.xml
@@ -0,0 +1,23 @@
+
+
+ 4.0.0
+
+ io.quarkus.ts.qe
+ parent
+ 1.0.0-SNAPSHOT
+ ../..
+
+ cache-spring
+ jar
+ Quarkus QE TS: Cache: Spring
+
+
+ io.quarkus
+ quarkus-spring-cache
+
+
+ io.quarkus
+ quarkus-spring-web
+
+
+
diff --git a/cache/spring/src/main/java/io/quarkus/ts/cache/spring/ApplicationScopeService.java b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/ApplicationScopeService.java
new file mode 100644
index 000000000..36bf9d27b
--- /dev/null
+++ b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/ApplicationScopeService.java
@@ -0,0 +1,7 @@
+package io.quarkus.ts.cache.spring;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class ApplicationScopeService extends BaseServiceWithCache {
+}
diff --git a/cache/spring/src/main/java/io/quarkus/ts/cache/spring/BaseServiceWithCache.java b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/BaseServiceWithCache.java
new file mode 100644
index 000000000..bd34ba044
--- /dev/null
+++ b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/BaseServiceWithCache.java
@@ -0,0 +1,48 @@
+package io.quarkus.ts.cache.spring;
+
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+
+public abstract class BaseServiceWithCache {
+
+ public static final String DEFAULT_CACHE_VALUE = "reset";
+ private static final String CACHE_NAME = "service-cache";
+
+ private static int counter = 0;
+
+ @Cacheable(CACHE_NAME)
+ public String getValue() {
+ return "Value: " + counter++;
+ }
+
+ @CacheEvict(CACHE_NAME)
+ public void invalidate() {
+ // do nothing
+ }
+
+ @Cacheable(CACHE_NAME)
+ public String getValueWithPrefix(String prefix) {
+ return prefix + ": " + counter++;
+ }
+
+ @CacheEvict(CACHE_NAME)
+ public void invalidateWithPrefix(String prefix) {
+ // do nothing
+ }
+
+ @CacheEvict(value = CACHE_NAME, allEntries = true)
+ public void invalidateAll() {
+ // do nothing
+ }
+
+ @CachePut(CACHE_NAME)
+ public String resetCache() {
+ return DEFAULT_CACHE_VALUE;
+ }
+
+ @CachePut(CACHE_NAME)
+ public String resetCacheWithPrefix(String prefix) {
+ return DEFAULT_CACHE_VALUE;
+ }
+}
diff --git a/cache/spring/src/main/java/io/quarkus/ts/cache/spring/RequestScopeService.java b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/RequestScopeService.java
new file mode 100644
index 000000000..567797cdb
--- /dev/null
+++ b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/RequestScopeService.java
@@ -0,0 +1,9 @@
+package io.quarkus.ts.cache.spring;
+
+import org.springframework.stereotype.Service;
+import org.springframework.web.context.annotation.RequestScope;
+
+@Service
+@RequestScope
+public class RequestScopeService extends BaseServiceWithCache {
+}
diff --git a/cache/spring/src/main/java/io/quarkus/ts/cache/spring/RestControllerWithCacheResource.java b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/RestControllerWithCacheResource.java
new file mode 100644
index 000000000..de875449d
--- /dev/null
+++ b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/RestControllerWithCacheResource.java
@@ -0,0 +1,61 @@
+package io.quarkus.ts.cache.spring;
+
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/api")
+public class RestControllerWithCacheResource {
+
+ private static final String CACHE_NAME = "api-cache";
+
+ private static int counter = 0;
+
+ @GetMapping
+ @Cacheable(CACHE_NAME)
+ public String getValue() {
+ return "Value: " + counter++;
+ }
+
+ @PostMapping("/invalidate-cache")
+ @CacheEvict(CACHE_NAME)
+ public void invalidate() {
+ // do nothing
+ }
+
+ @PostMapping("/cache/reset")
+ @CachePut(CACHE_NAME)
+ public String resetValueInCache() {
+ return BaseServiceWithCache.DEFAULT_CACHE_VALUE;
+ }
+
+ @GetMapping("/using-prefix/{prefix}")
+ @Cacheable(CACHE_NAME)
+ public String getValueWithPrefix(@PathVariable("prefix") String prefix) {
+ return prefix + ": " + counter++;
+ }
+
+ @PostMapping("/using-prefix/{prefix}/invalidate-cache")
+ @CacheEvict(CACHE_NAME)
+ public void invalidateWithPrefix(@PathVariable("prefix") String prefix) {
+ // do nothing
+ }
+
+ @PostMapping("/using-prefix/{prefix}/cache/reset")
+ @CachePut(CACHE_NAME)
+ public String resetValueInCacheWithPrefix(@PathVariable("prefix") String prefix) {
+ return BaseServiceWithCache.DEFAULT_CACHE_VALUE;
+ }
+
+ @PostMapping("/invalidate-cache-all")
+ @CacheEvict(value = CACHE_NAME, allEntries = true)
+ public void invalidateAll() {
+ // do nothing
+ }
+}
diff --git a/cache/spring/src/main/java/io/quarkus/ts/cache/spring/ServiceWithCacheResource.java b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/ServiceWithCacheResource.java
new file mode 100644
index 000000000..8c429f7d4
--- /dev/null
+++ b/cache/spring/src/main/java/io/quarkus/ts/cache/spring/ServiceWithCacheResource.java
@@ -0,0 +1,70 @@
+package io.quarkus.ts.cache.spring;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/services")
+public class ServiceWithCacheResource {
+
+ public static final String APPLICATION_SCOPE_SERVICE_PATH = "application-scope";
+ public static final String REQUEST_SCOPE_SERVICE_PATH = "request-scope";
+
+ @Autowired
+ ApplicationScopeService applicationScopeService;
+
+ @Autowired
+ RequestScopeService requestScopeService;
+
+ @GetMapping("/{service}")
+ public String getValueFromService(@PathVariable("service") String service) {
+ return lookupServiceByPathParam(service).getValue();
+ }
+
+ @PostMapping("/{service}/cache/reset")
+ public String resetCacheFromService(@PathVariable("service") String service) {
+ return lookupServiceByPathParam(service).resetCache();
+ }
+
+ @PostMapping("/{service}/invalidate-cache")
+ public void invalidateCacheFromService(@PathVariable("service") String service) {
+ lookupServiceByPathParam(service).invalidate();
+ }
+
+ @PostMapping("/{service}/invalidate-cache-all")
+ public void invalidateCacheAllFromService(@PathVariable("service") String service) {
+ lookupServiceByPathParam(service).invalidateAll();
+ }
+
+ @GetMapping("/{service}/using-prefix/{prefix}")
+ public String getValueUsingPrefixFromService(@PathVariable("service") String service,
+ @PathVariable("prefix") String prefix) {
+ return lookupServiceByPathParam(service).getValueWithPrefix(prefix);
+ }
+
+ @PostMapping("/{service}/using-prefix/{prefix}/invalidate-cache")
+ public void invalidateCacheUsingPrefixFromService(@PathVariable("service") String service,
+ @PathVariable("prefix") String prefix) {
+ lookupServiceByPathParam(service).invalidateWithPrefix(prefix);
+ }
+
+ @PostMapping("/{service}/using-prefix/{prefix}/cache/reset")
+ public String resetCacheUsingPrefixFromService(@PathVariable("service") String service,
+ @PathVariable("prefix") String prefix) {
+ return lookupServiceByPathParam(service).resetCacheWithPrefix(prefix);
+ }
+
+ private BaseServiceWithCache lookupServiceByPathParam(String service) {
+ if (APPLICATION_SCOPE_SERVICE_PATH.equals(service)) {
+ return applicationScopeService;
+ } else if (REQUEST_SCOPE_SERVICE_PATH.equals(service)) {
+ return requestScopeService;
+ }
+
+ throw new IllegalArgumentException("Service " + service + " is not recognised");
+ }
+}
diff --git a/cache/spring/src/main/resources/application.properties b/cache/spring/src/main/resources/application.properties
new file mode 100644
index 000000000..e69de29bb
diff --git a/cache/spring/src/test/java/io/quarkus/ts/cache/spring/OpenShiftServiceWithCacheResourceIT.java b/cache/spring/src/test/java/io/quarkus/ts/cache/spring/OpenShiftServiceWithCacheResourceIT.java
new file mode 100644
index 000000000..57376eb62
--- /dev/null
+++ b/cache/spring/src/test/java/io/quarkus/ts/cache/spring/OpenShiftServiceWithCacheResourceIT.java
@@ -0,0 +1,7 @@
+package io.quarkus.ts.cache.spring;
+
+import io.quarkus.test.scenarios.OpenShiftScenario;
+
+@OpenShiftScenario
+public class OpenShiftServiceWithCacheResourceIT extends ServiceWithCacheResourceIT {
+}
diff --git a/cache/spring/src/test/java/io/quarkus/ts/cache/spring/ServiceWithCacheResourceIT.java b/cache/spring/src/test/java/io/quarkus/ts/cache/spring/ServiceWithCacheResourceIT.java
new file mode 100644
index 000000000..4b3d82a8d
--- /dev/null
+++ b/cache/spring/src/test/java/io/quarkus/ts/cache/spring/ServiceWithCacheResourceIT.java
@@ -0,0 +1,190 @@
+package io.quarkus.ts.cache.spring;
+
+import static io.quarkus.ts.cache.spring.ServiceWithCacheResource.APPLICATION_SCOPE_SERVICE_PATH;
+import static io.quarkus.ts.cache.spring.ServiceWithCacheResource.REQUEST_SCOPE_SERVICE_PATH;
+import static io.restassured.RestAssured.given;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.apache.http.HttpStatus;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import io.quarkus.test.scenarios.QuarkusScenario;
+
+@QuarkusScenario
+public class ServiceWithCacheResourceIT {
+
+ private static final String SERVICE_APPLICATION_SCOPE_PATH = "/services/" + APPLICATION_SCOPE_SERVICE_PATH;
+ private static final String SERVICE_REQUEST_SCOPE_PATH = "/services/" + REQUEST_SCOPE_SERVICE_PATH;
+ private static final String REST_CONTROLLER_API_PATH = "/api";
+
+ private static final String PREFIX_ONE = "prefix1";
+ private static final String PREFIX_TWO = "prefix2";
+
+ /**
+ * Check whether the `@Cacheable` annotation works when used in a service.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldGetTheSameValueAlwaysWhenGettingValueFromPath(String path) {
+ // We call the service endpoint
+ String value = getFromPath(path);
+
+ // At this point, the cache is populated and we should get the same value from the cache
+ assertEquals(value, getFromPath(path), "Value was different which means cache is not working");
+ }
+
+ /**
+ * Check whether the `@CacheEvict` annotation invalidates the cache when used in a service.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldGetDifferentValueWhenInvalidateCacheFromPath(String path) {
+ // We call the service endpoint
+ String value = getFromPath(path);
+
+ // invalidate the cache
+ invalidateCacheFromPath(path);
+
+ // Then the value should be different as we have invalidated the cache.
+ assertNotEquals(value, getFromPath(path), "Value was equal which means cache invalidate didn't work");
+ }
+
+ /**
+ * Check whether the `@Cacheable` annotation works when used in a service.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldGetTheSameValueForSamePrefixesWhenGettingValueFromPath(String path) {
+ // We call the service endpoint
+ String value = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+
+ // At this point, the cache is populated and we should get the same value from the cache
+ assertEquals(value, getValueFromPathUsingPrefix(path, PREFIX_ONE),
+ "Value was different which means cache is not working");
+ // But different value using another prefix
+ assertNotEquals(value, getValueFromPathUsingPrefix(path, PREFIX_TWO),
+ "Value was equal which means @CacheKey didn't work");
+ }
+
+ /**
+ * Check whether the `@CacheEvict` annotation does not invalidate all the caches
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldGetTheSameValuesEvenAfterCallingToCacheInvalidateFromPath(String path) {
+ // We call the service endpoints
+ String valueOfPrefix1 = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+ String valueOfPrefix2 = getValueFromPathUsingPrefix(path, PREFIX_TWO);
+
+ // invalidate the cache: this should not invalidate all the keys
+ invalidateCacheFromPath(path);
+
+ // At this point, the cache is populated and we should get the same value for both prefixes
+ assertEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, PREFIX_ONE));
+ assertEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, PREFIX_TWO));
+ }
+
+ /**
+ * Check whether the `@CacheEvict` annotation work as expected using a key.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldGetDifferentValueWhenInvalidateCacheOnlyForOnePrefixFromPath(String path) {
+ // We call the service endpoints
+ String valueOfPrefix1 = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+ String valueOfPrefix2 = getValueFromPathUsingPrefix(path, PREFIX_TWO);
+
+ // invalidate the cache: this should not invalidate all the keys
+ invalidateCacheWithPrefixFromPath(path, PREFIX_ONE);
+
+ // The cache was invalidated only for prefix1, so the value should be different
+ assertNotEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, PREFIX_ONE));
+ // The cache was not invalidated for prefix2, so the value should be the same
+ assertEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, PREFIX_TWO));
+ }
+
+ /**
+ * Check whether the `@CacheEvict(allEntries=true)` annotation works as expected.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldGetDifferentValueWhenInvalidateAllTheCacheFromPath(String path) {
+ // We call the service endpoints
+ String value = getFromPath(path);
+ String valueOfPrefix1 = getValueFromPathUsingPrefix(path, PREFIX_ONE);
+ String valueOfPrefix2 = getValueFromPathUsingPrefix(path, PREFIX_TWO);
+
+ // invalidate all the cache
+ invalidateCacheAllFromPath(path);
+
+ // Then, all the values should be different:
+ assertNotEquals(value, getFromPath(path));
+ assertNotEquals(valueOfPrefix1, getValueFromPathUsingPrefix(path, PREFIX_ONE));
+ assertNotEquals(valueOfPrefix2, getValueFromPathUsingPrefix(path, PREFIX_TWO));
+ }
+
+ /**
+ * Check whether the `@CachePut` annotation works as expected.
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldPutAnEntryInCache(String path) {
+ // Overwrite value
+ resetValueInCache(path);
+
+ // Then, the value should be the one from the reset cache endpoint
+ assertEquals(BaseServiceWithCache.DEFAULT_CACHE_VALUE, getFromPath(path));
+ }
+
+ /**
+ * Check whether the `@CachePut` annotation works as expected using the prefix endpoints
+ */
+ @ParameterizedTest
+ @ValueSource(strings = { SERVICE_APPLICATION_SCOPE_PATH, SERVICE_REQUEST_SCOPE_PATH, REST_CONTROLLER_API_PATH })
+ public void shouldPutAnEntryUsingPrefixInCache(String path) {
+ // Overwrite value
+ resetValueInCacheFromPath(path, PREFIX_ONE);
+
+ // Then, the value should be the one from the put value endpoint
+ assertEquals(BaseServiceWithCache.DEFAULT_CACHE_VALUE, getValueFromPathUsingPrefix(path, PREFIX_ONE));
+ }
+
+ private void resetValueInCacheFromPath(String path, String prefix) {
+ resetValueInCache(path + "/using-prefix/" + prefix);
+ }
+
+ private void resetValueInCache(String path) {
+ postFromPath(path + "/cache/reset");
+ }
+
+ private void invalidateCacheAllFromPath(String path) {
+ postFromPath(path + "/invalidate-cache-all");
+ }
+
+ private void invalidateCacheWithPrefixFromPath(String path, String prefix) {
+ postFromPath(path + "/using-prefix/" + prefix + "/invalidate-cache");
+ }
+
+ private void invalidateCacheFromPath(String path) {
+ postFromPath(path + "/invalidate-cache");
+ }
+
+ private String getValueFromPathUsingPrefix(String path, String prefix) {
+ return getFromPath(path + "/using-prefix/" + prefix);
+ }
+
+ private String getFromPath(String path) {
+ return given()
+ .when().get(path)
+ .then()
+ .statusCode(HttpStatus.SC_OK)
+ .extract().asString();
+ }
+
+ private void postFromPath(String path) {
+ given().when().post(path);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 44d15ebf8..caae49f6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -94,6 +94,7 @@
spring/spring-web
logging/jboss
cache/caffeine
+ cache/spring