|
1 | 1 | package com.baeldung.cachecontrol; |
2 | 2 |
|
3 | | -import com.jayway.restassured.http.ContentType; |
| 3 | +import static com.jayway.restassured.RestAssured.given; |
| 4 | + |
4 | 5 | import org.junit.Test; |
5 | 6 | import org.junit.runner.RunWith; |
6 | 7 | import org.springframework.boot.context.embedded.LocalServerPort; |
7 | 8 | import org.springframework.boot.test.context.SpringBootTest; |
8 | 9 | import org.springframework.test.context.junit4.SpringRunner; |
9 | 10 |
|
10 | | -import static com.jayway.restassured.RestAssured.given; |
| 11 | +import com.jayway.restassured.http.ContentType; |
11 | 12 |
|
12 | 13 | @RunWith(SpringRunner.class) |
13 | 14 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = AppRunner.class) |
14 | | -public class ResourceEndpointTest { |
| 15 | +public class ResourceEndpointIntegrationTest { |
15 | 16 |
|
16 | 17 | @LocalServerPort |
17 | 18 | private int serverPort; |
18 | 19 |
|
19 | 20 | @Test |
20 | 21 | public void whenGetRequestForUser_shouldRespondWithDefaultCacheHeaders() { |
21 | | - given() |
22 | | - .when() |
23 | | - .get(getBaseUrl() + "/default/users/Michael") |
24 | | - .then() |
25 | | - .headers("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate") |
26 | | - .header("Pragma", "no-cache"); |
| 22 | + given().when().get(getBaseUrl() + "/default/users/Michael").then().headers("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate").header("Pragma", "no-cache"); |
27 | 23 | } |
28 | 24 |
|
29 | 25 | @Test |
30 | 26 | public void whenGetRequestForUser_shouldRespondMaxAgeCacheControl() { |
31 | | - given() |
32 | | - .when() |
33 | | - .get(getBaseUrl() + "/users/Michael") |
34 | | - .then() |
35 | | - .header("Cache-Control", "max-age=60"); |
| 27 | + given().when().get(getBaseUrl() + "/users/Michael").then().header("Cache-Control", "max-age=60"); |
36 | 28 | } |
37 | 29 |
|
38 | 30 | @Test |
39 | 31 | public void givenServiceEndpoint_whenGetRequestForUser_shouldResponseWithCacheControlMaxAge() { |
40 | | - given() |
41 | | - .when() |
42 | | - .get(getBaseUrl() + "/users/Michael") |
43 | | - .then() |
44 | | - .contentType(ContentType.JSON).and().statusCode(200).and() |
45 | | - .header("Cache-Control", "max-age=60"); |
| 32 | + given().when().get(getBaseUrl() + "/users/Michael").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "max-age=60"); |
46 | 33 | } |
47 | 34 |
|
48 | 35 | @Test |
49 | 36 | public void givenServiceEndpoint_whenGetRequestForNotCacheableContent_shouldResponseWithCacheControlNoCache() { |
50 | | - given() |
51 | | - .when() |
52 | | - .get(getBaseUrl() + "/timestamp") |
53 | | - .then() |
54 | | - .contentType(ContentType.JSON).and().statusCode(200).and() |
55 | | - .header("Cache-Control", "no-store"); |
| 37 | + given().when().get(getBaseUrl() + "/timestamp").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "no-store"); |
56 | 38 | } |
57 | 39 |
|
58 | 40 | @Test |
59 | 41 | public void givenServiceEndpoint_whenGetRequestForPrivateUser_shouldResponseWithSecurityDefaultCacheControl() { |
60 | | - given() |
61 | | - .when() |
62 | | - .get(getBaseUrl() + "/private/users/Michael") |
63 | | - .then() |
64 | | - .contentType(ContentType.JSON).and().statusCode(200).and() |
65 | | - .header("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); |
| 42 | + given().when().get(getBaseUrl() + "/private/users/Michael").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"); |
66 | 43 | } |
67 | 44 |
|
68 | 45 | private String getBaseUrl() { |
|
0 commit comments