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:
Ilkka Seppälä
2025-03-29 19:34:27 +02:00
committed by GitHub
parent 371439aeaa
commit 0ca162a55c
1863 changed files with 14403 additions and 17632 deletions
@@ -52,10 +52,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* {@code docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin }
* </pre>
*
* <p>Start Zipkin with the command above. Once Zipkin is running, you can
* access the Zipkin UI at `<a href="http://localhost:9411">...</a>`
* to view the tracing logs and analyze the request flows across your microservices.
*
* <p>Start Zipkin with the command above. Once Zipkin is running, you can access the Zipkin UI at
* `<a href="http://localhost:9411">...</a>` to view the tracing logs and analyze the request flows
* across your microservices.
*
* <p>To place an order and generate tracing data, you can use the following curl command:
*
@@ -65,7 +64,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*
* <p>This command sends a POST request to create an order, which will trigger interactions with the
* payment and product microservices, generating tracing logs that can be viewed in Zipkin.
*
*/
@SpringBootApplication
public class Main {
@@ -30,9 +30,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* This controller handles order processing by calling necessary microservices.
*/
/** This controller handles order processing by calling necessary microservices. */
@Slf4j
@RestController
public class OrderController {
@@ -31,9 +31,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;
/**
* Service to handle order processing logic.
*/
/** Service to handle order processing logic. */
@Slf4j
@Service
public class OrderService {
@@ -50,9 +48,8 @@ public class OrderService {
}
/**
* Processes an order by calling
* {@link OrderService#validateProduct()} and
* {@link OrderService#processPayment()}.
* Processes an order by calling {@link OrderService#validateProduct()} and {@link
* OrderService#processPayment()}.
*
* @return A string indicating whether the order was processed successfully or failed.
*/
@@ -70,10 +67,11 @@ public class OrderService {
*/
Boolean validateProduct() {
try {
ResponseEntity<Boolean> productValidationResult = restTemplateBuilder
.build()
.postForEntity("http://localhost:30302/product/validate", "validating product",
Boolean.class);
ResponseEntity<Boolean> productValidationResult =
restTemplateBuilder
.build()
.postForEntity(
"http://localhost:30302/product/validate", "validating product", Boolean.class);
LOGGER.info("Product validation result: {}", productValidationResult.getBody());
return productValidationResult.getBody();
} catch (ResourceAccessException | HttpClientErrorException e) {
@@ -89,10 +87,11 @@ public class OrderService {
*/
Boolean processPayment() {
try {
ResponseEntity<Boolean> paymentProcessResult = restTemplateBuilder
.build()
.postForEntity("http://localhost:30301/payment/process", "processing payment",
Boolean.class);
ResponseEntity<Boolean> paymentProcessResult =
restTemplateBuilder
.build()
.postForEntity(
"http://localhost:30301/payment/process", "processing payment", Boolean.class);
LOGGER.info("Payment processing result: {}", paymentProcessResult.getBody());
return paymentProcessResult.getBody();
} catch (ResourceAccessException | HttpClientErrorException e) {
@@ -28,12 +28,10 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.jupiter.api.Test;
/**
* Application test
*/
/** Application test */
class MainTest {
@Test
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> Main.main(new String[]{}));
assertDoesNotThrow(() -> Main.main(new String[] {}));
}
}
@@ -1,27 +1,31 @@
package com.iluwatar.order.microservice;/*
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.order.microservice; /*
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
*
* The MIT License
* Copyright © 2014-2022 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
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;
@@ -29,28 +33,19 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.http.ResponseEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
/**
* OrderControllerTest class to test the OrderController.
*/
/** OrderControllerTest class to test the OrderController. */
class OrderControllerTest {
@InjectMocks
private OrderController orderController;
@InjectMocks private OrderController orderController;
@Mock
private OrderService orderService;
@Mock private OrderService orderService;
@BeforeEach
void setup() {
MockitoAnnotations.openMocks(this);
}
/**
* Test to process the order successfully.
*/
/** Test to process the order successfully. */
@Test
void processOrderShouldReturnSuccessStatus() {
// Arrange
@@ -61,9 +56,7 @@ class OrderControllerTest {
assertEquals("Order processed successfully", response.getBody());
}
/**
* Test to process the order with failure.
*/
/** Test to process the order with failure. */
@Test
void ProcessOrderShouldReturnFailureStatusWhen() {
// Arrange
@@ -36,23 +36,18 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
/**
* OrderServiceTest class to test the OrderService.
*/
/** OrderServiceTest class to test the OrderService. */
class OrderServiceTest {
@InjectMocks
private OrderService orderService;
@InjectMocks private OrderService orderService;
@Mock
private RestTemplateBuilder restTemplateBuilder;
@Mock private RestTemplateBuilder restTemplateBuilder;
@Mock
private RestTemplate restTemplate;
@Mock private RestTemplate restTemplate;
@BeforeEach
void setup() {
@@ -60,15 +55,15 @@ class OrderServiceTest {
when(restTemplateBuilder.build()).thenReturn(restTemplate);
}
/**
* Test to process the order successfully.
*/
/** Test to process the order successfully. */
@Test
void testProcessOrder_Success() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(true));
when(restTemplate.postForEntity(eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(true));
// Act
String result = orderService.processOrder();
@@ -76,13 +71,12 @@ class OrderServiceTest {
assertEquals("Order processed successfully", result);
}
/**
* Test to process the order with failure caused by product validation failure.
*/
/** Test to process the order with failure caused by product validation failure. */
@Test
void testProcessOrder_FailureWithProductValidationFailure() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(false));
// Act
String result = orderService.processOrder();
@@ -90,15 +84,15 @@ class OrderServiceTest {
assertEquals("Order processing failed", result);
}
/**
* Test to process the order with failure caused by payment processing failure.
*/
/** Test to process the order with failure caused by payment processing failure. */
@Test
void testProcessOrder_FailureWithPaymentProcessingFailure() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(true));
when(restTemplate.postForEntity(eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(false));
// Act
String result = orderService.processOrder();
@@ -106,13 +100,12 @@ class OrderServiceTest {
assertEquals("Order processing failed", result);
}
/**
* Test to validate the product.
*/
/** Test to validate the product. */
@Test
void testValidateProduct() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(true));
// Act
Boolean result = orderService.validateProduct();
@@ -120,13 +113,12 @@ class OrderServiceTest {
assertEquals(true, result);
}
/**
* Test to process the payment.
*/
/** Test to process the payment. */
@Test
void testProcessPayment() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
.thenReturn(ResponseEntity.ok(true));
// Act
Boolean result = orderService.processPayment();
@@ -134,13 +126,12 @@ class OrderServiceTest {
assertEquals(true, result);
}
/**
* Test to validate the product with ResourceAccessException.
*/
/** Test to validate the product with ResourceAccessException. */
@Test
void testValidateProduct_ResourceAccessException() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenThrow(new ResourceAccessException("Service unavailable"));
// Act
Boolean result = orderService.validateProduct();
@@ -148,27 +139,27 @@ class OrderServiceTest {
assertEquals(false, result);
}
/**
* Test to validate the product with HttpClientErrorException.
*/
/** Test to validate the product with HttpClientErrorException. */
@Test
void testValidateProduct_HttpClientErrorException() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenThrow(new HttpClientErrorException(org.springframework.http.HttpStatus.BAD_REQUEST, "Bad request"));
when(restTemplate.postForEntity(
eq("http://localhost:30302/product/validate"), anyString(), eq(Boolean.class)))
.thenThrow(
new HttpClientErrorException(
org.springframework.http.HttpStatus.BAD_REQUEST, "Bad request"));
// Act
Boolean result = orderService.validateProduct();
// Assert
assertEquals(false, result);
}
/**
* Test to process the payment with ResourceAccessException.
*/
/** Test to process the payment with ResourceAccessException. */
@Test
void testProcessPayment_ResourceAccessException() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
when(restTemplate.postForEntity(
eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
.thenThrow(new ResourceAccessException("Service unavailable"));
// Act
Boolean result = orderService.processPayment();
@@ -176,14 +167,15 @@ class OrderServiceTest {
assertEquals(false, result);
}
/**
* Test to process the payment with HttpClientErrorException.
*/
/** Test to process the payment with HttpClientErrorException. */
@Test
void testProcessPayment_HttpClientErrorException() {
// Arrange
when(restTemplate.postForEntity(eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
.thenThrow(new HttpClientErrorException(org.springframework.http.HttpStatus.BAD_REQUEST, "Bad request"));
when(restTemplate.postForEntity(
eq("http://localhost:30301/payment/process"), anyString(), eq(Boolean.class)))
.thenThrow(
new HttpClientErrorException(
org.springframework.http.HttpStatus.BAD_REQUEST, "Bad request"));
// Act
Boolean result = orderService.processPayment();
// Assert
@@ -41,10 +41,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* journey.
*
* <p>This implementation demonstrates distributed tracing in a microservices architecture for an
* e-commerce platform. When a customer places an order, the OrderService interacts with
* both the PaymentService to process the payment and the ProductService to check the
* product inventory. Tracing logs are generated for each interaction, and these logs can be
* visualized using Zipkin.
* e-commerce platform. When a customer places an order, the OrderService interacts with both the
* PaymentService to process the payment and the ProductService to check the product inventory.
* Tracing logs are generated for each interaction, and these logs can be visualized using Zipkin.
*
* <p>To run Zipkin and view the tracing logs, you can use the following Docker command:
*
@@ -52,9 +51,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* {@code docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin }
* </pre>
*
* <p>Start Zipkin with the command above. Once Zipkin is running, you can
* access the Zipkin UI at <a href="http://localhost:9411">http://localhost:9411</a>
* to view the tracing logs and analyze the request flows across your microservices.
* <p>Start Zipkin with the command above. Once Zipkin is running, you can access the Zipkin UI at
* <a href="http://localhost:9411">http://localhost:9411</a> to view the tracing logs and analyze
* the request flows across your microservices.
*
* <p>To place an order and generate tracing data, you can use the following curl command:
*
@@ -64,7 +63,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*
* <p>This command sends a POST request to create an order, which will trigger interactions with the
* payment and product microservices, generating tracing logs that can be viewed in Zipkin.
*
*/
@SpringBootApplication
public class Main {
@@ -30,9 +30,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller for handling payment processing requests.
*/
/** Controller for handling payment processing requests. */
@Slf4j
@RestController
public class PaymentController {
@@ -24,16 +24,14 @@
*/
package com.iluwatar.payment.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
/**
* Application Context loads test
*/
import org.junit.jupiter.api.Test;
/** Application Context loads test */
class MainTest {
@Test
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> Main.main(new String[]{}));
assertDoesNotThrow(() -> Main.main(new String[] {}));
}
}
@@ -24,15 +24,13 @@
*/
package com.iluwatar.payment.microservice;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Payment controller test.
*/
/** Payment controller test. */
class ProductControllerTest {
private PaymentController paymentController;
@@ -41,9 +39,8 @@ class ProductControllerTest {
void setUp() {
paymentController = new PaymentController();
}
/**
* Test to process the payment.
*/
/** Test to process the payment. */
@Test
void testValidateProduct() {
// Arrange
@@ -54,9 +51,7 @@ class ProductControllerTest {
assertEquals(ResponseEntity.ok(true), response);
}
/**
* Test to process the payment with null request.
*/
/** Test to process the payment with null request. */
@Test
void testValidateProductWithNullRequest() {
// Arrange
+2 -11
View File
@@ -34,17 +34,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>microservices-distributed-tracing</artifactId>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>3.3.1</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -57,11 +46,13 @@
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<version>1.4.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
@@ -41,10 +41,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* journey.
*
* <p>This implementation demonstrates distributed tracing in a microservices architecture for an
* e-commerce platform. When a customer places an order, the OrderService interacts with
* both the PaymentService to process the payment and the ProductService to check the
* product inventory. Tracing logs are generated for each interaction, and these logs can be
* visualized using Zipkin.
* e-commerce platform. When a customer places an order, the OrderService interacts with both the
* PaymentService to process the payment and the ProductService to check the product inventory.
* Tracing logs are generated for each interaction, and these logs can be visualized using Zipkin.
*
* <p>To run Zipkin and view the tracing logs, you can use the following Docker command:
*
@@ -52,9 +51,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* {@code docker run -d -p 9411:9411 --name zipkin openzipkin/zipkin }
* </pre>
*
* <p>Start Zipkin with the command above. Once Zipkin is running, you can
* access the Zipkin UI at <a href="http://localhost:9411">http://localhost:9411</a>
* to view the tracing logs and analyze the request flows across your microservices.
* <p>Start Zipkin with the command above. Once Zipkin is running, you can access the Zipkin UI at
* <a href="http://localhost:9411">http://localhost:9411</a> to view the tracing logs and analyze
* the request flows across your microservices.
*
* <p>To place an order and generate tracing data, you can use the following curl command:
*
@@ -64,7 +63,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
*
* <p>This command sends a POST request to create an order, which will trigger interactions with the
* payment and product microservices, generating tracing logs that can be viewed in Zipkin.
*
*/
@SpringBootApplication
public class Main {
@@ -30,9 +30,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller for handling product validation requests.
*/
/** Controller for handling product validation requests. */
@Slf4j
@RestController
public class ProductController {
@@ -24,17 +24,15 @@
*/
package com.iluwatar.product.microservice;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import com.iluwatar.product.microservice.microservice.Main;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
/**
* Application test
*/
/** Application test */
class MainTest {
@Test
void shouldExecuteApplicationWithoutException() {
assertDoesNotThrow(() -> Main.main(new String[]{}));
assertDoesNotThrow(() -> Main.main(new String[] {}));
}
}
@@ -24,14 +24,13 @@
*/
package com.iluwatar.product.microservice;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.iluwatar.product.microservice.microservice.ProductController;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.ResponseEntity;
import static org.junit.jupiter.api.Assertions.assertEquals;
class ProductControllerTest {
private ProductController productController;
@@ -41,9 +40,7 @@ class ProductControllerTest {
productController = new ProductController();
}
/**
* Test to validate the product.
*/
/** Test to validate the product. */
@Test
void testValidateProduct() {
// Arrange
@@ -54,9 +51,7 @@ class ProductControllerTest {
assertEquals(ResponseEntity.ok(true), response);
}
/**
* Test to validate the product with null request.
*/
/** Test to validate the product with null request. */
@Test
void testValidateProductWithNullRequest() {
// Arrange