diff --git a/spring-security-cache-control/pom.xml b/spring-security-cache-control/pom.xml
index 787804e3fe..1d154f333d 100644
--- a/spring-security-cache-control/pom.xml
+++ b/spring-security-cache-control/pom.xml
@@ -40,10 +40,45 @@
javax.servlet-api
${javax.servlet-api.version}
+
+
+ junit
+ junit
+ test
+
+
+
+ org.hamcrest
+ hamcrest-core
+ test
+
+
+ org.hamcrest
+ hamcrest-library
+ test
+
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+
+ org.springframework
+ spring-test
+
+
+
+ com.jayway.restassured
+ rest-assured
+ ${rest-assured.version}
+
3.1.0
+ 2.9.0
\ No newline at end of file
diff --git a/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointTest.java b/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointTest.java
new file mode 100644
index 0000000000..d0a15efb2b
--- /dev/null
+++ b/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointTest.java
@@ -0,0 +1,47 @@
+package com.baeldung.cachecontrol;
+
+import com.jayway.restassured.http.ContentType;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+
+import static com.jayway.restassured.RestAssured.given;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
+public class ResourceEndpointTest {
+ private static final String URL_PREFIX = "http://localhost:8080";
+
+ @Test
+ public void givenServiceEndpoint_whenGetRequestForUser_shouldResponseWithCacheControlMaxAge() {
+ given()
+ .when()
+ .get(URL_PREFIX + "/users/Michael")
+ .then()
+ .contentType(ContentType.JSON).and().statusCode(200).and()
+ .header("Cache-Control", "max-age=60");
+ }
+
+ @Test
+ public void givenServiceEndpoint_whenGetRequestForNotCacheableContent_shouldResponseWithCacheControlNoCache() {
+ given()
+ .when()
+ .get(URL_PREFIX + "/timestamp")
+ .then()
+ .contentType(ContentType.JSON).and().statusCode(200).and()
+ .header("Cache-Control", "no-cache");
+ }
+
+ @Test
+ public void givenServiceEndpoint_whenGetRequestForPrivateUser_shouldResponseWithSecurityDefaultCacheControl() {
+ given()
+ .when()
+ .get(URL_PREFIX + "/private/users/Michael")
+ .then()
+ .contentType(ContentType.JSON).and().statusCode(200).and()
+ .header("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
+ }
+
+}
\ No newline at end of file
diff --git a/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/TestConfig.java b/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/TestConfig.java
new file mode 100644
index 0000000000..af393f4b98
--- /dev/null
+++ b/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/TestConfig.java
@@ -0,0 +1,11 @@
+package com.baeldung.cachecontrol;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+
+@Configuration
+@ComponentScan({ "com.baeldung" })
+public class TestConfig {
+
+}