Merge branch '2.7.x' into 3.0.x

This commit is contained in:
Phillip Webb
2023-02-21 23:15:40 -08:00
1890 changed files with 27173 additions and 21952 deletions

View File

@@ -100,8 +100,8 @@ abstract class AbstractLaunchScriptIntegrationTests {
private LaunchScriptTestContainer(String os, String version, String scriptsDir, String testScript) {
super(new ImageFromDockerfile("spring-boot-launch-script/" + os.toLowerCase() + "-" + version)
.withFileFromFile("Dockerfile",
new File("src/intTest/resources/conf/" + os + "/" + version + "/Dockerfile")));
.withFileFromFile("Dockerfile",
new File("src/intTest/resources/conf/" + os + "/" + version + "/Dockerfile")));
withCopyFileToContainer(MountableFile.forHostPath(findApplication().getAbsolutePath()), "/app.jar");
withCopyFileToContainer(
MountableFile.forHostPath("src/intTest/resources/scripts/" + scriptsDir + "test-functions.sh"),

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,7 +68,7 @@ class SysVinitLaunchScriptIntegrationTests extends AbstractLaunchScriptIntegrati
String output = doTest(os, version, "status-when-killed.sh");
assertThat(output).contains("Status: 1");
assertThat(output)
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
.has(coloredString(AnsiColor.RED, "Not running (process " + extractPid(output) + " not found)"));
}
@ParameterizedTest(name = "{0} {1}")
@@ -133,16 +133,16 @@ class SysVinitLaunchScriptIntegrationTests extends AbstractLaunchScriptIntegrati
@MethodSource("parameters")
void launchWithMissingLogFolderGeneratesAWarning(String os, String version) throws Exception {
String output = doTest(os, version, "launch-with-missing-log-folder.sh");
assertThat(output).has(
coloredString(AnsiColor.YELLOW, "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
assertThat(output)
.has(coloredString(AnsiColor.YELLOW, "LOG_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
}
@ParameterizedTest(name = "{0} {1}")
@MethodSource("parameters")
void launchWithMissingPidFolderGeneratesAWarning(String os, String version) throws Exception {
String output = doTest(os, version, "launch-with-missing-pid-folder.sh");
assertThat(output).has(
coloredString(AnsiColor.YELLOW, "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
assertThat(output)
.has(coloredString(AnsiColor.YELLOW, "PID_FOLDER /does/not/exist does not exist. Falling back to /tmp"));
}
@ParameterizedTest(name = "{0} {1}")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,16 +54,19 @@ class LoaderIntegrationTests {
try (GenericContainer<?> container = createContainer(javaRuntime)) {
container.start();
System.out.println(this.output.toUtf8String());
assertThat(this.output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:")
.doesNotContain("illegal").doesNotContain("jar written to temp");
assertThat(this.output.toUtf8String()).contains(">>>>> 287649 BYTES from")
.doesNotContain("WARNING:")
.doesNotContain("illegal")
.doesNotContain("jar written to temp");
}
}
private GenericContainer<?> createContainer(JavaRuntime javaRuntime) {
return javaRuntime.getContainer().withLogConsumer(this.output)
.withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
.withCommand("java", "-jar", "app.jar");
return javaRuntime.getContainer()
.withLogConsumer(this.output)
.withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar")
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
.withCommand("java", "-jar", "app.jar");
}
private File findApplication() {
@@ -116,7 +119,7 @@ class LoaderIntegrationTests {
static JavaRuntime oracleJdk17() {
ImageFromDockerfile image = new ImageFromDockerfile("spring-boot-loader/oracle-jdk-17")
.withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/Dockerfile"));
.withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/Dockerfile"));
return new JavaRuntime("Oracle JDK 17", JavaVersion.SEVENTEEN, () -> new GenericContainer<>(image));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,16 +82,17 @@ class EmbeddedServerContainerInvocationContextProvider
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
EmbeddedServletContainerTest annotation = context.getRequiredTestClass()
.getAnnotation(EmbeddedServletContainerTest.class);
return CONTAINERS.stream().map((container) -> getApplication(annotation, container))
.flatMap((builder) -> provideTestTemplateInvocationContexts(annotation, builder));
.getAnnotation(EmbeddedServletContainerTest.class);
return CONTAINERS.stream()
.map((container) -> getApplication(annotation, container))
.flatMap((builder) -> provideTestTemplateInvocationContexts(annotation, builder));
}
private Stream<EmbeddedServletContainerInvocationContext> provideTestTemplateInvocationContexts(
EmbeddedServletContainerTest annotation, Application application) {
return Stream.of(annotation.launchers())
.map((launcherClass) -> getAbstractApplicationLauncher(application, launcherClass))
.map((launcher) -> provideTestTemplateInvocationContext(application, launcher));
.map((launcherClass) -> getAbstractApplicationLauncher(application, launcherClass))
.map((launcher) -> provideTestTemplateInvocationContext(application, launcher));
}
private EmbeddedServletContainerInvocationContext provideTestTemplateInvocationContext(Application application,
@@ -186,8 +187,8 @@ class EmbeddedServerContainerInvocationContextProvider
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory(HttpClients.custom()
.setRetryStrategy(new DefaultHttpRequestRetryStrategy(10, TimeValue.of(1, TimeUnit.SECONDS)))
.build()));
.setRetryStrategy(new DefaultHttpRequestRetryStrategy(10, TimeValue.of(1, TimeUnit.SECONDS)))
.build()));
rest.setErrorHandler(new ResponseErrorHandler() {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,7 +68,7 @@ class EmbeddedServletContainerJarPackagingIntegrationTests {
@TestTemplate
void applicationClassesAreNotAvailableViaHttp(RestTemplate rest) {
ResponseEntity<String> entity = rest
.getForEntity("/BOOT-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
.getForEntity("/BOOT-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ class EmbeddedServletContainerWarDevelopmentIntegrationTests {
ResponseEntity<String> entity = rest.getForEntity("/resourcePaths", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(readLines(entity.getBody()))
.noneMatch((resourcePath) -> resourcePath.startsWith("/org/springframework/boot/loader"));
.noneMatch((resourcePath) -> resourcePath.startsWith("/org/springframework/boot/loader"));
}
private List<String> readLines(String input) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ class EmbeddedServletContainerWarPackagingIntegrationTests {
@TestTemplate
void applicationClassesAreNotAvailableViaHttp(RestTemplate rest) {
ResponseEntity<String> entity = rest
.getForEntity("/WEB-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
.getForEntity("/WEB-INF/classes/com/example/ResourceHandlingApplication.class", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@@ -98,14 +98,14 @@ class EmbeddedServletContainerWarPackagingIntegrationTests {
ResponseEntity<String> entity = rest.getForEntity("/resourcePaths", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(readLines(entity.getBody()))
.noneMatch((resourcePath) -> resourcePath.startsWith("/org/springframework/boot/loader"));
.noneMatch((resourcePath) -> resourcePath.startsWith("/org/springframework/boot/loader"));
}
@TestTemplate
void conditionalOnWarDeploymentBeanIsNotAvailableForEmbeddedServer(RestTemplate rest) {
assertThat(rest.getForEntity("/always", String.class).getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(rest.getForEntity("/conditionalOnWar", String.class).getStatusCode())
.isEqualTo(HttpStatus.NOT_FOUND);
.isEqualTo(HttpStatus.NOT_FOUND);
}
private List<String> readLines(String input) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ public class SecurityConfiguration {
requests.requestMatchers("/actuator/beans").hasRole("BEANS");
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
.hasRole("ACTUATOR");
.hasRole("ACTUATOR");
requests.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
requests.requestMatchers("/foo").permitAll();
requests.requestMatchers("/error").permitAll();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -156,21 +156,21 @@ abstract class AbstractSampleActuatorCustomSecurityTests {
@Test
void actuatorCustomMvcSecureEndpointWithAnonymous() {
ResponseEntity<String> entity = restTemplate()
.getForEntity(getManagementPath() + "/actuator/example/echo?text={t}", String.class, "test");
.getForEntity(getManagementPath() + "/actuator/example/echo?text={t}", String.class, "test");
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
void actuatorCustomMvcSecureEndpointWithUnauthorizedUser() {
ResponseEntity<String> entity = userRestTemplate()
.getForEntity(getManagementPath() + "/actuator/example/echo?text={t}", String.class, "test");
.getForEntity(getManagementPath() + "/actuator/example/echo?text={t}", String.class, "test");
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}
@Test
void actuatorCustomMvcSecureEndpointWithAuthorizedUser() {
ResponseEntity<String> entity = adminRestTemplate()
.getForEntity(getManagementPath() + "/actuator/example/echo?text={t}", String.class, "test");
.getForEntity(getManagementPath() + "/actuator/example/echo?text={t}", String.class, "test");
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("test");
assertThat(entity.getHeaders().getFirst("echo")).isEqualTo("test");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,7 +67,9 @@ class CorsSampleActuatorApplicationTests {
@Test
void preflightRequestToEndpointShouldReturnOk() throws Exception {
RequestEntity<?> envRequest = RequestEntity.options(new URI("/actuator/env"))
.header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build();
.header("Origin", "http://localhost:8080")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<?> exchange = this.testRestTemplate.exchange(envRequest, Map.class);
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@@ -75,7 +77,9 @@ class CorsSampleActuatorApplicationTests {
@Test
void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception {
RequestEntity<?> entity = RequestEntity.options(new URI("/actuator/env"))
.header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build();
.header("Origin", "http://localhost:9095")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity, byte[].class);
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ class ManagementPortAndPathSampleActuatorApplicationTests extends AbstractSample
@Test
void testMissing() {
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(entity.getBody()).contains("\"status\":404");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ class ManagementPortCustomServletPathSampleActuatorTests extends AbstractSampleA
@Test
void actuatorPathOnMainPortShouldNotMatch() {
ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/example/actuator/health", String.class);
.getForEntity("http://localhost:" + this.port + "/example/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,9 +59,11 @@ class SampleActuatorLog4J2ApplicationTests {
@Test
void validateLoggersEndpoint() throws Exception {
this.mvc.perform(get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol").header("Authorization",
getBasicAuth())).andExpect(status().isOk())
.andExpect(content().string("{\"configuredLevel\":\"WARN\",\"effectiveLevel\":\"WARN\"}"));
this.mvc
.perform(get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol").header("Authorization",
getBasicAuth()))
.andExpect(status().isOk())
.andExpect(content().string("{\"configuredLevel\":\"WARN\",\"effectiveLevel\":\"WARN\"}"));
}
private String getBasicAuth() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,14 +55,14 @@ class SampleActuatorUiApplicationPortTests {
void testMetrics() {
@SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,8 +49,8 @@ class SampleActuatorUiApplicationTests {
void testHome() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/",
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
.exchange("/", HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("<title>Hello");
}
@@ -73,11 +73,12 @@ class SampleActuatorUiApplicationTests {
void testError() {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/error",
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
.exchange("/error", HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(entity.getBody()).contains("<html>").contains("<body>")
.contains("Please contact the operator with the above information");
assertThat(entity.getBody()).contains("<html>")
.contains("<body>")
.contains("Please contact the operator with the above information");
}
private String getPassword() {

View File

@@ -58,14 +58,14 @@ abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
void testMetrics() {
testHome(); // makes sure some requests have been made
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate()
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"comp\",\"live\",\"ready\"]}");
}
@@ -73,7 +73,7 @@ abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
@Test
void testGroupWithComposite() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/health/comp", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/admin/health/comp", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains(
"components\":{\"a\":{\"status\":\"UP\",\"details\":{\"hello\":\"spring-a\"}},\"c\":{\"status\":\"UP\",\"details\":{\"hello\":\"spring-c\"}}");
@@ -83,15 +83,15 @@ abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
void testEnvNotFound() {
String unknownProperty = "test-does-not-exist";
assertThat(this.environment.containsProperty(unknownProperty)).isFalse();
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password").getForEntity(
"http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class);
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
void testMissing() {
ResponseEntity<String> entity = new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(entity.getBody()).contains("\"status\":404");
}
@@ -99,7 +99,7 @@ abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
@Test
void testErrorPage() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.port + "/error", Map.class));
.getForEntity("http://localhost:" + this.port + "/error", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(entity.getBody()).containsEntry("status", 999);
}
@@ -107,7 +107,7 @@ abstract class AbstractManagementPortAndPathSampleActuatorApplicationTests {
@Test
void testManagementErrorPage() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).containsEntry("status", 999);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,7 +67,9 @@ class CorsSampleActuatorApplicationTests {
@Test
void preflightRequestToEndpointShouldReturnOk() throws Exception {
RequestEntity<?> healthRequest = RequestEntity.options(new URI("/actuator/env"))
.header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build();
.header("Origin", "http://localhost:8080")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest, Map.class);
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@@ -75,7 +77,9 @@ class CorsSampleActuatorApplicationTests {
@Test
void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception {
RequestEntity<?> entity = RequestEntity.options(new URI("/actuator/env"))
.header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build();
.header("Origin", "http://localhost:9095")
.header("Access-Control-Request-Method", "GET")
.build();
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity, byte[].class);
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
}

View File

@@ -55,7 +55,7 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
@Test
void testCustomContextPath() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/admin/health", String.class);
.getForEntity("/admin/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
assertThat(entity.getBody()).contains("\"hello\":\"world\"");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ class ManagementAddressActuatorApplicationTests {
@Test
void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ class ManagementDifferentPortAndEndpointWithExceptionHandlerSampleActuatorApplic
@Test
void testExceptionHandlerRestControllerEndpoint() {
ResponseEntity<String> entity = new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/actuator/exception", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/exception", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.I_AM_A_TEAPOT);
assertThat(entity.getBody()).isEqualTo("this is a custom exception body");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ class ManagementDifferentPortSampleActuatorApplicationTests {
@Test
void linksEndpointShouldBeAvailable() {
ResponseEntity<String> entity = new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort, String.class);
.getForEntity("http://localhost:" + this.managementPort, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\"");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ class ManagementPathSampleActuatorApplicationTests {
@Test
void testHealth() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/admin/health", String.class);
.getForEntity("/admin/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

View File

@@ -69,14 +69,14 @@ class ManagementPortSampleActuatorApplicationTests {
void testMetrics() {
testHome(); // makes sure some requests have been made
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate()
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
assertThat(entity.getBody()).contains("\"example\"");
@@ -86,7 +86,7 @@ class ManagementPortSampleActuatorApplicationTests {
@Test
void testErrorPage() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).containsEntry("status", 999);
}
@@ -95,7 +95,7 @@ class ManagementPortSampleActuatorApplicationTests {
void securityContextIsAvailableToErrorHandling() {
this.errorAttributes.securityContext = null;
ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/404", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/404", Map.class));
assertThat(this.errorAttributes.securityContext.getAuthentication()).isNotNull();
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(entity.getBody()).containsEntry("status", 404);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ class ManagementPortWithLazyInitializationTests {
@Test
void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ class SampleActuatorApplicationIsolatedObjectMapperFalseTests {
@Test
void resourceShouldBeAvailableOnMainPort() {
ResponseEntity<String> entity = this.testRestTemplate.withBasicAuth("user", "password")
.getForEntity("/actuator/startup", String.class);
.getForEntity("/actuator/startup", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ class SampleActuatorApplicationIsolatedObjectMapperTrueTests {
@Test
void resourceShouldBeAvailableOnMainPort() {
ResponseEntity<String> entity = this.testRestTemplate.withBasicAuth("user", "password")
.getForEntity("/actuator/startup", String.class);
.getForEntity("/actuator/startup", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"timeline\":");
}

View File

@@ -111,8 +111,8 @@ class SampleActuatorApplicationTests {
@Test
void testErrorPage() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password").getForEntity("/foo",
String.class);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/foo", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
String body = entity.getBody();
assertThat(body).contains("\"error\":");
@@ -123,8 +123,8 @@ class SampleActuatorApplicationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<?> request = new HttpEntity<Void>(headers);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password").exchange("/foo",
HttpMethod.GET, request, String.class);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.exchange("/foo", HttpMethod.GET, request, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
String body = entity.getBody();
assertThat(body).as("Body was null").isNotNull();

View File

@@ -52,7 +52,7 @@ class ServletPathSampleActuatorApplicationTests {
@Test
void testHealth() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/spring/actuator/health", String.class);
.getForEntity("/spring/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

View File

@@ -59,7 +59,7 @@ class ShutdownSampleActuatorApplicationTests {
@DirtiesContext
void testShutdown() {
ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.withBasicAuth("user", "password")
.postForEntity("/actuator/shutdown", null, Map.class));
.postForEntity("/actuator/shutdown", null, Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(((String) entity.getBody().get("message"))).contains("Shutting down");
}

View File

@@ -38,8 +38,9 @@ public class SampleAntApplicationIT {
@Test
void runJar() throws Exception {
File libs = new File("build/ant/libs");
Process process = new JavaExecutable().processBuilder("-jar", "spring-boot-smoke-test-ant.jar").directory(libs)
.start();
Process process = new JavaExecutable().processBuilder("-jar", "spring-boot-smoke-test-ant.jar")
.directory(libs)
.start();
process.waitFor(5, TimeUnit.MINUTES);
assertThat(process.exitValue()).isZero();
String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,8 +52,8 @@ class SubversionConfigDataLoader implements ConfigDataLoader<SubversionConfigDat
@Override
public ConfigData load(ConfigDataLoaderContext context, SubversionConfigDataResource resource)
throws IOException, ConfigDataLocationNotFoundException {
context.getBootstrapContext().registerIfAbsent(SubversionServerCertificate.class,
InstanceSupplier.of(resource.getServerCertificate()));
context.getBootstrapContext()
.registerIfAbsent(SubversionServerCertificate.class, InstanceSupplier.of(resource.getServerCertificate()));
SubversionClient client = context.getBootstrapContext().get(SubversionClient.class);
String loaded = client.load(resource.getLocation());
PropertySource<?> propertySource = new MapPropertySource("svn", Collections.singletonMap("svn", loaded));
@@ -61,8 +61,9 @@ class SubversionConfigDataLoader implements ConfigDataLoader<SubversionConfigDat
}
private static void onBootstrapContextClosed(BootstrapContextClosedEvent event) {
event.getApplicationContext().getBeanFactory().registerSingleton("subversionClient",
event.getBootstrapContext().get(SubversionClient.class));
event.getApplicationContext()
.getBeanFactory()
.registerSingleton("subversionClient", event.getBootstrapContext().get(SubversionClient.class));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,8 +44,8 @@ class SubversionConfigDataLocationResolver implements ConfigDataLocationResolver
ConfigDataLocation location)
throws ConfigDataLocationNotFoundException, ConfigDataResourceNotFoundException {
String serverCertificate = context.getBinder().bind("spring.svn.server.certificate", String.class).orElse(null);
return Collections.singletonList(
new SubversionConfigDataResource(location.getNonPrefixedValue(PREFIX), serverCertificate));
return Collections
.singletonList(new SubversionConfigDataResource(location.getNonPrefixedValue(PREFIX), serverCertificate));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ class SampleBootstrapRegistryApplicationTests {
void testBootstrapper(CapturedOutput output) {
SampleBootstrapRegistryApplication.main(new String[0]);
assertThat(output).contains("svn my-data from svn / example.com[secret]")
.contains("client smoketest.bootstrapregistry.app.MySubversionClient");
.contains("client smoketest.bootstrapregistry.app.MySubversionClient");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,8 +50,9 @@ class SampleDataJdbcApplicationTests {
@Test
void testCustomers() throws Exception {
this.mvc.perform(get("/").param("name", "merEDith")).andExpect(status().isOk())
.andExpect(content().string(containsString("Meredith")));
this.mvc.perform(get("/").param("name", "merEDith"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Meredith")));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,7 +66,7 @@ class SampleDataJpaApplicationTests {
@Test
void testJmx() throws Exception {
assertThat(ManagementFactory.getPlatformMBeanServer()
.queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null)).hasSize(1);
.queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null)).hasSize(1);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ class CityRepositoryTests {
@Container
static PostgreSQLContainer<?> postgresql = new PostgreSQLContainer<>(DockerImageNames.postgresql())
.withDatabaseName("test_flyway");
.withDatabaseName("test_flyway");
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
@@ -59,7 +59,8 @@ class CityRepositoryTests {
@Test
void databaseHasBeenInitialized() {
StepVerifier.create(this.repository.findByState("DC").filter((city) -> city.getName().equals("Washington")))
.consumeNextWith((city) -> assertThat(city.getId()).isNotNull()).verifyComplete();
.consumeNextWith((city) -> assertThat(city.getId()).isNotNull())
.verifyComplete();
}
private static String r2dbcUrl() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ class CityRepositoryTests {
@Container
static PostgreSQLContainer<?> postgresql = new PostgreSQLContainer<>(DockerImageNames.postgresql())
.withDatabaseName("test_liquibase");
.withDatabaseName("test_liquibase");
@DynamicPropertySource
static void postgresqlProperties(DynamicPropertyRegistry registry) {
@@ -59,7 +59,8 @@ class CityRepositoryTests {
@Test
void databaseHasBeenInitialized() {
StepVerifier.create(this.repository.findByState("DC").filter((city) -> city.getName().equals("Washington")))
.consumeNextWith((city) -> assertThat(city.getId()).isNotNull()).verifyComplete();
.consumeNextWith((city) -> assertThat(city.getId()).isNotNull())
.verifyComplete();
}
private static String r2dbcUrl() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,12 @@ class SampleR2dbcApplicationTests {
@Test
void citiesEndpointReturnInitialState() {
this.webClient.get().uri("/cities").exchange().expectBody().jsonPath("$[*].id")
.isEqualTo(new JSONArray().appendElement(2000).appendElement(2001));
this.webClient.get()
.uri("/cities")
.exchange()
.expectBody()
.jsonPath("$[*].id")
.isEqualTo(new JSONArray().appendElement(2000).appendElement(2001));
}
@Test
@@ -51,9 +55,16 @@ class SampleR2dbcApplicationTests {
@Test
void healthEndpointHasR2dbcEntry() {
this.webClient.get().uri("/actuator/health").exchange().expectStatus().isOk().expectBody()
.jsonPath("components.r2dbc.status").isEqualTo("UP").jsonPath("components.r2dbc.details.database")
.isEqualTo("H2");
this.webClient.get()
.uri("/actuator/health")
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("components.r2dbc.status")
.isEqualTo("UP")
.jsonPath("components.r2dbc.details.database")
.isEqualTo("H2");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,15 +61,17 @@ class SampleDataRestApplicationTests {
@Test
void findByNameAndCountry() throws Exception {
this.mvc.perform(get("/api/cities/search/findByNameAndCountryAllIgnoringCase?name=Melbourne&country=Australia"))
.andExpect(status().isOk()).andExpect(jsonPath("state", equalTo("Victoria")))
.andExpect(jsonPath("name", equalTo("Melbourne")));
.andExpect(status().isOk())
.andExpect(jsonPath("state", equalTo("Victoria")))
.andExpect(jsonPath("name", equalTo("Melbourne")));
}
@Test
void findByContaining() throws Exception {
this.mvc.perform(
get("/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
.andExpect(status().isOk()).andExpect(jsonPath("_embedded.cities", hasSize(3)));
this.mvc
.perform(get("/api/cities/search/findByNameContainingAndCountryContainingAllIgnoringCase?name=&country=UK"))
.andExpect(status().isOk())
.andExpect(jsonPath("_embedded.cities", hasSize(3)));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,10 +36,11 @@ public class SecurityConfig {
@Bean
public DefaultSecurityFilterChain springWebFilterChain(HttpSecurity http) throws Exception {
return http.csrf((csrf) -> csrf.disable())
// Demonstrate that method security works
// Best practice to use both for defense in depth
.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll()).httpBasic(withDefaults())
.build();
// Demonstrate that method security works
// Best practice to use both for defense in depth
.authorizeHttpRequests((requests) -> requests.anyRequest().permitAll())
.httpBasic(withDefaults())
.build();
}
@Bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,22 +44,29 @@ class GreetingControllerTests {
@Test
void shouldGreetWithSpecificName() {
HttpGraphQlTester authenticated = withAdminCredentials(this.graphQlTester);
authenticated.documentName("greeting").variable("name", "Brian").execute().path("greeting").entity(String.class)
.isEqualTo("Hello, Brian!");
authenticated.documentName("greeting")
.variable("name", "Brian")
.execute()
.path("greeting")
.entity(String.class)
.isEqualTo("Hello, Brian!");
}
@Test
void shouldGreetWithDefaultName() {
HttpGraphQlTester authenticated = withAdminCredentials(this.graphQlTester);
authenticated.document("{ greeting }").execute().path("greeting").entity(String.class)
.isEqualTo("Hello, Spring!");
authenticated.document("{ greeting }")
.execute()
.path("greeting")
.entity(String.class)
.isEqualTo("Hello, Spring!");
}
private HttpGraphQlTester withAdminCredentials(HttpGraphQlTester graphQlTester) {
return graphQlTester.mutate()
.webTestClient(
(httpClient) -> httpClient.defaultHeaders((headers) -> headers.setBasicAuth("admin", "admin")))
.build();
.webTestClient(
(httpClient) -> httpClient.defaultHeaders((headers) -> headers.setBasicAuth("admin", "admin")))
.build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,14 +30,19 @@ class ProjectControllerTests {
@Test
void shouldFindSpringGraphQl() {
this.graphQlTester.document("{ project(slug: \"spring-graphql\") { name } }").execute().path("project.name")
.entity(String.class).isEqualTo("Spring GraphQL");
this.graphQlTester.document("{ project(slug: \"spring-graphql\") { name } }")
.execute()
.path("project.name")
.entity(String.class)
.isEqualTo("Spring GraphQL");
}
@Test
void shouldNotFindUnknownProject() {
this.graphQlTester.document("{ project(slug: \"spring-unknown\") { name } }").execute().path("project.name")
.pathDoesNotExist();
this.graphQlTester.document("{ project(slug: \"spring-unknown\") { name } }")
.execute()
.path("project.name")
.pathDoesNotExist();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,8 +63,12 @@ public class SampleIntegrationApplication {
@Bean
public IntegrationFlow integrationFlow(SampleEndpoint endpoint) {
return IntegrationFlow.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint)
.channel(outputChannel()).handle(fileWriter()).get();
return IntegrationFlow.from(fileReader(), new FixedRatePoller())
.channel(inputChannel())
.handle(endpoint)
.channel(outputChannel())
.handle(fileWriter())
.get();
}
public static void main(String[] args) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,8 +77,8 @@ class SampleIntegrationApplicationTests {
}
private void awaitOutputContaining(File outputDir, String requiredContents) {
Awaitility.waitAtMost(Duration.ofSeconds(30)).until(() -> outputIn(outputDir),
containsString(requiredContents));
Awaitility.waitAtMost(Duration.ofSeconds(30))
.until(() -> outputIn(outputDir), containsString(requiredContents));
}
private String outputIn(File outputDir) throws IOException {
@@ -91,7 +91,7 @@ class SampleIntegrationApplicationTests {
private Resource[] findResources(File outputDir) throws IOException {
return ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader())
.getResources("file:" + outputDir.getAbsolutePath() + "/*.txt");
.getResources("file:" + outputDir.getAbsolutePath() + "/*.txt");
}
private String readResources(Resource[] resources) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,10 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
public class SampleJerseyApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)
.applicationStartup(new BufferingApplicationStartup(2048))).run(args);
new SampleJerseyApplication()
.configure(new SpringApplicationBuilder(SampleJerseyApplication.class)
.applicationStartup(new BufferingApplicationStartup(2048)))
.run(args);
}
}

View File

@@ -65,21 +65,21 @@ class AbstractJerseyManagementPortTests {
@Test
void resourceShouldNotBeAvailableOnManagementPort() {
ResponseEntity<String> entity = this.testRestTemplate
.getForEntity("http://localhost:" + this.managementPort + "/test", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/test", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
void actuatorShouldBeAvailableOnManagementPort() {
ResponseEntity<String> entity = this.testRestTemplate
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
}
@Test
void actuatorShouldNotBeAvailableOnMainPort() {
ResponseEntity<String> entity = this.testRestTemplate
.getForEntity("http://localhost:" + this.port + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.port + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,10 +53,10 @@ class JerseyActuatorIsolatedObjectMapperFalseTests {
@Test
void resourceShouldBeAvailableOnMainPort() {
ResponseEntity<String> entity = this.testRestTemplate
.getForEntity("http://localhost:" + this.port + "/actuator/startup", String.class);
.getForEntity("http://localhost:" + this.port + "/actuator/startup", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(entity.getBody())
.contains("Java 8 date/time type `java.time.Clock$SystemClock` not supported by default");
.contains("Java 8 date/time type `java.time.Clock$SystemClock` not supported by default");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ class JerseyActuatorIsolatedObjectMapperTrueTests {
@Test
void resourceShouldBeAvailableOnMainPort() {
ResponseEntity<String> entity = this.testRestTemplate
.getForEntity("http://localhost:" + this.port + "/actuator/startup", String.class);
.getForEntity("http://localhost:" + this.port + "/actuator/startup", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"timeline\":");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ class JerseyApplicationPathAndManagementPortTests {
@Test
void applicationPathShouldNotAffectActuators() {
ResponseEntity<String> entity = this.testRestTemplate
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ class JerseyDifferentPortSampleActuatorApplicationTests {
@Test
void linksEndpointShouldBeAvailable() {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\"");
}

View File

@@ -56,14 +56,14 @@ class SampleLiquibaseApplicationTests {
assumeThat(serverNotRunning(ex)).isFalse();
}
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")
.contains("New row inserted into person")
.contains("ChangeSet classpath:/db/changelog/"
+ "db.changelog-master.yaml::2::marceloverdijk ran successfully")
.contains("Successfully released 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")
.contains("New row inserted into person")
.contains("ChangeSet classpath:/db/changelog/"
+ "db.changelog-master.yaml::2::marceloverdijk ran successfully")
.contains("Successfully released change log lock");
}
private boolean serverNotRunning(IllegalStateException ex) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -100,7 +100,8 @@ class SampleOauth2ResourceServerApplicationTests {
+ "8CJ453lo4gcBm1efURN3LIVc1V9NQY_ESBKVdwqYyoJPEanURLVGRd6cQKn6YrCbbIRHjqAyqOE-z3KmgDJnPriljfR5XhSGyM9eq"
+ "D9Xpy6zu_MAeMJJfSArp857zLPk-Wf5VP9STAcjyfdBIybMKnwBYr2qHMT675hQ\"}]}";
return new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.setResponseCode(200).setBody(body);
.setResponseCode(200)
.setBody(body);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,8 +73,12 @@ public class SampleParentContextApplication {
@Bean
public IntegrationFlow integrationFlow(SampleEndpoint endpoint) {
return IntegrationFlow.from(fileReader(), new FixedRatePoller()).channel(inputChannel()).handle(endpoint)
.channel(outputChannel()).handle(fileWriter()).get();
return IntegrationFlow.from(fileReader(), new FixedRatePoller())
.channel(inputChannel())
.handle(endpoint)
.channel(outputChannel())
.handle(fileWriter())
.get();
}
private static class FixedRatePoller implements Consumer<SourcePollingChannelAdapterSpec> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,8 +59,8 @@ class SampleIntegrationParentApplicationTests {
}
private void awaitOutputContaining(File outputDir, String requiredContents) {
Awaitility.waitAtMost(Duration.ofSeconds(30)).until(() -> outputIn(outputDir),
containsString(requiredContents));
Awaitility.waitAtMost(Duration.ofSeconds(30))
.until(() -> outputIn(outputDir), containsString(requiredContents));
}
private String outputIn(File outputDir) throws IOException {
@@ -73,7 +73,7 @@ class SampleIntegrationParentApplicationTests {
private Resource[] findResources(File outputDir) throws IOException {
return ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader())
.getResources("file:" + outputDir.getAbsolutePath() + "/*.txt");
.getResources("file:" + outputDir.getAbsolutePath() + "/*.txt");
}
private String readResources(Resource[] resources) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,15 +57,17 @@ class SamplePropertyValidationApplicationTests {
void bindInvalidHost() {
this.context.register(SamplePropertyValidationApplication.class);
TestPropertyValues.of("sample.host:xxxxxx", "sample.port:9090").applyTo(this.context);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh).havingRootCause()
.isInstanceOf(BindValidationException.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh)
.havingRootCause()
.isInstanceOf(BindValidationException.class);
}
@Test
void bindNullHost() {
this.context.register(SamplePropertyValidationApplication.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh).havingRootCause()
.isInstanceOf(BindValidationException.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(this.context::refresh)
.havingRootCause()
.isInstanceOf(BindValidationException.class);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,49 +42,69 @@ public class SampleQuartzApplication {
@Bean
public JobDetail helloJobDetail() {
return JobBuilder.newJob(SampleJob.class).withIdentity("helloJob", "samples").usingJobData("name", "World")
.storeDurably().build();
return JobBuilder.newJob(SampleJob.class)
.withIdentity("helloJob", "samples")
.usingJobData("name", "World")
.storeDurably()
.build();
}
@Bean
public JobDetail anotherJobDetail() {
return JobBuilder.newJob(SampleJob.class).withIdentity("anotherJob", "samples").usingJobData("name", "Everyone")
.storeDurably().build();
return JobBuilder.newJob(SampleJob.class)
.withIdentity("anotherJob", "samples")
.usingJobData("name", "Everyone")
.storeDurably()
.build();
}
@Bean
public Trigger everyTwoSecTrigger() {
return TriggerBuilder.newTrigger().forJob("helloJob", "samples").withIdentity("sampleTrigger")
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever()).build();
return TriggerBuilder.newTrigger()
.forJob("helloJob", "samples")
.withIdentity("sampleTrigger")
.withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever())
.build();
}
@Bean
public Trigger everyDayTrigger() {
return TriggerBuilder.newTrigger().forJob("helloJob", "samples").withIdentity("every-day", "samples")
.withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24)).build();
return TriggerBuilder.newTrigger()
.forJob("helloJob", "samples")
.withIdentity("every-day", "samples")
.withSchedule(SimpleScheduleBuilder.repeatHourlyForever(24))
.build();
}
@Bean
public Trigger threeAmWeekdaysTrigger() {
return TriggerBuilder.newTrigger().forJob("anotherJob", "samples").withIdentity("3am-weekdays", "samples")
.withSchedule(CronScheduleBuilder.atHourAndMinuteOnGivenDaysOfWeek(3, 0, 1, 2, 3, 4, 5)).build();
return TriggerBuilder.newTrigger()
.forJob("anotherJob", "samples")
.withIdentity("3am-weekdays", "samples")
.withSchedule(CronScheduleBuilder.atHourAndMinuteOnGivenDaysOfWeek(3, 0, 1, 2, 3, 4, 5))
.build();
}
@Bean
public Trigger onceAWeekTrigger() {
return TriggerBuilder.newTrigger().forJob("anotherJob", "samples").withIdentity("once-a-week", "samples")
.withSchedule(CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInWeeks(1))
.build();
return TriggerBuilder.newTrigger()
.forJob("anotherJob", "samples")
.withIdentity("once-a-week", "samples")
.withSchedule(CalendarIntervalScheduleBuilder.calendarIntervalSchedule().withIntervalInWeeks(1))
.build();
}
@Bean
public Trigger everyHourWorkingHourTuesdayAndThursdayTrigger() {
return TriggerBuilder.newTrigger().forJob("helloJob", "samples").withIdentity("every-hour-tue-thu", "samples")
.withSchedule(DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
.onDaysOfTheWeek(Calendar.TUESDAY, Calendar.THURSDAY)
.startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0))
.endingDailyAt(TimeOfDay.hourAndMinuteOfDay(18, 0)).withInterval(1, IntervalUnit.HOUR))
.build();
return TriggerBuilder.newTrigger()
.forJob("helloJob", "samples")
.withIdentity("every-hour-tue-thu", "samples")
.withSchedule(DailyTimeIntervalScheduleBuilder.dailyTimeIntervalSchedule()
.onDaysOfTheWeek(Calendar.TUESDAY, Calendar.THURSDAY)
.startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0))
.endingDailyAt(TimeOfDay.hourAndMinuteOfDay(18, 0))
.withInterval(1, IntervalUnit.HOUR))
.build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ class SampleQuartzApplicationWebTests {
@Test
void quartzTriggerDetailWhenNameDoesNotExistReturns404() {
ResponseEntity<String> response = this.restTemplate
.getForEntity("/actuator/quartz/triggers/samples/does-not-exist", String.class);
.getForEntity("/actuator/quartz/triggers/samples/does-not-exist", String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,14 +34,24 @@ class SampleReactiveOAuth2ClientApplicationTests {
@Test
void everythingShouldRedirectToLogin() {
this.webTestClient.get().uri("/").exchange().expectStatus().isFound().expectHeader().valueEquals("Location",
"/login");
this.webTestClient.get()
.uri("/")
.exchange()
.expectStatus()
.isFound()
.expectHeader()
.valueEquals("Location", "/login");
}
@Test
void loginShouldHaveBothOAuthClientsToChooseFrom() {
byte[] body = this.webTestClient.get().uri("/login").exchange().expectStatus().isOk().returnResult(String.class)
.getResponseBodyContent();
byte[] body = this.webTestClient.get()
.uri("/login")
.exchange()
.expectStatus()
.isOk()
.returnResult(String.class)
.getResponseBodyContent();
String bodyString = new String(body);
assertThat(bodyString).contains("/oauth2/authorization/yahoo");
assertThat(bodyString).contains("/oauth2/authorization/github-client-1");
@@ -50,8 +60,13 @@ class SampleReactiveOAuth2ClientApplicationTests {
@Test
void actuatorShouldBeSecuredByOAuth() {
this.webTestClient.get().uri("/actuator/health").exchange().expectStatus().isFound().expectHeader()
.valueEquals("Location", "/login");
this.webTestClient.get()
.uri("/actuator/health")
.exchange()
.expectStatus()
.isFound()
.expectHeader()
.valueEquals("Location", "/login");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,14 +58,25 @@ class SampleReactiveOAuth2ResourceServerApplicationTests {
@Test
void getWhenValidTokenShouldBeOk() {
this.webTestClient.get().uri("/").headers((headers) -> headers.setBearerAuth(VALID_TOKEN)).exchange()
.expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, subject!");
this.webTestClient.get()
.uri("/")
.headers((headers) -> headers.setBearerAuth(VALID_TOKEN))
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.isEqualTo("Hello, subject!");
}
@Test
void getWhenNoTokenShouldBeUnauthorized() {
this.webTestClient.get().uri("/").exchange().expectStatus().isUnauthorized().expectHeader()
.valueEquals(HttpHeaders.WWW_AUTHENTICATE, "Bearer");
this.webTestClient.get()
.uri("/")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.valueEquals(HttpHeaders.WWW_AUTHENTICATE, "Bearer");
}
private static MockResponse mockResponse() {
@@ -87,7 +98,8 @@ class SampleReactiveOAuth2ResourceServerApplicationTests {
+ "8CJ453lo4gcBm1efURN3LIVc1V9NQY_ESBKVdwqYyoJPEanURLVGRd6cQKn6YrCbbIRHjqAyqOE-z3KmgDJnPriljfR5XhSGyM9eq"
+ "D9Xpy6zu_MAeMJJfSArp857zLPk-Wf5VP9STAcjyfdBIybMKnwBYr2qHMT675hQ\"}]}";
return new MockResponse().setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.setResponseCode(200).setBody(body);
.setResponseCode(200)
.setBody(body);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,13 +50,14 @@ class SampleRSocketApplicationTests {
@Test
void rSocketEndpoint() {
RSocketRequester requester = this.builder
.rsocketStrategies((builder) -> builder.encoder(new SimpleAuthenticationEncoder()))
.setupMetadata(new UsernamePasswordMetadata("user", "password"),
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString()))
.tcp("localhost", this.port);
.rsocketStrategies((builder) -> builder.encoder(new SimpleAuthenticationEncoder()))
.setupMetadata(new UsernamePasswordMetadata("user", "password"),
MimeTypeUtils.parseMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.getString()))
.tcp("localhost", this.port);
Mono<Project> result = requester.route("find.project.spring-boot").retrieveMono(Project.class);
StepVerifier.create(result).assertNext((project) -> assertThat(project.getName()).isEqualTo("spring-boot"))
.verifyComplete();
StepVerifier.create(result)
.assertNext((project) -> assertThat(project.getName()).isEqualTo("spring-boot"))
.verifyComplete();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,10 +32,16 @@ public class SecurityConfiguration {
@Bean
public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
return new InMemoryUserDetailsManager(
User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER")
.build(),
User.withDefaultPasswordEncoder().username("admin").password("admin")
.authorities("ROLE_ACTUATOR", "ROLE_USER").build());
User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.authorities("ROLE_USER")
.build(),
User.withDefaultPasswordEncoder()
.username("admin")
.password("admin")
.authorities("ROLE_ACTUATOR", "ROLE_USER")
.build());
}
@Bean
@@ -43,7 +49,7 @@ public class SecurityConfiguration {
http.authorizeHttpRequests((requests) -> {
requests.requestMatchers(EndpointRequest.to("health")).permitAll();
requests.requestMatchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
.hasRole("ACTUATOR");
.hasRole("ACTUATOR");
requests.requestMatchers("/**").hasRole("USER");
});
http.httpBasic();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ class ManagementPortAndPathJerseyApplicationTests extends AbstractJerseySecureTe
@Test
void testMissing() {
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ class ManagementPortCustomApplicationPathJerseyTests extends AbstractJerseySecur
@Test
void actuatorPathOnMainPortShouldNotMatch() {
ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/example/actuator/health", String.class);
.getForEntity("http://localhost:" + this.port + "/example/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,14 +42,24 @@ class CorsSampleActuatorApplicationTests {
@Test
void preflightRequestToEndpointShouldReturnOk() {
this.webClient.options().uri("/actuator/env").header("Origin", "http://localhost:8080")
.header("Access-Control-Request-Method", "GET").exchange().expectStatus().isOk();
this.webClient.options()
.uri("/actuator/env")
.header("Origin", "http://localhost:8080")
.header("Access-Control-Request-Method", "GET")
.exchange()
.expectStatus()
.isOk();
}
@Test
void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() {
this.webClient.options().uri("/actuator/env").header("Origin", "http://localhost:9095")
.header("Access-Control-Request-Method", "GET").exchange().expectStatus().isForbidden();
this.webClient.options()
.uri("/actuator/env")
.header("Origin", "http://localhost:9095")
.header("Access-Control-Request-Method", "GET")
.exchange()
.expectStatus()
.isForbidden();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,29 +56,49 @@ class ManagementPortSampleSecureWebFluxTests {
@Test
void testHome() {
this.webClient.get().uri("http://localhost:" + this.port, String.class).header("Authorization", getBasicAuth())
.exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello user");
this.webClient.get()
.uri("http://localhost:" + this.port, String.class)
.header("Authorization", getBasicAuth())
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.isEqualTo("Hello user");
}
@Test
void actuatorPathOnMainPortShouldNotMatch() {
this.webClient.get().uri("http://localhost:" + this.port + "/actuator", String.class).exchange().expectStatus()
.isUnauthorized();
this.webClient.get().uri("http://localhost:" + this.port + "/actuator/health", String.class).exchange()
.expectStatus().isUnauthorized();
this.webClient.get()
.uri("http://localhost:" + this.port + "/actuator", String.class)
.exchange()
.expectStatus()
.isUnauthorized();
this.webClient.get()
.uri("http://localhost:" + this.port + "/actuator/health", String.class)
.exchange()
.expectStatus()
.isUnauthorized();
}
@Test
void testSecureActuator() {
this.webClient.get().uri("http://localhost:" + this.managementPort + "/actuator/env", String.class).exchange()
.expectStatus().isUnauthorized();
this.webClient.get()
.uri("http://localhost:" + this.managementPort + "/actuator/env", String.class)
.exchange()
.expectStatus()
.isUnauthorized();
}
@Test
void testInsecureActuator() {
String responseBody = this.webClient.get()
.uri("http://localhost:" + this.managementPort + "/actuator/health", String.class).exchange()
.expectStatus().isOk().expectBody(String.class).returnResult().getResponseBody();
.uri("http://localhost:" + this.managementPort + "/actuator/health", String.class)
.exchange()
.expectStatus()
.isOk()
.expectBody(String.class)
.returnResult()
.getResponseBody();
assertThat(responseBody).contains("\"status\":\"UP\"");
}
@@ -94,7 +114,7 @@ class ManagementPortSampleSecureWebFluxTests {
http.authorizeExchange((exchanges) -> {
exchanges.matchers(EndpointRequest.to("health")).permitAll();
exchanges.matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
.hasRole("ACTUATOR");
.hasRole("ACTUATOR");
exchanges.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
exchanges.pathMatchers("/login").permitAll();
exchanges.anyExchange().authenticated();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,33 +40,54 @@ class SampleSecureWebFluxApplicationTests {
@Test
void userDefinedMappingsSecureByDefault() {
this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isEqualTo(HttpStatus.UNAUTHORIZED);
this.webClient.get()
.uri("/")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
void healthInsecureByDefault() {
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isOk();
this.webClient.get()
.uri("/actuator/health")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk();
}
@Test
void otherActuatorsSecureByDefault() {
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isUnauthorized();
this.webClient.get()
.uri("/actuator/env")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isUnauthorized();
}
@Test
void userDefinedMappingsAccessibleOnLogin() {
this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).header("Authorization", getBasicAuth())
.exchange().expectBody(String.class).isEqualTo("Hello user");
this.webClient.get()
.uri("/")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth())
.exchange()
.expectBody(String.class)
.isEqualTo("Hello user");
}
@Test
void actuatorsAccessibleOnLogin() {
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth()).exchange().expectBody(String.class)
.isEqualTo("{\"status\":\"UP\"}");
this.webClient.get()
.uri("/actuator/health")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth())
.exchange()
.expectBody(String.class)
.isEqualTo("{\"status\":\"UP\"}");
}
private String getBasicAuth() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,46 +50,82 @@ class SampleSecureWebFluxCustomSecurityTests {
@Test
void userDefinedMappingsSecure() {
this.webClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isEqualTo(HttpStatus.UNAUTHORIZED);
this.webClient.get()
.uri("/")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.UNAUTHORIZED);
}
@Test
void healthDoesNotRequireAuthentication() {
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isOk();
this.webClient.get()
.uri("/actuator/health")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk();
}
@Test
void actuatorsSecuredByRole() {
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth()).exchange().expectStatus().isForbidden();
this.webClient.get()
.uri("/actuator/env")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth())
.exchange()
.expectStatus()
.isForbidden();
}
@Test
void actuatorsAccessibleOnCorrectLogin() {
this.webClient.get().uri("/actuator/env").accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuthForAdmin()).exchange().expectStatus().isOk();
this.webClient.get()
.uri("/actuator/env")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuthForAdmin())
.exchange()
.expectStatus()
.isOk();
}
@Test
void actuatorExcludedFromEndpointRequestMatcher() {
this.webClient.get().uri("/actuator/mappings").accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth()).exchange().expectStatus().isOk();
this.webClient.get()
.uri("/actuator/mappings")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuth())
.exchange()
.expectStatus()
.isOk();
}
@Test
void staticResourceShouldBeAccessible() {
this.webClient.get().uri("/css/bootstrap.min.css").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isOk();
this.webClient.get()
.uri("/css/bootstrap.min.css")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk();
}
@Test
void actuatorLinksIsSecure() {
this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isUnauthorized();
this.webClient.get().uri("/actuator").accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuthForAdmin()).exchange().expectStatus().isOk();
this.webClient.get()
.uri("/actuator")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isUnauthorized();
this.webClient.get()
.uri("/actuator")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", getBasicAuthForAdmin())
.exchange()
.expectStatus()
.isOk();
}
private String getBasicAuth() {
@@ -107,10 +143,16 @@ class SampleSecureWebFluxCustomSecurityTests {
@Bean
MapReactiveUserDetailsService userDetailsService() {
return new MapReactiveUserDetailsService(
User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER")
.build(),
User.withDefaultPasswordEncoder().username("admin").password("admin")
.authorities("ROLE_ACTUATOR", "ROLE_USER").build());
User.withDefaultPasswordEncoder()
.username("user")
.password("password")
.authorities("ROLE_USER")
.build(),
User.withDefaultPasswordEncoder()
.username("admin")
.password("admin")
.authorities("ROLE_ACTUATOR", "ROLE_USER")
.build());
}
@Bean
@@ -118,7 +160,7 @@ class SampleSecureWebFluxCustomSecurityTests {
http.authorizeExchange((exchanges) -> {
exchanges.matchers(EndpointRequest.to("health")).permitAll();
exchanges.matchers(EndpointRequest.toAnyEndpoint().excluding(MappingsEndpoint.class))
.hasRole("ACTUATOR");
.hasRole("ACTUATOR");
exchanges.matchers(PathRequest.toStaticResources().atCommonLocations()).permitAll();
exchanges.pathMatchers("/login").permitAll();
exchanges.anyExchange().authenticated();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,8 +36,9 @@ public class SampleSecureApplication implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")));
SecurityContextHolder.getContext()
.setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")));
try {
System.out.println(this.service.secure());
}

View File

@@ -58,13 +58,14 @@ class SampleSecureApplicationTests {
@Test
void secure() {
assertThatExceptionOfType(AuthenticationException.class)
.isThrownBy(() -> SampleSecureApplicationTests.this.service.secure());
.isThrownBy(() -> SampleSecureApplicationTests.this.service.secure());
}
@Test
void authenticated() {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")));
SecurityContextHolder.getContext()
.setAuthentication(new UsernamePasswordAuthenticationToken("user", "N/A",
AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")));
assertThat(this.service.secure()).isEqualTo("Hello Security");
}
@@ -78,7 +79,7 @@ class SampleSecureApplicationTests {
void denied() {
SecurityContextHolder.getContext().setAuthentication(this.authentication);
assertThatExceptionOfType(AccessDeniedException.class)
.isThrownBy(() -> SampleSecureApplicationTests.this.service.denied());
.isThrownBy(() -> SampleSecureApplicationTests.this.service.denied());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,8 +55,8 @@ class SampleServletApplicationTests {
@Test
void testHome() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/",
String.class);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword())
.getForEntity("/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("Hello World");
}

View File

@@ -64,7 +64,7 @@ class SampleSessionMongoApplicationTests {
@Container
static MongoDBContainer mongo = new MongoDBContainer(DockerImageNames.mongo()).withStartupAttempts(3)
.withStartupTimeout(Duration.ofMinutes(2));
.withStartupTimeout(Duration.ofMinutes(2));
@DynamicPropertySource
static void applicationProperties(DynamicPropertyRegistry registry) {
@@ -85,7 +85,7 @@ class SampleSessionMongoApplicationTests {
@Test
void health() {
ResponseEntity<String> entity = this.restTemplate
.getForEntity("http://localhost:" + this.port + "/actuator/health", String.class);
.getForEntity("http://localhost:" + this.port + "/actuator/health", String.class);
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
assertThat(entity.getBody()).contains("maxWireVersion");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ class SampleSessionWebFluxMongoApplicationTests {
@Container
private static final MongoDBContainer mongo = new MongoDBContainer(DockerImageNames.mongo()).withStartupAttempts(3)
.withStartupTimeout(Duration.ofMinutes(2));
.withStartupTimeout(Duration.ofMinutes(2));
@LocalServerPort
private int port;
@@ -67,20 +67,22 @@ class SampleSessionWebFluxMongoApplicationTests {
client.get().header("Authorization", getBasicAuth()).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
return response.bodyToMono(String.class)
.map((sessionId) -> Tuples.of(response.cookies().getFirst("SESSION").getValue(), sessionId));
.map((sessionId) -> Tuples.of(response.cookies().getFirst("SESSION").getValue(), sessionId));
}).flatMap((tuple) -> {
String sessionCookie = tuple.getT1();
return client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
return response.bodyToMono(String.class)
.doOnNext((sessionId) -> assertThat(sessionId).isEqualTo(tuple.getT2()))
.thenReturn(sessionCookie);
.doOnNext((sessionId) -> assertThat(sessionId).isEqualTo(tuple.getT2()))
.thenReturn(sessionCookie);
});
}).delayElement(Duration.ofSeconds(10))
.flatMap((sessionCookie) -> client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
return response.releaseBody();
})).block(Duration.ofSeconds(30));
})
.delayElement(Duration.ofSeconds(10))
.flatMap((sessionCookie) -> client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
return response.releaseBody();
}))
.block(Duration.ofSeconds(30));
}
private String getBasicAuth() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,20 +66,22 @@ class SampleSessionWebFluxRedisApplicationTests {
client.get().header("Authorization", getBasicAuth()).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
return response.bodyToMono(String.class)
.map((sessionId) -> Tuples.of(response.cookies().getFirst("SESSION").getValue(), sessionId));
.map((sessionId) -> Tuples.of(response.cookies().getFirst("SESSION").getValue(), sessionId));
}).flatMap((tuple) -> {
String sessionCookie = tuple.getT1();
return client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
return response.bodyToMono(String.class)
.doOnNext((sessionId) -> assertThat(sessionId).isEqualTo(tuple.getT2()))
.thenReturn(sessionCookie);
.doOnNext((sessionId) -> assertThat(sessionId).isEqualTo(tuple.getT2()))
.thenReturn(sessionCookie);
});
}).delayElement(Duration.ofSeconds(10))
.flatMap((sessionCookie) -> client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
return response.releaseBody();
})).block(Duration.ofSeconds(30));
})
.delayElement(Duration.ofSeconds(10))
.flatMap((sessionCookie) -> client.get().cookie("SESSION", sessionCookie).exchangeToMono((response) -> {
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
return response.releaseBody();
}))
.block(Duration.ofSeconds(30));
}
private String getBasicAuth() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ class SampleTestApplicationWebIntegrationTests {
@Test
void test() {
assertThat(this.restTemplate.getForEntity("/{username}/vehicle", String.class, "sframework").getStatusCode())
.isEqualTo(HttpStatus.OK);
.isEqualTo(HttpStatus.OK);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,19 +41,19 @@ class UserEntityTests {
@Test
void createWhenUsernameIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new User(null, VIN))
.withMessage("Username must not be empty");
.withMessage("Username must not be empty");
}
@Test
void createWhenUsernameIsEmptyShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new User("", VIN))
.withMessage("Username must not be empty");
.withMessage("Username must not be empty");
}
@Test
void createWhenVinIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new User("sboot", null))
.withMessage("VIN must not be null");
.withMessage("VIN must not be null");
}
@Test

View File

@@ -36,19 +36,19 @@ class VehicleIdentificationNumberTests {
@Test
void createWhenVinIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber(null))
.withMessage("VIN must not be null");
.withMessage("VIN must not be null");
}
@Test
void createWhenVinIsMoreThan17CharsShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("012345678901234567"))
.withMessage("VIN must be exactly 17 characters");
.withMessage("VIN must be exactly 17 characters");
}
@Test
void createWhenVinIsLessThan17CharsShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("0123456789012345"))
.withMessage("VIN must be exactly 17 characters");
.withMessage("VIN must be exactly 17 characters");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,13 +54,13 @@ class RemoteVehicleDetailsServiceTests {
@Test
void getVehicleDetailsWhenVinIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null))
.withMessage("VIN must not be null");
.withMessage("VIN must not be null");
}
@Test
void getVehicleDetailsWhenResultIsSuccessShouldReturnDetails() {
this.server.expect(requestTo("/vehicle/" + VIN + "/details"))
.andRespond(withSuccess(getClassPathResource("vehicledetails.json"), MediaType.APPLICATION_JSON));
.andRespond(withSuccess(getClassPathResource("vehicledetails.json"), MediaType.APPLICATION_JSON));
VehicleDetails details = this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN));
assertThat(details.getMake()).isEqualTo("Honda");
assertThat(details.getModel()).isEqualTo("Civic");
@@ -70,14 +70,14 @@ class RemoteVehicleDetailsServiceTests {
void getVehicleDetailsWhenResultIsNotFoundShouldThrowException() {
this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withStatus(HttpStatus.NOT_FOUND));
assertThatExceptionOfType(VehicleIdentificationNumberNotFoundException.class)
.isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)));
.isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)));
}
@Test
void getVehicleDetailsWhenResultIServerErrorShouldThrowException() {
this.server.expect(requestTo("/vehicle/" + VIN + "/details")).andRespond(withServerError());
assertThatExceptionOfType(HttpServerErrorException.class)
.isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)));
.isThrownBy(() -> this.service.getVehicleDetails(new VehicleIdentificationNumber(VIN)));
}
private ClassPathResource getClassPathResource(String path) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,8 +57,9 @@ class UserVehicleControllerApplicationTests {
@Test
void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk())
.andExpect(content().string("Honda Civic"));
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string("Honda Civic"));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,22 +59,25 @@ class UserVehicleControllerTests {
@Test
void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception {
given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN)).andExpect(status().isOk())
.andExpect(content().string("Honda Civic"));
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string("Honda Civic"));
}
@Test
void getVehicleWhenRequestingJsonShouldReturnMakeAndModel() throws Exception {
given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().json("{'make':'Honda','model':'Civic'}"));
this.mvc.perform(get("/sboot/vehicle").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().json("{'make':'Honda','model':'Civic'}"));
}
@Test
void getVehicleWhenRequestingHtmlShouldReturnMakeAndModel() throws Exception {
given(this.userVehicleService.getVehicleDetails("sboot")).willReturn(new VehicleDetails("Honda", "Civic"));
this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML)).andExpect(status().isOk())
.andExpect(content().string(containsString("<h1>Honda Civic</h1>")));
this.mvc.perform(get("/sboot/vehicle.html").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(content().string(containsString("<h1>Honda Civic</h1>")));
}
@Test
@@ -86,7 +89,7 @@ class UserVehicleControllerTests {
@Test
void getVehicleWhenVinNotFoundShouldReturnNotFound() throws Exception {
given(this.userVehicleService.getVehicleDetails("sboot"))
.willThrow(new VehicleIdentificationNumberNotFoundException(VIN));
.willThrow(new VehicleIdentificationNumberNotFoundException(VIN));
this.mvc.perform(get("/sboot/vehicle")).andExpect(status().isNotFound());
}
@@ -94,7 +97,7 @@ class UserVehicleControllerTests {
void welcomeCommandLineRunnerShouldNotBeAvailable() {
// Since we're a @WebMvcTest WelcomeCommandLineRunner should not be available.
Assertions.assertThatThrownBy(() -> this.applicationContext.getBean(WelcomeCommandLineRunner.class))
.isInstanceOf(NoSuchBeanDefinitionException.class);
.isInstanceOf(NoSuchBeanDefinitionException.class);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,14 +59,14 @@ class UserVehicleServiceTests {
@Test
void getVehicleDetailsWhenUsernameIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null))
.withMessage("Username must not be null");
.withMessage("Username must not be null");
}
@Test
void getVehicleDetailsWhenUsernameNotFoundShouldThrowException() {
given(this.userRepository.findByUsername(anyString())).willReturn(null);
assertThatExceptionOfType(UserNameNotFoundException.class)
.isThrownBy(() -> this.service.getVehicleDetails("sboot"));
.isThrownBy(() -> this.service.getVehicleDetails("sboot"));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ class SampleTomcatTwoConnectorsApplicationTests {
assertThat(this.ports.getHttpsPort()).isEqualTo(this.port);
assertThat(this.ports.getHttpPort()).isNotEqualTo(this.port);
ResponseEntity<String> entity = this.restTemplate
.getForEntity("http://localhost:" + this.ports.getHttpPort() + "/hello", String.class);
.getForEntity("http://localhost:" + this.ports.getHttpPort() + "/hello", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("hello");
ResponseEntity<String> httpsEntity = this.restTemplate.getForEntity("https://localhost:" + this.port + "/hello",

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,20 +57,23 @@ class MessageControllerWebTests {
@Test
void testHome() throws Exception {
this.mockMvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string(containsString("<title>Messages")));
this.mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("<title>Messages")));
}
@Test
void testCreate() throws Exception {
this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound())
.andExpect(header().string("location", RegexMatcher.matches("/[0-9]+")));
this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO"))
.andExpect(status().isFound())
.andExpect(header().string("location", RegexMatcher.matches("/[0-9]+")));
}
@Test
void testCreateValidation() throws Exception {
this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk())
.andExpect(content().string(containsString("is required")));
this.mockMvc.perform(post("/").param("text", "").param("summary", ""))
.andExpect(status().isOk())
.andExpect(content().string(containsString("is required")));
}
private static class RegexMatcher extends TypeSafeMatcher<String> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,8 +58,11 @@ public class SampleMethodSecurityApplication implements WebMvcConfigurer {
@Bean
public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
return new InMemoryUserDetailsManager(
User.withDefaultPasswordEncoder().username("admin").password("admin")
.roles("ADMIN", "USER", "ACTUATOR").build(),
User.withDefaultPasswordEncoder()
.username("admin")
.password("admin")
.roles("ADMIN", "USER", "ACTUATOR")
.build(),
User.withDefaultPasswordEncoder().username("user").password("user").roles("USER").build());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ abstract class AbstractErrorPageTests {
@Test
void testBadCredentials() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "wrongpassword")
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNull();
@@ -68,7 +68,7 @@ abstract class AbstractErrorPageTests {
@Test
void testPublicNotFoundPageWithCorrectCredentials() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "password")
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse.get("error").asText()).isEqualTo("Not Found");
@@ -77,7 +77,7 @@ abstract class AbstractErrorPageTests {
@Test
void testPublicNotFoundPageWithBadCredentials() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "wrong")
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNull();
@@ -86,7 +86,7 @@ abstract class AbstractErrorPageTests {
@Test
void testCorrectCredentialsWithControllerException() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "password")
.exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse.get("error").asText()).isEqualTo("Internal Server Error");
@@ -95,7 +95,7 @@ abstract class AbstractErrorPageTests {
@Test
void testCorrectCredentials() {
final ResponseEntity<String> response = this.testRestTemplate.withBasicAuth("username", "password")
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, String.class);
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
response.getBody();
assertThat(response.getBody()).isEqualTo("test");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
@Test
void testBadCredentials() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "wrongpassword")
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse.get("error").asText()).isEqualTo("Unauthorized");
@@ -74,7 +74,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
@Test
void testPublicNotFoundPageWithCorrectCredentials() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "password")
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse.get("error").asText()).isEqualTo("Not Found");
@@ -83,7 +83,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
@Test
void testPublicNotFoundPageWithBadCredentials() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "wrong")
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse.get("error").asText()).isEqualTo("Unauthorized");
@@ -92,7 +92,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
@Test
void testCorrectCredentialsWithControllerException() {
final ResponseEntity<JsonNode> response = this.testRestTemplate.withBasicAuth("username", "password")
.exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class);
.exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse.get("error").asText()).isEqualTo("Internal Server Error");
@@ -101,7 +101,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
@Test
void testCorrectCredentials() {
final ResponseEntity<String> response = this.testRestTemplate.withBasicAuth("username", "password")
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, String.class);
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isEqualTo("test");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,10 +45,10 @@ class NoSessionErrorPageTests extends AbstractErrorPageTests {
@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
http.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests((requests) -> {
requests.requestMatchers("/public/**").permitAll();
requests.anyRequest().authenticated();
});
.authorizeHttpRequests((requests) -> {
requests.requestMatchers("/public/**").permitAll();
requests.anyRequest().authenticated();
});
http.httpBasic();
return http.build();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,20 +57,23 @@ class MessageControllerWebTests {
@Test
void testHome() throws Exception {
this.mockMvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string(containsString("<title>Messages")));
this.mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("<title>Messages")));
}
@Test
void testCreate() throws Exception {
this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO")).andExpect(status().isFound())
.andExpect(header().string("location", RegexMatcher.matches("/[0-9]+")));
this.mockMvc.perform(post("/").param("text", "FOO text").param("summary", "FOO"))
.andExpect(status().isFound())
.andExpect(header().string("location", RegexMatcher.matches("/[0-9]+")));
}
@Test
void testCreateValidation() throws Exception {
this.mockMvc.perform(post("/").param("text", "").param("summary", "")).andExpect(status().isOk())
.andExpect(content().string(containsString("is required")));
this.mockMvc.perform(post("/").param("text", "").param("summary", ""))
.andExpect(status().isOk())
.andExpect(content().string(containsString("is required")));
}
private static class RegexMatcher extends TypeSafeMatcher<String> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ class SampleWebFluxApplicationActuatorDifferentPortTests {
@Test
void linksEndpointShouldBeAvailable() {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
.getForEntity("http://localhost:" + this.managementPort + "/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\"");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,8 +40,12 @@ class SampleWebFluxApplicationActuatorIsolatedObjectMapperFalseTests {
@Test
void linksEndpointShouldBeAvailable() {
this.webClient.get().uri("/actuator/startup").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.is5xxServerError();
this.webClient.get()
.uri("/actuator/startup")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.is5xxServerError();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,8 +45,14 @@ class SampleWebFluxApplicationActuatorIsolatedObjectMapperTrueTests {
@Test
void linksEndpointShouldBeAvailable() {
this.webClient.get().uri("/actuator/startup").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
.isOk().expectBody().consumeWith(this::assertExpectedJson);
this.webClient.get()
.uri("/actuator/startup")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.consumeWith(this::assertExpectedJson);
}
private void assertExpectedJson(EntityExchangeResult<byte[]> result) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,21 +38,36 @@ class SampleWebFluxApplicationTests {
@Test
void testWelcome() {
this.webClient.get().uri("/").accept(MediaType.TEXT_PLAIN).exchange().expectBody(String.class)
.isEqualTo("Hello World");
this.webClient.get()
.uri("/")
.accept(MediaType.TEXT_PLAIN)
.exchange()
.expectBody(String.class)
.isEqualTo("Hello World");
}
@Test
void testEcho() {
this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN)
.body(Mono.just("Hello WebFlux!"), String.class).exchange().expectBody(String.class)
.isEqualTo("Hello WebFlux!");
this.webClient.post()
.uri("/echo")
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.TEXT_PLAIN)
.body(Mono.just("Hello WebFlux!"), String.class)
.exchange()
.expectBody(String.class)
.isEqualTo("Hello WebFlux!");
}
@Test
void testActuatorStatus() {
this.webClient.get().uri("/actuator/health").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
.expectBody().json("{\"status\":\"UP\"}");
this.webClient.get()
.uri("/actuator/health")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.json("{\"status\":\"UP\"}");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,8 +64,8 @@ class WebServiceServerTestSampleWsApplicationTests {
StreamSource source = new StreamSource(new StringReader(request));
this.client.sendRequest(RequestCreators.withPayload(source)).andExpect(ResponseMatchers.noFault());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
then(this.service).should().bookHoliday(dateFormat.parse("2013-10-20"), dateFormat.parse("2013-11-22"),
"John Doe");
then(this.service).should()
.bookHoliday(dateFormat.parse("2013-10-20"), dateFormat.parse("2013-11-22"), "John Doe");
}
}

View File

@@ -54,8 +54,8 @@ class SampleWebSocketsApplicationTests {
void echoEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();
@@ -67,8 +67,8 @@ class SampleWebSocketsApplicationTests {
void reverseEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();

View File

@@ -59,8 +59,8 @@ class CustomContainerWebSocketsApplicationTests {
void echoEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();
@@ -72,8 +72,8 @@ class CustomContainerWebSocketsApplicationTests {
void reverseEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();

View File

@@ -54,8 +54,8 @@ class SampleWebSocketsApplicationTests {
void echoEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();
@@ -67,8 +67,8 @@ class SampleWebSocketsApplicationTests {
void reverseEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();

View File

@@ -59,8 +59,8 @@ class CustomContainerWebSocketsApplicationTests {
void echoEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();
@@ -72,8 +72,8 @@ class CustomContainerWebSocketsApplicationTests {
void reverseEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();

View File

@@ -54,8 +54,8 @@ class SampleWebSocketsApplicationTests {
void echoEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/echo/websocket")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();
@@ -67,8 +67,8 @@ class SampleWebSocketsApplicationTests {
void reverseEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/reverse")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();

View File

@@ -59,8 +59,8 @@ class CustomContainerWebSocketsApplicationTests {
void echoEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/echo/websocket")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();
@@ -72,8 +72,8 @@ class CustomContainerWebSocketsApplicationTests {
void reverseEndpoint() {
ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class)
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
.run("--spring.main.web-application-type=none");
.properties("websocket.uri:ws://localhost:" + this.port + "/ws/reverse")
.run("--spring.main.web-application-type=none");
long count = context.getBean(ClientConfiguration.class).latch.getCount();
AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
context.close();