Initial commit

The bootstrap of this project is done by leveraging
and adapting the infrastructure created in
https://github.com/spring-projects/spring-aot-smoke-tests.
This commit is contained in:
Sébastien Deleuze
2023-06-27 12:48:52 +02:00
commit 82d82b0980
53 changed files with 2859 additions and 0 deletions

View File

@@ -0,0 +1 @@
Tests if WebMVC with Tomcat is working.

View File

@@ -0,0 +1,18 @@
plugins {
id "java"
id "org.springframework.boot"
id "org.springframework.cr.smoke-test"
}
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter-web")
testImplementation("org.springframework.boot:spring-boot-starter-test")
appTestImplementation(project(":cr-smoke-test-support"))
}
crSmokeTest {
webApplication = true
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2022 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.webmvc;
import org.junit.jupiter.api.Test;
import org.springframework.cr.smoketest.support.junit.ApplicationTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserters;
import static org.assertj.core.api.Assertions.assertThat;
@ApplicationTest
class WebMvcApplicationTests {
@Test
void stringResponseBody(WebTestClient client) {
client.get()
.exchange()
.expectStatus()
.isOk()
.expectBody()
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent()))
.isEqualTo("Hello from Spring MVC and Tomcat"));
}
@Test
void resourceInStatic(WebTestClient client) {
client.get()
.uri("foo.html")
.exchange()
.expectStatus()
.isOk()
.expectBody()
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Foo"));
}
}

View File

@@ -0,0 +1,13 @@
package com.example.webmvc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WebMvcApplication {
public static void main(String[] args) {
SpringApplication.run(WebMvcApplication.class, args);
}
}

View File

@@ -0,0 +1,14 @@
package com.example.webmvc;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class WebMvcController {
@GetMapping("/")
public String hello() {
return "Hello from Spring MVC and Tomcat";
}
}

View File

@@ -0,0 +1 @@
Foo

View File

@@ -0,0 +1,40 @@
package com.example.webmvc;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
@SpringBootTest(webEnvironment = RANDOM_PORT)
class RandomPortTests {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate template;
@Test
void check() {
assertThat(this.port).isNotZero();
}
@Test
void stringResponseBody() {
ResponseEntity<String> response = this.template.getForEntity("/", String.class);
assertThat(response.getBody()).isEqualTo("Hello from Spring MVC and Tomcat");
}
@Test
void resourceInStatic() {
ResponseEntity<String> response = this.template.getForEntity("/foo.html", String.class);
assertThat(response.getBody()).isEqualTo("Foo");
}
}