testing cleanup

This commit is contained in:
eugenp
2017-03-11 23:31:41 +02:00
parent 84c71b3dbf
commit e8faa73d74
6 changed files with 16 additions and 37 deletions

View File

@@ -1,68 +1,45 @@
package com.baeldung.cachecontrol;
import com.jayway.restassured.http.ContentType;
import static com.jayway.restassured.RestAssured.given;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static com.jayway.restassured.RestAssured.given;
import com.jayway.restassured.http.ContentType;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = AppRunner.class)
public class ResourceEndpointTest {
public class ResourceEndpointIntegrationTest {
@LocalServerPort
private int serverPort;
@Test
public void whenGetRequestForUser_shouldRespondWithDefaultCacheHeaders() {
given()
.when()
.get(getBaseUrl() + "/default/users/Michael")
.then()
.headers("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate")
.header("Pragma", "no-cache");
given().when().get(getBaseUrl() + "/default/users/Michael").then().headers("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate").header("Pragma", "no-cache");
}
@Test
public void whenGetRequestForUser_shouldRespondMaxAgeCacheControl() {
given()
.when()
.get(getBaseUrl() + "/users/Michael")
.then()
.header("Cache-Control", "max-age=60");
given().when().get(getBaseUrl() + "/users/Michael").then().header("Cache-Control", "max-age=60");
}
@Test
public void givenServiceEndpoint_whenGetRequestForUser_shouldResponseWithCacheControlMaxAge() {
given()
.when()
.get(getBaseUrl() + "/users/Michael")
.then()
.contentType(ContentType.JSON).and().statusCode(200).and()
.header("Cache-Control", "max-age=60");
given().when().get(getBaseUrl() + "/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(getBaseUrl() + "/timestamp")
.then()
.contentType(ContentType.JSON).and().statusCode(200).and()
.header("Cache-Control", "no-store");
given().when().get(getBaseUrl() + "/timestamp").then().contentType(ContentType.JSON).and().statusCode(200).and().header("Cache-Control", "no-store");
}
@Test
public void givenServiceEndpoint_whenGetRequestForPrivateUser_shouldResponseWithSecurityDefaultCacheControl() {
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");
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");
}
private String getBaseUrl() {