diff --git a/patterns/simplehexagonalexample/pom.xml b/patterns/simplehexagonalexample/pom.xml deleted file mode 100644 index 31e829b7dc..0000000000 --- a/patterns/simplehexagonalexample/pom.xml +++ /dev/null @@ -1,32 +0,0 @@ - - 4.0.0 - 1.0.0-SNAPSHOT - simple-hexagonal-example - simple-hexagonal-example - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - \ No newline at end of file diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java deleted file mode 100644 index de8b2f4793..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/DailyQuoteMain.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.simplehexagonalex; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import com.baeldung.simplehexagonalex.controller.QuoteCliController; -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; - -@SpringBootApplication -public class DailyQuoteMain implements CommandLineRunner { - - private static final Logger LOG = LoggerFactory.getLogger(DailyQuoteMain.class); - @Autowired - private QuoteCliController quoteCliController; - - public static void main(final String[] args) { - - SpringApplication.run(DailyQuoteMain.class, args); - } - - @Override - public void run(String... args) throws Exception { - - QuoteOfTheDay quoteOfTheDay = quoteCliController.getQuote("cliController"); - - LOG.info(quoteOfTheDay.toString()); - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java deleted file mode 100644 index 9ecb2bf822..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteCliController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.simplehexagonalex.controller; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.service.QuoteService; - -@Component -public class QuoteCliController { - - private static final Logger LOG = LoggerFactory.getLogger(QuoteCliController.class); - - @Autowired - private QuoteService quoteService; - - public QuoteOfTheDay getQuote(String userId) { - - LOG.info("Getting quote"); - return quoteService.getQuote(userId); - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java deleted file mode 100644 index 061cff8cec..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/controller/QuoteRestController.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.simplehexagonalex.controller; - -import org.springframework.beans.factory.annotation.Autowired; -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; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.service.QuoteService; - -@RestController -@RequestMapping("/quote") -public class QuoteRestController { - - @Autowired - private QuoteService quoteService; - - @GetMapping(path = "/{userId}") - public QuoteOfTheDay getEmployee(@PathVariable("userId") String userId) { - return quoteService.getQuote(userId); - } - -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java deleted file mode 100644 index c74c224c70..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/QuoteOfTheDay.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.simplehexagonalex.domain; - -import java.util.Objects; - -public class QuoteOfTheDay { - - private String userName; - private String quote; - private String provider; - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getQuote() { - return quote; - } - - public void setQuote(String quote) { - this.quote = quote; - } - - public String getProvider() { - return provider; - } - - public void setProvider(String provider) { - this.provider = provider; - } - - @Override - public int hashCode() { - return Objects.hash(provider, quote, userName); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - QuoteOfTheDay other = (QuoteOfTheDay) obj; - return Objects.equals(provider, other.provider) && Objects.equals(quote, other.quote) && Objects.equals(userName, other.userName); - } - - @Override - public String toString() { - return "QuoteOfTheDay [userName=" + userName + ", quote=" + quote + ", provider=" + provider + "]"; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java deleted file mode 100644 index 7e70cebd12..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/repository/QuoteOfTheDayFromProvider.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.simplehexagonalex.domain.repository; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; - -public interface QuoteOfTheDayFromProvider { - - QuoteOfTheDay getQuote(); -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java deleted file mode 100644 index 16f7015ace..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteAggregator.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.simplehexagonalex.domain.service; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; - -@Service -public class QuoteAggregator implements QuoteService { - - @Autowired - private QuoteOfTheDayFromProvider quoteOfTheDayFromProvider; - - @Override - public QuoteOfTheDay getQuote(String userName) { - - QuoteOfTheDay quoteOfTheDay = quoteOfTheDayFromProvider.getQuote(); - quoteOfTheDay.setUserName(userName); - return quoteOfTheDay; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java deleted file mode 100644 index 300387a41d..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/domain/service/QuoteService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.simplehexagonalex.domain.service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; - -public interface QuoteService { - - QuoteOfTheDay getQuote(String userName); -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java deleted file mode 100644 index 0cbbc60726..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuote.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primary.quoteadapter; - -import java.util.List; -import java.util.Objects; - -public class ProviderQuote { - - private String quote; - private String length; - private String author; - private List tags; - private String category; - private String language; - private String date; - private String permalink; - private String id; - private String background; - private String title; - - public ProviderQuote() { - - } - - public ProviderQuote(String quote, String length, String author, List tags, String category, String language, String date, String permalink, String id, String background, String title) { - super(); - this.quote = quote; - this.length = length; - this.author = author; - this.tags = tags; - this.category = category; - this.language = language; - this.date = date; - this.permalink = permalink; - this.id = id; - this.background = background; - this.title = title; - } - - public String getQuote() { - return quote; - } - - public String getLength() { - return length; - } - - public String getAuthor() { - return author; - } - - public List getTags() { - return tags; - } - - public String getCategory() { - return category; - } - - public String getLanguage() { - return language; - } - - public String getDate() { - return date; - } - - public String getPermalink() { - return permalink; - } - - public String getId() { - return id; - } - - public String getBackground() { - return background; - } - - public String getTitle() { - return title; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public int hashCode() { - return Objects.hash(id); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ProviderQuote other = (ProviderQuote) obj; - return Objects.equals(id, other.id); - } - - @Override - public String toString() { - return "TheysaysoQuote [quote=" + quote + ", length=" + length + ", " + "author=" + author + ", tags=" + tags + ", category=" + category + ", language=" + language + ", date=" + date + ", permalink=" + permalink + ", id=" + id + ", background=" - + background + ", title=" + title + "]"; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java deleted file mode 100644 index ded08f7b18..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteAdapter.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primary.quoteadapter; - -import java.net.URI; - -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Service("providerQuoteAdapter") -@Primary -public class ProviderQuoteAdapter implements QuoteOfTheDayFromProvider { - - @Autowired - private Environment env; - - @Override - public QuoteOfTheDay getQuote() { - - QuoteOfTheDay quoteOfTheDay = new QuoteOfTheDay(); - ProviderQuoteEnvelope providerQuote; - try { - providerQuote = getProviderQuote(); - quoteOfTheDay.setQuote(providerQuote.getContents() - .getQuotes() - .get(0) - .getQuote()); - quoteOfTheDay.setProvider(providerQuote.getCopyright() - .getUrl()); - } catch (Exception e) { - quoteOfTheDay.setQuote("Unable to get the quote"); - quoteOfTheDay.setProvider("none"); - } - return quoteOfTheDay; - } - - private ProviderQuoteEnvelope getProviderQuote() throws Exception { - - HttpGet request = new HttpGet(URI.create(env.getProperty("theysayso.quote.provider.url"))); - CloseableHttpClient client = HttpClients.createDefault(); - CloseableHttpResponse response = client.execute(request); - ProviderQuoteEnvelope providersQuote = new ObjectMapper().readValue(response.getEntity() - .getContent(), ProviderQuoteEnvelope.class); - return providersQuote; - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java deleted file mode 100644 index 611549f23d..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/repository/primary/quoteadapter/ProviderQuoteEnvelope.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primary.quoteadapter; - -import java.util.List; - -public class ProviderQuoteEnvelope { - - private Success success; - private Contents contents; - private String baseurl; - private Copyright copyright; - - public ProviderQuoteEnvelope() { - - } - - public ProviderQuoteEnvelope(Success success, Contents contents, String baseurl, Copyright copyright) { - super(); - this.success = success; - this.contents = contents; - this.baseurl = baseurl; - this.copyright = copyright; - } - - public Success getSuccess() { - return success; - } - - public Contents getContents() { - return contents; - } - - public String getBaseurl() { - return baseurl; - } - - public Copyright getCopyright() { - return copyright; - } - - public class Contents { - private List quotes; - - public List getQuotes() { - return quotes; - } - } - - public class Copyright { - private int year; - private String url; - - public int getYear() { - return year; - } - - public String getUrl() { - return url; - } - } - - public class Success { - private int total; - - public int getTotal() { - return total; - } - } -} diff --git a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java b/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java deleted file mode 100644 index 54c28fc94e..0000000000 --- a/patterns/simplehexagonalexample/src/main/java/com/baeldung/simplehexagonalex/reposity/mock/quoteadapter/MockQuoteAdapter.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.simplehexagonalex.reposity.mock.quoteadapter; - -import org.springframework.stereotype.Service; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; - -@Service -public class MockQuoteAdapter implements QuoteOfTheDayFromProvider { - - @Override - public QuoteOfTheDay getQuote() { - - QuoteOfTheDay quoteOfTheDay = new QuoteOfTheDay(); - quoteOfTheDay.setQuote("Mock quote of the day"); - quoteOfTheDay.setProvider("Mock Provider"); - - return quoteOfTheDay; - } -} diff --git a/patterns/simplehexagonalexample/src/main/resources/application.properties b/patterns/simplehexagonalexample/src/main/resources/application.properties deleted file mode 100644 index dd9413bfd5..0000000000 --- a/patterns/simplehexagonalexample/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -theysayso.quote.provider.url=https://quotes.rest/qod?language=en \ No newline at end of file diff --git a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java b/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java deleted file mode 100644 index 602f7ea5d4..0000000000 --- a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/MockAccessProviderUnitTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primaryQuoteProvider; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.reposity.mock.quoteadapter.MockQuoteAdapter; - -public class MockAccessProviderUnitTest { - - @Test - public void givenProvider_whenConnect_thenResponse() throws Exception { - - MockQuoteAdapter provider = new MockQuoteAdapter(); - QuoteOfTheDay quote = provider.getQuote(); - assertNotNull(quote); - assertEquals("Mock quote of the day", quote.getQuote()); - assertEquals("Mock Provider", quote.getProvider()); - } -} diff --git a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java b/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java deleted file mode 100644 index 47e1dde136..0000000000 --- a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/PrimaryAccessProviderIntegrationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primaryQuoteProvider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; - -import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay; -import com.baeldung.simplehexagonalex.domain.repository.QuoteOfTheDayFromProvider; - -@SpringBootTest -public class PrimaryAccessProviderIntegrationTest { - - @Autowired - @Qualifier("providerQuoteAdapter") - QuoteOfTheDayFromProvider provider; - - @Test - public void whenQuoteProvider_thenResponse() throws Exception { - - QuoteOfTheDay quote = provider.getQuote(); - assertNotNull(quote); - assertThat(quote.getProvider()).contains("theysaidso"); - } -} diff --git a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java b/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java deleted file mode 100644 index 552b5d51c2..0000000000 --- a/patterns/simplehexagonalexample/src/test/java/com/baeldung/simplehexagonalex/repository/primaryQuoteProvider/QuoteRequestIntegrationTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.simplehexagonalex.repository.primaryQuoteProvider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; - -@SpringBootTest -@AutoConfigureMockMvc -public class QuoteRequestIntegrationTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void whenRestQuoteRequest_thenResponse() throws Exception { - - MvcResult result = this.mockMvc.perform(get("/quote/tester")) - .andDo(print()) - .andExpect(status().isOk()) - .andReturn(); - - String content = result.getResponse() - .getContentAsString(); - - assertThat(content).contains("tester"); - assertThat(content).contains("theysaidso"); - } -} \ No newline at end of file diff --git a/patterns/simplehexagonalexample/src/test/resources/application.properties b/patterns/simplehexagonalexample/src/test/resources/application.properties deleted file mode 100644 index dd9413bfd5..0000000000 --- a/patterns/simplehexagonalexample/src/test/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -theysayso.quote.provider.url=https://quotes.rest/qod?language=en \ No newline at end of file