Introduce Jetty sample
This commit is contained in:
1
framework/webmvc-jetty/README.adoc
Normal file
1
framework/webmvc-jetty/README.adoc
Normal file
@@ -0,0 +1 @@
|
||||
Tests if WebMVC with Jetty is working.
|
||||
31
framework/webmvc-jetty/build.gradle
Normal file
31
framework/webmvc-jetty/build.gradle
Normal file
@@ -0,0 +1,31 @@
|
||||
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")
|
||||
implementation("org.springframework.boot:spring-boot-starter-jetty")
|
||||
modules {
|
||||
module("org.springframework.boot:spring-boot-starter-tomcat") {
|
||||
replacedBy("org.springframework.boot:spring-boot-starter-jetty", "Use Jetty instead of Tomcat")
|
||||
}
|
||||
}
|
||||
// Downgrade for Jetty, see https://github.com/spring-projects/spring-boot/issues/33044
|
||||
implementation("jakarta.servlet:jakarta.servlet-api") {
|
||||
version {
|
||||
strictly "5.0.0"
|
||||
}
|
||||
}
|
||||
implementation("org.crac:crac:0.1.3")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
appTestImplementation(project(":cr-smoke-test-support"))
|
||||
}
|
||||
|
||||
crSmokeTest {
|
||||
webApplication = true
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.test.web.reactive.server.WebTestClient;
|
||||
|
||||
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 Jetty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceInStatic(WebTestClient client) {
|
||||
client.get()
|
||||
.uri("foo.html")
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isOk()
|
||||
.expectBody()
|
||||
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Foo"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 Jetty";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Foo
|
||||
@@ -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 Jetty");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceInStatic() {
|
||||
ResponseEntity<String> response = this.template.getForEntity("/foo.html", String.class);
|
||||
assertThat(response.getBody()).isEqualTo("Foo");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user