BAEL-542 wrote live tests
This commit is contained in:
parent
25111c5b89
commit
c3cc42f458
@ -40,10 +40,45 @@
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${javax.servlet-api.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jayway.restassured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>${rest-assured.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user