diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 263d2af089..4902368d7e 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -54,6 +54,7 @@ spring-boot-mvc-2 spring-boot-mvc-3 spring-boot-mvc-birt + spring-boot-mvc-jersey spring-boot-nashorn spring-boot-parent spring-boot-performance diff --git a/spring-boot-modules/spring-boot-mvc-jersey/README.md b/spring-boot-modules/spring-boot-mvc-jersey/README.md new file mode 100644 index 0000000000..07f9e78ea6 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/README.md @@ -0,0 +1,8 @@ +## Spring Boot Admin + +This module contains articles about Spring Boot: JAX-RS vs Spring + + +### Relevant Articles: + +- [REST API: JAX-RS vs Spring](https://www.baeldung.com/TBD) diff --git a/spring-boot-modules/spring-boot-mvc-jersey/pom.xml b/spring-boot-modules/spring-boot-mvc-jersey/pom.xml new file mode 100644 index 0000000000..ab117c4d2e --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ + + + spring-boot-mvc-jersey + 0.0.1-SNAPSHOT + pom + + spring-boot-mvc-jersey + + + spring-boot-jersey + spring-boot-mvc + + diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/pom.xml b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/pom.xml new file mode 100644 index 0000000000..5756a27eca --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.4.2 + + + + com.baeldung.boot + spring-boot-jersey + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-jersey + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/java/com/baeldung/boot/jersey/JerseyApplication.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/java/com/baeldung/boot/jersey/JerseyApplication.java new file mode 100644 index 0000000000..b8ee0d0115 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/java/com/baeldung/boot/jersey/JerseyApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.boot.jersey; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class JerseyApplication { + + public static void main(String[] args) { + SpringApplication.run(JerseyApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/java/com/baeldung/boot/jersey/controllers/HelloController.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/java/com/baeldung/boot/jersey/controllers/HelloController.java new file mode 100644 index 0000000000..2774e458de --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/java/com/baeldung/boot/jersey/controllers/HelloController.java @@ -0,0 +1,20 @@ +package com.baeldung.boot.jersey.controllers; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +@Path("/hello") +public class HelloController { + + @GET + @Path("/{name}") + @Produces(MediaType.TEXT_PLAIN) + public Response hello(@PathParam("name") String name) { + return Response.ok("Hello, " + name).build(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/resources/application.properties b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/java/com/baeldung/boot/jersey/JerseyApplicationIntegrationTests.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/java/com/baeldung/boot/jersey/JerseyApplicationIntegrationTests.java new file mode 100644 index 0000000000..9bd6bbf029 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/java/com/baeldung/boot/jersey/JerseyApplicationIntegrationTests.java @@ -0,0 +1,13 @@ +package com.baeldung.boot.jersey; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class JerseyApplicationIntegrationTests { + + @Test + void contextLoads() { + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/java/com/baeldung/boot/jersey/controllers/HelloControllerUnitTest.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/java/com/baeldung/boot/jersey/controllers/HelloControllerUnitTest.java new file mode 100644 index 0000000000..e0c48da5bd --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-jersey/src/test/java/com/baeldung/boot/jersey/controllers/HelloControllerUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.boot.jersey.controllers; + +import javax.ws.rs.core.Response; + +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.test.context.junit.jupiter.SpringExtension; + +@Import(HelloController.class) +@ExtendWith(SpringExtension.class) +public class HelloControllerUnitTest { + + @Autowired + private HelloController helloController; + + @Test + public void whenHelloIsInvokedWithCaio_thenReturn200AsStatusAndHelloCaioAsBody() { + Response response = this.helloController.hello("Caio"); + assertThat(response.getStatus()).isEqualTo(200); + assertThat(response.getEntity()).isEqualTo("Hello, Caio"); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/pom.xml b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/pom.xml new file mode 100644 index 0000000000..69d355e574 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.4.2 + + + + com.baeldung.boot + spring-boot-mvc + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/java/com/baeldung/boot/mvc/MvcApplication.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/java/com/baeldung/boot/mvc/MvcApplication.java new file mode 100644 index 0000000000..9c42c72fd7 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/java/com/baeldung/boot/mvc/MvcApplication.java @@ -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); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/java/com/baeldung/boot/mvc/controllers/HelloController.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/java/com/baeldung/boot/mvc/controllers/HelloController.java new file mode 100644 index 0000000000..0b4c569ba9 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/java/com/baeldung/boot/mvc/controllers/HelloController.java @@ -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); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/resources/application.properties b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/java/com/baeldung/boot/mvc/MvcApplicationIntegrationTests.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/java/com/baeldung/boot/mvc/MvcApplicationIntegrationTests.java new file mode 100644 index 0000000000..d05cb97e47 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/java/com/baeldung/boot/mvc/MvcApplicationIntegrationTests.java @@ -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() { + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/java/com/baeldung/boot/mvc/controllers/HelloControllerUnitTest.java b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/java/com/baeldung/boot/mvc/controllers/HelloControllerUnitTest.java new file mode 100644 index 0000000000..3bef9df4fd --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-jersey/spring-boot-mvc/src/test/java/com/baeldung/boot/mvc/controllers/HelloControllerUnitTest.java @@ -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 whenHelloIsInvokedWithCaio_thenReturn200AsStatusAndHelloCaioAsBody() { + ResponseEntity response = this.helloController.hello("Caio"); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).isEqualTo("Hello, Caio"); + } + +}