From 436e396ba3e62b7a9c0782091b6700d7374589bf Mon Sep 17 00:00:00 2001 From: Alexander Alvonellos Date: Sat, 22 Oct 2022 23:38:02 -0400 Subject: [PATCH 1/5] added new service --- spring-boot-with-integration-tests/pom.xml | 44 +++++++++++++++++++ spring-boot-with-integration-tests/readme.md | 29 ++++++++++++ .../src/main/java/netgloo/Application.java | 13 ++++++ .../netgloo/controllers/MainController.java | 13 ++++++ .../src/main/resources/static/hello.html | 9 ++++ 5 files changed, 108 insertions(+) create mode 100644 spring-boot-with-integration-tests/pom.xml create mode 100644 spring-boot-with-integration-tests/readme.md create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/Application.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/controllers/MainController.java create mode 100644 spring-boot-with-integration-tests/src/main/resources/static/hello.html diff --git a/spring-boot-with-integration-tests/pom.xml b/spring-boot-with-integration-tests/pom.xml new file mode 100644 index 0000000..85ad6e1 --- /dev/null +++ b/spring-boot-with-integration-tests/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + netgloo + spring-boot-basewebapp + 0.0.1-SNAPSHOT + jar + + spring-boot-basewebapp + Spring Boot base web application + + + org.springframework.boot + spring-boot-starter-parent + 1.3.5.RELEASE + + + + + UTF-8 + netgloo.Application + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/spring-boot-with-integration-tests/readme.md b/spring-boot-with-integration-tests/readme.md new file mode 100644 index 0000000..7b5c696 --- /dev/null +++ b/spring-boot-with-integration-tests/readme.md @@ -0,0 +1,29 @@ +## Spring Boot basic web application + +Basic Spring Boot web application serving static content. + +See here for more informations: http://blog.netgloo.com/2014/05/18/very-basic-web-application-with-spring-mvc-spring-boot-and-eclipse-sts/ + + +### Build and run + +#### Prerequisites + +- Java 8 +- Maven 3.0+ + +#### Using the terminal + +Go on the project's root folder, then type: + + $ mvn spring-boot:run + +#### From Eclipse (Spring Tool Suite) + +Import as *Existing Maven Project* and run it as *Spring Boot App*. + + +### Usage + +- Launch the application and go on http://localhost:8080/ +- You can see the content from the static page `hello.html` diff --git a/spring-boot-with-integration-tests/src/main/java/netgloo/Application.java b/spring-boot-with-integration-tests/src/main/java/netgloo/Application.java new file mode 100644 index 0000000..323244c --- /dev/null +++ b/spring-boot-with-integration-tests/src/main/java/netgloo/Application.java @@ -0,0 +1,13 @@ +package netgloo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-boot-with-integration-tests/src/main/java/netgloo/controllers/MainController.java b/spring-boot-with-integration-tests/src/main/java/netgloo/controllers/MainController.java new file mode 100644 index 0000000..a5a0888 --- /dev/null +++ b/spring-boot-with-integration-tests/src/main/java/netgloo/controllers/MainController.java @@ -0,0 +1,13 @@ +package netgloo.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +@Controller +public class MainController { + + @RequestMapping("/") + public String index() { + return "hello.html"; + } + +} diff --git a/spring-boot-with-integration-tests/src/main/resources/static/hello.html b/spring-boot-with-integration-tests/src/main/resources/static/hello.html new file mode 100644 index 0000000..46fdfa5 --- /dev/null +++ b/spring-boot-with-integration-tests/src/main/resources/static/hello.html @@ -0,0 +1,9 @@ + + + +

Hello world!

+

+ By Netgloo! +

+ + From fe74f120c9cd4ccee6a19df583ad8b491310c279 Mon Sep 17 00:00:00 2001 From: Alexander Alvonellos Date: Sat, 22 Oct 2022 23:46:15 -0400 Subject: [PATCH 2/5] Added run configuration and updated pom.xml --- .../.run/Spring Boot Application.run.xml | 11 +++++++++++ spring-boot-with-integration-tests/pom.xml | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml diff --git a/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml b/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml new file mode 100644 index 0000000..5efbbeb --- /dev/null +++ b/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/spring-boot-with-integration-tests/pom.xml b/spring-boot-with-integration-tests/pom.xml index 85ad6e1..1ad8b2d 100644 --- a/spring-boot-with-integration-tests/pom.xml +++ b/spring-boot-with-integration-tests/pom.xml @@ -8,8 +8,8 @@ 0.0.1-SNAPSHOT jar - spring-boot-basewebapp - Spring Boot base web application + spring-boot-with-integration-tests + Spring Boot base web application with integration tests org.springframework.boot From 1625346ff695c9466b38713f1a4a97a031a97f3a Mon Sep 17 00:00:00 2001 From: Alexander Alvonellos Date: Sun, 23 Oct 2022 00:33:50 -0400 Subject: [PATCH 3/5] Added custom exceptions, controller advices, one service layer component, one repository layer component, and tests to simulate what a production microservice would look like. This service performs CRUD on a key-value database. --- .../.run/Spring Boot Application.run.xml | 2 +- spring-boot-with-integration-tests/pom.xml | 81 ++++++++- .../netgloo/controllers/KVController.java | 101 +++++++++++ .../netgloo/controllers/MainController.java | 13 -- .../exceptions/APIControllerAdvice.java | 41 +++++ .../java/netgloo/exceptions/APIError.java | 16 ++ .../java/netgloo/exceptions/APIException.java | 12 ++ .../exceptions/APIIdNotFoundException.java | 17 ++ .../main/java/netgloo/models/KVEntity.java | 50 ++++++ .../java/netgloo/repository/KVDatabase.java | 9 + .../main/java/netgloo/service/KVService.java | 73 ++++++++ .../java/netgloo/test/KVControllerTest.java | 163 ++++++++++++++++++ .../main/java/netgloo/test/KVServiceTest.java | 113 ++++++++++++ 13 files changed, 676 insertions(+), 15 deletions(-) create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/controllers/KVController.java delete mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/controllers/MainController.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/exceptions/APIControllerAdvice.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/exceptions/APIError.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/exceptions/APIException.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/exceptions/APIIdNotFoundException.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/models/KVEntity.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/repository/KVDatabase.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/service/KVService.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/test/KVControllerTest.java create mode 100644 spring-boot-with-integration-tests/src/main/java/netgloo/test/KVServiceTest.java diff --git a/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml b/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml index 5efbbeb..c0a2f79 100644 --- a/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml +++ b/spring-boot-with-integration-tests/.run/Spring Boot Application.run.xml @@ -1,6 +1,6 @@ -