Add two modules for BAEL-4688

This commit is contained in:
Simone Cusimano
2021-01-25 20:10:11 +01:00
parent 395089b01c
commit d3e6fcfc5b
20 changed files with 753 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,21 @@
package com.baeldung.boot.mvc.controllers;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/hello")
public class HelloController {
@GetMapping(value = "/{name}", produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<?> hello(@PathVariable String name) {
return new ResponseEntity<>("Hello, " + name, HttpStatus.OK);
}
}

View File

@@ -0,0 +1,13 @@
package com.baeldung.boot.mvc;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MvcApplicationIntegrationTests {
@Test
void contextLoads() {
}
}

View File

@@ -0,0 +1,27 @@
package com.baeldung.boot.mvc.controllers;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@Import(HelloController.class)
@ExtendWith(SpringExtension.class)
public class HelloControllerUnitTest {
@Autowired
private HelloController helloController;
@Test
public void helloTest() {
ResponseEntity response = this.helloController.hello("Caio");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isEqualTo("Hello, Caio");
}
}