This commit is contained in:
Phillip Webb
2017-11-01 15:48:03 -07:00
parent 44d8e09aac
commit c55b5d7111
62 changed files with 237 additions and 229 deletions

View File

@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.server.port=0", "management.server.context-path=/management"})
"management.server.port=0", "management.server.context-path=/management" })
@DirtiesContext
public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@@ -59,17 +59,17 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@Test
public void testSecureActuator() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/management/application/health",
String.class);
ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.managementPort
+ "/management/application/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
public void testInsecureActuator() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/management/application/status",
String.class);
ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.managementPort
+ "/management/application/status", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}
@@ -77,9 +77,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@Test
public void testMissing() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
.getForEntity(
"http://localhost:" + this.managementPort + "/management/application/missing",
String.class);
.getForEntity("http://localhost:" + this.managementPort
+ "/management/application/missing", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(entity.getBody()).contains("\"status\":404");
}

View File

@@ -62,8 +62,8 @@ public class ManagementAddressActuatorApplicationTests {
@Test
public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate()
.withBasicAuth("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/admin/application/health",
.withBasicAuth("user", getPassword()).getForEntity("http://localhost:"
+ this.managementPort + "/admin/application/health",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");

View File

@@ -49,9 +49,9 @@ public class ServletPathSampleActuatorApplicationTests {
@Test
public void testErrorPath() throws Exception {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword())
.getForEntity("/spring/error",
Map.class);
ResponseEntity<Map> entity = this.restTemplate
.withBasicAuth("user", getPassword())
.getForEntity("/spring/error", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody();

View File

@@ -30,7 +30,7 @@ public class City implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23)
@SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23)
@GeneratedValue(generator = "city_generator")
private Long id;

View File

@@ -36,7 +36,7 @@ public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28)
@SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28)
@GeneratedValue(generator = "hotel_generator")
private Long id;

View File

@@ -38,7 +38,7 @@ public class Review implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="review_generator", sequenceName="review_sequence", initialValue = 64)
@SequenceGenerator(name = "review_generator", sequenceName = "review_sequence", initialValue = 64)
@GeneratedValue(generator = "review_generator")
private Long id;

View File

@@ -30,7 +30,7 @@ public class City implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="city_generator", sequenceName="city_sequence", initialValue = 23)
@SequenceGenerator(name = "city_generator", sequenceName = "city_sequence", initialValue = 23)
@GeneratedValue(generator = "city_generator")
private Long id;

View File

@@ -33,7 +33,7 @@ public class Hotel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="hotel_generator", sequenceName="hotel_sequence", initialValue = 28)
@SequenceGenerator(name = "hotel_generator", sequenceName = "hotel_sequence", initialValue = 28)
@GeneratedValue(generator = "hotel_generator")
private Long id;

View File

@@ -24,7 +24,7 @@ import javax.persistence.SequenceGenerator;
@Entity
public class Person {
@Id
@SequenceGenerator(name="person_generator", sequenceName="person_sequence", allocationSize = 1)
@SequenceGenerator(name = "person_generator", sequenceName = "person_sequence", allocationSize = 1)
@GeneratedValue(generator = "person_generator")
private Long id;
private String firstName;

View File

@@ -28,7 +28,7 @@ import javax.persistence.SequenceGenerator;
public class Note {
@Id
@SequenceGenerator(name="note_generator", sequenceName="note_sequence", initialValue = 5)
@SequenceGenerator(name = "note_generator", sequenceName = "note_sequence", initialValue = 5)
@GeneratedValue(generator = "note_generator")
private long id;

View File

@@ -57,10 +57,8 @@ public class SampleOAuth2ClientApplicationTests {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/login",
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody())
.contains("/oauth2/authorization/github-client-1");
assertThat(entity.getBody())
.contains("/oauth2/authorization/github-client-2");
assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-1");
assertThat(entity.getBody()).contains("/oauth2/authorization/github-client-2");
}
}

View File

@@ -49,8 +49,8 @@ public class SamplePropertyValidationApplicationTests {
@Test
public void bindValidProperties() {
this.context.register(SamplePropertyValidationApplication.class);
TestPropertyValues.of("sample.host:192.168.0.1",
"sample.port:9090").applyTo(this.context);
TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090")
.applyTo(this.context);
this.context.refresh();
SampleProperties properties = this.context.getBean(SampleProperties.class);
assertThat(properties.getHost()).isEqualTo("192.168.0.1");
@@ -60,8 +60,8 @@ public class SamplePropertyValidationApplicationTests {
@Test
public void bindInvalidHost() {
this.context.register(SamplePropertyValidationApplication.class);
TestPropertyValues.of("sample.host:xxxxxx",
"sample.port:9090").applyTo(this.context);
TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090")
.applyTo(this.context);
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage("Failed to bind properties under 'sample'");
this.context.refresh();
@@ -79,8 +79,8 @@ public class SamplePropertyValidationApplicationTests {
public void validatorOnlyCalledOnSupportedClass() {
this.context.register(SamplePropertyValidationApplication.class);
this.context.register(ServerProperties.class); // our validator will not apply
TestPropertyValues.of("sample.host:192.168.0.1",
"sample.port:9090").applyTo(this.context);
TestPropertyValues.of("sample.host:192.168.0.1", "sample.port:9090")
.applyTo(this.context);
this.context.refresh();
SampleProperties properties = this.context.getBean(SampleProperties.class);
assertThat(properties.getHost()).isEqualTo("192.168.0.1");