From eb0841a9308c4a8c20604012e2702e3bc6b7c245 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Wed, 12 Feb 2020 16:06:47 +0100 Subject: [PATCH 1/9] initial commit of Hexagonal Architecture --- spring-boot-modules/pom.xml | 1 + .../spring-boot-hexagonal/README.md | 4 + .../spring-boot-hexagonal/pom.xml | 76 +++++++++++++++++++ .../main/java/com/baeldung/Application.java | 13 ++++ .../adapter/DocumentRepositoryImpl.java | 24 ++++++ .../baeldung/adapter/DocumentRestAdapter.java | 24 ++++++ .../java/com/baeldung/domain/Document.java | 13 ++++ .../java/com/baeldung/port/DocumentRepo.java | 11 +++ .../com/baeldung/port/DocumentService.java | 11 +++ .../port/impl/DocumentServiceImpl.java | 24 ++++++ .../src/main/resources/application.properties | 1 + .../java/com/baeldung/ApplicationTests.java | 16 ++++ 12 files changed, 218 insertions(+) create mode 100644 spring-boot-modules/spring-boot-hexagonal/README.md create mode 100644 spring-boot-modules/spring-boot-hexagonal/pom.xml create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 234c52f638..3a503bf837 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -49,6 +49,7 @@ spring-boot-springdoc spring-boot-testing spring-boot-vue + spring-boot-hexagonal diff --git a/spring-boot-modules/spring-boot-hexagonal/README.md b/spring-boot-modules/spring-boot-hexagonal/README.md new file mode 100644 index 0000000000..44728b185e --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/README.md @@ -0,0 +1,4 @@ +## HEXAGONAL Architecture + +This module contains articles about Hexagonal Architecture implemented via Spring Boot. + diff --git a/spring-boot-modules/spring-boot-hexagonal/pom.xml b/spring-boot-modules/spring-boot-hexagonal/pom.xml new file mode 100644 index 0000000000..4d6109d24f --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + spring-boot-hexagonal + spring-boot-hexagonal + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + + + + org.projectlombok + lombok + 1.18.12 + + + + + + spring-boot-hexagonal + + + src/main/resources + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + org.apache.maven.plugins + maven-assembly-plugin + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + + + + + + + UTF-8 + + + diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..17be2b0d79 --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.ajay.documentservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DocumentserviceApplication { + + public static void main(String[] args) { + SpringApplication.run(DocumentserviceApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java new file mode 100644 index 0000000000..e22ccb5cbf --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java @@ -0,0 +1,24 @@ +package com.ajay.documentservice.adapter; + +import com.ajay.documentservice.domain.Document; +import com.ajay.documentservice.port.DocumentRepo; +import org.springframework.stereotype.Repository; + +import java.util.HashMap; +import java.util.Map; + +@Repository +public class DocumentRepositoryImpl implements DocumentRepo { + + private Map documentMap = new HashMap<>(); + + @Override + public void storeDocument(Document document) { + documentMap.put(document.getId(), document); + } + + @Override + public Document findDocumentById(String id) { + return documentMap.get(id); + } +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java new file mode 100644 index 0000000000..2a3cffb0e8 --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java @@ -0,0 +1,24 @@ +package com.ajay.documentservice.adapter; + +import com.ajay.documentservice.domain.Document; +import com.ajay.documentservice.port.DocumentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/doc") +public class DocumentRestAdapter { + @Autowired + private DocumentService documentService; + + @PostMapping + public void createDocument(@RequestBody Document document) { + documentService.createDocument(document); + } + + @GetMapping("/{id}") + public Document findById(@PathVariable String id) { + return documentService.findById(id); + } + +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java new file mode 100644 index 0000000000..14ab4900e2 --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java @@ -0,0 +1,13 @@ +package com.ajay.documentservice.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + +@Data +@AllArgsConstructor +@Builder +public class Document { + private String id; + private String data; +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java new file mode 100644 index 0000000000..2e18dd92ee --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java @@ -0,0 +1,11 @@ +package com.ajay.documentservice.port; + + +import com.ajay.documentservice.domain.Document; + +public interface DocumentRepo { + void storeDocument(Document document); + + Document findDocumentById(String id); +} + diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java new file mode 100644 index 0000000000..6ed9edaf2c --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java @@ -0,0 +1,11 @@ +package com.ajay.documentservice.port; + +import com.ajay.documentservice.domain.Document; + +public interface DocumentService { + + void createDocument(Document document); + + Document findById(String id); + +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java new file mode 100644 index 0000000000..2549ca834c --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java @@ -0,0 +1,24 @@ +package com.ajay.documentservice.port.impl; + +import com.ajay.documentservice.domain.Document; +import com.ajay.documentservice.port.DocumentRepo; +import com.ajay.documentservice.port.DocumentService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class DocumentServiceImpl implements DocumentService { + + @Autowired + private DocumentRepo documentRepo; + + @Override + public void createDocument(Document document) { + documentRepo.storeDocument(document); + } + + @Override + public Document findById(String id) { + return documentRepo.findDocumentById(id); + } +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties b/spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java new file mode 100644 index 0000000000..ce3b754df3 --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java @@ -0,0 +1,16 @@ +package com.ajay.documentservice.documentservice; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest +@RunWith(SpringRunner.class) +class ApplicationTests { + + @Test + public void contextLoads() { + } + +} From ab401f3d4e61e1baf943794f24c41a6852724c86 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Wed, 12 Feb 2020 16:10:36 +0100 Subject: [PATCH 2/9] updated package name --- .../src/main/java/com/baeldung/Application.java | 2 +- .../main/java/com/baeldung/adapter/DocumentRepositoryImpl.java | 2 +- .../src/main/java/com/baeldung/adapter/DocumentRestAdapter.java | 2 +- .../src/main/java/com/baeldung/domain/Document.java | 2 +- .../src/main/java/com/baeldung/port/DocumentRepo.java | 2 +- .../src/main/java/com/baeldung/port/DocumentService.java | 2 +- .../main/java/com/baeldung/port/impl/DocumentServiceImpl.java | 2 +- .../src/test/java/com/baeldung/ApplicationTests.java | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java index 17be2b0d79..5e4bcc0435 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java index e22ccb5cbf..eabdaa63b8 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.adapter; +package com.baeldung.adapter; import com.ajay.documentservice.domain.Document; import com.ajay.documentservice.port.DocumentRepo; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java index 2a3cffb0e8..d8c89d5c6e 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.adapter; +package com.baeldung.adapter; import com.ajay.documentservice.domain.Document; import com.ajay.documentservice.port.DocumentService; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java index 14ab4900e2..77c1079cdc 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.domain; +package com.baeldung.domain; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java index 2e18dd92ee..d5591f9aa4 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.port; +package com.baeldung.port; import com.ajay.documentservice.domain.Document; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java index 6ed9edaf2c..5df49efa88 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.port; +package com.baeldung.port; import com.ajay.documentservice.domain.Document; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java index 2549ca834c..a2942b2d59 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.port.impl; +package com.baeldung.port.impl; import com.ajay.documentservice.domain.Document; import com.ajay.documentservice.port.DocumentRepo; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java index ce3b754df3..f531a9fba0 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java @@ -1,4 +1,4 @@ -package com.ajay.documentservice.documentservice; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 58a287e25b628bd2398a88b81e31d8c185e9b4c8 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Wed, 12 Feb 2020 17:15:44 +0100 Subject: [PATCH 3/9] renamed packages. --- .../spring-boot-hexagonal/pom.xml | 6 ----- .../main/java/com/baeldung/Application.java | 4 ++-- .../adapter/DocumentRepositoryImpl.java | 5 +++-- .../baeldung/adapter/DocumentRestAdapter.java | 6 +++-- .../java/com/baeldung/domain/Document.java | 22 +++++++++++++------ .../java/com/baeldung/port/DocumentRepo.java | 3 +-- .../com/baeldung/port/DocumentService.java | 2 +- .../port/impl/DocumentServiceImpl.java | 7 +++--- ...ionTests.java => ApplicationUnitTest.java} | 2 +- 9 files changed, 31 insertions(+), 26 deletions(-) rename spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/{ApplicationTests.java => ApplicationUnitTest.java} (91%) diff --git a/spring-boot-modules/spring-boot-hexagonal/pom.xml b/spring-boot-modules/spring-boot-hexagonal/pom.xml index 4d6109d24f..54d61fa806 100644 --- a/spring-boot-modules/spring-boot-hexagonal/pom.xml +++ b/spring-boot-modules/spring-boot-hexagonal/pom.xml @@ -24,12 +24,6 @@ spring-boot-starter-test - - org.projectlombok - lombok - 1.18.12 - - diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java index 5e4bcc0435..a898f9cf05 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java @@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class DocumentserviceApplication { +public class Application { public static void main(String[] args) { - SpringApplication.run(DocumentserviceApplication.class, args); + SpringApplication.run(Application.class, args); } } diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java index eabdaa63b8..1248133665 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java @@ -1,9 +1,10 @@ package com.baeldung.adapter; -import com.ajay.documentservice.domain.Document; -import com.ajay.documentservice.port.DocumentRepo; import org.springframework.stereotype.Repository; +import com.baeldung.domain.Document; +import com.baeldung.port.DocumentRepo; + import java.util.HashMap; import java.util.Map; diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java index d8c89d5c6e..e7fa5d0b42 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java @@ -1,10 +1,12 @@ package com.baeldung.adapter; -import com.ajay.documentservice.domain.Document; -import com.ajay.documentservice.port.DocumentService; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import com.baeldung.domain.Document; +import com.baeldung.port.DocumentService; + @RestController @RequestMapping("/doc") public class DocumentRestAdapter { diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java index 77c1079cdc..58381d536d 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java @@ -1,13 +1,21 @@ package com.baeldung.domain; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; - -@Data -@AllArgsConstructor -@Builder public class Document { private String id; private String data; + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getData() { + return data; + } + public void setData(String data) { + this.data = data; + } + + } diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java index d5591f9aa4..96dba3d954 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java @@ -1,7 +1,6 @@ package com.baeldung.port; - -import com.ajay.documentservice.domain.Document; +import com.baeldung.domain.Document; public interface DocumentRepo { void storeDocument(Document document); diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java index 5df49efa88..5d5bfb2035 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java @@ -1,6 +1,6 @@ package com.baeldung.port; -import com.ajay.documentservice.domain.Document; +import com.baeldung.domain.Document; public interface DocumentService { diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java index a2942b2d59..1b50e1efe2 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java @@ -1,11 +1,12 @@ package com.baeldung.port.impl; -import com.ajay.documentservice.domain.Document; -import com.ajay.documentservice.port.DocumentRepo; -import com.ajay.documentservice.port.DocumentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.baeldung.domain.Document; +import com.baeldung.port.DocumentRepo; +import com.baeldung.port.DocumentService; + @Service public class DocumentServiceImpl implements DocumentService { diff --git a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java similarity index 91% rename from spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java rename to spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java index f531a9fba0..f7592c0cc8 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationTests.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @RunWith(SpringRunner.class) -class ApplicationTests { +class ApplicationUnitTest { @Test public void contextLoads() { From 7d1f2555a2fb4e855d4bcee65a4da9983a3d7f3c Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Sat, 15 Feb 2020 09:32:50 +0100 Subject: [PATCH 4/9] reformatted as per standard formatter and incorporated review comments. --- .../spring-boot-hexagonal/pom.xml | 102 ++++++++---------- .../main/java/com/baeldung/Application.java | 10 +- .../adapter/DocumentRepositoryImpl.java | 26 ++--- .../baeldung/adapter/DocumentRestAdapter.java | 29 +++-- .../java/com/baeldung/domain/Document.java | 36 ++++--- .../baeldung/domain/port/DocumentRepo.java | 9 ++ .../baeldung/domain/port/DocumentService.java | 11 ++ .../domain/port/impl/DocumentServiceImpl.java | 25 +++++ .../java/com/baeldung/port/DocumentRepo.java | 10 -- .../com/baeldung/port/DocumentService.java | 11 -- .../port/impl/DocumentServiceImpl.java | 25 ----- .../com/baeldung/ApplicationUnitTest.java | 10 +- 12 files changed, 143 insertions(+), 161 deletions(-) create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java create mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java diff --git a/spring-boot-modules/spring-boot-hexagonal/pom.xml b/spring-boot-modules/spring-boot-hexagonal/pom.xml index 54d61fa806..c4ff36c2cf 100644 --- a/spring-boot-modules/spring-boot-hexagonal/pom.xml +++ b/spring-boot-modules/spring-boot-hexagonal/pom.xml @@ -1,70 +1,52 @@ - 4.0.0 - spring-boot-hexagonal - spring-boot-hexagonal + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 + spring-boot-hexagonal + spring-boot-hexagonal - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + - - - org.springframework.boot - spring-boot-starter-web - + + + org.springframework.boot + spring-boot-starter-web + - - org.springframework.boot - spring-boot-starter-test - + + org.springframework.boot + spring-boot-starter-test + - + - - spring-boot-hexagonal - - - src/main/resources - true - - - - - org.springframework.boot - spring-boot-maven-plugin - - exec - - - - org.apache.maven.plugins - maven-assembly-plugin - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - + + spring-boot-hexagonal + + + src/main/resources + true + + + + + org.springframework.boot + spring-boot-maven-plugin + + exec + + + + - - UTF-8 - + + UTF-8 + diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java index a898f9cf05..37dbe7dab8 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java @@ -5,9 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + } diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java index 1248133665..32414442ef 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java @@ -3,23 +3,23 @@ package com.baeldung.adapter; import org.springframework.stereotype.Repository; import com.baeldung.domain.Document; -import com.baeldung.port.DocumentRepo; +import com.baeldung.domain.port.DocumentRepo; import java.util.HashMap; import java.util.Map; @Repository public class DocumentRepositoryImpl implements DocumentRepo { - - private Map documentMap = new HashMap<>(); - - @Override - public void storeDocument(Document document) { - documentMap.put(document.getId(), document); - } - - @Override - public Document findDocumentById(String id) { - return documentMap.get(id); - } + + private Map documentMap = new HashMap<>(); + + @Override + public void storeDocument(Document document) { + documentMap.put(document.getId(), document); + } + + @Override + public Document findDocumentById(String id) { + return documentMap.get(id); + } } diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java index e7fa5d0b42..985a5257c0 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java @@ -1,26 +1,25 @@ package com.baeldung.adapter; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.baeldung.domain.Document; -import com.baeldung.port.DocumentService; +import com.baeldung.domain.port.DocumentService; @RestController @RequestMapping("/doc") public class DocumentRestAdapter { - @Autowired - private DocumentService documentService; - - @PostMapping - public void createDocument(@RequestBody Document document) { - documentService.createDocument(document); - } - - @GetMapping("/{id}") - public Document findById(@PathVariable String id) { - return documentService.findById(id); - } - + @Autowired + private DocumentService documentService; + + @PostMapping + public void createDocument(@RequestBody Document document) { + documentService.createDocument(document); + } + + @GetMapping("/{id}") + public Document findById(@PathVariable String id) { + return documentService.findById(id); + } + } diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java index 58381d536d..24d0a95071 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java @@ -1,21 +1,23 @@ package com.baeldung.domain; public class Document { - private String id; - private String data; - - public String getId() { - return id; - } - public void setId(String id) { - this.id = id; - } - public String getData() { - return data; - } - public void setData(String data) { - this.data = data; - } - - + private String id; + private String data; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + } diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java new file mode 100644 index 0000000000..001e3251e4 --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java @@ -0,0 +1,9 @@ +package com.baeldung.domain.port; + +import com.baeldung.domain.Document; + +public interface DocumentRepo { + void storeDocument(Document document); + + Document findDocumentById(String id); +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java new file mode 100644 index 0000000000..009c26c01f --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java @@ -0,0 +1,11 @@ +package com.baeldung.domain.port; + +import com.baeldung.domain.Document; + +public interface DocumentService { + + void createDocument(Document document); + + Document findById(String id); + +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java new file mode 100644 index 0000000000..f5c351406e --- /dev/null +++ b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java @@ -0,0 +1,25 @@ +package com.baeldung.domain.port.impl; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.domain.Document; +import com.baeldung.domain.port.DocumentRepo; +import com.baeldung.domain.port.DocumentService; + +@Service +public class DocumentServiceImpl implements DocumentService { + + @Autowired + private DocumentRepo documentRepo; + + @Override + public void createDocument(Document document) { + documentRepo.storeDocument(document); + } + + @Override + public Document findById(String id) { + return documentRepo.findDocumentById(id); + } +} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java deleted file mode 100644 index 96dba3d954..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentRepo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.port; - -import com.baeldung.domain.Document; - -public interface DocumentRepo { - void storeDocument(Document document); - - Document findDocumentById(String id); -} - diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java deleted file mode 100644 index 5d5bfb2035..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/DocumentService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.port; - -import com.baeldung.domain.Document; - -public interface DocumentService { - - void createDocument(Document document); - - Document findById(String id); - -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java deleted file mode 100644 index 1b50e1efe2..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/port/impl/DocumentServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.port.impl; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.domain.Document; -import com.baeldung.port.DocumentRepo; -import com.baeldung.port.DocumentService; - -@Service -public class DocumentServiceImpl implements DocumentService { - - @Autowired - private DocumentRepo documentRepo; - - @Override - public void createDocument(Document document) { - documentRepo.storeDocument(document); - } - - @Override - public Document findById(String id) { - return documentRepo.findDocumentById(id); - } -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java index f7592c0cc8..2ce9b1cf24 100644 --- a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java +++ b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java @@ -8,9 +8,9 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest @RunWith(SpringRunner.class) class ApplicationUnitTest { - - @Test - public void contextLoads() { - } - + + @Test + public void contextLoads() { + } + } From ec45eb9b4499980cbfc6187d52cb8328b0ff37b0 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Sat, 7 Mar 2020 15:21:12 +0100 Subject: [PATCH 5/9] java abstract number class --- .../AbstractNumberUnitTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 java-numbers-3/src/test/java/com/baeldung/abstractnumber/AbstractNumberUnitTest.java diff --git a/java-numbers-3/src/test/java/com/baeldung/abstractnumber/AbstractNumberUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/abstractnumber/AbstractNumberUnitTest.java new file mode 100644 index 0000000000..521f2d37a6 --- /dev/null +++ b/java-numbers-3/src/test/java/com/baeldung/abstractnumber/AbstractNumberUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.abstractnumber; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class AbstractNumberUnitTest { + + private final static double DOUBLE_VALUE = 9999.999; + private final static float FLOAT_VALUE = 101.99F; + private final static long LONG_VALUE = 1000L; + private final static int INTEGER_VALUE = 100; + private final static short SHORT_VALUE = 127; + private final static byte BYTE_VALUE = 120; + + @Test + public void givenDoubleValue_whenShortValueUsed_thenShortValueReturned() { + Double doubleValue = Double.valueOf(DOUBLE_VALUE); + assertEquals(9999, doubleValue.shortValue()); + } + + @Test + public void givenFloatValue_whenByteValueUsed_thenByteValueReturned() { + Float floatValue = Float.valueOf(FLOAT_VALUE); + assertEquals(101, floatValue.byteValue()); + } + + @Test + public void givenLongValue_whenInitValueUsed_thenInitValueReturned() { + Long longValue = Long.valueOf(LONG_VALUE); + assertEquals(1000, longValue.intValue()); + } + + @Test + public void givenIntegerValue_whenLongValueUsed_thenLongValueReturned() { + Integer integerValue = Integer.valueOf(INTEGER_VALUE); + assertEquals(100, integerValue.longValue()); + } + + @Test + public void givenShortValue_whenFloatValueUsed_thenFloatValueReturned() { + Short shortValue = Short.valueOf(SHORT_VALUE); + assertEquals(127.0F, shortValue.floatValue(), 0); + } + + @Test + public void givenByteValue_whenDoubleValueUsed_thenDoubleValueReturned() { + Byte byteValue = Byte.valueOf(BYTE_VALUE); + assertEquals(120.0, byteValue.doubleValue(), 0); + } + +} From 2bf71bac2bf948c9f1a0496965705d537eba7e24 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Sat, 14 Mar 2020 11:52:42 +0100 Subject: [PATCH 6/9] added new section --- java-numbers-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index 08e8dae8ef..a331a979ad 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -2,3 +2,4 @@ - [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers) - [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long) +- [Guide to the Java Number Class](http://inprogress.baeldung.com/?p=180694&preview=true) From 83ea1a11266876926ec2f1ee17fb39e183b6b0c2 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Sat, 14 Mar 2020 12:25:31 +0100 Subject: [PATCH 7/9] REmoved files --- .../spring-boot-hexagonal/README.md | 4 -- .../spring-boot-hexagonal/pom.xml | 52 ------------------- .../main/java/com/baeldung/Application.java | 13 ----- .../adapter/DocumentRepositoryImpl.java | 25 --------- .../baeldung/adapter/DocumentRestAdapter.java | 25 --------- .../java/com/baeldung/domain/Document.java | 23 -------- .../baeldung/domain/port/DocumentRepo.java | 9 ---- .../baeldung/domain/port/DocumentService.java | 11 ---- .../domain/port/impl/DocumentServiceImpl.java | 25 --------- .../src/main/resources/application.properties | 1 - .../com/baeldung/ApplicationUnitTest.java | 16 ------ 11 files changed, 204 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-hexagonal/README.md delete mode 100644 spring-boot-modules/spring-boot-hexagonal/pom.xml delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java diff --git a/spring-boot-modules/spring-boot-hexagonal/README.md b/spring-boot-modules/spring-boot-hexagonal/README.md deleted file mode 100644 index 44728b185e..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/README.md +++ /dev/null @@ -1,4 +0,0 @@ -## HEXAGONAL Architecture - -This module contains articles about Hexagonal Architecture implemented via Spring Boot. - diff --git a/spring-boot-modules/spring-boot-hexagonal/pom.xml b/spring-boot-modules/spring-boot-hexagonal/pom.xml deleted file mode 100644 index c4ff36c2cf..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - 4.0.0 - spring-boot-hexagonal - spring-boot-hexagonal - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - - - - - - spring-boot-hexagonal - - - src/main/resources - true - - - - - org.springframework.boot - spring-boot-maven-plugin - - exec - - - - - - - UTF-8 - - - diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 37dbe7dab8..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung; - -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-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java deleted file mode 100644 index 32414442ef..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRepositoryImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.adapter; - -import org.springframework.stereotype.Repository; - -import com.baeldung.domain.Document; -import com.baeldung.domain.port.DocumentRepo; - -import java.util.HashMap; -import java.util.Map; - -@Repository -public class DocumentRepositoryImpl implements DocumentRepo { - - private Map documentMap = new HashMap<>(); - - @Override - public void storeDocument(Document document) { - documentMap.put(document.getId(), document); - } - - @Override - public Document findDocumentById(String id) { - return documentMap.get(id); - } -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java deleted file mode 100644 index 985a5257c0..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/adapter/DocumentRestAdapter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.adapter; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import com.baeldung.domain.Document; -import com.baeldung.domain.port.DocumentService; - -@RestController -@RequestMapping("/doc") -public class DocumentRestAdapter { - @Autowired - private DocumentService documentService; - - @PostMapping - public void createDocument(@RequestBody Document document) { - documentService.createDocument(document); - } - - @GetMapping("/{id}") - public Document findById(@PathVariable String id) { - return documentService.findById(id); - } - -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java deleted file mode 100644 index 24d0a95071..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/Document.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.domain; - -public class Document { - private String id; - private String data; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } - -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java deleted file mode 100644 index 001e3251e4..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentRepo.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.domain.port; - -import com.baeldung.domain.Document; - -public interface DocumentRepo { - void storeDocument(Document document); - - Document findDocumentById(String id); -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java deleted file mode 100644 index 009c26c01f..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/DocumentService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.domain.port; - -import com.baeldung.domain.Document; - -public interface DocumentService { - - void createDocument(Document document); - - Document findById(String id); - -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java b/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java deleted file mode 100644 index f5c351406e..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/java/com/baeldung/domain/port/impl/DocumentServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.domain.port.impl; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.domain.Document; -import com.baeldung.domain.port.DocumentRepo; -import com.baeldung.domain.port.DocumentService; - -@Service -public class DocumentServiceImpl implements DocumentService { - - @Autowired - private DocumentRepo documentRepo; - - @Override - public void createDocument(Document document) { - documentRepo.storeDocument(document); - } - - @Override - public Document findById(String id) { - return documentRepo.findDocumentById(id); - } -} diff --git a/spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties b/spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties deleted file mode 100644 index 8b13789179..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java b/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java deleted file mode 100644 index 2ce9b1cf24..0000000000 --- a/spring-boot-modules/spring-boot-hexagonal/src/test/java/com/baeldung/ApplicationUnitTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@SpringBootTest -@RunWith(SpringRunner.class) -class ApplicationUnitTest { - - @Test - public void contextLoads() { - } - -} From f69a7dc961abe0b88cf44b4d1c1f983e1585319f Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Sat, 14 Mar 2020 12:29:22 +0100 Subject: [PATCH 8/9] cleanup --- spring-boot-modules/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 16541408a4..c8d153d4bb 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -53,7 +53,6 @@ spring-boot-springdoc spring-boot-testing spring-boot-vue - spring-boot-hexagonal From 74b0b6aa549e056effba836fc36d5db7149c89b7 Mon Sep 17 00:00:00 2001 From: ajay74984 <51405689+ajay74984@users.noreply.github.com> Date: Sat, 21 Mar 2020 11:17:11 +0100 Subject: [PATCH 9/9] revert changes --- java-numbers-3/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index a331a979ad..08e8dae8ef 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -2,4 +2,3 @@ - [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers) - [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long) -- [Guide to the Java Number Class](http://inprogress.baeldung.com/?p=180694&preview=true)