📍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

@ -24,8 +24,7 @@
package com.iluwatar.api.gateway;
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;
/**
@ -45,7 +44,7 @@ public class ApiGateway {
*
* @return Product information for clients on a desktop
*/
@RequestMapping(path = "/desktop", method = RequestMethod.GET)
@GetMapping("/desktop")
public DesktopProduct getProductDesktop() {
var desktopProduct = new DesktopProduct();
desktopProduct.setImagePath(imageClient.getImagePath());
@ -58,7 +57,7 @@ public class ApiGateway {
*
* @return Product information for clients on a mobile device
*/
@RequestMapping(path = "/mobile", method = RequestMethod.GET)
@GetMapping("/mobile")
public MobileProduct getProductMobile() {
var mobileProduct = new MobileProduct();
mobileProduct.setPrice(priceClient.getPrice());

View File

@ -23,10 +23,16 @@
package com.iluwatar.api.gateway;
import lombok.Getter;
import lombok.Setter;
/**
* Encapsulates all of the information that a desktop client needs to display a product.
*/
@Getter
@Setter
public class DesktopProduct {
/**
* The price of the product.
*/
@ -37,19 +43,4 @@ public class DesktopProduct {
*/
private String imagePath;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
}

View File

@ -23,24 +23,21 @@
package com.iluwatar.api.gateway;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import org.slf4j.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* An adapter to communicate with the Image microservice.
*/
@Slf4j
@Component
public class ImageClientImpl implements ImageClient {
private static final Logger LOGGER = getLogger(ImageClientImpl.class);
/**
* Makes a simple HTTP Get request to the Image microservice.
@ -60,8 +57,11 @@ public class ImageClientImpl implements ImageClient {
var httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
logResponse(httpResponse);
return httpResponse.body();
} catch (IOException | InterruptedException e) {
LOGGER.error("Failure occurred while getting image path", e);
} catch (IOException ioe) {
LOGGER.error("Failure occurred while getting image path", ioe);
} catch (InterruptedException ie) {
LOGGER.error("Failure occurred while getting image path", ie);
Thread.currentThread().interrupt();
}
return null;

View File

@ -23,20 +23,17 @@
package com.iluwatar.api.gateway;
import lombok.Getter;
import lombok.Setter;
/**
* Encapsulates all of the information that mobile client needs to display a product.
*/
@Getter
@Setter
public class MobileProduct {
/**
* The price of the product.
*/
private String price;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}

View File

@ -23,25 +23,22 @@
package com.iluwatar.api.gateway;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import org.slf4j.Logger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* An adapter to communicate with the Price microservice.
*/
@Slf4j
@Component
public class PriceClientImpl implements PriceClient {
private static final Logger LOGGER = getLogger(PriceClientImpl.class);
/**
* Makes a simple HTTP Get request to the Price microservice.
@ -61,8 +58,11 @@ public class PriceClientImpl implements PriceClient {
var httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
logResponse(httpResponse);
return httpResponse.body();
} catch (IOException | InterruptedException e) {
} catch (IOException e) {
LOGGER.error("Failure occurred while getting price info", e);
} catch (InterruptedException e) {
LOGGER.error("Failure occurred while getting price info", e);
Thread.currentThread().interrupt();
}
return null;

View File

@ -35,7 +35,7 @@ import org.mockito.MockitoAnnotations;
/**
* Test API Gateway Pattern
*/
public class ApiGatewayTest {
class ApiGatewayTest {
@InjectMocks
private ApiGateway apiGateway;
@ -55,7 +55,7 @@ public class ApiGatewayTest {
* Tests getting the data for a desktop client
*/
@Test
public void testGetProductDesktop() {
void testGetProductDesktop() {
var imagePath = "/product-image.png";
var price = "20";
when(imageClient.getImagePath()).thenReturn(imagePath);
@ -71,7 +71,7 @@ public class ApiGatewayTest {
* Tests getting the data for a mobile client
*/
@Test
public void testGetProductMobile() {
void testGetProductMobile() {
var price = "20";
when(priceClient.getPrice()).thenReturn(price);