Browse Source

Add nullability annotations to tests in smoke-test/spring-boot-smoke-test-web-secure

See gh-47263
pull/47665/head
Moritz Halbritter 2 months ago
parent
commit
a1a7d8d989
  1. 4
      smoke-test/spring-boot-smoke-test-web-secure/build.gradle
  2. 2
      smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractErrorPageTests.java
  3. 6
      smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractUnauthenticatedErrorPageTests.java
  4. 9
      smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java

4
smoke-test/spring-boot-smoke-test-web-secure/build.gradle

@ -28,3 +28,7 @@ dependencies { @@ -28,3 +28,7 @@ dependencies {
testImplementation(project(":starter:spring-boot-starter-webmvc-test"))
testImplementation("org.apache.httpcomponents.client5:httpclient5")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}

2
smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractErrorPageTests.java

@ -73,6 +73,7 @@ abstract class AbstractErrorPageTests { @@ -73,6 +73,7 @@ abstract class AbstractErrorPageTests {
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Not Found");
}
@ -91,6 +92,7 @@ abstract class AbstractErrorPageTests { @@ -91,6 +92,7 @@ abstract class AbstractErrorPageTests {
.exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Internal Server Error");
}

6
smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/AbstractUnauthenticatedErrorPageTests.java

@ -52,6 +52,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { @@ -52,6 +52,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
.exchange(this.pathPrefix + "/test", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Unauthorized");
}
@ -61,6 +62,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { @@ -61,6 +62,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Unauthorized");
}
@ -70,6 +72,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { @@ -70,6 +72,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Not Found");
}
@ -79,6 +82,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { @@ -79,6 +82,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Not Found");
}
@ -88,6 +92,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { @@ -88,6 +92,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
.exchange(this.pathPrefix + "/public/notfound", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Unauthorized");
}
@ -97,6 +102,7 @@ abstract class AbstractUnauthenticatedErrorPageTests { @@ -97,6 +102,7 @@ abstract class AbstractUnauthenticatedErrorPageTests {
.exchange(this.pathPrefix + "/fail", HttpMethod.GET, null, JsonNode.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
JsonNode jsonResponse = response.getBody();
assertThat(jsonResponse).isNotNull();
assertThat(jsonResponse.get("error").asString()).isEqualTo("Internal Server Error");
}

9
smoke-test/spring-boot-smoke-test-web-secure/src/test/java/smoketest/web/secure/SampleWebSecureApplicationTests.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package smoketest.web.secure;
import java.net.URI;
import java.util.Collections;
import jakarta.servlet.DispatcherType;
@ -68,7 +69,9 @@ class SampleWebSecureApplicationTests { @@ -68,7 +69,9 @@ class SampleWebSecureApplicationTests {
ResponseEntity<String> entity = this.restTemplate.withRedirects(HttpRedirects.DONT_FOLLOW)
.exchange("/home", HttpMethod.GET, new HttpEntity<>(headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/login");
URI location = entity.getHeaders().getLocation();
assertThat(location).isNotNull();
assertThat(location.toString()).endsWith(this.port + "/login");
}
@Test
@ -92,7 +95,9 @@ class SampleWebSecureApplicationTests { @@ -92,7 +95,9 @@ class SampleWebSecureApplicationTests {
ResponseEntity<String> entity = this.restTemplate.withRedirects(HttpRedirects.DONT_FOLLOW)
.exchange("/login", HttpMethod.POST, new HttpEntity<>(form, headers), String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation().toString()).endsWith(this.port + "/");
URI location = entity.getHeaders().getLocation();
assertThat(location).isNotNull();
assertThat(location.toString()).endsWith(this.port + "/");
}
@org.springframework.boot.test.context.TestConfiguration(proxyBeanMethods = false)

Loading…
Cancel
Save