📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -26,8 +26,7 @@ package com.iluwatar.aggregator.microservices;
import static java.util.Objects.requireNonNullElse;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
@ -37,20 +36,18 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public class Aggregator {
@Resource
private ProductInformationClient informationClient;
@Resource
private ProductInventoryClient inventoryClient;
/**
* Retrieves product data.
*
* @return a Product.
*/
@RequestMapping(path = "/product", method = RequestMethod.GET)
@GetMapping("/product")
public Product getProduct() {
var product = new Product();

View File

@ -23,9 +23,14 @@
package com.iluwatar.aggregator.microservices;
import lombok.Getter;
import lombok.Setter;
/**
* Encapsulates all the data for a Product that clients will request.
*/
@Getter
@Setter
public class Product {
/**
@ -39,20 +44,4 @@ public class Product {
*/
private int productInventories;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getProductInventories() {
return productInventories;
}
public void setProductInventories(int productInventories) {
this.productInventories = productInventories;
}
}

View File

@ -28,18 +28,16 @@ import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* An adapter to communicate with information micro-service.
*/
@Slf4j
@Component
public class ProductInformationClientImpl implements ProductInformationClient {
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class);
@Override
public String getProductTitle() {
var request = HttpRequest.newBuilder()
@ -54,6 +52,7 @@ public class ProductInformationClientImpl implements ProductInformationClient {
LOGGER.error("IOException Occurred", ioe);
} catch (InterruptedException ie) {
LOGGER.error("InterruptedException Occurred", ie);
Thread.currentThread().interrupt();
}
return null;
}

View File

@ -28,18 +28,16 @@ import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* An adapter to communicate with inventory micro-service.
*/
@Slf4j
@Component
public class ProductInventoryClientImpl implements ProductInventoryClient {
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
@Override
public Integer getProductInventories() {
var response = "";
@ -56,6 +54,7 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
LOGGER.error("IOException Occurred", ioe);
} catch (InterruptedException ie) {
LOGGER.error("InterruptedException Occurred", ie);
Thread.currentThread().interrupt();
}
if ("".equalsIgnoreCase(response)) {
return null;

View File

@ -23,19 +23,19 @@
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
*/
public class AggregatorTest {
class AggregatorTest {
@InjectMocks
private Aggregator aggregator;
@ -55,7 +55,7 @@ public class AggregatorTest {
* Tests getting the data for a desktop client
*/
@Test
public void testGetProduct() {
void testGetProduct() {
var title = "The Product Title.";
var inventories = 5;

View File

@ -23,8 +23,7 @@
package com.iluwatar.information.microservice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
@ -38,7 +37,7 @@ public class InformationController {
*
* @return product inventory.
*/
@RequestMapping(value = "/information", method = RequestMethod.GET)
@GetMapping("/information")
public String getProductTitle() {
return "The Product Title.";
}

View File

@ -23,17 +23,17 @@
package com.iluwatar.information.microservice;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Information Rest Controller
*/
public class InformationControllerTest {
class InformationControllerTest {
@Test
public void shouldGetProductTitle() {
void shouldGetProductTitle() {
var infoController = new InformationController();
var title = infoController.getProductTitle();
assertEquals("The Product Title.", title);

View File

@ -23,8 +23,7 @@
package com.iluwatar.inventory.microservice;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
@ -38,7 +37,7 @@ public class InventoryController {
*
* @return product inventory.
*/
@RequestMapping(value = "/inventories", method = RequestMethod.GET)
@GetMapping("/inventories")
public int getProductInventories() {
return 5;
}

View File

@ -23,16 +23,17 @@
package com.iluwatar.inventory.microservice;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test Inventory Rest Controller
*/
public class InventoryControllerTest {
class InventoryControllerTest {
@Test
public void testGetProductInventories() {
void testGetProductInventories() {
var inventoryController = new InventoryController();
var numberOfInventories = inventoryController.getProductInventories();
assertEquals(5, numberOfInventories);