mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-13 10:15:44 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
1 parent
371439aeaa
commit
0ca162a55c
1863 files changed
+14403
-17632
No files matched your search
@@ -38,6 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>6.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+4
-7
@@ -37,11 +37,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class Aggregator {
|
||||
|
||||
@Resource
|
||||
private ProductInformationClient informationClient;
|
||||
@Resource private ProductInformationClient informationClient;
|
||||
|
||||
@Resource
|
||||
private ProductInventoryClient inventoryClient;
|
||||
@Resource private ProductInventoryClient inventoryClient;
|
||||
|
||||
/**
|
||||
* Retrieves product data.
|
||||
@@ -55,13 +53,12 @@ public class Aggregator {
|
||||
var productTitle = informationClient.getProductTitle();
|
||||
var productInventory = inventoryClient.getProductInventories();
|
||||
|
||||
//Fallback to error message
|
||||
// Fallback to error message
|
||||
product.setTitle(requireNonNullElse(productTitle, "Error: Fetching Product Title Failed"));
|
||||
|
||||
//Fallback to default error inventory
|
||||
// Fallback to default error inventory
|
||||
product.setProductInventories(requireNonNullElse(productInventory, -1));
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-3
@@ -27,9 +27,7 @@ package com.iluwatar.aggregator.microservices;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Spring Boot EntryPoint Class.
|
||||
*/
|
||||
/** Spring Boot EntryPoint Class. */
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
|
||||
+3
-11
@@ -27,22 +27,14 @@ package com.iluwatar.aggregator.microservices;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Encapsulates all the data for a Product that clients will request.
|
||||
*/
|
||||
/** Encapsulates all the data for a Product that clients will request. */
|
||||
@Getter
|
||||
@Setter
|
||||
public class Product {
|
||||
|
||||
/**
|
||||
* The title of the product.
|
||||
*/
|
||||
/** The title of the product. */
|
||||
private String title;
|
||||
|
||||
|
||||
/**
|
||||
* The inventories of the product.
|
||||
*/
|
||||
/** The inventories of the product. */
|
||||
private int productInventories;
|
||||
|
||||
}
|
||||
+1
-4
@@ -24,11 +24,8 @@
|
||||
*/
|
||||
package com.iluwatar.aggregator.microservices;
|
||||
|
||||
/**
|
||||
* Interface for the Information micro-service.
|
||||
*/
|
||||
/** Interface for the Information micro-service. */
|
||||
public interface ProductInformationClient {
|
||||
|
||||
String getProductTitle();
|
||||
|
||||
}
|
||||
+6
-7
@@ -32,19 +32,18 @@ import java.net.http.HttpResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An adapter to communicate with information micro-service.
|
||||
*/
|
||||
/** An adapter to communicate with information micro-service. */
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProductInformationClientImpl implements ProductInformationClient {
|
||||
|
||||
@Override
|
||||
public String getProductTitle() {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create("http://localhost:51515/information"))
|
||||
.build();
|
||||
var request =
|
||||
HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create("http://localhost:51515/information"))
|
||||
.build();
|
||||
var client = HttpClient.newHttpClient();
|
||||
try {
|
||||
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.aggregator.microservices;
|
||||
|
||||
/**
|
||||
* Interface to Inventory micro-service.
|
||||
*/
|
||||
/** Interface to Inventory micro-service. */
|
||||
public interface ProductInventoryClient {
|
||||
|
||||
Integer getProductInventories();
|
||||
|
||||
+6
-7
@@ -32,9 +32,7 @@ import java.net.http.HttpResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An adapter to communicate with inventory micro-service.
|
||||
*/
|
||||
/** An adapter to communicate with inventory micro-service. */
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
@@ -43,10 +41,11 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
public Integer getProductInventories() {
|
||||
var response = "";
|
||||
|
||||
var request = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create("http://localhost:51516/inventories"))
|
||||
.build();
|
||||
var request =
|
||||
HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create("http://localhost:51516/inventories"))
|
||||
.build();
|
||||
var client = HttpClient.newHttpClient();
|
||||
try {
|
||||
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
+8
-16
@@ -24,37 +24,30 @@
|
||||
*/
|
||||
package com.iluwatar.aggregator.microservices;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test Aggregation of domain objects
|
||||
*/
|
||||
/** Test Aggregation of domain objects */
|
||||
class AggregatorTest {
|
||||
|
||||
@InjectMocks
|
||||
private Aggregator aggregator;
|
||||
@InjectMocks private Aggregator aggregator;
|
||||
|
||||
@Mock
|
||||
private ProductInformationClient informationClient;
|
||||
@Mock private ProductInformationClient informationClient;
|
||||
|
||||
@Mock
|
||||
private ProductInventoryClient inventoryClient;
|
||||
@Mock private ProductInventoryClient inventoryClient;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
MockitoAnnotations.openMocks(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests getting the data for a desktop client
|
||||
*/
|
||||
/** Tests getting the data for a desktop client */
|
||||
@Test
|
||||
void testGetProduct() {
|
||||
var title = "The Product Title.";
|
||||
@@ -68,5 +61,4 @@ class AggregatorTest {
|
||||
assertEquals(title, testProduct.getTitle());
|
||||
assertEquals(inventories, testProduct.getProductInventories());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>6.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+1
-3
@@ -27,9 +27,7 @@ package com.iluwatar.information.microservice;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Inventory Application starts container (Spring Boot) and exposes the Inventory micro-service.
|
||||
*/
|
||||
/** Inventory Application starts container (Spring Boot) and exposes the Inventory micro-service. */
|
||||
@SpringBootApplication
|
||||
public class InformationApplication {
|
||||
|
||||
|
||||
+1
-3
@@ -27,9 +27,7 @@ package com.iluwatar.information.microservice;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller providing endpoints to retrieve information about products.
|
||||
*/
|
||||
/** Controller providing endpoints to retrieve information about products. */
|
||||
@RestController
|
||||
public class InformationController {
|
||||
|
||||
|
||||
+3
-6
@@ -24,13 +24,11 @@
|
||||
*/
|
||||
package com.iluwatar.information.microservice;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test for Information Rest Controller
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Test for Information Rest Controller */
|
||||
class InformationControllerTest {
|
||||
|
||||
@Test
|
||||
@@ -39,5 +37,4 @@ class InformationControllerTest {
|
||||
var title = infoController.getProductTitle();
|
||||
assertEquals("The Product Title.", title);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>6.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+1
-4
@@ -27,14 +27,11 @@ package com.iluwatar.inventory.microservice;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Inventory Application starts container (Spring Boot) and exposes the Inventory micro-service.
|
||||
*/
|
||||
/** Inventory Application starts container (Spring Boot) and exposes the Inventory micro-service. */
|
||||
@SpringBootApplication
|
||||
public class InventoryApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(InventoryApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-4
@@ -27,9 +27,7 @@ package com.iluwatar.inventory.microservice;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller providing endpoints to retrieve product inventories.
|
||||
*/
|
||||
/** Controller providing endpoints to retrieve product inventories. */
|
||||
@RestController
|
||||
public class InventoryController {
|
||||
|
||||
@@ -42,5 +40,4 @@ public class InventoryController {
|
||||
public int getProductInventories() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-5
@@ -24,13 +24,11 @@
|
||||
*/
|
||||
package com.iluwatar.inventory.microservice;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Test Inventory Rest Controller
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Test Inventory Rest Controller */
|
||||
class InventoryControllerTest {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,17 +34,6 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>microservices-aggregrator</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<type>pom</type>
|
||||
<version>3.2.4</version>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<modules>
|
||||
<module>information-microservice</module>
|
||||
<module>aggregator-service</module>
|
||||
|
||||
Reference in new issue
Block a user