Use AssertJ in spring-boot-samples
See gh-5083
This commit is contained in:
@@ -27,7 +27,7 @@ import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for demo application.
|
||||
@@ -48,7 +48,7 @@ public class SampleActiveMqTests {
|
||||
public void sendSimpleMessage() throws InterruptedException, JMSException {
|
||||
this.producer.send("Test message");
|
||||
Thread.sleep(1000L);
|
||||
assertTrue(this.outputCapture.toString().contains("Test message"));
|
||||
assertThat(this.outputCapture.toString().contains("Test message")).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for service demo application.
|
||||
@@ -51,10 +51,10 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Daniel", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Daniel");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for service demo application.
|
||||
@@ -42,7 +42,7 @@ public class SampleActuatorNoWebApplicationTests {
|
||||
|
||||
@Test
|
||||
public void endpointsExist() throws Exception {
|
||||
assertNotNull(this.endpoint);
|
||||
assertThat(this.endpoint).isNotNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for separate management and main service ports.
|
||||
@@ -53,7 +53,7 @@ public class SampleActuatorUiApplicationPortTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,15 +61,15 @@ public class SampleActuatorUiApplicationPortTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("{\"status\":\"UP\"}", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -59,17 +58,16 @@ public class SampleActuatorUiApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
|
||||
entity.getBody().contains("<title>Hello"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("<title>Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +75,7 @@ public class SampleActuatorUiApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,13 +85,9 @@ public class SampleActuatorUiApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/error", HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("<html>"));
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("<body>"));
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody()
|
||||
.contains("Please contact the operator with the above information"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
assertThat(entity.getBody()).contains("<html>").contains("<body>")
|
||||
.contains("Please contact the operator with the above information");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for endpoints configuration.
|
||||
@@ -59,11 +58,11 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/oops", Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("None", body.get("error"));
|
||||
assertEquals(999, body.get("status"));
|
||||
assertThat(body.get("error")).isEqualTo("None");
|
||||
assertThat(body.get("status")).isEqualTo(999);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +70,9 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/admin/health",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
System.err.println(entity.getBody());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"hello\":\"world\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
assertThat(entity.getBody()).contains("\"hello\":\"world\"");
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for separate management and main service ports.
|
||||
@@ -61,10 +60,10 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +72,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,9 +80,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,9 +89,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/missing",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":404"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(entity.getBody()).contains("\"status\":404");
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -31,9 +31,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for insecured service endpoints (even with Spring Security on
|
||||
@@ -56,12 +54,11 @@ public class InsecureManagementSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error"));
|
||||
assertFalse("Wrong headers: " + entity.getHeaders(),
|
||||
entity.getHeaders().containsKey("Set-Cookie"));
|
||||
assertThat(body.get("error")).isEqualTo("Unauthorized");
|
||||
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,11 +72,10 @@ public class InsecureManagementSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertTrue("Wrong body: " + body,
|
||||
body.containsKey("counter.status.401.unmapped"));
|
||||
assertThat(body).containsKey("counter.status.401.unmapped");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for insecured service endpoints (even with Spring Security on
|
||||
@@ -53,12 +52,11 @@ public class InsecureSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertFalse("Wrong headers: " + entity.getHeaders(),
|
||||
entity.getHeaders().containsKey("Set-Cookie"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for separate management and main service ports.
|
||||
@@ -56,7 +55,7 @@ public class ManagementAddressActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,9 +63,8 @@ public class ManagementAddressActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for endpoints configuration.
|
||||
@@ -52,9 +50,8 @@ public class ManagementPathSampleActuatorApplicationTests {
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/admin/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,12 +59,11 @@ public class ManagementPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error"));
|
||||
assertFalse("Wrong headers: " + entity.getHeaders(),
|
||||
entity.getHeaders().containsKey("Set-Cookie"));
|
||||
assertThat(body.get("error")).isEqualTo("Unauthorized");
|
||||
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for separate management and main service ports.
|
||||
@@ -61,10 +60,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +72,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,9 +80,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/health",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,9 +90,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
.getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/admin/missing",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":404"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(entity.getBody()).contains("\"status\":404");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,10 +99,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/error", Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals(999, body.get("status"));
|
||||
assertThat(body.get("status")).isEqualTo(999);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,11 +110,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
// TODO: should be 500?
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals(999, body.get("status"));
|
||||
assertThat(body.get("status")).isEqualTo(999);
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for separate management and main service ports.
|
||||
@@ -60,10 +59,10 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,16 +71,15 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,10 +87,10 @@ public class ManagementPortSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.managementPort + "/error", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals(999, body.get("status"));
|
||||
assertThat(body.get("status")).isEqualTo(999);
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for switching off management endpoints.
|
||||
@@ -56,10 +56,10 @@ public class NoManagementSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public class NoManagementSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for /health with {@code endpoints.health.sensitive=false}.
|
||||
@@ -49,9 +48,8 @@ public class NonSensitiveHealthTests {
|
||||
public void testSecureHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertFalse("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"hello\":1"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).doesNotContain("\"hello\":1");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for service demo application.
|
||||
@@ -65,12 +62,11 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error"));
|
||||
assertFalse("Wrong headers: " + entity.getHeaders(),
|
||||
entity.getHeaders().containsKey("Set-Cookie"));
|
||||
assertThat(body.get("error")).isEqualTo("Unauthorized");
|
||||
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,16 +74,16 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/metrics/", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/metrics/foo", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/metrics.json", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,10 +91,10 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,10 +103,10 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertTrue("Wrong body: " + body, body.containsKey("counter.status.200.root"));
|
||||
assertThat(body).containsKey("counter.status.200.root");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,49 +114,45 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/env", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertTrue("Wrong body: " + body, body.containsKey("systemProperties"));
|
||||
assertThat(body).containsKey("systemProperties");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertFalse("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"hello\":\"1\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
assertThat(entity.getBody()).doesNotContain("\"hello\":\"1\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecureHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"hello\":1"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"hello\":1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInfo() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/info", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(), entity.getBody()
|
||||
.contains("\"artifact\":\"spring-boot-sample-actuator\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody())
|
||||
.contains("\"artifact\":\"spring-boot-sample-actuator\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testErrorPage() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/foo", String.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
String body = entity.getBody();
|
||||
assertNotNull(body);
|
||||
assertTrue("Wrong body: " + body, body.contains("\"error\":"));
|
||||
assertThat(body).contains("\"error\":");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,11 +163,10 @@ public class SampleActuatorApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET,
|
||||
request, String.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
String body = entity.getBody();
|
||||
assertNotNull("Body was null", body);
|
||||
assertTrue("Wrong body: " + body,
|
||||
body.contains("This application has no explicit mapping for /error"));
|
||||
assertThat(body).as("Body was null").isNotNull();
|
||||
assertThat(body).contains("This application has no explicit mapping for /error");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,14 +176,14 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/trace", List.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> list = entity.getBody();
|
||||
Map<String, Object> trace = list.get(list.size() - 1);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace
|
||||
.get("info")).get("headers")).get("response");
|
||||
assertEquals("200", map.get("status"));
|
||||
assertThat(map.get("status")).isEqualTo("200");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,24 +191,23 @@ public class SampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/error", Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("None", body.get("error"));
|
||||
assertEquals(999, body.get("status"));
|
||||
assertThat(body.get("error")).isEqualTo("None");
|
||||
assertThat(body.get("status")).isEqualTo(999);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testBeans() throws Exception {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/beans", List.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals(1, entity.getBody().size());
|
||||
@SuppressWarnings("unchecked")
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).hasSize(1);
|
||||
Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0);
|
||||
assertTrue("Wrong body: " + body,
|
||||
((String) body.get("context")).startsWith("application"));
|
||||
assertThat(((String) body.get("context"))).startsWith("application");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,11 +216,10 @@ public class SampleActuatorApplicationTests {
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port + "/configprops",
|
||||
Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertTrue("Wrong body: " + body,
|
||||
body.containsKey("spring.datasource.CONFIGURATION_PROPERTIES"));
|
||||
assertThat(body).containsKey("spring.datasource.CONFIGURATION_PROPERTIES");
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for insecured service endpoints (even with Spring Security on
|
||||
@@ -54,12 +53,11 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/spring/", Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertFalse("Wrong headers: " + entity.getHeaders(),
|
||||
entity.getHeaders().containsKey("Set-Cookie"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +65,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/spring/metrics", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for endpoints configuration.
|
||||
@@ -54,20 +52,19 @@ public class ServletPathSampleActuatorApplicationTests {
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", "password")
|
||||
.getForEntity("http://localhost:" + this.port + "/spring/error",
|
||||
Map.class);
|
||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("None", body.get("error"));
|
||||
assertEquals(999, body.get("status"));
|
||||
assertThat(body.get("error")).isEqualTo("None");
|
||||
assertThat(body.get("status")).isEqualTo(999);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHealth() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/spring/health", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body: " + entity.getBody(),
|
||||
entity.getBody().contains("\"status\":\"UP\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,12 +72,11 @@ public class ServletPathSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/spring/", Map.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error"));
|
||||
assertFalse("Wrong headers: " + entity.getHeaders(),
|
||||
entity.getHeaders().containsKey("Set-Cookie"));
|
||||
assertThat(body.get("error")).isEqualTo("Unauthorized");
|
||||
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for separate management and main service ports.
|
||||
@@ -57,10 +56,10 @@ public class ShutdownSampleActuatorApplicationTests {
|
||||
@SuppressWarnings("rawtypes")
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertEquals("Hello Phil", body.get("message"));
|
||||
assertThat(body.get("message")).isEqualTo("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,11 +68,10 @@ public class ShutdownSampleActuatorApplicationTests {
|
||||
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
|
||||
.postForEntity("http://localhost:" + this.port + "/shutdown", null,
|
||||
Map.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = entity.getBody();
|
||||
assertTrue("Wrong body: " + body,
|
||||
((String) body.get("message")).contains("Shutting down"));
|
||||
assertThat(((String) body.get("message"))).contains("Shutting down");
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package sample.ant;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
@@ -48,12 +46,12 @@ public class SampleAntApplicationIT {
|
||||
}
|
||||
|
||||
});
|
||||
assertThat("Number of jars", jarFiles.length, equalTo(1));
|
||||
assertThat(jarFiles).hasSize(1);
|
||||
Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
|
||||
process.waitFor(5, TimeUnit.MINUTES);
|
||||
assertThat(process.exitValue(), equalTo(0));
|
||||
assertThat(process.exitValue()).isEqualTo(0);
|
||||
String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
|
||||
assertThat(output, containsString("Spring Boot Ant Example"));
|
||||
assertThat(output).contains("Spring Boot Ant Example");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleAopApplication}.
|
||||
@@ -57,14 +57,14 @@ public class SampleAopApplicationTests {
|
||||
public void testDefaultSettings() throws Exception {
|
||||
SampleAopApplication.main(new String[0]);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLineOverrides() throws Exception {
|
||||
SampleAopApplication.main(new String[] { "--name=Gordon" });
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Gordon"));
|
||||
assertThat(output).contains("Hello Gordon");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,9 +42,7 @@ import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleAtmosphereApplication.class)
|
||||
@@ -68,9 +66,9 @@ public class SampleAtmosphereApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertThat(count, equalTo(0L));
|
||||
assertThat(messagePayloadReference.get(),
|
||||
containsString("{\"message\":\"test\",\"author\":\"test\",\"time\":"));
|
||||
assertThat(count).isEqualTo(0L);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.contains("{\"message\":\"test\",\"author\":\"test\",\"time\":");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -22,8 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SampleBatchApplicationTests {
|
||||
|
||||
@@ -32,11 +31,10 @@ public class SampleBatchApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
assertEquals(0, SpringApplication
|
||||
.exit(SpringApplication.run(SampleBatchApplication.class)));
|
||||
assertThat(SpringApplication
|
||||
.exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("completed with the following parameters"));
|
||||
assertThat(output).contains("completed with the following parameters");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,7 @@ import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleCacheApplication.class)
|
||||
@@ -43,11 +40,11 @@ public class SampleCacheApplicationTests {
|
||||
@Test
|
||||
public void validateCache() {
|
||||
Cache countries = this.cacheManager.getCache("countries");
|
||||
assertThat(countries, is(notNullValue()));
|
||||
assertThat(countries).isNotNull();
|
||||
countries.clear(); // Simple test assuming the cache is empty
|
||||
assertThat(countries.get("BE"), is(nullValue()));
|
||||
assertThat(countries.get("BE")).isNull();
|
||||
Country be = this.countryRepository.findByCode("BE");
|
||||
assertThat((Country) countries.get("BE").get(), is(be));
|
||||
assertThat((Country) countries.get("BE").get()).isEqualTo(be);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.TestExecutionListeners.MergeMode;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleCassandraApplication}.
|
||||
@@ -51,8 +51,7 @@ public class SampleCassandraApplicationTests {
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
String output = SampleCassandraApplicationTests.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("firstName='Alice', lastName='Smith'"));
|
||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.core.NestedCheckedException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleElasticsearchApplication}.
|
||||
@@ -53,8 +53,7 @@ public class SampleElasticsearchApplicationTests {
|
||||
}
|
||||
}
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("firstName='Alice', lastName='Smith'"));
|
||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
private boolean serverNotRunning(IllegalStateException ex) {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package sample.data.gemfire;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -31,9 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* The SampleDataGemFireApplicationTests class is a test suite with test cases testing the
|
||||
@@ -50,70 +46,38 @@ public class SampleDataGemFireApplicationTests {
|
||||
|
||||
private final AtomicLong ID_GENERATOR = new AtomicLong(0l);
|
||||
|
||||
protected List<Gemstone> asList(final Iterable<Gemstone> gemstones) {
|
||||
List<Gemstone> gemstoneList = new ArrayList<Gemstone>();
|
||||
|
||||
if (gemstones != null) {
|
||||
for (Gemstone gemstone : gemstones) {
|
||||
gemstoneList.add(gemstone);
|
||||
}
|
||||
}
|
||||
|
||||
return gemstoneList;
|
||||
}
|
||||
|
||||
protected Gemstone createGemstone(final String name) {
|
||||
return createGemstone(this.ID_GENERATOR.incrementAndGet(), name);
|
||||
}
|
||||
|
||||
protected Gemstone createGemstone(final Long id, final String name) {
|
||||
return new Gemstone(id, name);
|
||||
}
|
||||
|
||||
protected List<Gemstone> getGemstones(final String... names) {
|
||||
List<Gemstone> gemstones = new ArrayList<Gemstone>(names.length);
|
||||
|
||||
for (String name : names) {
|
||||
gemstones.add(createGemstone(null, name));
|
||||
}
|
||||
|
||||
return gemstones;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
assertNotNull("A reference to the GemstoneService was not properly configured!",
|
||||
this.gemstoneService);
|
||||
assertThat(this.gemstoneService).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGemstonesApp() {
|
||||
assertEquals(0, this.gemstoneService.count());
|
||||
assertTrue(asList(this.gemstoneService.list()).isEmpty());
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(0);
|
||||
assertThat(this.gemstoneService.list()).isEmpty();
|
||||
|
||||
this.gemstoneService.save(createGemstone("Diamond"));
|
||||
this.gemstoneService.save(createGemstone("Ruby"));
|
||||
|
||||
assertEquals(2, this.gemstoneService.count());
|
||||
assertTrue(asList(this.gemstoneService.list())
|
||||
.containsAll(getGemstones("Diamond", "Ruby")));
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
||||
assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
|
||||
|
||||
try {
|
||||
this.gemstoneService.save(createGemstone("Coal"));
|
||||
}
|
||||
catch (IllegalGemstoneException expected) {
|
||||
catch (IllegalGemstoneException ex) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
assertEquals(2, this.gemstoneService.count());
|
||||
assertTrue(asList(this.gemstoneService.list())
|
||||
.containsAll(getGemstones("Diamond", "Ruby")));
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(2);
|
||||
assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
|
||||
|
||||
this.gemstoneService.save(createGemstone("Pearl"));
|
||||
this.gemstoneService.save(createGemstone("Sapphire"));
|
||||
|
||||
assertEquals(4, this.gemstoneService.count());
|
||||
assertTrue(asList(this.gemstoneService.list())
|
||||
.containsAll(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")));
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
||||
assertThat(this.gemstoneService.list())
|
||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||
|
||||
try {
|
||||
this.gemstoneService.save(createGemstone("Quartz"));
|
||||
@@ -121,11 +85,28 @@ public class SampleDataGemFireApplicationTests {
|
||||
catch (IllegalGemstoneException expected) {
|
||||
}
|
||||
|
||||
assertEquals(4, this.gemstoneService.count());
|
||||
assertTrue(asList(this.gemstoneService.list())
|
||||
.containsAll(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")));
|
||||
assertEquals(createGemstone("Diamond"), this.gemstoneService.get("Diamond"));
|
||||
assertEquals(createGemstone("Pearl"), this.gemstoneService.get("Pearl"));
|
||||
assertThat(this.gemstoneService.count()).isEqualTo(4);
|
||||
assertThat(this.gemstoneService.list())
|
||||
.contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
|
||||
assertThat(this.gemstoneService.get("Diamond"))
|
||||
.isEqualTo(createGemstone("Diamond"));
|
||||
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(createGemstone("Pearl"));
|
||||
}
|
||||
|
||||
private Gemstone[] getGemstones(String... names) {
|
||||
Gemstone[] gemstones = new Gemstone[names.length];
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
gemstones[i] = createGemstone(null, names[i]);
|
||||
}
|
||||
return gemstones;
|
||||
}
|
||||
|
||||
private Gemstone createGemstone(String name) {
|
||||
return createGemstone(this.ID_GENERATOR.incrementAndGet(), name);
|
||||
}
|
||||
|
||||
private Gemstone createGemstone(Long id, String name) {
|
||||
return new Gemstone(id, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -74,9 +74,9 @@ public class SampleDataJpaApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testJmx() throws Exception {
|
||||
assertEquals(1, ManagementFactory.getPlatformMBeanServer()
|
||||
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null)
|
||||
.size());
|
||||
assertThat(ManagementFactory.getPlatformMBeanServer()
|
||||
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null))
|
||||
.hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,9 +26,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link CityRepository}.
|
||||
@@ -46,6 +44,6 @@ public class CityRepositoryIntegrationTests {
|
||||
public void findsFirstPageOfCities() {
|
||||
|
||||
Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
|
||||
assertThat(cities.getTotalElements(), is(greaterThan(20L)));
|
||||
assertThat(cities.getTotalElements()).isGreaterThan(20L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link HotelRepository}.
|
||||
@@ -57,17 +54,17 @@ public class HotelRepositoryIntegrationTests {
|
||||
City city = this.cityRepository
|
||||
.findAll(new PageRequest(0, 1, Direction.ASC, "name")).getContent()
|
||||
.get(0);
|
||||
assertThat(city.getName(), is("Atlanta"));
|
||||
assertThat(city.getName()).isEqualTo("Atlanta");
|
||||
|
||||
Page<HotelSummary> hotels = this.repository.findByCity(city,
|
||||
new PageRequest(0, 10, Direction.ASC, "name"));
|
||||
Hotel hotel = this.repository.findByCityAndName(city,
|
||||
hotels.getContent().get(0).getName());
|
||||
assertThat(hotel.getName(), is("Doubletree"));
|
||||
assertThat(hotel.getName()).isEqualTo("Doubletree");
|
||||
|
||||
List<RatingCount> counts = this.repository.findRatingCounts(hotel);
|
||||
assertThat(counts, hasSize(1));
|
||||
assertThat(counts.get(0).getRating(), is(Rating.AVERAGE));
|
||||
assertThat(counts.get(0).getCount(), is(greaterThan(1L)));
|
||||
assertThat(counts).hasSize(1);
|
||||
assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE);
|
||||
assertThat(counts.get(0).getCount()).isGreaterThan(1L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleMongoApplication}.
|
||||
@@ -44,8 +44,7 @@ public class SampleMongoApplicationTests {
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
String output = SampleMongoApplicationTests.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("firstName='Alice', lastName='Smith'"));
|
||||
assertThat(output).contains("firstName='Alice', lastName='Smith'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleRedisApplication}.
|
||||
@@ -45,8 +45,7 @@ public class SampleRedisApplicationTests {
|
||||
}
|
||||
}
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Found key spring.boot.redis.test"));
|
||||
assertThat(output).contains("Found key spring.boot.redis.test");
|
||||
}
|
||||
|
||||
private boolean redisServerRunning(Throwable ex) {
|
||||
|
||||
@@ -27,11 +27,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link CityRepository}.
|
||||
@@ -50,15 +46,15 @@ public class CityRepositoryIntegrationTests {
|
||||
public void findsFirstPageOfCities() {
|
||||
|
||||
Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
|
||||
assertThat(cities.getTotalElements(), is(greaterThan(20L)));
|
||||
assertThat(cities.getTotalElements()).isGreaterThan(20L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByNameAndCountry() {
|
||||
City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne",
|
||||
"Australia");
|
||||
assertThat(city, notNullValue());
|
||||
assertThat(city.getName(), is(equalTo("Melbourne")));
|
||||
assertThat(city).isNotNull();
|
||||
assertThat(city.getName()).isEqualTo("Melbourne");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,6 +62,6 @@ public class CityRepositoryIntegrationTests {
|
||||
Page<City> cities = this.repository
|
||||
.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK",
|
||||
new PageRequest(0, 10));
|
||||
assertThat(cities.getTotalElements(), is(equalTo(3L)));
|
||||
assertThat(cities.getTotalElements()).isEqualTo(3L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.core.NestedCheckedException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SampleSolrApplicationTests {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SampleSolrApplicationTests {
|
||||
}
|
||||
}
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("name=Sony Playstation"));
|
||||
assertThat(output).contains("name=Sony Playstation");
|
||||
}
|
||||
|
||||
private boolean serverNotRunning(IllegalStateException ex) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleFlywayApplication.class)
|
||||
@@ -35,8 +35,8 @@ public class SampleFlywayApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testDefaultSettings() throws Exception {
|
||||
assertEquals(new Integer(1), this.template
|
||||
.queryForObject("SELECT COUNT(*) from PERSON", Integer.class));
|
||||
assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON",
|
||||
Integer.class)).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleHateoasApplication.class)
|
||||
@@ -50,10 +47,10 @@ public class SampleHateoasApplicationTests {
|
||||
public void hasHalLinks() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/customers/1", String.class);
|
||||
assertThat(entity.getStatusCode(), equalTo(HttpStatus.OK));
|
||||
assertThat(entity.getBody(), startsWith(
|
||||
"{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\""));
|
||||
assertThat(entity.getBody(), containsString("_links\":{\"self\":{\"href\""));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).startsWith(
|
||||
"{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\"");
|
||||
assertThat(entity.getBody()).contains("_links\":{\"self\":{\"href\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,9 +61,9 @@ public class SampleHateoasApplicationTests {
|
||||
URI.create("http://localhost:" + this.port + "/customers/1"));
|
||||
ResponseEntity<String> response = new TestRestTemplate().exchange(request,
|
||||
String.class);
|
||||
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
|
||||
assertThat(response.getHeaders().getContentType(),
|
||||
equalTo(MediaType.parseMediaType("application/json;charset=UTF-8")));
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.getHeaders().getContentType())
|
||||
.isEqualTo(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -83,8 +83,8 @@ public class SampleHypermediaJpaApplicationIntegrationTests {
|
||||
public void browser() throws Exception {
|
||||
MvcResult response = this.mockMvc.perform(get("/").accept(MediaType.TEXT_HTML))
|
||||
.andExpect(status().isFound()).andReturn();
|
||||
assertEquals("/browser/index.html#",
|
||||
response.getResponse().getHeaders("location").get(0));
|
||||
assertThat(response.getResponse().getHeaders("location").get(0))
|
||||
.isEqualTo("/browser/index.html#");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleHypermediaUiApplication.class)
|
||||
@@ -47,14 +47,14 @@ public class SampleHypermediaUiApplicationTests {
|
||||
public void home() {
|
||||
String response = new TestRestTemplate()
|
||||
.getForObject("http://localhost:" + this.port, String.class);
|
||||
assertTrue("Wrong body: " + response, response.contains("Hello World"));
|
||||
assertThat(response).contains("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void links() {
|
||||
String response = new TestRestTemplate().getForObject(
|
||||
"http://localhost:" + this.port + "/actuator", String.class);
|
||||
assertTrue("Wrong body: " + response, response.contains("\"_links\":"));
|
||||
assertThat(response).contains("\"_links\":");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,7 +65,7 @@ public class SampleHypermediaUiApplicationTests {
|
||||
new RequestEntity<Void>(headers, HttpMethod.GET,
|
||||
new URI("http://localhost:" + this.port + "/actuator")),
|
||||
String.class);
|
||||
assertTrue("Wrong body: " + response, response.getBody().contains("\"_links\":"));
|
||||
assertThat(response.getBody()).contains("\"_links\":");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +75,7 @@ public class SampleHypermediaUiApplicationTests {
|
||||
ResponseEntity<String> response = new TestRestTemplate()
|
||||
.exchange(new RequestEntity<Void>(headers, HttpMethod.GET,
|
||||
new URI("http://localhost:" + this.port)), String.class);
|
||||
assertTrue("Wrong body: " + response, response.getBody().contains("Hello World"));
|
||||
assertThat(response.getBody()).contains("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleHypermediaApplication.class)
|
||||
@@ -47,7 +47,7 @@ public class SampleHypermediaApplicationHomePageTests {
|
||||
public void home() {
|
||||
String response = new TestRestTemplate()
|
||||
.getForObject("http://localhost:" + this.port, String.class);
|
||||
assertTrue("Wrong body: " + response, response.contains("404"));
|
||||
assertThat(response).contains("404");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class SampleHypermediaApplicationHomePageTests {
|
||||
new RequestEntity<Void>(headers, HttpMethod.GET,
|
||||
new URI("http://localhost:" + this.port + "/actuator")),
|
||||
String.class);
|
||||
assertTrue("Wrong body: " + response, response.getBody().contains("\"_links\":"));
|
||||
assertThat(response.getBody()).contains("\"_links\":");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +69,7 @@ public class SampleHypermediaApplicationHomePageTests {
|
||||
new RequestEntity<Void>(headers, HttpMethod.GET,
|
||||
new URI("http://localhost:" + this.port + "/actuator/")),
|
||||
String.class);
|
||||
assertTrue("Wrong body: " + response, response.getBody().contains("HAL Browser"));
|
||||
assertThat(response.getBody()).contains("HAL Browser");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.core.io.support.ResourcePatternUtils;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for service demo application.
|
||||
@@ -71,7 +71,7 @@ public class SampleIntegrationApplicationTests {
|
||||
public void testVanillaExchange() throws Exception {
|
||||
SpringApplication.run(ProducerApplication.class, "World");
|
||||
String output = getOutput();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World"));
|
||||
assertThat(output).contains("Hello World");
|
||||
}
|
||||
|
||||
private String getOutput() throws Exception {
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleJerseyApplication.class)
|
||||
@@ -44,22 +44,22 @@ public class SampleJerseyApplicationTests {
|
||||
public void contextLoads() {
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.getForEntity("http://localhost:" + this.port + "/hello", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverse() {
|
||||
ResponseEntity<String> entity = this.restTemplate.getForEntity(
|
||||
"http://localhost:" + this.port + "/reverse?input=olleh", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("hello", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validation() {
|
||||
ResponseEntity<String> entity = this.restTemplate
|
||||
.getForEntity("http://localhost:" + this.port + "/reverse", String.class);
|
||||
assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleJersey1Application.class)
|
||||
@@ -37,8 +37,9 @@ public class SampleJersey1ApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
assertEquals("Hello World", new TestRestTemplate()
|
||||
.getForObject("http://localhost:" + this.port + "/", String.class));
|
||||
assertThat(new TestRestTemplate()
|
||||
.getForObject("http://localhost:" + this.port + "/", String.class))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -64,8 +64,8 @@ public class SampleJettySslApplicationTests {
|
||||
.setHttpClient(httpClient);
|
||||
ResponseEntity<String> entity = testRestTemplate
|
||||
.getForEntity("https://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -58,8 +58,8 @@ public class SampleJettyApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,13 +74,13 @@ public class SampleJettyApplicationTests {
|
||||
"http://localhost:" + this.port, HttpMethod.GET, requestEntity,
|
||||
byte[].class);
|
||||
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()));
|
||||
try {
|
||||
assertEquals("Hello World",
|
||||
StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
finally {
|
||||
inflater.close();
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -64,8 +64,8 @@ public class SampleJetty8SslApplicationTests {
|
||||
.setHttpClient(httpClient);
|
||||
ResponseEntity<String> entity = testRestTemplate
|
||||
.getForEntity("https://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -58,8 +58,8 @@ public class SampleJetty8ApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +71,12 @@ public class SampleJetty8ApplicationTests {
|
||||
ResponseEntity<byte[]> entity = restTemplate.exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET, requestEntity,
|
||||
byte[].class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()));
|
||||
try {
|
||||
assertEquals("Hello World",
|
||||
StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
finally {
|
||||
inflater.close();
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -58,8 +58,8 @@ public class SampleJetty93ApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +71,12 @@ public class SampleJetty93ApplicationTests {
|
||||
ResponseEntity<byte[]> entity = restTemplate.exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET, requestEntity,
|
||||
byte[].class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()));
|
||||
try {
|
||||
assertEquals("Hello World",
|
||||
StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
finally {
|
||||
inflater.close();
|
||||
|
||||
@@ -21,8 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link SampleJooqApplication}.
|
||||
@@ -37,11 +36,11 @@ public class SampleJooqApplicationTests {
|
||||
@Test
|
||||
public void outputResults() throws Exception {
|
||||
SampleJooqApplication.main(NO_ARGS);
|
||||
assertThat(this.out.toString(), containsString("jOOQ Fetch 1 Greg Turnquest"));
|
||||
assertThat(this.out.toString(), containsString("jOOQ Fetch 2 Craig Walls"));
|
||||
assertThat(this.out.toString(),
|
||||
containsString("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, "
|
||||
+ "Spring Boot in Action : Craig Walls]"));
|
||||
assertThat(this.out.toString()).contains("jOOQ Fetch 1 Greg Turnquest");
|
||||
assertThat(this.out.toString()).contains("jOOQ Fetch 2 Craig Walls");
|
||||
assertThat(this.out.toString())
|
||||
.contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, "
|
||||
+ "Spring Boot in Action : Craig Walls]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JpaNoteRepository}.
|
||||
@@ -43,7 +43,7 @@ public class JpaNoteRepositoryIntegrationTests {
|
||||
@Test
|
||||
public void findsAllNotes() {
|
||||
List<Note> notes = this.repository.findAll();
|
||||
assertEquals(4, notes.size());
|
||||
assertThat(notes).hasSize(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link JpaTagRepository}.
|
||||
@@ -43,7 +43,7 @@ public class JpaTagRepositoryIntegrationTests {
|
||||
@Test
|
||||
public void findsAllTags() {
|
||||
List<Tag> tags = this.repository.findAll();
|
||||
assertEquals(3, tags.size());
|
||||
assertThat(tags).hasSize(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package sample.atomikos;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.core.SubstringMatcher;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -39,25 +38,22 @@ public class SampleAtomikosApplicationTests {
|
||||
public void testTransactionRollback() throws Exception {
|
||||
SampleAtomikosApplication.main(new String[] {});
|
||||
String output = this.outputCapture.toString();
|
||||
assertThat(output, containsString(1, "---->"));
|
||||
assertThat(output, containsString(1, "----> josh"));
|
||||
assertThat(output, containsString(2, "Count is 1"));
|
||||
assertThat(output, containsString(1, "Simulated error"));
|
||||
assertThat(output).has(substring(1, "---->"));
|
||||
assertThat(output).has(substring(1, "----> josh"));
|
||||
assertThat(output).has(substring(2, "Count is 1"));
|
||||
assertThat(output).has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
private Matcher<? super String> containsString(final int times, String s) {
|
||||
return new SubstringMatcher(s) {
|
||||
private Condition<String> substring(final int times, final String substring) {
|
||||
return new Condition<String>(
|
||||
"containing '" + substring + "' " + times + " times") {
|
||||
|
||||
@Override
|
||||
protected String relationship() {
|
||||
return "containing " + times + " times";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean evalSubstringOf(String s) {
|
||||
public boolean matches(String value) {
|
||||
int i = 0;
|
||||
while (s.contains(this.substring)) {
|
||||
s = s.substring(s.indexOf(this.substring) + this.substring.length());
|
||||
while (value.contains(substring)) {
|
||||
int beginIndex = value.indexOf(substring) + substring.length();
|
||||
value = value.substring(beginIndex);
|
||||
i++;
|
||||
}
|
||||
return i == times;
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
package sample.bitronix;
|
||||
|
||||
import bitronix.tm.resource.jms.PoolingConnectionFactory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.core.SubstringMatcher;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -26,10 +25,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -45,10 +41,10 @@ public class SampleBitronixApplicationTests {
|
||||
public void testTransactionRollback() throws Exception {
|
||||
SampleBitronixApplication.main(new String[] {});
|
||||
String output = this.outputCapture.toString();
|
||||
assertThat(output, containsString(1, "---->"));
|
||||
assertThat(output, containsString(1, "----> josh"));
|
||||
assertThat(output, containsString(2, "Count is 1"));
|
||||
assertThat(output, containsString(1, "Simulated error"));
|
||||
assertThat(output).has(substring(1, "---->"));
|
||||
assertThat(output).has(substring(1, "----> josh"));
|
||||
assertThat(output).has(substring(2, "Count is 1"));
|
||||
assertThat(output).has(substring(1, "Simulated error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,25 +54,22 @@ public class SampleBitronixApplicationTests {
|
||||
Object jmsConnectionFactory = context.getBean("jmsConnectionFactory");
|
||||
Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory");
|
||||
Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory");
|
||||
assertThat(jmsConnectionFactory, sameInstance(xaJmsConnectionFactory));
|
||||
assertThat(jmsConnectionFactory, instanceOf(PoolingConnectionFactory.class));
|
||||
assertThat(nonXaJmsConnectionFactory,
|
||||
not(instanceOf(PoolingConnectionFactory.class)));
|
||||
assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory);
|
||||
assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class);
|
||||
assertThat(nonXaJmsConnectionFactory)
|
||||
.isNotInstanceOf(PoolingConnectionFactory.class);
|
||||
}
|
||||
|
||||
private Matcher<? super String> containsString(final int times, String s) {
|
||||
return new SubstringMatcher(s) {
|
||||
private Condition<String> substring(final int times, final String substring) {
|
||||
return new Condition<String>(
|
||||
"containing '" + substring + "' " + times + " times") {
|
||||
|
||||
@Override
|
||||
protected String relationship() {
|
||||
return "containing " + times + " times";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean evalSubstringOf(String s) {
|
||||
public boolean matches(String value) {
|
||||
int i = 0;
|
||||
while (s.contains(this.substring)) {
|
||||
s = s.substring(s.indexOf(this.substring) + this.substring.length());
|
||||
while (value.contains(substring)) {
|
||||
int beginIndex = value.indexOf(substring) + substring.length();
|
||||
value = value.substring(beginIndex);
|
||||
i++;
|
||||
}
|
||||
return i == times;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.core.NestedCheckedException;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SampleLiquibaseApplicationTests {
|
||||
|
||||
@@ -42,23 +42,22 @@ public class SampleLiquibaseApplicationTests {
|
||||
}
|
||||
}
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output,
|
||||
output.contains("Successfully acquired change log lock")
|
||||
&& output.contains("Creating database history "
|
||||
+ "table with name: PUBLIC.DATABASECHANGELOG")
|
||||
&& output.contains("Table person created")
|
||||
&& output.contains("ChangeSet classpath:/db/"
|
||||
assertThat(output).contains("Successfully acquired change log lock")
|
||||
.contains("Creating database history "
|
||||
+ "table with name: PUBLIC.DATABASECHANGELOG")
|
||||
.contains("Table person created")
|
||||
.contains("ChangeSet classpath:/db/"
|
||||
+ "changelog/db.changelog-master.yaml::1::"
|
||||
+ "marceloverdijk ran successfully")
|
||||
&& output.contains("New row inserted into person")
|
||||
&& output.contains("ChangeSet classpath:/db/changelog/"
|
||||
.contains("New row inserted into person")
|
||||
.contains("ChangeSet classpath:/db/changelog/"
|
||||
+ "db.changelog-master.yaml::2::"
|
||||
+ "marceloverdijk ran successfully")
|
||||
&& output.contains("Successfully released change log lock"));
|
||||
.contains("Successfully released change log lock");
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private boolean serverNotRunning(IllegalStateException ex) {
|
||||
@SuppressWarnings("serial")
|
||||
NestedCheckedException nested = new NestedCheckedException("failed", ex) {
|
||||
};
|
||||
if (nested.contains(ConnectException.class)) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for {@link SampleDropwizardMetricsApplication}.
|
||||
@@ -49,7 +49,7 @@ public class SampleDropwizardMetricsApplicationTests {
|
||||
@Test
|
||||
public void timerCreated() {
|
||||
this.gauges.submit("timer.test", 1234);
|
||||
assertEquals(1, this.registry.getTimers().get("timer.test").getCount());
|
||||
assertThat(this.registry.getTimers().get("timer.test").getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SampleProfileApplicationTests {
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SampleProfileApplicationTests {
|
||||
public void testDefaultProfile() throws Exception {
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +59,7 @@ public class SampleProfileApplicationTests {
|
||||
System.setProperty("spring.profiles.active", "goodbye");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone"));
|
||||
assertThat(output).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class SampleProfileApplicationTests {
|
||||
System.setProperty("spring.profiles.active", "generic");
|
||||
SampleProfileApplication.main(new String[0]);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Bonjour Phil"));
|
||||
assertThat(output).contains("Bonjour Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +81,7 @@ public class SampleProfileApplicationTests {
|
||||
SampleProfileApplication
|
||||
.main(new String[] { "--spring.profiles.active=goodbye" });
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone"));
|
||||
assertThat(output).contains("Goodbye Everyone");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SamplePropertyValidationApplication}.
|
||||
@@ -53,8 +53,8 @@ public class SamplePropertyValidationApplicationTests {
|
||||
"sample.port:9090");
|
||||
this.context.refresh();
|
||||
SampleProperties properties = this.context.getBean(SampleProperties.class);
|
||||
assertEquals("192.168.0.1", properties.getHost());
|
||||
assertEquals(Integer.valueOf(9090), properties.getPort());
|
||||
assertThat(properties.getHost()).isEqualTo("192.168.0.1");
|
||||
assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,8 +84,8 @@ public class SamplePropertyValidationApplicationTests {
|
||||
"sample.port:9090");
|
||||
this.context.refresh();
|
||||
SampleProperties properties = this.context.getBean(SampleProperties.class);
|
||||
assertEquals("192.168.0.1", properties.getHost());
|
||||
assertEquals(Integer.valueOf(9090), properties.getPort());
|
||||
assertThat(properties.getHost()).isEqualTo("192.168.0.1");
|
||||
assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
@@ -100,11 +99,11 @@ public class SampleSecureOAuth2ApplicationTests {
|
||||
Flight flight = this.objectMapper.readValue(
|
||||
flightsAction.getResponse().getContentAsString(), Flight.class);
|
||||
|
||||
assertThat(flight.getOrigin(), is("Nashville"));
|
||||
assertThat(flight.getDestination(), is("Dallas"));
|
||||
assertThat(flight.getAirline(), is("Spring Ways"));
|
||||
assertThat(flight.getFlightNumber(), is("OAUTH2"));
|
||||
assertThat(flight.getTraveler(), is("Greg Turnquist"));
|
||||
assertThat(flight.getOrigin()).isEqualTo("Nashville");
|
||||
assertThat(flight.getDestination()).isEqualTo("Dallas");
|
||||
assertThat(flight.getAirline()).isEqualTo("Spring Ways");
|
||||
assertThat(flight.getFlightNumber()).isEqualTo("OAUTH2");
|
||||
assertThat(flight.getTraveler()).isEqualTo("Greg Turnquist");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -70,25 +70,25 @@ public class SampleSecureApplicationTests {
|
||||
|
||||
@Test(expected = AuthenticationException.class)
|
||||
public void secure() throws Exception {
|
||||
assertEquals(this.service.secure(), "Hello Security");
|
||||
assertThat("Hello Security").isEqualTo(this.service.secure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authenticated() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.authentication);
|
||||
assertEquals(this.service.secure(), "Hello Security");
|
||||
assertThat("Hello Security").isEqualTo(this.service.secure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preauth() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.authentication);
|
||||
assertEquals(this.service.authorized(), "Hello World");
|
||||
assertThat("Hello World").isEqualTo(this.service.authorized());
|
||||
}
|
||||
|
||||
@Test(expected = AccessDeniedException.class)
|
||||
public void denied() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(this.authentication);
|
||||
assertEquals(this.service.denied(), "Goodbye World");
|
||||
assertThat("Goodbye World").isEqualTo(this.service.denied());
|
||||
}
|
||||
|
||||
@PropertySource("classpath:test.properties")
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -53,15 +53,15 @@ public class SampleServletApplicationTests {
|
||||
public void testHomeIsSecure() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
private String getPassword() {
|
||||
|
||||
@@ -30,10 +30,7 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleSessionRedisApplication}.
|
||||
@@ -73,12 +70,12 @@ public class SampleSessionRedisApplicationTests {
|
||||
HttpMethod.GET, uri);
|
||||
|
||||
String uuid2 = restTemplate.exchange(request, String.class).getBody();
|
||||
assertThat(uuid1, is(equalTo(uuid2)));
|
||||
assertThat(uuid1).isEqualTo(uuid2);
|
||||
|
||||
Thread.sleep(5000);
|
||||
|
||||
String uuid3 = restTemplate.exchange(request, String.class).getBody();
|
||||
assertThat(uuid2, is(not(equalTo(uuid3))));
|
||||
assertThat(uuid2).isNotEqualTo(uuid3);
|
||||
}
|
||||
|
||||
private boolean redisServerRunning(Throwable ex) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleSimpleApplication}.
|
||||
@@ -57,14 +57,14 @@ public class SampleSimpleApplicationTests {
|
||||
public void testDefaultSettings() throws Exception {
|
||||
SampleSimpleApplication.main(new String[0]);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Phil"));
|
||||
assertThat(output).contains("Hello Phil");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCommandLineOverrides() throws Exception {
|
||||
SampleSimpleApplication.main(new String[] { "--name=Gordon" });
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello Gordon"));
|
||||
assertThat(output).contains("Hello Gordon");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SampleSimpleApplication}.
|
||||
@@ -41,9 +40,9 @@ public class SpringTestSampleSimpleApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testContextLoads() throws Exception {
|
||||
assertNotNull(this.ctx);
|
||||
assertTrue(this.ctx.containsBean("helloWorldService"));
|
||||
assertTrue(this.ctx.containsBean("sampleSimpleApplication"));
|
||||
assertThat(this.ctx).isNotNull();
|
||||
assertThat(this.ctx.containsBean("helloWorldService")).isTrue();
|
||||
assertThat(this.ctx.containsBean("sampleSimpleApplication")).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -46,8 +46,8 @@ public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTes
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for JSP application.
|
||||
@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
|
||||
public void testJspWithEl() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("/resources/text.txt"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("/resources/text.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}.
|
||||
@@ -111,13 +111,13 @@ public class SampleTomcatTwoConnectorsApplicationTests {
|
||||
ResponseEntity<String> entity = template.getForEntity(
|
||||
"http://localhost:" + this.context.getBean("port") + "/hello",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("hello", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("hello");
|
||||
|
||||
ResponseEntity<String> httpsEntity = template
|
||||
.getForEntity("https://localhost:" + this.port + "/hello", String.class);
|
||||
assertEquals(HttpStatus.OK, httpsEntity.getStatusCode());
|
||||
assertEquals("hello", httpsEntity.getBody());
|
||||
assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(httpsEntity.getBody()).isEqualTo("hello");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -23,19 +23,19 @@ import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import sample.tomcat.ssl.SampleTomcatSslApplication;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleTomcatSslApplication.class)
|
||||
@@ -60,8 +60,8 @@ public class SampleTomcatSslApplicationTests {
|
||||
.setHttpClient(httpClient);
|
||||
ResponseEntity<String> entity = testRestTemplate
|
||||
.getForEntity("https://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello, world", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello, world");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package sample.tomcat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoConfigurationSampleTomcatApplication;
|
||||
import sample.tomcat.service.HelloWorldService;
|
||||
import sample.tomcat.web.SampleController;
|
||||
@@ -33,6 +32,7 @@ import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfigurat
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -41,7 +41,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -77,8 +77,8 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -58,8 +58,8 @@ public class SampleTomcatApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,12 +71,12 @@ public class SampleTomcatApplicationTests {
|
||||
ResponseEntity<byte[]> entity = restTemplate.exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET, requestEntity,
|
||||
byte[].class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()));
|
||||
try {
|
||||
assertEquals("Hello World",
|
||||
StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
finally {
|
||||
inflater.close();
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for JSP application.
|
||||
@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
|
||||
public void testJspWithEl() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("/resources/text.txt"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("/resources/text.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -49,20 +48,18 @@ public class SampleTraditionalApplicationTests {
|
||||
public void testHomeJsp() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
assertTrue("Wrong body:\n" + body, body.contains("<html>"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("<h1>Home</h1>"));
|
||||
assertThat(body).contains("<html>").contains("<h1>Home</h1>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticPage() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/index.html", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String body = entity.getBody();
|
||||
assertTrue("Wrong body:\n" + body, body.contains("<html>"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("<h1>Hello</h1>"));
|
||||
assertThat(body).contains("<html>").contains("<h1>Hello</h1>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -64,8 +64,8 @@ public class SampleUndertowSslApplicationTests {
|
||||
.setHttpClient(httpClient);
|
||||
ResponseEntity<String> entity = testRestTemplate
|
||||
.getForEntity("https://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals("Hello World", entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -73,12 +73,12 @@ public class SampleUndertowApplicationTests {
|
||||
ResponseEntity<byte[]> entity = restTemplate.exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET, requestEntity,
|
||||
byte[].class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
GZIPInputStream inflater = new GZIPInputStream(
|
||||
new ByteArrayInputStream(entity.getBody()));
|
||||
try {
|
||||
assertEquals("Hello World",
|
||||
StreamUtils.copyToString(inflater, Charset.forName("UTF-8")));
|
||||
assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
finally {
|
||||
inflater.close();
|
||||
@@ -88,8 +88,8 @@ public class SampleUndertowApplicationTests {
|
||||
private void assertOkResponse(String path, String body) {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + path, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertEquals(body, entity.getBody());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo(body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.boot.test.OutputCapture;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for Velocity application with no web layer.
|
||||
@@ -41,7 +41,7 @@ public class SampleVelocityApplicationTests {
|
||||
@Test
|
||||
public void testVelocityTemplate() throws Exception {
|
||||
String result = SampleVelocityApplicationTests.output.toString();
|
||||
assertTrue("Wrong output: " + result, result.contains("Hello, Andy"));
|
||||
assertThat(result).contains("Hello, Andy");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for FreeMarker application.
|
||||
@@ -55,10 +54,9 @@ public class SampleWebFreeMarkerApplicationTests {
|
||||
@Test
|
||||
public void testFreeMarkerTemplate() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("Hello, Andy"));
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("Hello, Andy");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,12 +66,12 @@ public class SampleWebFreeMarkerApplicationTests {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
|
||||
|
||||
ResponseEntity<String> responseEntity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + port + "/does-not-exist", HttpMethod.GET,
|
||||
"http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
|
||||
requestEntity, String.class);
|
||||
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + responseEntity.getBody(),
|
||||
responseEntity.getBody().contains("Something went wrong: 404 Not Found"));
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(responseEntity.getBody())
|
||||
.contains("Something went wrong: 404 Not Found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -54,11 +52,9 @@ public class SampleGroovyTemplateApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
|
||||
entity.getBody().contains("<title>Messages"));
|
||||
assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(),
|
||||
entity.getBody().contains("layout:fragment"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("<title>Messages");
|
||||
assertThat(entity.getBody()).doesNotContain("layout:fragment");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,16 +64,15 @@ public class SampleGroovyTemplateApplicationTests {
|
||||
map.set("summary", "FOO");
|
||||
URI location = new TestRestTemplate()
|
||||
.postForLocation("http://localhost:" + this.port, map);
|
||||
assertTrue("Wrong location:\n" + location,
|
||||
location.toString().contains("localhost:" + this.port));
|
||||
assertThat(location.toString()).contains("localhost:" + this.port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for JSP application.
|
||||
@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
|
||||
public void testJspWithEl() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("/resources/text.txt"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("/resources/text.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -62,9 +61,8 @@ public class SampleMethodSecurityApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
|
||||
entity.getBody().contains("<title>Login"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("<title>Login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,9 +77,9 @@ public class SampleMethodSecurityApplicationTests {
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertEquals("http://localhost:" + this.port + "/",
|
||||
entity.getHeaders().getLocation().toString());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.isEqualTo("http://localhost:" + this.port + "/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,36 +94,35 @@ public class SampleMethodSecurityApplicationTests {
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
String cookie = entity.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
ResponseEntity<String> page = new TestRestTemplate().exchange(
|
||||
entity.getHeaders().getLocation(), HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode());
|
||||
assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(),
|
||||
page.getBody().contains("Access denied"));
|
||||
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||
assertThat(page.getBody()).contains("Access denied");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagementProtected() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/beans", String.class);
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagementAuthorizedAccess() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
|
||||
.getForEntity("http://localhost:" + this.port + "/beans", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagementUnauthorizedAccess() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate("user", "user")
|
||||
.getForEntity("http://localhost:" + this.port + "/beans", String.class);
|
||||
assertEquals(HttpStatus.FORBIDDEN, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) {
|
||||
|
||||
@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for Mustache application.
|
||||
@@ -56,9 +55,8 @@ public class SampleWebMustacheApplicationTests {
|
||||
public void testMustacheTemplate() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("Hello, Andy"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("Hello, Andy");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,9 +69,9 @@ public class SampleWebMustacheApplicationTests {
|
||||
"http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
|
||||
requestEntity, String.class);
|
||||
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + responseEntity.getBody(),
|
||||
responseEntity.getBody().contains("Something went wrong: 404 Not Found"));
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(responseEntity.getBody())
|
||||
.contains("Something went wrong: 404 Not Found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import sample.web.secure.custom.SampleWebSecureCustomApplication;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -39,9 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -64,9 +62,9 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.endsWith(this.port + "/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,9 +74,8 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong content:\n" + entity.getBody(),
|
||||
entity.getBody().contains("_csrf"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("_csrf");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,23 +90,22 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/"));
|
||||
assertNotNull("Missing cookie:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().get("Set-Cookie"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.endsWith(this.port + "/");
|
||||
assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
ResponseEntity<String> page = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/login", String.class);
|
||||
assertEquals(HttpStatus.OK, page.getStatusCode());
|
||||
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String cookie = page.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*")
|
||||
.matcher(page.getBody());
|
||||
assertTrue("No csrf token: " + page.getBody(), matcher.matches());
|
||||
Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
|
||||
Matcher matcher = pattern.matcher(page.getBody());
|
||||
assertThat(matcher.matches()).as(page.getBody()).isTrue();
|
||||
headers.set("X-CSRF-TOKEN", matcher.group(1));
|
||||
return headers;
|
||||
}
|
||||
@@ -118,8 +114,8 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,10 +30,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for GitHub SSO application.
|
||||
@@ -55,9 +52,9 @@ public class SampleGithubApplicationTests {
|
||||
TestRestTemplate restTemplate = new TestRestTemplate();
|
||||
ResponseEntity<Void> entity = restTemplate
|
||||
.getForEntity("http://localhost:" + this.port, Void.class);
|
||||
assertThat(entity.getStatusCode(), is(HttpStatus.FOUND));
|
||||
assertThat(entity.getHeaders().getLocation(),
|
||||
is(equalTo(URI.create("http://localhost:" + this.port + "/login"))));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation())
|
||||
.isEqualTo(URI.create("http://localhost:" + this.port + "/login"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,9 +62,9 @@ public class SampleGithubApplicationTests {
|
||||
TestRestTemplate restTemplate = new TestRestTemplate();
|
||||
ResponseEntity<Void> entity = restTemplate
|
||||
.getForEntity("http://localhost:" + this.port + "/login", Void.class);
|
||||
assertThat(entity.getStatusCode(), is(HttpStatus.FOUND));
|
||||
assertThat(entity.getHeaders().getLocation().toString(),
|
||||
startsWith("https://github.com/login/oauth"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.startsWith("https://github.com/login/oauth");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -63,9 +61,9 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.endsWith(this.port + "/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,9 +73,8 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong content:\n" + entity.getBody(),
|
||||
entity.getBody().contains("_csrf"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("_csrf");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,23 +89,22 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/"));
|
||||
assertNotNull("Missing cookie:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().get("Set-Cookie"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.endsWith(this.port + "/");
|
||||
assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
ResponseEntity<String> page = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/login", String.class);
|
||||
assertEquals(HttpStatus.OK, page.getStatusCode());
|
||||
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String cookie = page.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*")
|
||||
.matcher(page.getBody());
|
||||
assertTrue("No csrf token: " + page.getBody(), matcher.matches());
|
||||
Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
|
||||
Matcher matcher = pattern.matcher(page.getBody());
|
||||
assertThat(matcher.matches()).as(page.getBody()).isTrue();
|
||||
headers.set("X-CSRF-TOKEN", matcher.group(1));
|
||||
return headers;
|
||||
}
|
||||
@@ -117,8 +113,8 @@ public class SampleWebSecureCustomApplicationTests {
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -63,9 +61,9 @@ public class SampleSecureApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port, HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/login"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.endsWith(this.port + "/login");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,9 +73,8 @@ public class SampleSecureApplicationTests {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().exchange(
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.GET,
|
||||
new HttpEntity<Void>(headers), String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong content:\n" + entity.getBody(),
|
||||
entity.getBody().contains("_csrf"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("_csrf");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,23 +89,22 @@ public class SampleSecureApplicationTests {
|
||||
"http://localhost:" + this.port + "/login", HttpMethod.POST,
|
||||
new HttpEntity<MultiValueMap<String, String>>(form, headers),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertTrue("Wrong location:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().getLocation().toString().endsWith(port + "/"));
|
||||
assertNotNull("Missing cookie:\n" + entity.getHeaders(),
|
||||
entity.getHeaders().get("Set-Cookie"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
assertThat(entity.getHeaders().getLocation().toString())
|
||||
.endsWith(this.port + "/");
|
||||
assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
|
||||
}
|
||||
|
||||
private HttpHeaders getHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
ResponseEntity<String> page = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port + "/login", String.class);
|
||||
assertEquals(HttpStatus.OK, page.getStatusCode());
|
||||
assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String cookie = page.getHeaders().getFirst("Set-Cookie");
|
||||
headers.set("Cookie", cookie);
|
||||
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*")
|
||||
.matcher(page.getBody());
|
||||
assertTrue("No csrf token: " + page.getBody(), matcher.matches());
|
||||
Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
|
||||
Matcher matcher = pattern.matcher(page.getBody());
|
||||
assertThat(matcher.matches()).as(page.getBody()).isTrue();
|
||||
headers.set("X-CSRF-TOKEN", matcher.group(1));
|
||||
return headers;
|
||||
}
|
||||
@@ -117,8 +113,8 @@ public class SampleSecureApplicationTests {
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,20 +18,19 @@ package sample.webstatic;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import sample.web.staticcontent.SampleWebStaticApplication;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -51,9 +50,8 @@ public class SampleWebStaticApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
|
||||
entity.getBody().contains("<title>Static"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("<title>Static");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,11 +61,10 @@ public class SampleWebStaticApplicationTests {
|
||||
"http://localhost:" + this.port
|
||||
+ "/webjars/bootstrap/3.0.3/css/bootstrap.min.css",
|
||||
String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(),
|
||||
MediaType.valueOf("text/css;charset=UTF-8"),
|
||||
entity.getHeaders().getContentType());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
assertThat(entity.getHeaders().getContentType())
|
||||
.isEqualTo(MediaType.valueOf("text/css;charset=UTF-8"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import sample.web.ui.SampleWebUiApplication;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.TestRestTemplate;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -33,9 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for demo application.
|
||||
@@ -55,11 +53,9 @@ public class SampleWebUiApplicationTests {
|
||||
public void testHome() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(),
|
||||
entity.getBody().contains("<title>Messages"));
|
||||
assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(),
|
||||
entity.getBody().contains("layout:fragment"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("<title>Messages");
|
||||
assertThat(entity.getBody()).doesNotContain("layout:fragment");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,16 +65,15 @@ public class SampleWebUiApplicationTests {
|
||||
map.set("summary", "FOO");
|
||||
URI location = new TestRestTemplate()
|
||||
.postForLocation("http://localhost:" + this.port, map);
|
||||
assertTrue("Wrong location:\n" + location,
|
||||
location.toString().contains("localhost:" + this.port));
|
||||
assertThat(location.toString()).contains("localhost:" + this.port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCss() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
|
||||
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("body");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Basic integration tests for Velocity application.
|
||||
@@ -56,9 +55,8 @@ public class SampleWebVelocityApplicationTests {
|
||||
public void testVelocityTemplate() throws Exception {
|
||||
ResponseEntity<String> entity = new TestRestTemplate()
|
||||
.getForEntity("http://localhost:" + this.port, String.class);
|
||||
assertEquals(HttpStatus.OK, entity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + entity.getBody(),
|
||||
entity.getBody().contains("Hello, Andy"));
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).contains("Hello, Andy");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,9 +69,9 @@ public class SampleWebVelocityApplicationTests {
|
||||
"http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
|
||||
requestEntity, String.class);
|
||||
|
||||
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
|
||||
assertTrue("Wrong body:\n" + responseEntity.getBody(),
|
||||
responseEntity.getBody().contains("Something went wrong: 404 Not Found"));
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
|
||||
assertThat(responseEntity.getBody())
|
||||
.contains("Something went wrong: 404 Not Found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import samples.websocket.jetty.client.GreetingService;
|
||||
import samples.websocket.jetty.client.SimpleClientWebSocketHandler;
|
||||
import samples.websocket.jetty.client.SimpleGreetingService;
|
||||
@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class)
|
||||
@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.isEqualTo("Did you say \"Hello world!\"?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import samples.websocket.jetty.SampleJettyWebSocketsApplication;
|
||||
import samples.websocket.jetty.client.GreetingService;
|
||||
import samples.websocket.jetty.client.SimpleClientWebSocketHandler;
|
||||
@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class,
|
||||
@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.isEqualTo("Did you say \"Hello world!\"?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -35,7 +34,7 @@ public class SnakeTimerTests {
|
||||
SnakeTimer.addSnake(snake);
|
||||
|
||||
SnakeTimer.broadcast("");
|
||||
assertThat(SnakeTimer.getSnakes().size(), is(0));
|
||||
assertThat(SnakeTimer.getSnakes()).hasSize(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import samples.websocket.tomcat.client.GreetingService;
|
||||
import samples.websocket.tomcat.client.SimpleClientWebSocketHandler;
|
||||
import samples.websocket.tomcat.client.SimpleGreetingService;
|
||||
@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class)
|
||||
@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.isEqualTo("Did you say \"Hello world!\"?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import samples.websocket.tomcat.SampleTomcatWebSocketApplication;
|
||||
import samples.websocket.tomcat.client.GreetingService;
|
||||
import samples.websocket.tomcat.client.SimpleClientWebSocketHandler;
|
||||
@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class,
|
||||
@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.isEqualTo("Did you say \"Hello world!\"?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -35,6 +34,6 @@ public class SnakeTimerTests {
|
||||
SnakeTimer.addSnake(snake);
|
||||
|
||||
SnakeTimer.broadcast("");
|
||||
assertThat(SnakeTimer.getSnakes().size(), is(0));
|
||||
assertThat(SnakeTimer.getSnakes()).hasSize(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import samples.websocket.undertow.client.GreetingService;
|
||||
import samples.websocket.undertow.client.SimpleClientWebSocketHandler;
|
||||
import samples.websocket.undertow.client.SimpleGreetingService;
|
||||
@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class)
|
||||
@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.isEqualTo("Did you say \"Hello world!\"?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import samples.websocket.undertow.SampleUndertowWebSocketsApplication;
|
||||
import samples.websocket.undertow.client.GreetingService;
|
||||
import samples.websocket.undertow.client.SimpleClientWebSocketHandler;
|
||||
@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.socket.client.WebSocketConnectionManager;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class,
|
||||
@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get())
|
||||
.isEqualTo("Did you say \"Hello world!\"?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
|
||||
AtomicReference<String> messagePayloadReference = context
|
||||
.getBean(ClientConfiguration.class).messagePayload;
|
||||
context.close();
|
||||
assertEquals(0, count);
|
||||
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get());
|
||||
assertThat(count).isEqualTo(0);
|
||||
assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -20,8 +20,7 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -35,6 +34,6 @@ public class SnakeTimerTests {
|
||||
SnakeTimer.addSnake(snake);
|
||||
|
||||
SnakeTimer.broadcast("");
|
||||
assertThat(SnakeTimer.getSnakes().size(), is(0));
|
||||
assertThat(SnakeTimer.getSnakes()).hasSize(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.ws.client.core.WebServiceTemplate;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(SampleWsApplication.class)
|
||||
@@ -68,7 +67,7 @@ public class SampleWsApplicationTests {
|
||||
StreamResult result = new StreamResult(System.out);
|
||||
|
||||
this.webServiceTemplate.sendSourceAndReceiveToResult(source, result);
|
||||
assertThat(this.output.toString(), containsString("Booking holiday for"));
|
||||
assertThat(this.output.toString()).contains("Booking holiday for");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.OutputCapture;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SampleSpringXmlApplicationTests {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class SampleSpringXmlApplicationTests {
|
||||
public void testDefaultSettings() throws Exception {
|
||||
SampleSpringXmlApplication.main(new String[0]);
|
||||
String output = this.outputCapture.toString();
|
||||
assertTrue("Wrong output: " + output, output.contains("Hello World"));
|
||||
assertThat(output).contains("Hello World");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user