Skip to content

Commit c3cc42f

Browse files
Tomasz Lelekmogronalol
authored andcommitted
BAEL-542 wrote live tests
1 parent 25111c5 commit c3cc42f

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎spring-security-cache-control/pom.xml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,45 @@
4040
<artifactId>javax.servlet-api</artifactId>
4141
<version>${javax.servlet-api.version}</version>
4242
</dependency>
43+
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.hamcrest</groupId>
52+
<artifactId>hamcrest-core</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.hamcrest</groupId>
57+
<artifactId>hamcrest-library</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.mockito</groupId>
63+
<artifactId>mockito-core</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.springframework</groupId>
69+
<artifactId>spring-test</artifactId>
70+
</dependency>
71+
72+
<dependency>
73+
<groupId>com.jayway.restassured</groupId>
74+
<artifactId>rest-assured</artifactId>
75+
<version>${rest-assured.version}</version>
76+
</dependency>
4377
</dependencies>
4478

4579
<properties>
4680
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
81+
<rest-assured.version>2.9.0</rest-assured.version>
4782
</properties>
4883

4984
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.baeldung.cachecontrol;
2+
3+
import com.jayway.restassured.http.ContentType;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.test.context.ContextConfiguration;
7+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
8+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
9+
10+
import static com.jayway.restassured.RestAssured.given;
11+
12+
@RunWith(SpringJUnit4ClassRunner.class)
13+
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
14+
public class ResourceEndpointTest {
15+
private static final String URL_PREFIX = "http://localhost:8080";
16+
17+
@Test
18+
public void givenServiceEndpoint_whenGetRequestForUser_shouldResponseWithCacheControlMaxAge() {
19+
given()
20+
.when()
21+
.get(URL_PREFIX + "/users/Michael")
22+
.then()
23+
.contentType(ContentType.JSON).and().statusCode(200).and()
24+
.header("Cache-Control", "max-age=60");
25+
}
26+
27+
@Test
28+
public void givenServiceEndpoint_whenGetRequestForNotCacheableContent_shouldResponseWithCacheControlNoCache() {
29+
given()
30+
.when()
31+
.get(URL_PREFIX + "/timestamp")
32+
.then()
33+
.contentType(ContentType.JSON).and().statusCode(200).and()
34+
.header("Cache-Control", "no-cache");
35+
}
36+
37+
@Test
38+
public void givenServiceEndpoint_whenGetRequestForPrivateUser_shouldResponseWithSecurityDefaultCacheControl() {
39+
given()
40+
.when()
41+
.get(URL_PREFIX + "/private/users/Michael")
42+
.then()
43+
.contentType(ContentType.JSON).and().statusCode(200).and()
44+
.header("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
45+
}
46+
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.cachecontrol;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
7+
@Configuration
8+
@ComponentScan({ "com.baeldung" })
9+
public class TestConfig {
10+
11+
}

0 commit comments

Comments
 (0)