BAEL-542 wrote live tests

This commit is contained in:
Tomasz Lelek
2017-01-26 20:34:40 +01:00
committed by Andrew Morgan
parent 25111c5b89
commit c3cc42f458
3 changed files with 93 additions and 0 deletions

View File

@@ -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");
}
}

View File

@@ -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 {
}