JAVA-8395: Delete module simplehexagonalexample
This commit is contained in:
parent
ddf531faa7
commit
6f5a8b2674
|
@ -1,32 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<artifactId>simple-hexagonal-example</artifactId>
|
||||
<name>simple-hexagonal-example</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 + "]";
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.baeldung.simplehexagonalex.domain.repository;
|
||||
|
||||
import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay;
|
||||
|
||||
public interface QuoteOfTheDayFromProvider {
|
||||
|
||||
QuoteOfTheDay getQuote();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.baeldung.simplehexagonalex.domain.service;
|
||||
|
||||
import com.baeldung.simplehexagonalex.domain.QuoteOfTheDay;
|
||||
|
||||
public interface QuoteService {
|
||||
|
||||
QuoteOfTheDay getQuote(String userName);
|
||||
}
|
|
@ -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<String> 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<String> 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<String> 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 + "]";
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<ProviderQuote> quotes;
|
||||
|
||||
public List<ProviderQuote> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
theysayso.quote.provider.url=https://quotes.rest/qod?language=en
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
theysayso.quote.provider.url=https://quotes.rest/qod?language=en
|
Loading…
Reference in New Issue