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

Binary file not shown.

View File

@ -10,12 +10,12 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class JedisTest { public class JedisIntegrationTest {
private Jedis jedis; private Jedis jedis;
private static RedisServer redisServer; private static RedisServer redisServer;
public JedisTest() { public JedisIntegrationTest() {
jedis = new Jedis(); jedis = new Jedis();
} }

View File

@ -14,7 +14,7 @@ import java.io.IOException;
/** /**
* Created by johnson on 3/9/17. * Created by johnson on 3/9/17.
*/ */
public class RedissonConfigurationTest { public class RedissonConfigurationIntegrationTest {
private static RedisServer redisServer; private static RedisServer redisServer;
private static RedissonClient client; private static RedissonClient client;

View File

@ -22,7 +22,7 @@ import java.util.stream.StreamSupport;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class RedissonTest { public class RedissonIntegrationTest {
private static RedisServer redisServer; private static RedisServer redisServer;
private static RedissonClient client; private static RedissonClient client;

View File

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

View File

@ -2,10 +2,11 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>MyStrutsApp</artifactId> <artifactId>struts</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>struts</name> <name>struts</name>
<build> <build>
<sourceDirectory>src/main/java</sourceDirectory> <sourceDirectory>src/main/java</sourceDirectory>
<resources> <resources>
@ -13,6 +14,7 @@
<directory>src/main/resources</directory> <directory>src/main/resources</directory>
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>