From ebfae111490864cd815a4f66909f731bff11b6ff Mon Sep 17 00:00:00 2001 From: Sasa M Date: Thu, 28 May 2020 01:12:42 +0200 Subject: [PATCH 01/44] Customer order application project --- .../spring-boot-microservices/README.md | 13 +++ .../customer-service/.gitignore | 41 +++++++ .../customer-service/pom.xml | 85 ++++++++++++++ .../baeldung/customerservice/Customer.java | 14 +++ .../customerservice/CustomerApplication.java | 25 ++++ .../customerservice/CustomerService.java | 56 +++++++++ .../src/main/resources/application.properties | 4 + .../customerservice/CustomerServiceTest.java | 33 ++++++ .../src/test/resources/application.properties | 2 + .../order-service/.gitignore | 41 +++++++ .../order-service/order-client/pom.xml | 17 +++ .../orderservice/client/OrderClient.java | 6 + .../orderservice/client/OrderClientImpl.java | 35 ++++++ .../orderservice/client/OrderDTO.java | 16 +++ .../orderservice/client/OrderResponse.java | 15 +++ .../src/main/resources/application.properties | 1 + .../order-service/order-server/pom.xml | 29 +++++ .../java/com/baeldung/orderservice/Order.java | 18 +++ .../orderservice/OrderApplication.java | 24 ++++ .../baeldung/orderservice/OrderService.java | 75 ++++++++++++ .../src/main/resources/application.properties | 4 + .../orderservice/OrderServiceTest.java | 35 ++++++ .../order-service/pom.xml | 108 +++++++++++++++++ .../payment-service/.gitignore | 41 +++++++ .../payment-service/payment-client/pom.xml | 17 +++ .../PaymentClient.java | 6 + .../PaymentClientImpl.java | 35 ++++++ .../PaymentDTO.java | 17 +++ .../PaymentResponse.java | 18 +++ .../src/main/resources/application.properties | 0 .../payment-service/payment-server/pom.xml | 22 ++++ .../paymentservice/CardValidator.java | 31 +++++ .../com/baeldung/paymentservice/Payment.java | 19 +++ .../paymentservice/PaymentApplication.java | 15 +++ .../paymentservice/PaymentService.java | 39 +++++++ .../src/main/resources/application.properties | 3 + .../payment-service/pom.xml | 110 ++++++++++++++++++ .../spring-boot-microservices/pom.xml | 46 ++++++++ .../postman/customer-order.postman_collection | 87 ++++++++++++++ .../java/com/baeldung/CustomerOrderApp.java | 23 ++++ 40 files changed, 1226 insertions(+) create mode 100644 spring-boot-modules/spring-boot-microservices/README.md create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/.gitignore create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java create mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/.gitignore create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java create mode 100644 spring-boot-modules/spring-boot-microservices/order-service/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/.gitignore create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection create mode 100644 spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java diff --git a/spring-boot-modules/spring-boot-microservices/README.md b/spring-boot-modules/spring-boot-microservices/README.md new file mode 100644 index 0000000000..d2008c51fc --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/README.md @@ -0,0 +1,13 @@ +--------------------------------- CustomerOrderApp installation steps---------------------------------- + +1. Clone or download sample project from GitHub repo: https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/customer-order-app +2. Unzip project folder to local disk for example to: C:/baeldung-tutorials/customer-order-app +3. Run `mvn clean install -DskipTests=true` +4. Navigate to payment-service/payment-server module folder and type `mvn spring-boot:run` +5. Open another CMD PROMPT window. + Navigate to order-service/order-server module folder and type `mvn spring-boot:run` +6. Open another CMD PROMPT window. + Navigate to customer-service module folder and type `mvn spring-boot:run` + +7. Launch the Postman application from your machine and import the collection of POST requests located in the _postman_ folder + diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/.gitignore b/spring-boot-modules/spring-boot-microservices/customer-service/.gitignore new file mode 100644 index 0000000000..0e9415ada6 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/.gitignore @@ -0,0 +1,41 @@ +#https://github.com/spring-projects/spring-boot/blob/master/.gitignore + +*# +*.iml +*.ipr +*.iws +*.jar +*.sw? +*~ +.#* +.*.md.html +.DS_Store +.classpath +.factorypath +.gradle +.idea +.metadata +.project +.recommenders +.settings +.springBeans +/build +/code +MANIFEST.MF +_site/ +activemq-data +bin +build +build.log +dependency-reduced-pom.xml +dump.rdb +interpolated*.xml +lib/ +manifest.yml +overridedb.* +target +transaction-logs +.flattened-pom.xml +secrets.yml +.gradletasknamecache +.sts4-cache diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/pom.xml b/spring-boot-modules/spring-boot-microservices/customer-service/pom.xml new file mode 100644 index 0000000000..a02ce2e1d8 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/pom.xml @@ -0,0 +1,85 @@ + + + + CustomerOrderApp + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + com.baeldung.customerservice + customer-service + jar + + + 1.8 + 1.8 + 1.8 + UTF-8 + + + + + + org.springframework.boot + spring-boot-dependencies + 2.3.0.RELEASE + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-configuration-processor + + + junit + junit + test + + + com.baeldung.orderservice + order-client + 1.0-SNAPSHOT + compile + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + exec + + + + + + + + diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java new file mode 100644 index 0000000000..7d10510cbc --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java @@ -0,0 +1,14 @@ +package com.baeldung.customerservice; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Customer { + + private int id; + private String firstName; + private String lastName; + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java new file mode 100644 index 0000000000..489129a3d2 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderClientImpl; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; + +/** + * Spring Boot application starter class + */ +@SpringBootApplication +public class CustomerApplication { + public static void main(String[] args) { + SpringApplication.run(CustomerApplication.class, args); + } + + @Bean + public OrderClient getOrderClient() { + + return new OrderClientImpl(new RestTemplateBuilder()); + } + +} diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java new file mode 100644 index 0000000000..ab8872de1c --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java @@ -0,0 +1,56 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RestController +public class CustomerService { + + @Autowired + private OrderClient orderClient; + + private List customers = Arrays.asList( + + new Customer(1, "John", "Smith"), + new Customer(2, "Deny", "Dominic")); + + + @GetMapping + public List getAllCustomers() { + return customers; + } + + @GetMapping("/{id}") + public Customer getCustomerById(@PathVariable int id) { + return customers.stream() + .filter(customer -> customer.getId() == id) + .findFirst() + .orElseThrow(IllegalArgumentException::new); + } + + + @PostMapping(value = "/order") + public String sendOrder(@RequestBody Map body) { + + OrderDTO dto = new OrderDTO(); + dto.setCustomerId((Integer) body.get("customerId")); + dto.setItemId((String) body.get("itemId")); + + OrderResponse response = orderClient.order(dto); + + return response.getStatus(); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties new file mode 100644 index 0000000000..d439ae9b76 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#Spring Boot server configuration +server.servlet.context-path=/customer-service +server.port=8001 + diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java new file mode 100644 index 0000000000..1c44146811 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java @@ -0,0 +1,33 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = CustomerApplication.class) +public class CustomerServiceTest { + + @Autowired + private OrderClient orderClient; + + @Test + public void testAddOrderSuccess(){ + + + OrderDTO dto = new OrderDTO(2,"A152"); + + OrderResponse response = orderClient.order(dto); + + Assert.assertNotNull("Order Id not generated", response.getOrderId()); + Assert.assertEquals("A152", response.getProductId()); + Assert.assertEquals("CREATED", response.getStatus()); + } + +} diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties b/spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties new file mode 100644 index 0000000000..1d50559005 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties @@ -0,0 +1,2 @@ +local.server.port=8001 +server.servlet.context-path=/customer-service \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/order-service/.gitignore b/spring-boot-modules/spring-boot-microservices/order-service/.gitignore new file mode 100644 index 0000000000..0e9415ada6 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/.gitignore @@ -0,0 +1,41 @@ +#https://github.com/spring-projects/spring-boot/blob/master/.gitignore + +*# +*.iml +*.ipr +*.iws +*.jar +*.sw? +*~ +.#* +.*.md.html +.DS_Store +.classpath +.factorypath +.gradle +.idea +.metadata +.project +.recommenders +.settings +.springBeans +/build +/code +MANIFEST.MF +_site/ +activemq-data +bin +build +build.log +dependency-reduced-pom.xml +dump.rdb +interpolated*.xml +lib/ +manifest.yml +overridedb.* +target +transaction-logs +.flattened-pom.xml +secrets.yml +.gradletasknamecache +.sts4-cache diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml new file mode 100644 index 0000000000..22176bb85e --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + + com.baeldung.orderservice + order-service + 1.0-SNAPSHOT + + order-client + com.baeldung.orderservice + order-client + Order service client module + http://projects.spring.io/spring-boot/ + + diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java new file mode 100644 index 0000000000..2dd6b13248 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java @@ -0,0 +1,6 @@ +package com.baeldung.orderservice.client; + +public interface OrderClient { + + OrderResponse order(OrderDTO orderDTO); +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java new file mode 100644 index 0000000000..70ec77fab6 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java @@ -0,0 +1,35 @@ +package com.baeldung.orderservice.client; + +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + + +@Component +public class OrderClientImpl implements OrderClient { + + private RestTemplate restTemplate; + + public OrderClientImpl(RestTemplateBuilder builder) { + + this.restTemplate = builder.build(); + } + + @Override + public OrderResponse order(OrderDTO orderDTO) { + + String serviceUrl = "http://localhost:8002/order-service"; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity request = new HttpEntity<>(orderDTO, headers); + + OrderResponse orderResponse = restTemplate.postForObject(serviceUrl + "/create", request, OrderResponse.class); + + return orderResponse; + + } +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java new file mode 100644 index 0000000000..c31c9f6bec --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.orderservice.client; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderDTO { + + private int customerId; + private String itemId; + +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java new file mode 100644 index 0000000000..e8d2059cbb --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java @@ -0,0 +1,15 @@ +package com.baeldung.orderservice.client; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderResponse { + + private int orderId; + private String productId; + private String status; +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties new file mode 100644 index 0000000000..53e503689f --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=8002 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml new file mode 100644 index 0000000000..722bfa5aac --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml @@ -0,0 +1,29 @@ + + + + order-service + com.baeldung.orderservice + 1.0-SNAPSHOT + + 4.0.0 + + com.baeldung.orderservice + order-server + + + com.baeldung.orderservice + order-client + 1.0-SNAPSHOT + compile + + + com.baeldung.paymentservice + payment-client + 1.0-SNAPSHOT + compile + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java new file mode 100644 index 0000000000..719305064f --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java @@ -0,0 +1,18 @@ +package com.baeldung.orderservice; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Order { + + private Integer id; + private Integer customerId; + private String itemId; + private String date; + +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java new file mode 100644 index 0000000000..2d09479a57 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java @@ -0,0 +1,24 @@ +package com.baeldung.orderservice; + +import com.baeldung.paymentservice.PaymentClient; +import com.baeldung.paymentservice.PaymentClientImpl; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; + +/** + * Spring Boot application starter class + */ +@SpringBootApplication +public class OrderApplication { + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } + + @Bean + public PaymentClient getPaymentClient() { + + return new PaymentClientImpl(new RestTemplateBuilder()); + } +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java new file mode 100644 index 0000000000..5ad66e1052 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java @@ -0,0 +1,75 @@ +package com.baeldung.orderservice; + +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +import com.baeldung.paymentservice.PaymentClient; +import com.baeldung.paymentservice.PaymentDTO; +import com.baeldung.paymentservice.PaymentResponse; +import org.apache.commons.lang.time.DateFormatUtils; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@RestController +public class OrderService { + + @Autowired + private PaymentClient paymentClient; + + private List orders = Arrays.asList( + + new Order(1, 1, "A101", "2020/02/14"), + new Order(2, 1, "A101", "2020/02/14"), + new Order(3, 2, "A150", "2020/02/17")); + + @GetMapping + public List getAllOrders() { + return orders; + } + + @GetMapping("/{id}") + public List getOrdersByCustomer(@PathVariable int id) { + return orders.stream() + .filter(order -> order.getCustomerId() == id).collect(Collectors.toList()); + } + + @PostMapping("/create") + public OrderResponse createOrder(@RequestBody OrderDTO request) { + + int lastIndex = orders.size(); + Order order = new Order(); + order.setId(lastIndex + 1); + order.setCustomerId(request.getCustomerId()); + order.setItemId(request.getItemId()); + String date = DateFormatUtils.format(new Date(), "yyyy/MM/dd"); + order.setDate(date); + + return new OrderResponse(order.getId(), order.getItemId(), "CREATED"); + } + + @PostMapping("/pay/{orderNumber}") + public PaymentResponse sendPayment(@PathVariable String orderNumber, @RequestBody Map body) { + + PaymentDTO dto = new PaymentDTO(); + dto.setFirstName((String) body.get("firstName")); + dto.setLastName((String) body.get("lastName")); + dto.setCardNumber((String) body.get("cardNumber")); + dto.setAmount((Double) body.get("amount")); + dto.setCurrency((String) body.get("currency")); + + PaymentResponse paymentResponse = paymentClient.pay(orderNumber, dto); + + return paymentResponse; + + } +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties new file mode 100644 index 0000000000..f4fe5e7079 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#Spring Boot server configuration +server.servlet.context-path=/order-service +server.port=8002 + diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java new file mode 100644 index 0000000000..2630f908be --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java @@ -0,0 +1,35 @@ +package com.baeldung.orderservice; + +import com.baeldung.paymentservice.PaymentClient; +import com.baeldung.paymentservice.PaymentDTO; +import com.baeldung.paymentservice.PaymentResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = OrderApplication.class) +public class OrderServiceTest { + + @Autowired + private PaymentClient paymentClient; + + + @Test + public void testSendPaySuccess(){ + + + PaymentDTO dto = new PaymentDTO("Sasa","Milenkovic","4260-6720-3283-7081",150.0,"USD"); + + PaymentResponse response = paymentClient.pay("A152", dto); + + Assert.assertNotNull("Payment Id not generated", response.getPaymentId()); + Assert.assertEquals("CREDITCARD", response.getPaymentMethod()); + Assert.assertEquals("Sasa Milenkovic", response.getCustomerFullName()); + Assert.assertEquals(new Double(150.0), response.getAmount()); + Assert.assertEquals("USD", response.getCurrency()); + } +} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/pom.xml new file mode 100644 index 0000000000..603b845cef --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/order-service/pom.xml @@ -0,0 +1,108 @@ + + + + CustomerOrderApp + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + com.baeldung.orderservice + order-service + pom + + order-client + order-server + + + + 1.8 + 2.6 + 1.8 + 1.8 + UTF-8 + com.baeldung.orderservice.OrderApplication + + + + + + org.springframework.boot + spring-boot-dependencies + 2.3.0.RELEASE + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + commons-lang + commons-lang + ${commons-lang.version} + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-configuration-processor + + + org.springframework.boot + spring-boot-test-autoconfigure + test + + + junit + junit + test + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${orderservice.mainclass} + + + + + repackage + + + exe + + + + start-application + + com.baeldung.orderservice.OrderApplication + ../order-server/target/classes + + + start + + + + + + + + diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/.gitignore b/spring-boot-modules/spring-boot-microservices/payment-service/.gitignore new file mode 100644 index 0000000000..0e9415ada6 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/.gitignore @@ -0,0 +1,41 @@ +#https://github.com/spring-projects/spring-boot/blob/master/.gitignore + +*# +*.iml +*.ipr +*.iws +*.jar +*.sw? +*~ +.#* +.*.md.html +.DS_Store +.classpath +.factorypath +.gradle +.idea +.metadata +.project +.recommenders +.settings +.springBeans +/build +/code +MANIFEST.MF +_site/ +activemq-data +bin +build +build.log +dependency-reduced-pom.xml +dump.rdb +interpolated*.xml +lib/ +manifest.yml +overridedb.* +target +transaction-logs +.flattened-pom.xml +secrets.yml +.gradletasknamecache +.sts4-cache diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml new file mode 100644 index 0000000000..19c1bb7e39 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + payment-service + com.baeldung.paymentservice + 1.0-SNAPSHOT + + + + com.baeldung.paymentservice + payment-client + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java new file mode 100644 index 0000000000..f9e24725b8 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java @@ -0,0 +1,6 @@ +package com.baeldung.paymentservice; + +public interface PaymentClient { + + PaymentResponse pay (String orderNumber, PaymentDTO paymentDTO); +} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java new file mode 100644 index 0000000000..87609b098e --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java @@ -0,0 +1,35 @@ +package com.baeldung.paymentservice; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Component +public class PaymentClientImpl implements PaymentClient { + + private RestTemplate restTemplate; + + public PaymentClientImpl(RestTemplateBuilder builder) { + + this.restTemplate = builder.build(); + } + + @Override + public PaymentResponse pay(String orderNumber, PaymentDTO paymentDTO) { + + String serviceUrl = "http://localhost:8003/payment-service"; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity request = new HttpEntity<>(paymentDTO, headers); + + PaymentResponse paymentResponse = restTemplate.postForObject(serviceUrl + "/pay/" + orderNumber, request, PaymentResponse.class); + + return paymentResponse; + + } +} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java new file mode 100644 index 0000000000..cd81b78366 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java @@ -0,0 +1,17 @@ +package com.baeldung.paymentservice; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PaymentDTO { + + private String firstName; + private String lastName; + private String cardNumber; + private double amount; + private String currency; +} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java new file mode 100644 index 0000000000..4a155d4571 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java @@ -0,0 +1,18 @@ +package com.baeldung.paymentservice; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PaymentResponse{ + + private String paymentId; + private String paymentMethod; + private String customerFullName; + private Double amount; + private String currency; + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml new file mode 100644 index 0000000000..eb429553dd --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + + com.baeldung.paymentservice + payment-service + 1.0-SNAPSHOT + + com.baeldung.paymentservice + payment-server + payment-server + + + com.baeldung.paymentservice + payment-client + 1.0-SNAPSHOT + compile + + + diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java new file mode 100644 index 0000000000..e4f0a3a68a --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java @@ -0,0 +1,31 @@ +package com.baeldung.paymentservice; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class CardValidator { + + public static boolean validate(String cardNumber){ + + boolean isValid = false; + + String regex = "^(?:(?4[0-9]{12}(?:[0-9]{3})?)|" + + "(?5[1-5][0-9]{14})|" + + "(?6(?:011|5[0-9]{2})[0-9]{12})|" + + "(?3[47][0-9]{13})|" + + "(?3(?:0[0-5]|[68][0-9])?[0-9]{11})|" + + "(?(?:2131|1800|35[0-9]{3})[0-9]{11}))$"; + + + Pattern pattern = Pattern.compile(regex); + cardNumber = cardNumber.replaceAll("-", ""); + Matcher matcher = pattern.matcher(cardNumber); + + if(matcher.matches()){ + + isValid = true; + } + + return isValid; + } +} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java new file mode 100644 index 0000000000..9789195c98 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java @@ -0,0 +1,19 @@ +package com.baeldung.paymentservice; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Payment { + + private String paymentId; + private String paymentMethod; + private String customerFullName; + private double amount; + private String currency; + +} + diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java new file mode 100644 index 0000000000..0e9336dcfe --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.paymentservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * + * Spring Boot application starter class + */ +@SpringBootApplication +public class PaymentApplication { + public static void main(String[] args) { + SpringApplication.run(PaymentApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java new file mode 100644 index 0000000000..f44e342cd7 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java @@ -0,0 +1,39 @@ +package com.baeldung.paymentservice; + +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.smartcardio.CardException; +import java.util.UUID; + + +@RestController +public class PaymentService { + + + @PostMapping("/pay/{orderNum}") + public PaymentResponse createPayment(@PathVariable String orderNum, @RequestBody PaymentDTO paymentDTO) { + + Payment payment = new Payment(); + payment.setPaymentId(UUID.randomUUID().toString().replace("-", "")); + String firstName = paymentDTO.getFirstName(); + String lastName = paymentDTO.getLastName(); + payment.setCustomerFullName(firstName + " " + lastName); + String cardNumber = paymentDTO.getCardNumber(); + + if(CardValidator.validate(cardNumber)){ + payment.setPaymentMethod("CREDITCARD"); + } else try { + throw new CardException("Card with number:"+ cardNumber + " is invalid"); + } catch (CardException e) { + e.printStackTrace(); + } + payment.setAmount(paymentDTO.getAmount()); + payment.setCurrency(paymentDTO.getCurrency()); + + return new PaymentResponse(payment.getPaymentId(), payment.getPaymentMethod(), payment.getCustomerFullName(), payment.getAmount(), payment.getCurrency()); + + } +} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties new file mode 100644 index 0000000000..8f3550946e --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties @@ -0,0 +1,3 @@ +#Spring Boot server configuration +server.servlet.context-path=/payment-service +server.port=8003 diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/pom.xml b/spring-boot-modules/spring-boot-microservices/payment-service/pom.xml new file mode 100644 index 0000000000..474ab6fe93 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/payment-service/pom.xml @@ -0,0 +1,110 @@ + + + + CustomerOrderApp + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + com.baeldung.paymentservice + payment-service + pom + + payment-client + payment-server + + + + 1.8 + 2.6 + 1.8 + 1.8 + UTF-8 + com.baeldung.paymentservice.PaymentApplication + + + + + + org.springframework.boot + spring-boot-dependencies + 2.3.0.RELEASE + pom + import + + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + commons-lang + commons-lang + ${commons-lang.version} + + + + org.springframework.boot + spring-boot-starter-json + + + + org.springframework.boot + spring-boot-test + test + + + + org.springframework.boot + spring-boot-test-autoconfigure + test + + + junit + junit + test + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${paymentservice.mainclass} + + + + + repackage + + + exe + + + + start-application + + com.baeldung.paymentservice.PaymentApplication + ../payment-server/target/classes + + + start + + + + + + + + diff --git a/spring-boot-modules/spring-boot-microservices/pom.xml b/spring-boot-modules/spring-boot-microservices/pom.xml new file mode 100644 index 0000000000..1cdd7595d4 --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + com.baeldung + CustomerOrderApp + pom + 1.0-SNAPSHOT + CustomerOrderApp + http://maven.apache.org + + + org.springframework.boot + spring-boot-starter-parent + 2.3.0.RELEASE + + + + + UTF-8 + 1.8 + 1.8 + + + + customer-service + order-service + payment-service + + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-autoconfigure + + + diff --git a/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection b/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection new file mode 100644 index 0000000000..aa9960aead --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection @@ -0,0 +1,87 @@ +{ + "info": { + "_postman_id": "92594398-49cc-4a7c-b44f-1037307afbd3", + "name": "postman-requests", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Crete new Customer order", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "multipart/form-data", + "type": "text", + "disabled": true + }, + { + "key": "Accept-Charset", + "value": "utf-8", + "type": "text", + "disabled": true + }, + { + "key": "boundary", + "value": "nAp4nMEt-BuGuuLlq-6fnASQErGjSamaG", + "type": "text", + "disabled": true + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"customerId\":2,\n \"itemId\":\"A152\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:8001/customer-service/order", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8001", + "path": [ + "customer-service", + "order" + ] + } + }, + "response": [] + }, + { + "name": "Send Order for payment", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n\t\n\"firstName\":\"John\",\n\"lastName\":\"Smith\",\n\"cardNumber\":\"4260-6720-3283-7081\",\n\"amount\":150.0,\n\"currency\":\"USD\"\n\t\n\t\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "localhost:8002/order-service/pay/A152", + "host": [ + "localhost" + ], + "port": "8002", + "path": [ + "order-service", + "pay", + "A152" + ] + } + }, + "response": [] + } + ], + "protocolProfileBehavior": {} +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java b/spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java new file mode 100644 index 0000000000..15455ca16c --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java @@ -0,0 +1,23 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +/** + * Customer Order Spring Boot Main Application + * + * */ + +@SpringBootApplication +@ComponentScan(basePackages = "com.baeldung.*") +public class CustomerOrderApp +{ + + public static void main( String[] args ) + { + + SpringApplication.run(CustomerOrderApp.class,args); + + } +} From c63c9b889e11ee062e6e7f256f9280820cd6ebd4 Mon Sep 17 00:00:00 2001 From: Sasa M Date: Sun, 7 Jun 2020 01:56:45 +0200 Subject: [PATCH 02/44] Update to customer order modules - added shared-dto --- .../spring-boot-microservices/README.md | 14 +-- .../baeldung/orderservice/OrderService.java | 18 --- .../order-service/pom.xml | 20 ++++ .../payment-service/.gitignore | 41 ------- .../payment-service/payment-client/pom.xml | 17 --- .../PaymentClient.java | 6 - .../PaymentClientImpl.java | 35 ------ .../PaymentResponse.java | 18 --- .../src/main/resources/application.properties | 0 .../payment-service/payment-server/pom.xml | 22 ---- .../paymentservice/CardValidator.java | 31 ----- .../com/baeldung/paymentservice/Payment.java | 19 --- .../paymentservice/PaymentApplication.java | 15 --- .../paymentservice/PaymentService.java | 39 ------- .../src/main/resources/application.properties | 3 - .../payment-service/pom.xml | 110 ------------------ .../spring-boot-microservices/pom.xml | 2 +- .../postman/customer-order.postman_collection | 30 +---- .../shared-dto/pom.xml | 53 +++++++++ .../main/java/com/baeldung/CustomerDTO.java} | 6 +- .../src/main/java/com/baeldung/OrderDTO.java | 16 +++ 21 files changed, 100 insertions(+), 415 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/.gitignore delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-microservices/payment-service/pom.xml create mode 100644 spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml rename spring-boot-modules/spring-boot-microservices/{payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java => shared-dto/src/main/java/com/baeldung/CustomerDTO.java} (76%) create mode 100644 spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java diff --git a/spring-boot-modules/spring-boot-microservices/README.md b/spring-boot-modules/spring-boot-microservices/README.md index d2008c51fc..a85d52b2bc 100644 --- a/spring-boot-modules/spring-boot-microservices/README.md +++ b/spring-boot-modules/spring-boot-microservices/README.md @@ -1,13 +1,11 @@ --------------------------------- CustomerOrderApp installation steps---------------------------------- -1. Clone or download sample project from GitHub repo: https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/customer-order-app -2. Unzip project folder to local disk for example to: C:/baeldung-tutorials/customer-order-app +1. Clone or download sample project from GitHub repo: https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-microservices +2. Unzip project folder to local disk for example to: C:/baeldung-tutorials/spring-boot-microservices/customer-order-app 3. Run `mvn clean install -DskipTests=true` -4. Navigate to payment-service/payment-server module folder and type `mvn spring-boot:run` -5. Open another CMD PROMPT window. - Navigate to order-service/order-server module folder and type `mvn spring-boot:run` -6. Open another CMD PROMPT window. +4. Navigate to order-service/order-server module folder and type `mvn spring-boot:run` +5. Open another CMD PROMPT window. Navigate to customer-service module folder and type `mvn spring-boot:run` -7. Launch the Postman application from your machine and import the collection of POST requests located in the _postman_ folder - +6. Launch the Postman application from your machine and import the collection located in the _postman_ folder in project root +7. Verify successful request from the POSTMAN to http://localhost:8001/customer-service/order diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java index 5ad66e1052..09d72e63f4 100644 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java +++ b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java @@ -17,14 +17,11 @@ import org.springframework.web.bind.annotation.RestController; import java.util.Arrays; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; @RestController public class OrderService { - @Autowired - private PaymentClient paymentClient; private List orders = Arrays.asList( @@ -57,19 +54,4 @@ public class OrderService { return new OrderResponse(order.getId(), order.getItemId(), "CREATED"); } - @PostMapping("/pay/{orderNumber}") - public PaymentResponse sendPayment(@PathVariable String orderNumber, @RequestBody Map body) { - - PaymentDTO dto = new PaymentDTO(); - dto.setFirstName((String) body.get("firstName")); - dto.setLastName((String) body.get("lastName")); - dto.setCardNumber((String) body.get("cardNumber")); - dto.setAmount((Double) body.get("amount")); - dto.setCurrency((String) body.get("currency")); - - PaymentResponse paymentResponse = paymentClient.pay(orderNumber, dto); - - return paymentResponse; - - } } diff --git a/spring-boot-modules/spring-boot-microservices/order-service/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/pom.xml index 603b845cef..fcdfdac595 100644 --- a/spring-boot-modules/spring-boot-microservices/order-service/pom.xml +++ b/spring-boot-modules/spring-boot-microservices/order-service/pom.xml @@ -19,6 +19,7 @@ 1.8 2.6 + 0.0.2 1.8 1.8 UTF-8 @@ -47,6 +48,11 @@ commons-lang ${commons-lang.version} + + org.qunix + structure-maven-plugin + ${structure-maven.version} + org.springframework.boot spring-boot-starter-json @@ -102,6 +108,20 @@ + + org.qunix + structure-maven-plugin + ${structure-maven.version} + false + + + compile + + modules + + + + diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/.gitignore b/spring-boot-modules/spring-boot-microservices/payment-service/.gitignore deleted file mode 100644 index 0e9415ada6..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -#https://github.com/spring-projects/spring-boot/blob/master/.gitignore - -*# -*.iml -*.ipr -*.iws -*.jar -*.sw? -*~ -.#* -.*.md.html -.DS_Store -.classpath -.factorypath -.gradle -.idea -.metadata -.project -.recommenders -.settings -.springBeans -/build -/code -MANIFEST.MF -_site/ -activemq-data -bin -build -build.log -dependency-reduced-pom.xml -dump.rdb -interpolated*.xml -lib/ -manifest.yml -overridedb.* -target -transaction-logs -.flattened-pom.xml -secrets.yml -.gradletasknamecache -.sts4-cache diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml deleted file mode 100644 index 19c1bb7e39..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - 4.0.0 - - payment-service - com.baeldung.paymentservice - 1.0-SNAPSHOT - - - - com.baeldung.paymentservice - payment-client - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java deleted file mode 100644 index f9e24725b8..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClient.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.paymentservice; - -public interface PaymentClient { - - PaymentResponse pay (String orderNumber, PaymentDTO paymentDTO); -} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java deleted file mode 100644 index 87609b098e..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentClientImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.paymentservice; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - -@Component -public class PaymentClientImpl implements PaymentClient { - - private RestTemplate restTemplate; - - public PaymentClientImpl(RestTemplateBuilder builder) { - - this.restTemplate = builder.build(); - } - - @Override - public PaymentResponse pay(String orderNumber, PaymentDTO paymentDTO) { - - String serviceUrl = "http://localhost:8003/payment-service"; - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - - HttpEntity request = new HttpEntity<>(paymentDTO, headers); - - PaymentResponse paymentResponse = restTemplate.postForObject(serviceUrl + "/pay/" + orderNumber, request, PaymentResponse.class); - - return paymentResponse; - - } -} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java deleted file mode 100644 index 4a155d4571..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentResponse.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.paymentservice; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class PaymentResponse{ - - private String paymentId; - private String paymentMethod; - private String customerFullName; - private Double amount; - private String currency; - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml deleted file mode 100644 index eb429553dd..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/pom.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - 4.0.0 - - - com.baeldung.paymentservice - payment-service - 1.0-SNAPSHOT - - com.baeldung.paymentservice - payment-server - payment-server - - - com.baeldung.paymentservice - payment-client - 1.0-SNAPSHOT - compile - - - diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java deleted file mode 100644 index e4f0a3a68a..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/CardValidator.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.paymentservice; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class CardValidator { - - public static boolean validate(String cardNumber){ - - boolean isValid = false; - - String regex = "^(?:(?4[0-9]{12}(?:[0-9]{3})?)|" + - "(?5[1-5][0-9]{14})|" + - "(?6(?:011|5[0-9]{2})[0-9]{12})|" + - "(?3[47][0-9]{13})|" + - "(?3(?:0[0-5]|[68][0-9])?[0-9]{11})|" + - "(?(?:2131|1800|35[0-9]{3})[0-9]{11}))$"; - - - Pattern pattern = Pattern.compile(regex); - cardNumber = cardNumber.replaceAll("-", ""); - Matcher matcher = pattern.matcher(cardNumber); - - if(matcher.matches()){ - - isValid = true; - } - - return isValid; - } -} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java deleted file mode 100644 index 9789195c98..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/Payment.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.paymentservice; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Payment { - - private String paymentId; - private String paymentMethod; - private String customerFullName; - private double amount; - private String currency; - -} - diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java deleted file mode 100644 index 0e9336dcfe..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.paymentservice; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * - * Spring Boot application starter class - */ -@SpringBootApplication -public class PaymentApplication { - public static void main(String[] args) { - SpringApplication.run(PaymentApplication.class, args); - } -} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java deleted file mode 100644 index f44e342cd7..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/java/com/baeldung/paymentservice/PaymentService.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.paymentservice; - -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import javax.smartcardio.CardException; -import java.util.UUID; - - -@RestController -public class PaymentService { - - - @PostMapping("/pay/{orderNum}") - public PaymentResponse createPayment(@PathVariable String orderNum, @RequestBody PaymentDTO paymentDTO) { - - Payment payment = new Payment(); - payment.setPaymentId(UUID.randomUUID().toString().replace("-", "")); - String firstName = paymentDTO.getFirstName(); - String lastName = paymentDTO.getLastName(); - payment.setCustomerFullName(firstName + " " + lastName); - String cardNumber = paymentDTO.getCardNumber(); - - if(CardValidator.validate(cardNumber)){ - payment.setPaymentMethod("CREDITCARD"); - } else try { - throw new CardException("Card with number:"+ cardNumber + " is invalid"); - } catch (CardException e) { - e.printStackTrace(); - } - payment.setAmount(paymentDTO.getAmount()); - payment.setCurrency(paymentDTO.getCurrency()); - - return new PaymentResponse(payment.getPaymentId(), payment.getPaymentMethod(), payment.getCustomerFullName(), payment.getAmount(), payment.getCurrency()); - - } -} diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties deleted file mode 100644 index 8f3550946e..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-server/src/main/resources/application.properties +++ /dev/null @@ -1,3 +0,0 @@ -#Spring Boot server configuration -server.servlet.context-path=/payment-service -server.port=8003 diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/pom.xml b/spring-boot-modules/spring-boot-microservices/payment-service/pom.xml deleted file mode 100644 index 474ab6fe93..0000000000 --- a/spring-boot-modules/spring-boot-microservices/payment-service/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - CustomerOrderApp - com.baeldung - 1.0-SNAPSHOT - - 4.0.0 - - com.baeldung.paymentservice - payment-service - pom - - payment-client - payment-server - - - - 1.8 - 2.6 - 1.8 - 1.8 - UTF-8 - com.baeldung.paymentservice.PaymentApplication - - - - - - org.springframework.boot - spring-boot-dependencies - 2.3.0.RELEASE - pom - import - - - - - - - - org.springframework.boot - spring-boot-starter-web - - - - commons-lang - commons-lang - ${commons-lang.version} - - - - org.springframework.boot - spring-boot-starter-json - - - - org.springframework.boot - spring-boot-test - test - - - - org.springframework.boot - spring-boot-test-autoconfigure - test - - - junit - junit - test - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - ${paymentservice.mainclass} - - - - - repackage - - - exe - - - - start-application - - com.baeldung.paymentservice.PaymentApplication - ../payment-server/target/classes - - - start - - - - - - - - diff --git a/spring-boot-modules/spring-boot-microservices/pom.xml b/spring-boot-modules/spring-boot-microservices/pom.xml index 1cdd7595d4..774a1080ec 100644 --- a/spring-boot-modules/spring-boot-microservices/pom.xml +++ b/spring-boot-modules/spring-boot-microservices/pom.xml @@ -24,7 +24,7 @@ customer-service order-service - payment-service + shared-dto diff --git a/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection b/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection index aa9960aead..6f7fd9d35a 100644 --- a/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection +++ b/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection @@ -52,36 +52,8 @@ } }, "response": [] - }, - { - "name": "Send Order for payment", - "request": { - "method": "POST", - "header": [], - "body": { - "mode": "raw", - "raw": "{\n\t\n\"firstName\":\"John\",\n\"lastName\":\"Smith\",\n\"cardNumber\":\"4260-6720-3283-7081\",\n\"amount\":150.0,\n\"currency\":\"USD\"\n\t\n\t\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "localhost:8002/order-service/pay/A152", - "host": [ - "localhost" - ], - "port": "8002", - "path": [ - "order-service", - "pay", - "A152" - ] - } - }, - "response": [] } + ], "protocolProfileBehavior": {} } \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml b/spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml new file mode 100644 index 0000000000..d61a5bb34b --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml @@ -0,0 +1,53 @@ + + + + + CustomerOrderApp + com.baeldung + 1.0-SNAPSHOT + + 4.0.0 + + com.baeldung + shared-dto + + shared-dto + + + + UTF-8 + 1.8 + 1.8 + 0.0.2 + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + + + + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + false + + + compile + + files + + + + + + + + diff --git a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java b/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java similarity index 76% rename from spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java rename to spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java index cd81b78366..549a0dbaf0 100644 --- a/spring-boot-modules/spring-boot-microservices/payment-service/payment-client/src/main/java/com.baeldung.paymentservice/PaymentDTO.java +++ b/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java @@ -7,11 +7,11 @@ import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor -public class PaymentDTO { +public class CustomerDTO { private String firstName; private String lastName; + private String homeAddress; private String cardNumber; - private double amount; - private String currency; + } diff --git a/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java b/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java new file mode 100644 index 0000000000..c31c9f6bec --- /dev/null +++ b/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.orderservice.client; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderDTO { + + private int customerId; + private String itemId; + +} From 28af7f1e3de6500eeecc29ed40348bf0e72347bd Mon Sep 17 00:00:00 2001 From: Sasa M Date: Tue, 9 Jun 2020 13:06:34 +0200 Subject: [PATCH 03/44] Delete old project files in spring-boot-modules --- .../spring-boot-microservices/README.md | 11 -- .../customer-service/.gitignore | 41 ------ .../customer-service/pom.xml | 85 ------------ .../baeldung/customerservice/Customer.java | 14 -- .../customerservice/CustomerApplication.java | 25 ---- .../customerservice/CustomerService.java | 56 -------- .../src/main/resources/application.properties | 4 - .../customerservice/CustomerServiceTest.java | 33 ----- .../src/test/resources/application.properties | 2 - .../order-service/.gitignore | 41 ------ .../order-service/order-client/pom.xml | 17 --- .../orderservice/client/OrderClient.java | 6 - .../orderservice/client/OrderClientImpl.java | 35 ----- .../orderservice/client/OrderDTO.java | 16 --- .../orderservice/client/OrderResponse.java | 15 -- .../src/main/resources/application.properties | 1 - .../order-service/order-server/pom.xml | 29 ---- .../java/com/baeldung/orderservice/Order.java | 18 --- .../orderservice/OrderApplication.java | 24 ---- .../baeldung/orderservice/OrderService.java | 57 -------- .../src/main/resources/application.properties | 4 - .../orderservice/OrderServiceTest.java | 35 ----- .../order-service/pom.xml | 128 ------------------ .../spring-boot-microservices/pom.xml | 46 ------- .../postman/customer-order.postman_collection | 59 -------- .../shared-dto/pom.xml | 53 -------- .../main/java/com/baeldung/CustomerDTO.java | 17 --- .../src/main/java/com/baeldung/OrderDTO.java | 16 --- .../java/com/baeldung/CustomerOrderApp.java | 23 ---- 29 files changed, 911 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-microservices/README.md delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/.gitignore delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java delete mode 100644 spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/.gitignore delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java delete mode 100644 spring-boot-modules/spring-boot-microservices/order-service/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection delete mode 100644 spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml delete mode 100644 spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java delete mode 100644 spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java delete mode 100644 spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java diff --git a/spring-boot-modules/spring-boot-microservices/README.md b/spring-boot-modules/spring-boot-microservices/README.md deleted file mode 100644 index a85d52b2bc..0000000000 --- a/spring-boot-modules/spring-boot-microservices/README.md +++ /dev/null @@ -1,11 +0,0 @@ ---------------------------------- CustomerOrderApp installation steps---------------------------------- - -1. Clone or download sample project from GitHub repo: https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-microservices -2. Unzip project folder to local disk for example to: C:/baeldung-tutorials/spring-boot-microservices/customer-order-app -3. Run `mvn clean install -DskipTests=true` -4. Navigate to order-service/order-server module folder and type `mvn spring-boot:run` -5. Open another CMD PROMPT window. - Navigate to customer-service module folder and type `mvn spring-boot:run` - -6. Launch the Postman application from your machine and import the collection located in the _postman_ folder in project root -7. Verify successful request from the POSTMAN to http://localhost:8001/customer-service/order diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/.gitignore b/spring-boot-modules/spring-boot-microservices/customer-service/.gitignore deleted file mode 100644 index 0e9415ada6..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -#https://github.com/spring-projects/spring-boot/blob/master/.gitignore - -*# -*.iml -*.ipr -*.iws -*.jar -*.sw? -*~ -.#* -.*.md.html -.DS_Store -.classpath -.factorypath -.gradle -.idea -.metadata -.project -.recommenders -.settings -.springBeans -/build -/code -MANIFEST.MF -_site/ -activemq-data -bin -build -build.log -dependency-reduced-pom.xml -dump.rdb -interpolated*.xml -lib/ -manifest.yml -overridedb.* -target -transaction-logs -.flattened-pom.xml -secrets.yml -.gradletasknamecache -.sts4-cache diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/pom.xml b/spring-boot-modules/spring-boot-microservices/customer-service/pom.xml deleted file mode 100644 index a02ce2e1d8..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - CustomerOrderApp - com.baeldung - 1.0-SNAPSHOT - - 4.0.0 - - com.baeldung.customerservice - customer-service - jar - - - 1.8 - 1.8 - 1.8 - UTF-8 - - - - - - org.springframework.boot - spring-boot-dependencies - 2.3.0.RELEASE - pom - import - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-json - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-configuration-processor - - - junit - junit - test - - - com.baeldung.orderservice - order-client - 1.0-SNAPSHOT - compile - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - repackage - - - exec - - - - - - - - diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java deleted file mode 100644 index 7d10510cbc..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/Customer.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.customerservice; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class Customer { - - private int id; - private String firstName; - private String lastName; - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java deleted file mode 100644 index 489129a3d2..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.customerservice; - -import com.baeldung.orderservice.client.OrderClient; -import com.baeldung.orderservice.client.OrderClientImpl; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; - -/** - * Spring Boot application starter class - */ -@SpringBootApplication -public class CustomerApplication { - public static void main(String[] args) { - SpringApplication.run(CustomerApplication.class, args); - } - - @Bean - public OrderClient getOrderClient() { - - return new OrderClientImpl(new RestTemplateBuilder()); - } - -} diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java deleted file mode 100644 index ab8872de1c..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.customerservice; - -import com.baeldung.orderservice.client.OrderClient; -import com.baeldung.orderservice.client.OrderDTO; -import com.baeldung.orderservice.client.OrderResponse; -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.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -@RestController -public class CustomerService { - - @Autowired - private OrderClient orderClient; - - private List customers = Arrays.asList( - - new Customer(1, "John", "Smith"), - new Customer(2, "Deny", "Dominic")); - - - @GetMapping - public List getAllCustomers() { - return customers; - } - - @GetMapping("/{id}") - public Customer getCustomerById(@PathVariable int id) { - return customers.stream() - .filter(customer -> customer.getId() == id) - .findFirst() - .orElseThrow(IllegalArgumentException::new); - } - - - @PostMapping(value = "/order") - public String sendOrder(@RequestBody Map body) { - - OrderDTO dto = new OrderDTO(); - dto.setCustomerId((Integer) body.get("customerId")); - dto.setItemId((String) body.get("itemId")); - - OrderResponse response = orderClient.order(dto); - - return response.getStatus(); - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties deleted file mode 100644 index d439ae9b76..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Spring Boot server configuration -server.servlet.context-path=/customer-service -server.port=8001 - diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java b/spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java deleted file mode 100644 index 1c44146811..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.customerservice; - -import com.baeldung.orderservice.client.OrderClient; -import com.baeldung.orderservice.client.OrderDTO; -import com.baeldung.orderservice.client.OrderResponse; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = CustomerApplication.class) -public class CustomerServiceTest { - - @Autowired - private OrderClient orderClient; - - @Test - public void testAddOrderSuccess(){ - - - OrderDTO dto = new OrderDTO(2,"A152"); - - OrderResponse response = orderClient.order(dto); - - Assert.assertNotNull("Order Id not generated", response.getOrderId()); - Assert.assertEquals("A152", response.getProductId()); - Assert.assertEquals("CREATED", response.getStatus()); - } - -} diff --git a/spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties b/spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties deleted file mode 100644 index 1d50559005..0000000000 --- a/spring-boot-modules/spring-boot-microservices/customer-service/src/test/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -local.server.port=8001 -server.servlet.context-path=/customer-service \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/order-service/.gitignore b/spring-boot-modules/spring-boot-microservices/order-service/.gitignore deleted file mode 100644 index 0e9415ada6..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/.gitignore +++ /dev/null @@ -1,41 +0,0 @@ -#https://github.com/spring-projects/spring-boot/blob/master/.gitignore - -*# -*.iml -*.ipr -*.iws -*.jar -*.sw? -*~ -.#* -.*.md.html -.DS_Store -.classpath -.factorypath -.gradle -.idea -.metadata -.project -.recommenders -.settings -.springBeans -/build -/code -MANIFEST.MF -_site/ -activemq-data -bin -build -build.log -dependency-reduced-pom.xml -dump.rdb -interpolated*.xml -lib/ -manifest.yml -overridedb.* -target -transaction-logs -.flattened-pom.xml -secrets.yml -.gradletasknamecache -.sts4-cache diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml deleted file mode 100644 index 22176bb85e..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-client/pom.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - 4.0.0 - - - com.baeldung.orderservice - order-service - 1.0-SNAPSHOT - - order-client - com.baeldung.orderservice - order-client - Order service client module - http://projects.spring.io/spring-boot/ - - diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java deleted file mode 100644 index 2dd6b13248..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.orderservice.client; - -public interface OrderClient { - - OrderResponse order(OrderDTO orderDTO); -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java deleted file mode 100644 index 70ec77fab6..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.orderservice.client; - -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; - - -@Component -public class OrderClientImpl implements OrderClient { - - private RestTemplate restTemplate; - - public OrderClientImpl(RestTemplateBuilder builder) { - - this.restTemplate = builder.build(); - } - - @Override - public OrderResponse order(OrderDTO orderDTO) { - - String serviceUrl = "http://localhost:8002/order-service"; - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - - HttpEntity request = new HttpEntity<>(orderDTO, headers); - - OrderResponse orderResponse = restTemplate.postForObject(serviceUrl + "/create", request, OrderResponse.class); - - return orderResponse; - - } -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java deleted file mode 100644 index c31c9f6bec..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.orderservice.client; - - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OrderDTO { - - private int customerId; - private String itemId; - -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java deleted file mode 100644 index e8d2059cbb..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.orderservice.client; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OrderResponse { - - private int orderId; - private String productId; - private String status; -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties deleted file mode 100644 index 53e503689f..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-client/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -server.port=8002 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml deleted file mode 100644 index 722bfa5aac..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - order-service - com.baeldung.orderservice - 1.0-SNAPSHOT - - 4.0.0 - - com.baeldung.orderservice - order-server - - - com.baeldung.orderservice - order-client - 1.0-SNAPSHOT - compile - - - com.baeldung.paymentservice - payment-client - 1.0-SNAPSHOT - compile - - - - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java deleted file mode 100644 index 719305064f..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.orderservice; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class Order { - - private Integer id; - private Integer customerId; - private String itemId; - private String date; - -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java deleted file mode 100644 index 2d09479a57..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.orderservice; - -import com.baeldung.paymentservice.PaymentClient; -import com.baeldung.paymentservice.PaymentClientImpl; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; - -/** - * Spring Boot application starter class - */ -@SpringBootApplication -public class OrderApplication { - public static void main(String[] args) { - SpringApplication.run(OrderApplication.class, args); - } - - @Bean - public PaymentClient getPaymentClient() { - - return new PaymentClientImpl(new RestTemplateBuilder()); - } -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java deleted file mode 100644 index 09d72e63f4..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.orderservice; - -import com.baeldung.orderservice.client.OrderDTO; -import com.baeldung.orderservice.client.OrderResponse; -import com.baeldung.paymentservice.PaymentClient; -import com.baeldung.paymentservice.PaymentDTO; -import com.baeldung.paymentservice.PaymentResponse; -import org.apache.commons.lang.time.DateFormatUtils; -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.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - - -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.stream.Collectors; - -@RestController -public class OrderService { - - - private List orders = Arrays.asList( - - new Order(1, 1, "A101", "2020/02/14"), - new Order(2, 1, "A101", "2020/02/14"), - new Order(3, 2, "A150", "2020/02/17")); - - @GetMapping - public List getAllOrders() { - return orders; - } - - @GetMapping("/{id}") - public List getOrdersByCustomer(@PathVariable int id) { - return orders.stream() - .filter(order -> order.getCustomerId() == id).collect(Collectors.toList()); - } - - @PostMapping("/create") - public OrderResponse createOrder(@RequestBody OrderDTO request) { - - int lastIndex = orders.size(); - Order order = new Order(); - order.setId(lastIndex + 1); - order.setCustomerId(request.getCustomerId()); - order.setItemId(request.getItemId()); - String date = DateFormatUtils.format(new Date(), "yyyy/MM/dd"); - order.setDate(date); - - return new OrderResponse(order.getId(), order.getItemId(), "CREATED"); - } - -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties deleted file mode 100644 index f4fe5e7079..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -#Spring Boot server configuration -server.servlet.context-path=/order-service -server.port=8002 - diff --git a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java b/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java deleted file mode 100644 index 2630f908be..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/order-server/src/test/java/com/baeldung/orderservice/OrderServiceTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.orderservice; - -import com.baeldung.paymentservice.PaymentClient; -import com.baeldung.paymentservice.PaymentDTO; -import com.baeldung.paymentservice.PaymentResponse; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = OrderApplication.class) -public class OrderServiceTest { - - @Autowired - private PaymentClient paymentClient; - - - @Test - public void testSendPaySuccess(){ - - - PaymentDTO dto = new PaymentDTO("Sasa","Milenkovic","4260-6720-3283-7081",150.0,"USD"); - - PaymentResponse response = paymentClient.pay("A152", dto); - - Assert.assertNotNull("Payment Id not generated", response.getPaymentId()); - Assert.assertEquals("CREDITCARD", response.getPaymentMethod()); - Assert.assertEquals("Sasa Milenkovic", response.getCustomerFullName()); - Assert.assertEquals(new Double(150.0), response.getAmount()); - Assert.assertEquals("USD", response.getCurrency()); - } -} diff --git a/spring-boot-modules/spring-boot-microservices/order-service/pom.xml b/spring-boot-modules/spring-boot-microservices/order-service/pom.xml deleted file mode 100644 index fcdfdac595..0000000000 --- a/spring-boot-modules/spring-boot-microservices/order-service/pom.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - CustomerOrderApp - com.baeldung - 1.0-SNAPSHOT - - 4.0.0 - - com.baeldung.orderservice - order-service - pom - - order-client - order-server - - - - 1.8 - 2.6 - 0.0.2 - 1.8 - 1.8 - UTF-8 - com.baeldung.orderservice.OrderApplication - - - - - - org.springframework.boot - spring-boot-dependencies - 2.3.0.RELEASE - pom - import - - - - - - - org.springframework.boot - spring-boot-starter-web - - - commons-lang - commons-lang - ${commons-lang.version} - - - org.qunix - structure-maven-plugin - ${structure-maven.version} - - - org.springframework.boot - spring-boot-starter-json - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-configuration-processor - - - org.springframework.boot - spring-boot-test-autoconfigure - test - - - junit - junit - test - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - ${orderservice.mainclass} - - - - - repackage - - - exe - - - - start-application - - com.baeldung.orderservice.OrderApplication - ../order-server/target/classes - - - start - - - - - - org.qunix - structure-maven-plugin - ${structure-maven.version} - false - - - compile - - modules - - - - - - - - diff --git a/spring-boot-modules/spring-boot-microservices/pom.xml b/spring-boot-modules/spring-boot-microservices/pom.xml deleted file mode 100644 index 774a1080ec..0000000000 --- a/spring-boot-modules/spring-boot-microservices/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - 4.0.0 - com.baeldung - CustomerOrderApp - pom - 1.0-SNAPSHOT - CustomerOrderApp - http://maven.apache.org - - - org.springframework.boot - spring-boot-starter-parent - 2.3.0.RELEASE - - - - - UTF-8 - 1.8 - 1.8 - - - - customer-service - order-service - shared-dto - - - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-autoconfigure - - - diff --git a/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection b/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection deleted file mode 100644 index 6f7fd9d35a..0000000000 --- a/spring-boot-modules/spring-boot-microservices/postman/customer-order.postman_collection +++ /dev/null @@ -1,59 +0,0 @@ -{ - "info": { - "_postman_id": "92594398-49cc-4a7c-b44f-1037307afbd3", - "name": "postman-requests", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" - }, - "item": [ - { - "name": "Crete new Customer order", - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "multipart/form-data", - "type": "text", - "disabled": true - }, - { - "key": "Accept-Charset", - "value": "utf-8", - "type": "text", - "disabled": true - }, - { - "key": "boundary", - "value": "nAp4nMEt-BuGuuLlq-6fnASQErGjSamaG", - "type": "text", - "disabled": true - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"customerId\":2,\n \"itemId\":\"A152\"\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "http://localhost:8001/customer-service/order", - "protocol": "http", - "host": [ - "localhost" - ], - "port": "8001", - "path": [ - "customer-service", - "order" - ] - } - }, - "response": [] - } - - ], - "protocolProfileBehavior": {} -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml b/spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml deleted file mode 100644 index d61a5bb34b..0000000000 --- a/spring-boot-modules/spring-boot-microservices/shared-dto/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - CustomerOrderApp - com.baeldung - 1.0-SNAPSHOT - - 4.0.0 - - com.baeldung - shared-dto - - shared-dto - - - - UTF-8 - 1.8 - 1.8 - 0.0.2 - - - - - org.qunix - structure-maven-plugin - ${structure-maven.version} - - - - - - - - org.qunix - structure-maven-plugin - ${structure-maven.version} - false - - - compile - - files - - - - - - - - diff --git a/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java b/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java deleted file mode 100644 index 549a0dbaf0..0000000000 --- a/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/CustomerDTO.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.paymentservice; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class CustomerDTO { - - private String firstName; - private String lastName; - private String homeAddress; - private String cardNumber; - -} diff --git a/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java b/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java deleted file mode 100644 index c31c9f6bec..0000000000 --- a/spring-boot-modules/spring-boot-microservices/shared-dto/src/main/java/com/baeldung/OrderDTO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.orderservice.client; - - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class OrderDTO { - - private int customerId; - private String itemId; - -} diff --git a/spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java b/spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java deleted file mode 100644 index 15455ca16c..0000000000 --- a/spring-boot-modules/spring-boot-microservices/src/main/java/com/baeldung/CustomerOrderApp.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - -/** - * Customer Order Spring Boot Main Application - * - * */ - -@SpringBootApplication -@ComponentScan(basePackages = "com.baeldung.*") -public class CustomerOrderApp -{ - - public static void main( String[] args ) - { - - SpringApplication.run(CustomerOrderApp.class,args); - - } -} From c2a7a971a5aa5cd7a0de5e991156946439a3fe80 Mon Sep 17 00:00:00 2001 From: Sasa M Date: Tue, 9 Jun 2020 13:10:48 +0200 Subject: [PATCH 04/44] Add modified project modules in spring cloud module --- .../customer-service/pom.xml | 88 +++++++++++++ .../baeldung/customerservice/Customer.java | 14 ++ .../customerservice/CustomerApplication.java | 25 ++++ .../customerservice/CustomerService.java | 56 ++++++++ .../src/main/resources/application.properties | 4 + .../CustomerServiceUnitTest.java | 33 +++++ .../src/test/resources/application.properties | 2 + .../order-service/order-client/pom.xml | 16 +++ .../orderservice/client/OrderClient.java | 6 + .../orderservice/client/OrderClientImpl.java | 35 +++++ .../orderservice/client/OrderDTO.java | 16 +++ .../orderservice/client/OrderResponse.java | 15 +++ .../src/main/resources/application.properties | 1 + .../order-service/order-server/pom.xml | 23 ++++ .../java/com/baeldung/orderservice/Order.java | 18 +++ .../orderservice/OrderApplication.java | 17 +++ .../baeldung/orderservice/OrderService.java | 54 ++++++++ .../src/main/resources/application.properties | 4 + .../order-service/pom.xml | 122 ++++++++++++++++++ spring-cloud/spring-cloud-bootstrap/pom.xml | 3 + .../spring-cloud-bootstrap/shared-dto/pom.xml | 59 +++++++++ .../java/com/baeldung/shared/CustomerDTO.java | 17 +++ .../java/com/baeldung/shared/OrderDTO.java | 16 +++ 23 files changed, 644 insertions(+) create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java create mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties create mode 100644 spring-cloud/spring-cloud-bootstrap/order-service/pom.xml create mode 100644 spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml create mode 100644 spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java create mode 100644 spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml new file mode 100644 index 0000000000..0fcc3b4fdf --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml @@ -0,0 +1,88 @@ + + + + 4.0.0 + com.baeldung.customerservice + customer-service + customer-service + jar + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 + + + + 1.8 + 1.8 + 1.8 + UTF-8 + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-configuration-processor + + + junit + junit + test + + + org.projectlombok + lombok + true + + + com.baeldung.orderservice + order-client + 1.0-SNAPSHOT + compile + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + exec + + + + + + + + diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java new file mode 100644 index 0000000000..7d10510cbc --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/Customer.java @@ -0,0 +1,14 @@ +package com.baeldung.customerservice; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Customer { + + private int id; + private String firstName; + private String lastName; + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java new file mode 100644 index 0000000000..489129a3d2 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderClientImpl; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; + +/** + * Spring Boot application starter class + */ +@SpringBootApplication +public class CustomerApplication { + public static void main(String[] args) { + SpringApplication.run(CustomerApplication.class, args); + } + + @Bean + public OrderClient getOrderClient() { + + return new OrderClientImpl(new RestTemplateBuilder()); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java new file mode 100644 index 0000000000..ab8872de1c --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/java/com/baeldung/customerservice/CustomerService.java @@ -0,0 +1,56 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +@RestController +public class CustomerService { + + @Autowired + private OrderClient orderClient; + + private List customers = Arrays.asList( + + new Customer(1, "John", "Smith"), + new Customer(2, "Deny", "Dominic")); + + + @GetMapping + public List getAllCustomers() { + return customers; + } + + @GetMapping("/{id}") + public Customer getCustomerById(@PathVariable int id) { + return customers.stream() + .filter(customer -> customer.getId() == id) + .findFirst() + .orElseThrow(IllegalArgumentException::new); + } + + + @PostMapping(value = "/order") + public String sendOrder(@RequestBody Map body) { + + OrderDTO dto = new OrderDTO(); + dto.setCustomerId((Integer) body.get("customerId")); + dto.setItemId((String) body.get("itemId")); + + OrderResponse response = orderClient.order(dto); + + return response.getStatus(); + } + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties new file mode 100644 index 0000000000..d439ae9b76 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#Spring Boot server configuration +server.servlet.context-path=/customer-service +server.port=8001 + diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java new file mode 100644 index 0000000000..6a8527c86e --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.customerservice; + +import com.baeldung.orderservice.client.OrderClient; +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = CustomerApplication.class) +public class CustomerServiceUnitTest { + + @Autowired + private OrderClient orderClient; + + @Test + public void testAddOrderSuccess(){ + + + OrderDTO dto = new OrderDTO(2,"A152"); + + OrderResponse response = orderClient.order(dto); + + Assert.assertNotNull("Order Id not generated", response.getOrderId()); + Assert.assertEquals("A152", response.getProductId()); + Assert.assertEquals("CREATED", response.getStatus()); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties new file mode 100644 index 0000000000..1d50559005 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/resources/application.properties @@ -0,0 +1,2 @@ +local.server.port=8001 +server.servlet.context-path=/customer-service \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml new file mode 100644 index 0000000000..23d197dda8 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + com.baeldung.orderservice + order-service + 1.0-SNAPSHOT + + order-client + com.baeldung.orderservice + order-client + Order service client module + http://projects.spring.io/spring-boot/ + + diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java new file mode 100644 index 0000000000..2dd6b13248 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClient.java @@ -0,0 +1,6 @@ +package com.baeldung.orderservice.client; + +public interface OrderClient { + + OrderResponse order(OrderDTO orderDTO); +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java new file mode 100644 index 0000000000..70ec77fab6 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderClientImpl.java @@ -0,0 +1,35 @@ +package com.baeldung.orderservice.client; + +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + + +@Component +public class OrderClientImpl implements OrderClient { + + private RestTemplate restTemplate; + + public OrderClientImpl(RestTemplateBuilder builder) { + + this.restTemplate = builder.build(); + } + + @Override + public OrderResponse order(OrderDTO orderDTO) { + + String serviceUrl = "http://localhost:8002/order-service"; + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity request = new HttpEntity<>(orderDTO, headers); + + OrderResponse orderResponse = restTemplate.postForObject(serviceUrl + "/create", request, OrderResponse.class); + + return orderResponse; + + } +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java new file mode 100644 index 0000000000..c31c9f6bec --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.orderservice.client; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderDTO { + + private int customerId; + private String itemId; + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java new file mode 100644 index 0000000000..e8d2059cbb --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/java/com/baeldung/orderservice/client/OrderResponse.java @@ -0,0 +1,15 @@ +package com.baeldung.orderservice.client; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderResponse { + + private int orderId; + private String productId; + private String status; +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties new file mode 100644 index 0000000000..53e503689f --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=8002 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml new file mode 100644 index 0000000000..c2ce7a7bf3 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml @@ -0,0 +1,23 @@ + + + + order-service + com.baeldung.orderservice + 1.0-SNAPSHOT + + 4.0.0 + + com.baeldung.orderservice + order-server + + + com.baeldung.orderservice + order-client + 1.0-SNAPSHOT + compile + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java new file mode 100644 index 0000000000..719305064f --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/Order.java @@ -0,0 +1,18 @@ +package com.baeldung.orderservice; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Order { + + private Integer id; + private Integer customerId; + private String itemId; + private String date; + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java new file mode 100644 index 0000000000..eb89959ee0 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.orderservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; + +/** + * Spring Boot application starter class + */ +@SpringBootApplication +public class OrderApplication { + public static void main(String[] args) { + SpringApplication.run(OrderApplication.class, args); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java new file mode 100644 index 0000000000..a43bbcec65 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/java/com/baeldung/orderservice/OrderService.java @@ -0,0 +1,54 @@ +package com.baeldung.orderservice; + +import com.baeldung.orderservice.client.OrderDTO; +import com.baeldung.orderservice.client.OrderResponse; +import org.apache.commons.lang.time.DateFormatUtils; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@RestController +public class OrderService { + + + private List orders = Arrays.asList( + + new Order(1, 1, "A101", "2020/02/14"), + new Order(2, 1, "A101", "2020/02/14"), + new Order(3, 2, "A150", "2020/02/17")); + + @GetMapping + public List getAllOrders() { + return orders; + } + + @GetMapping("/{id}") + public List getOrdersByCustomer(@PathVariable int id) { + return orders.stream() + .filter(order -> order.getCustomerId() == id).collect(Collectors.toList()); + } + + @PostMapping("/create") + public OrderResponse createOrder(@RequestBody OrderDTO request) { + + int lastIndex = orders.size(); + Order order = new Order(); + order.setId(lastIndex + 1); + order.setCustomerId(request.getCustomerId()); + order.setItemId(request.getItemId()); + String date = DateFormatUtils.format(new Date(), "yyyy/MM/dd"); + order.setDate(date); + + return new OrderResponse(order.getId(), order.getItemId(), "CREATED"); + } + +} diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties new file mode 100644 index 0000000000..f4fe5e7079 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/src/main/resources/application.properties @@ -0,0 +1,4 @@ +#Spring Boot server configuration +server.servlet.context-path=/order-service +server.port=8002 + diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml new file mode 100644 index 0000000000..600efe2c0a --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml @@ -0,0 +1,122 @@ + + + + 4.0.0 + com.baeldung.orderservice + order-service + order-service + pom + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 + + + + order-client + order-server + + + + 1.8 + 2.6 + 0.0.2 + 1.8 + 1.8 + UTF-8 + com.baeldung.orderservice.OrderApplication + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + commons-lang + commons-lang + ${commons-lang.version} + + + org.projectlombok + lombok + true + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-configuration-processor + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${orderservice.mainclass} + + + + + repackage + + + exec + + + + start-application + + com.baeldung.orderservice.OrderApplication + ../order-server/target/classes + + + start + + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + false + + + compile + + modules + + + + + + + + diff --git a/spring-cloud/spring-cloud-bootstrap/pom.xml b/spring-cloud/spring-cloud-bootstrap/pom.xml index 2447b90538..ed9b148564 100644 --- a/spring-cloud/spring-cloud-bootstrap/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/pom.xml @@ -20,6 +20,9 @@ svc-book svc-rating zipkin + customer-service + order-service + shared-dto \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml b/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml new file mode 100644 index 0000000000..b7a7226196 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml @@ -0,0 +1,59 @@ + + + + + 4.0.0 + com.baeldung + shared-dto + shared-dto + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../../parent-boot-2 + + + + + UTF-8 + 1.8 + 1.8 + 0.0.2 + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + + + org.projectlombok + lombok + true + + + + + + + + org.qunix + structure-maven-plugin + ${structure-maven.version} + false + + + compile + + files + + + + + + + + diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java new file mode 100644 index 0000000000..40cc15c600 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java @@ -0,0 +1,17 @@ +package com.baeldung.shared; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CustomerDTO { + + private String firstName; + private String lastName; + private String homeAddress; + private String cardNumber; + +} diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java new file mode 100644 index 0000000000..0640b84291 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/OrderDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.shared; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class OrderDTO { + + private int customerId; + private String itemId; + +} From 6b5bc4e3242f175d39a9a2de23eced0b3a6b3d94 Mon Sep 17 00:00:00 2001 From: Sasa M Date: Tue, 9 Jun 2020 18:22:01 +0200 Subject: [PATCH 05/44] Unit test deleted in customer-service module --- .../CustomerServiceUnitTest.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java b/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java deleted file mode 100644 index 6a8527c86e..0000000000 --- a/spring-cloud/spring-cloud-bootstrap/customer-service/src/test/java/com/baeldung/customerservice/CustomerServiceUnitTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.customerservice; - -import com.baeldung.orderservice.client.OrderClient; -import com.baeldung.orderservice.client.OrderDTO; -import com.baeldung.orderservice.client.OrderResponse; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = CustomerApplication.class) -public class CustomerServiceUnitTest { - - @Autowired - private OrderClient orderClient; - - @Test - public void testAddOrderSuccess(){ - - - OrderDTO dto = new OrderDTO(2,"A152"); - - OrderResponse response = orderClient.order(dto); - - Assert.assertNotNull("Order Id not generated", response.getOrderId()); - Assert.assertEquals("A152", response.getProductId()); - Assert.assertEquals("CREATED", response.getStatus()); - } - -} From 934b3ecec5b716771b8f58650ca3ec6885b1ec1e Mon Sep 17 00:00:00 2001 From: Sasa M Date: Tue, 9 Jun 2020 19:06:42 +0200 Subject: [PATCH 06/44] Setting correct pom version in the modules --- .../customer-service/pom.xml | 8 ++------ .../order-service/order-client/pom.xml | 16 +++++++++------- .../order-service/order-server/pom.xml | 16 ++++++++-------- .../spring-cloud-bootstrap/order-service/pom.xml | 3 ++- .../spring-cloud-bootstrap/shared-dto/pom.xml | 1 + 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml index 0fcc3b4fdf..3e33e27c6c 100644 --- a/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/customer-service/pom.xml @@ -5,6 +5,7 @@ 4.0.0 com.baeldung.customerservice customer-service + 1.0.0-SNAPSHOT customer-service jar @@ -47,11 +48,6 @@ org.springframework.boot spring-boot-configuration-processor - - junit - junit - test - org.projectlombok lombok @@ -60,7 +56,7 @@ com.baeldung.orderservice order-client - 1.0-SNAPSHOT + 1.0.0-SNAPSHOT compile diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml index 23d197dda8..4c8cf742b1 100644 --- a/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-client/pom.xml @@ -1,16 +1,18 @@ - 4.0.0 - - com.baeldung.orderservice - order-service - 1.0-SNAPSHOT - - order-client com.baeldung.orderservice + order-client + 1.0.0-SNAPSHOT order-client Order service client module http://projects.spring.io/spring-boot/ + + com.baeldung.orderservice + order-service + 1.0.0-SNAPSHOT + + diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml index c2ce7a7bf3..d6c521c5df 100644 --- a/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/order-service/order-server/pom.xml @@ -1,21 +1,21 @@ - + 4.0.0 + com.baeldung.orderservice + order-server + 1.0.0-SNAPSHOT order-service com.baeldung.orderservice - 1.0-SNAPSHOT + 1.0.0-SNAPSHOT - 4.0.0 - - com.baeldung.orderservice - order-server com.baeldung.orderservice order-client - 1.0-SNAPSHOT + 1.0.0-SNAPSHOT compile diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml index 600efe2c0a..141931e078 100644 --- a/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml @@ -5,8 +5,9 @@ 4.0.0 com.baeldung.orderservice order-service + 1.0.0-SNAPSHOT order-service - pom + jar com.baeldung diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml b/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml index b7a7226196..59dde717b5 100644 --- a/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/pom.xml @@ -6,6 +6,7 @@ 4.0.0 com.baeldung shared-dto + 1.0.0-SNAPSHOT shared-dto From 9e00e32ad97a508d39a98e32da766cabe195f4f1 Mon Sep 17 00:00:00 2001 From: Sasa M Date: Tue, 9 Jun 2020 19:23:16 +0200 Subject: [PATCH 07/44] Setting correct packaging --- spring-cloud/spring-cloud-bootstrap/order-service/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml index 141931e078..8f3c9ceaff 100644 --- a/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/order-service/pom.xml @@ -7,7 +7,7 @@ order-service 1.0.0-SNAPSHOT order-service - jar + pom com.baeldung From 22b367c0cd9dcae7a7ac2fc2db648544395c7fa8 Mon Sep 17 00:00:00 2001 From: Sasa M Date: Sun, 14 Jun 2020 00:43:19 +0200 Subject: [PATCH 08/44] deliverydto package added to shared-dto module --- .../com/baeldung/deliverydto/CustomerDTO.java | 16 ++++++++++++++++ .../java/com/baeldung/shared/CustomerDTO.java | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java new file mode 100644 index 0000000000..aa6b3ceac8 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/deliverydto/CustomerDTO.java @@ -0,0 +1,16 @@ +package com.baeldung.deliverydto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class CustomerDTO { + private String firstName; + private String lastName; + private String homeAddress; + private String contactNumber; + // constructor, getters, setters +} diff --git a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java index 40cc15c600..905773609d 100644 --- a/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java +++ b/spring-cloud/spring-cloud-bootstrap/shared-dto/src/main/java/com/baeldung/shared/CustomerDTO.java @@ -8,10 +8,8 @@ import lombok.NoArgsConstructor; @NoArgsConstructor @AllArgsConstructor public class CustomerDTO { - private String firstName; private String lastName; - private String homeAddress; private String cardNumber; - + // constructor, getters, setters } From f2957bf7ea227e9521d08e8da3e2f2ed1473cd6e Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Mon, 15 Jun 2020 01:17:30 +0530 Subject: [PATCH 09/44] circular buffer implementation --- .../circularbuffer/CircularBuffer.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java new file mode 100644 index 0000000000..c36831636f --- /dev/null +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -0,0 +1,73 @@ +package com.baeldung.circularbuffer; + +public class CircularBuffer { + + private int capacity, writeIndex, readIndex; + private E[] data; + + @SuppressWarnings("unchecked") + public CircularBuffer(int capacity) { + + this.capacity = capacity; + this.data = (E[]) new Object[capacity]; + + this.readIndex = 0; + this.writeIndex = -1; + } + + public boolean offer(E element) { + + if (!isFull()) { + + writeIndex += 1; + int nextWriteIndex = writeIndex % capacity; + data[nextWriteIndex] = element; + + return true; + } + + return false; + } + + public E poll() { + + if (!isEmpty()) { + + int nextReadIndex = readIndex % capacity; + readIndex += 1; + + return data[nextReadIndex]; + } + + return null; + } + + public E peek() { + + if (!isEmpty()) { + + return data[readIndex % capacity]; + } + + return null; + } + + public int capacity() { + return capacity; + } + + public int size() { + + return (writeIndex - readIndex) + 1; + } + + public boolean isEmpty() { + + return writeIndex < readIndex; + } + + public boolean isFull() { + + return size() >= capacity; + } +} From 5263fbf07003875c2dc8b4e1ac2be2b749136b9b Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Mon, 15 Jun 2020 01:18:22 +0530 Subject: [PATCH 10/44] circular buffer test init --- .../CircularBufferUnitTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java new file mode 100644 index 0000000000..34658b9251 --- /dev/null +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.circularbuffer; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class CircularBufferUnitTest { + + private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; + + @Test + public void givenCircularBuffer_WhenAnElementIsAddedAndRemoved_thenBufferIsEmpty() { + + int capacity = 2; + CircularBuffer buffer = new CircularBuffer<>(capacity); + + assertEquals(capacity, buffer.capacity()); + + buffer.offer("Rectangle"); + + assertEquals(false, buffer.isEmpty()); + assertEquals(1, buffer.size()); + + buffer.poll(); + + assertEquals(true, buffer.isEmpty()); + } + + @Test + public void givenCircularBuffer_WhenElementsAreAddedToCapacity_thenBufferIsFull() { + + int capacity = shapes.length; + CircularBuffer buffer = new CircularBuffer<>(capacity); + + assertEquals(true, buffer.isEmpty()); + + for (String shape : shapes) { + buffer.offer(shape); + } + + assertEquals(true, buffer.isFull()); + } + +} From a4efb737a865c8212ea95940c9fe9aed4719fee9 Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Mon, 15 Jun 2020 18:44:01 +0530 Subject: [PATCH 11/44] write and read sequence volatile --- .../circularbuffer/CircularBuffer.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java index c36831636f..a74b480231 100644 --- a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -1,28 +1,36 @@ package com.baeldung.circularbuffer; public class CircularBuffer { + + private static final int DEFAULT_CAPACITY = 8; - private int capacity, writeIndex, readIndex; - private E[] data; + private final int capacity; + private final E[] data; + private volatile int writeSequence, readSequence; @SuppressWarnings("unchecked") public CircularBuffer(int capacity) { - this.capacity = capacity; + this.capacity = (capacity < 1 ? DEFAULT_CAPACITY : capacity); this.data = (E[]) new Object[capacity]; - this.readIndex = 0; - this.writeIndex = -1; + this.readSequence = 0; + this.writeSequence = -1; } + /** + * Adds a new element to the buffer, if the buffer is not full + * @param element + * @return + */ public boolean offer(E element) { if (!isFull()) { - writeIndex += 1; - int nextWriteIndex = writeIndex % capacity; - data[nextWriteIndex] = element; + int nextWriteSeq = writeSequence + 1; + data[nextWriteSeq % capacity] = element; + writeSequence += 1; return true; } @@ -33,20 +41,9 @@ public class CircularBuffer { if (!isEmpty()) { - int nextReadIndex = readIndex % capacity; - readIndex += 1; - - return data[nextReadIndex]; - } - - return null; - } - - public E peek() { - - if (!isEmpty()) { - - return data[readIndex % capacity]; + E nextValue = data[readSequence % capacity]; + readSequence += 1; + return nextValue; } return null; @@ -58,12 +55,12 @@ public class CircularBuffer { public int size() { - return (writeIndex - readIndex) + 1; + return (writeSequence - readSequence) + 1; } public boolean isEmpty() { - return writeIndex < readIndex; + return writeSequence < readSequence; } public boolean isFull() { From 02e7129ff59c855b835f8eb915563d6b18644cd6 Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Mon, 15 Jun 2020 18:44:24 +0530 Subject: [PATCH 12/44] simple producer consumer test --- .../CircularBufferUnitTest.java | 3 +- .../ProducerConsumerLiveTest.java | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java index 34658b9251..0809444901 100644 --- a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java @@ -2,7 +2,7 @@ package com.baeldung.circularbuffer; import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CircularBufferUnitTest { @@ -40,5 +40,4 @@ public class CircularBufferUnitTest { assertEquals(true, buffer.isFull()); } - } diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java new file mode 100644 index 0000000000..06b1c5e4cf --- /dev/null +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java @@ -0,0 +1,77 @@ +package com.baeldung.circularbuffer; + +import static org.junit.Assert.assertArrayEquals; + +import java.util.concurrent.locks.LockSupport; + +import org.junit.jupiter.api.Test; + +public class ProducerConsumerLiveTest { + + private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; + + @Test + public void givenACircularBuffer_whenInterleavingProducerConsumer_thenElementsMatch() throws InterruptedException { + CircularBuffer buffer = new CircularBuffer(shapes.length); + String[] consumedShapes = new String[shapes.length]; + + Thread producer = new Thread(new Producer(shapes, buffer)); + Thread consumer = new Thread(new Consumer(consumedShapes, buffer)); + + producer.start(); + consumer.start(); + + producer.join(); + consumer.join(); + + assertArrayEquals(shapes, consumedShapes); + } + + static class Producer implements Runnable { + + private String[] producerShapes; + private CircularBuffer buffer; + + public Producer(String[] producerShapes, CircularBuffer buffer) { + this.producerShapes = producerShapes; + this.buffer = buffer; + } + + @Override + public void run() { + + for (int i = 0; i < producerShapes.length;) { + if (buffer.offer(producerShapes[i])) { + System.out.println("Produced: " + producerShapes[i]); + i++; + LockSupport.parkNanos(5); + } + } + } + } + + static class Consumer implements Runnable { + + private CircularBuffer buffer; + private String[] consumedShapes; + + public Consumer(String[] consumedShapes, CircularBuffer buffer) { + this.consumedShapes = consumedShapes; + this.buffer = buffer; + } + + @Override + public void run() { + + for (int i = 0; i < consumedShapes.length;) { + String shape = buffer.poll(); + if (shape != null) { + consumedShapes[i++] = shape; + + LockSupport.parkNanos(5); + System.out.println("Consumed: " + shape); + } + } + } + } +} From 7479e7b5a04b921e6d0fa12d03b6fe1b0561bff7 Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Mon, 15 Jun 2020 19:27:30 +0530 Subject: [PATCH 13/44] unit test for empty and full buffer --- .../circularbuffer/CircularBuffer.java | 7 +----- .../CircularBufferUnitTest.java | 25 ++++++++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java index a74b480231..6f60621bc8 100644 --- a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -1,7 +1,7 @@ package com.baeldung.circularbuffer; public class CircularBuffer { - + private static final int DEFAULT_CAPACITY = 8; private final int capacity; @@ -18,11 +18,6 @@ public class CircularBuffer { this.writeSequence = -1; } - /** - * Adds a new element to the buffer, if the buffer is not full - * @param element - * @return - */ public boolean offer(E element) { if (!isFull()) { diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java index 0809444901..801a46b45c 100644 --- a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java @@ -1,5 +1,8 @@ package com.baeldung.circularbuffer; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; @@ -9,7 +12,7 @@ public class CircularBufferUnitTest { private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; @Test - public void givenCircularBuffer_WhenAnElementIsAddedAndRemoved_thenBufferIsEmpty() { + public void givenCircularBuffer_whenAnElementIsAddedAndRemoved_thenBufferIsEmpty() { int capacity = 2; CircularBuffer buffer = new CircularBuffer<>(capacity); @@ -18,26 +21,36 @@ public class CircularBufferUnitTest { buffer.offer("Rectangle"); - assertEquals(false, buffer.isEmpty()); + assertFalse(buffer.isEmpty()); assertEquals(1, buffer.size()); buffer.poll(); - assertEquals(true, buffer.isEmpty()); + assertTrue(buffer.isEmpty()); } @Test - public void givenCircularBuffer_WhenElementsAreAddedToCapacity_thenBufferIsFull() { + public void givenCircularBuffer_whenFilledToCapacity_thenNoMoreElementsCanBeAdded() { int capacity = shapes.length; CircularBuffer buffer = new CircularBuffer<>(capacity); - assertEquals(true, buffer.isEmpty()); + assertTrue(buffer.isEmpty()); for (String shape : shapes) { buffer.offer(shape); } - assertEquals(true, buffer.isFull()); + assertTrue(buffer.isFull()); + assertFalse(buffer.offer("Octagon")); + } + + @Test + public void givenCircularBuffer_whenBufferIsEmpty_thenReturnsNull() { + + CircularBuffer buffer = new CircularBuffer<>(1); + + assertTrue(buffer.isEmpty()); + assertNull(buffer.poll()); } } From 9ba617bbf61f6f3e4aac5c736ad4b6e6e3ca087d Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Thu, 18 Jun 2020 02:25:41 +0530 Subject: [PATCH 14/44] polishing --- .../circularbuffer/CircularBuffer.java | 16 +++++++++--- .../CircularBufferUnitTest.java | 26 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java index 6f60621bc8..271fc5f376 100644 --- a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -11,7 +11,7 @@ public class CircularBuffer { @SuppressWarnings("unchecked") public CircularBuffer(int capacity) { - this.capacity = (capacity < 1 ? DEFAULT_CAPACITY : capacity); + this.capacity = (capacity < 1) ? DEFAULT_CAPACITY : capacity; this.data = (E[]) new Object[capacity]; this.readSequence = 0; @@ -20,7 +20,7 @@ public class CircularBuffer { public boolean offer(E element) { - if (!isFull()) { + if (isNotFull()) { int nextWriteSeq = writeSequence + 1; data[nextWriteSeq % capacity] = element; @@ -34,7 +34,7 @@ public class CircularBuffer { public E poll() { - if (!isEmpty()) { + if (isNotEmpty()) { E nextValue = data[readSequence % capacity]; readSequence += 1; @@ -62,4 +62,14 @@ public class CircularBuffer { return size() >= capacity; } + + private boolean isNotEmpty() { + + return !isEmpty(); + } + + private boolean isNotFull() { + + return !isFull(); + } } diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java index 801a46b45c..4b8e8646f3 100644 --- a/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/CircularBufferUnitTest.java @@ -10,14 +10,30 @@ import org.junit.jupiter.api.Test; public class CircularBufferUnitTest { private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; + private final int defaultCapacity = shapes.length; @Test - public void givenCircularBuffer_whenAnElementIsAddedAndRemoved_thenBufferIsEmpty() { + public void givenCircularBuffer_whenAnElementIsEnqueued_thenSizeIsOne() { + CircularBuffer buffer = new CircularBuffer<>(defaultCapacity); - int capacity = 2; - CircularBuffer buffer = new CircularBuffer<>(capacity); + assertTrue(buffer.offer("Square")); + assertEquals(1, buffer.size()); + } - assertEquals(capacity, buffer.capacity()); + @Test + public void givenCircularBuffer_whenAnElementIsDequeued_thenElementMatchesEnqueuedElement() { + CircularBuffer buffer = new CircularBuffer<>(defaultCapacity); + + buffer.offer("Triangle"); + + String shape = buffer.poll(); + assertEquals("Triangle", shape); + } + + @Test + public void givenCircularBuffer_whenAnElementIsEnqueuedAndDeququed_thenBufferIsEmpty() { + + CircularBuffer buffer = new CircularBuffer<>(defaultCapacity); buffer.offer("Rectangle"); @@ -30,7 +46,7 @@ public class CircularBufferUnitTest { } @Test - public void givenCircularBuffer_whenFilledToCapacity_thenNoMoreElementsCanBeAdded() { + public void givenCircularBuffer_whenFilledToCapacity_thenNoMoreElementsCanBeEnqueued() { int capacity = shapes.length; CircularBuffer buffer = new CircularBuffer<>(capacity); From 7cfede4a5831ff6e5971f842d676d869186a9ec8 Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Thu, 18 Jun 2020 23:06:07 +0300 Subject: [PATCH 15/44] BAEL-4090: Initial module structure --- gradle-5/build.gradle | 63 ++---- gradle-5/build/lint.patch | 11 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- gradle-5/java-exec/build.gradle | 47 +++++ .../build/distributions/java-exec-0.0.1.tar | Bin 0 -> 20480 bytes .../build/distributions/java-exec-0.0.1.zip | Bin 0 -> 5080 bytes gradle-5/java-exec/build/scripts/java-exec | 188 ++++++++++++++++++ .../java-exec/build/scripts/java-exec.bat | 100 ++++++++++ .../com/baeldung/gradle/exec/MainClass.java | 0 gradle-5/settings.gradle | 3 + gradle-5/unused-dependencies/.gitignore | 1 + gradle-5/unused-dependencies/build.gradle | 12 ++ .../baeldung/unused/UnusedDependencies.java | 12 ++ 13 files changed, 388 insertions(+), 51 deletions(-) create mode 100644 gradle-5/build/lint.patch create mode 100644 gradle-5/java-exec/build.gradle create mode 100644 gradle-5/java-exec/build/distributions/java-exec-0.0.1.tar create mode 100644 gradle-5/java-exec/build/distributions/java-exec-0.0.1.zip create mode 100755 gradle-5/java-exec/build/scripts/java-exec create mode 100644 gradle-5/java-exec/build/scripts/java-exec.bat rename gradle-5/{ => java-exec}/src/main/java/com/baeldung/gradle/exec/MainClass.java (100%) create mode 100644 gradle-5/settings.gradle create mode 100644 gradle-5/unused-dependencies/.gitignore create mode 100644 gradle-5/unused-dependencies/build.gradle create mode 100644 gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java diff --git a/gradle-5/build.gradle b/gradle-5/build.gradle index a728845dff..e816cc956d 100644 --- a/gradle-5/build.gradle +++ b/gradle-5/build.gradle @@ -1,54 +1,17 @@ -plugins { - id "application" -} -apply plugin :"java" - -description = "Java MainClass execution examples" -group = "com.baeldung" -version = "0.0.1" -sourceCompatibility = "1.8" -targetCompatibility = "1.8" - -ext { - javaMainClass = "com.baeldung.gradle.exec.MainClass" +plugins{ + id "nebula.lint" version "16.9.0" } -jar { - manifest { - attributes( - "Main-Class": javaMainClass - ) +description = "Gradle 5 root project" +allprojects { + apply plugin :"java" + apply plugin :"nebula.lint" + group = "com.baeldung" + version = "0.0.1" + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + + repositories { + jcenter() } -} - -application { - mainClassName = javaMainClass -} - -task runWithJavaExec(type: JavaExec) { - group = "Execution" - description = "Run the main class with JavaExecTask" - classpath = sourceSets.main.runtimeClasspath - main = javaMainClass -} - -task runWithExec(type: Exec) { - dependsOn build - group = "Execution" - description = "Run the main class with ExecTask" - commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass -} - -task runWithExecJarExecutable(type: Exec) { - dependsOn jar - group = "Execution" - description = "Run the output executable jar with ExecTask" - commandLine "java", "-jar", jar.archiveFile.get() -} - -task runWithExecJarOnClassPath(type: Exec) { - dependsOn jar - group = "Execution" - description = "Run the mainClass from the output jar in classpath with ExecTask" - commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass } \ No newline at end of file diff --git a/gradle-5/build/lint.patch b/gradle-5/build/lint.patch new file mode 100644 index 0000000000..b665fcf95e --- /dev/null +++ b/gradle-5/build/lint.patch @@ -0,0 +1,11 @@ +diff --git a/unused-dependencies/build.gradle b/unused-dependencies/build.gradle +--- a/unused-dependencies/build.gradle ++++ b/unused-dependencies/build.gradle +@@ -2,7 +2,5 @@ + description = "Gradle Unused Dependencies example" + + dependencies { +- implementation('com.google.guava:guava:29.0-jre') +- implementation('org.springframework.boot:spring-boot:2.3.1.RELEASE') + testImplementation('junit:junit:4.12') + } diff --git a/gradle-5/gradle/wrapper/gradle-wrapper.properties b/gradle-5/gradle/wrapper/gradle-wrapper.properties index b33419deee..4c46317507 100644 --- a/gradle-5/gradle/wrapper/gradle-wrapper.properties +++ b/gradle-5/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip diff --git a/gradle-5/java-exec/build.gradle b/gradle-5/java-exec/build.gradle new file mode 100644 index 0000000000..08aa738902 --- /dev/null +++ b/gradle-5/java-exec/build.gradle @@ -0,0 +1,47 @@ +apply plugin: "application" + +description = "Java MainClass execution examples" + +ext { + javaMainClass = "com.baeldung.gradle.exec.MainClass" +} + +jar { + manifest { + attributes( + "Main-Class": javaMainClass + ) + } +} + +application { + mainClassName = javaMainClass +} + +task runWithJavaExec(type: JavaExec) { + group = "Execution" + description = "Run the main class with JavaExecTask" + classpath = sourceSets.main.runtimeClasspath + main = javaMainClass +} + +task runWithExec(type: Exec) { + dependsOn build + group = "Execution" + description = "Run the main class with ExecTask" + commandLine "java", "-classpath", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass +} + +task runWithExecJarExecutable(type: Exec) { + dependsOn jar + group = "Execution" + description = "Run the output executable jar with ExecTask" + commandLine "java", "-jar", jar.archiveFile.get() +} + +task runWithExecJarOnClassPath(type: Exec) { + dependsOn jar + group = "Execution" + description = "Run the mainClass from the output jar in classpath with ExecTask" + commandLine "java", "-classpath", jar.archiveFile.get() , javaMainClass +} \ No newline at end of file diff --git a/gradle-5/java-exec/build/distributions/java-exec-0.0.1.tar b/gradle-5/java-exec/build/distributions/java-exec-0.0.1.tar new file mode 100644 index 0000000000000000000000000000000000000000..02c5799319c836b400663799939d9e1876bd1b77 GIT binary patch literal 20480 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 literal 0 HcmV?d00001 diff --git a/gradle-5/java-exec/build/distributions/java-exec-0.0.1.zip b/gradle-5/java-exec/build/distributions/java-exec-0.0.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..71369c77a0e8d991cfc45f7c0c707b2843876cab GIT binary patch literal 5080 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 rhVWNff1>_8Vg3h&3HZ;+{DpcsZ \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/.." >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="java-exec" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and JAVA_EXEC_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/lib/java-exec-0.0.1.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $JAVA_EXEC_OPTS -classpath "\"$CLASSPATH\"" com.baeldung.gradle.exec.MainClass "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradle-5/java-exec/build/scripts/java-exec.bat b/gradle-5/java-exec/build/scripts/java-exec.bat new file mode 100644 index 0000000000..d72b659657 --- /dev/null +++ b/gradle-5/java-exec/build/scripts/java-exec.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem java-exec startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME%.. + +@rem Add default JVM options here. You can also use JAVA_OPTS and JAVA_EXEC_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\lib\java-exec-0.0.1.jar + +@rem Execute java-exec +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %JAVA_EXEC_OPTS% -classpath "%CLASSPATH%" com.baeldung.gradle.exec.MainClass %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable JAVA_EXEC_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%JAVA_EXEC_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/gradle-5/src/main/java/com/baeldung/gradle/exec/MainClass.java b/gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java similarity index 100% rename from gradle-5/src/main/java/com/baeldung/gradle/exec/MainClass.java rename to gradle-5/java-exec/src/main/java/com/baeldung/gradle/exec/MainClass.java diff --git a/gradle-5/settings.gradle b/gradle-5/settings.gradle new file mode 100644 index 0000000000..1997e12ca5 --- /dev/null +++ b/gradle-5/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name='gradle-5-articles' +include 'java-exec' +include 'unused-dependencies' \ No newline at end of file diff --git a/gradle-5/unused-dependencies/.gitignore b/gradle-5/unused-dependencies/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/gradle-5/unused-dependencies/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/gradle-5/unused-dependencies/build.gradle b/gradle-5/unused-dependencies/build.gradle new file mode 100644 index 0000000000..dad023fa85 --- /dev/null +++ b/gradle-5/unused-dependencies/build.gradle @@ -0,0 +1,12 @@ + +description = "Gradle Unused Dependencies example" + +dependencies { + implementation('com.google.guava:guava:29.0-jre') + testImplementation('junit:junit:4.12') +} + +gradleLint { + rules=['all-dependency'] + reportFormat = 'text' +} diff --git a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java new file mode 100644 index 0000000000..216227a2f1 --- /dev/null +++ b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java @@ -0,0 +1,12 @@ +package com.baeldung.unused; + +public class UnusedDependencies { + + public static void main(String[] args) { + System.out.println("Hello world"); + +// List list = ImmutableList.of("Baledung", "is", "cool"); +// System.out.println(list.stream().collect(Collectors.joining(" "))); + } + +} From 3b2b8e14212e115420b6c308969415fb5443fadc Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Fri, 19 Jun 2020 16:50:21 +0300 Subject: [PATCH 16/44] BAEL-4090: Setup for errors --- gradle-5/.gitignore | 1 + gradle-5/build.gradle | 4 +++ gradle-5/unused-dependencies/build.gradle | 14 +++++--- .../baeldung/unused/UnusedDependencies.java | 36 +++++++++++++++++-- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 gradle-5/.gitignore diff --git a/gradle-5/.gitignore b/gradle-5/.gitignore new file mode 100644 index 0000000000..094e431ce9 --- /dev/null +++ b/gradle-5/.gitignore @@ -0,0 +1 @@ +**/build/** diff --git a/gradle-5/build.gradle b/gradle-5/build.gradle index e816cc956d..84cf05bad6 100644 --- a/gradle-5/build.gradle +++ b/gradle-5/build.gradle @@ -6,6 +6,10 @@ description = "Gradle 5 root project" allprojects { apply plugin :"java" apply plugin :"nebula.lint" + gradleLint { + rules=['unused-dependency'] + reportFormat = 'text' + } group = "com.baeldung" version = "0.0.1" sourceCompatibility = "1.8" diff --git a/gradle-5/unused-dependencies/build.gradle b/gradle-5/unused-dependencies/build.gradle index dad023fa85..78cf53843e 100644 --- a/gradle-5/unused-dependencies/build.gradle +++ b/gradle-5/unused-dependencies/build.gradle @@ -2,11 +2,15 @@ description = "Gradle Unused Dependencies example" dependencies { + // unused dependency sample implementation('com.google.guava:guava:29.0-jre') + // indirect dependency sample + implementation('org.apache.httpcomponents:httpclient:4.5.12') + // webjars sample + implementation('org.webjars:jquery:3.1.1') + // empty jars + implementation('org.codehaus.cargo:empty-jar:1.7.13') + // family jar + implementation('org.apache.openjpa:openjpa:3.1.1') testImplementation('junit:junit:4.12') } - -gradleLint { - rules=['all-dependency'] - reportFormat = 'text' -} diff --git a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java index 216227a2f1..db557a1fa1 100644 --- a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java +++ b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java @@ -1,12 +1,42 @@ package com.baeldung.unused; +import java.lang.reflect.Method; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.http.HttpHeaders; +import org.apache.http.ssl.SSLContextBuilder; + +import com.google.common.collect.ImmutableList; + public class UnusedDependencies { public static void main(String[] args) { System.out.println("Hello world"); - -// List list = ImmutableList.of("Baledung", "is", "cool"); -// System.out.println(list.stream().collect(Collectors.joining(" "))); + useGuava(); + useHttpCore(); + useHttpClientWithReflection(); } + private static void useGuava() { + List list = ImmutableList.of("Baledung", "is", "cool"); + System.out.println(list.stream() + .collect(Collectors.joining(" "))); + } + + private static void useHttpCore() { + SSLContextBuilder.create(); + // does not trigger the direct dep violation + System.out.println(HttpHeaders.ACCEPT); + } + + private static void useHttpClientWithReflection() { + try { + Class httpBuilder = Class.forName("org.apache.http.impl.client.HttpClientBuilder"); + Method create = httpBuilder.getMethod("create", null); + create.invoke(httpBuilder, null); + } catch (Exception e) { + e.printStackTrace(); + } + } } From 061e3e24d9c358654e92190424751f79bed1ef1e Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Fri, 19 Jun 2020 16:54:41 +0300 Subject: [PATCH 17/44] BAEL-4090: Remove build directories --- gradle-5/.gitignore | 1 + gradle-5/build/lint.patch | 11 - gradle-5/java-exec/.gitignore | 1 + .../build/distributions/java-exec-0.0.1.tar | Bin 20480 -> 0 bytes .../build/distributions/java-exec-0.0.1.zip | Bin 5080 -> 0 bytes gradle-5/java-exec/build/scripts/java-exec | 188 ------------------ .../java-exec/build/scripts/java-exec.bat | 100 ---------- 7 files changed, 2 insertions(+), 299 deletions(-) delete mode 100644 gradle-5/build/lint.patch create mode 100644 gradle-5/java-exec/.gitignore delete mode 100644 gradle-5/java-exec/build/distributions/java-exec-0.0.1.tar delete mode 100644 gradle-5/java-exec/build/distributions/java-exec-0.0.1.zip delete mode 100755 gradle-5/java-exec/build/scripts/java-exec delete mode 100644 gradle-5/java-exec/build/scripts/java-exec.bat diff --git a/gradle-5/.gitignore b/gradle-5/.gitignore index 094e431ce9..4ded91f387 100644 --- a/gradle-5/.gitignore +++ b/gradle-5/.gitignore @@ -1 +1,2 @@ **/build/** +/build/ diff --git a/gradle-5/build/lint.patch b/gradle-5/build/lint.patch deleted file mode 100644 index b665fcf95e..0000000000 --- a/gradle-5/build/lint.patch +++ /dev/null @@ -1,11 +0,0 @@ -diff --git a/unused-dependencies/build.gradle b/unused-dependencies/build.gradle ---- a/unused-dependencies/build.gradle -+++ b/unused-dependencies/build.gradle -@@ -2,7 +2,5 @@ - description = "Gradle Unused Dependencies example" - - dependencies { -- implementation('com.google.guava:guava:29.0-jre') -- implementation('org.springframework.boot:spring-boot:2.3.1.RELEASE') - testImplementation('junit:junit:4.12') - } diff --git a/gradle-5/java-exec/.gitignore b/gradle-5/java-exec/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/gradle-5/java-exec/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/gradle-5/java-exec/build/distributions/java-exec-0.0.1.tar b/gradle-5/java-exec/build/distributions/java-exec-0.0.1.tar deleted file mode 100644 index 02c5799319c836b400663799939d9e1876bd1b77..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20480 zcmeHNeQ;dWb(iggki{;<(3Uiv^!j<%k{s=azATVg<3(CoYiW0dR<>jiNKd<0yU*;t zw|?)fJ{rd}o}|;6bV@!bohGydTGHtZr74pXXq!JWZe5bWKpP-UO4>ASJ(K>yOa>Up zq)gi1x%a)d`&J*Zji8xfUxN32oOABE=lh(ilj@Qh<|{lOjzwaT?r7UPaK&PMv4Q@6 z7L!-=FTG{my$1$*2KsvY4;)~z?w;=6SR3nq2Y6XSvS!(;*%phf`EZ#pnm2cu=>K2f zC!6$N))uzh2ChK=2L=wb^#5+y#CrN~dKWnf2YEYJtUDGv(AU@O_wI8~FJgn=|N9RN z^tQ3L?UR?n^n2X@C&qTXFVNO@_0?_DPkwuX1h(Cg+6VEQPEIAlsmw@pN1Gq;p*zmq zF#>=T{=1SJvN&D&W_IQkN)uDe_Y(&v@VwN7Keo+A7A{#%C@$)3COr( zGsLv2=|g4JvLbo<_qT3OXU`qJ?i0^UKdf|I{gd#G*Z%12-Q%~EzW&)Cz5mwTJAXC% z^3o^Ap13P_$NgXW@(0ql{A9;lxBr6{+I{`*H)GM)7TwC&mKYT*@ z({I1ifse?arQiJo41*fBWgr zJpJ^GuiSoa!uY`(BX6C(^V2!&)}4>sdP`>UwfWJLFWtSH76J?t?F#e(|jNz#nCv{zm3Q>95_m^uKRD^Ot?r zDgK#HUH`L(e|q1kj$7_{;NCx*_@BqS{;HNfGh~LJI`S8fTBWQ0^U!lQyz3ZaBC;s)&8vLc10ztdZNVYC7TKHkylA&&fL6$Es!Z?pxpJ{J~N`4?OLVXpt zK2*mmHlsjZAupn^4<^4J1>qyjWSV`%CG^PIxy{HldCbJv`>!I*58!|2fwy~yOQ-eg zlR#6hk1lBXFGBq{fP%bL|NAuc&OEHAfA8HEElKs?#{FM+Z(nzF{nytw(9^2_wn+S& zlG(c_TC+^y_FP|LRw)qJ8`#T+jOwbX6-zeji9tJdi8BMwny!|aTC+=riD&1|iU^c( zEzfm}7g$X%a8sZps%jpX&X+EBoST+r=&UCaV;w|OaXu-X2eIg?QDYT#mFb4fY8D3x z&0>pMnKQnU=T)0&Izt|*mNiw+bGEG6C9#Y{1Z=Pq4hdtyMhV4Kz*kq9vDgU5R9i62 z=qlNE)f$XOmzS3#s$e%_n8j#WZpMm^r-qW5Trv!n1=2CS%q@$V{8UXdvDt-HrdGjG zUR?m6Wp!D|rD$?|vkl^S+0<-JFLp7@ShSZ_lY`BIX4$5;P_upFa`wTn>qY`q;VV^>_=oZ|5+pB>)N-7J?J0^a;xj#4Ri4)twLJEv7i(&fv!b!YO&!}|Rc=-^ zi_~d>y#lC|wTfn|ws=#wfx2>FSzCI69RAOk7p@qMa$q`DX5~!{_CotOmf1feA-8gI z?1d$4n^&+3)NFB^B_<~3MziT8zD#n~Cj>ShT>GqI#`dK1g<; z3!=21WL!Xtcf4$I-^claX6kAMo-KHtSE7=(09w=n1w-e7T;h0gIIhfBmkaYsAP?R> zv{`{StIS6u5rrM{_z1Ytm1rzH;a~;@F(0Ua%_P#vxZ;_HB3{CGl5^tA{DNw6htZfa zFVtBmumWFHYh{}qJ)UMpRhlx~hDStT$-@oRvSo_lP zOPXou6|M`?71hp*@+08NipmTDDb%XLkkvAUb3>1KTl0kB38KDpM0!x9=Z3(?dJgUD zW~Wbs{|&ZE)e^B!Hl!P@od~phR+TquNDgqxMFTmR>Jh;rS#0Fp+dY&D<4@^%Q%IXk z+l_CczAJDU6%ErO%`bC?SnF865|mD^usBmh^iWt>g{@1+Uh~@V)yDUfF+FFI;c;#} zl}=5?=WC*BVc}7Dn3omrWWifmn4e-Xk!(Fw&oGssq#_n^<17nPSoMEc$7YF$8=@U( z$&54-`t0}s-Makg%z^csPk0FNiD0r0pM)&pzA_|Cz%`Q%_=dy3w~WJ!XSnOp zJyql8>P8xEqTIMw(3X}lf=nT!b{A8Thuz!@7nU{XDk~Ywq9%2!ZE`EBytzsyql-@k zBYzJ?OUE)Abbe$qF+84h(rmEdiOnkE8NwT+93x{m6$rCR{fm}2^oHnO;RQ{N${|=p z%j?!G5_f$YLn6&l>PzQN1Ax+lP*TyIwjDzEb zt_F;nt~CZ~)Kf$pJql+FH4OoXJRY1N`RSr6SIuILBB>Awq7y`n#)8_RB@HQ2axaKX zX0ubnsma`AVmdy*2;s5tIE%6{?6`oQu*AA?kJs+Ky;|k0fUxP+j&i5Dq}g2bFcgO%pdk-}C8?wUitd z9luA10>^XIBOTCFU6|cdt`$%%fMXd(ktZ#V&PS+K3>7d?Aem_Km?wH{h(xah4=a9= z4~-^=#?ZIO`V?TwX^u|1%EEa-`xu8aNVO7if!DJU;@x3oo}f0p&>J??W)Lze2N{H< zDHE~`xMDFc=(L-)_#_7-F~>AS4Kk8>i5$cc$>5&(F1;>H*FPBNqxXi{pKyFE|ev$GU>G=-gp*&-ua(e`NjEUxzUXz^gT6}=lT4$cOx z=xi|B&ge@N>w^X+7i7IMJTdB?Dc>e0kL2JjVp$4lomA-#8Ras%4NMC#F7@IiF+-7E zl=x2D*M)3UE*t28i{hJA;=nmoGiYWgYI>`-VA+~o6BUnHqy9?-399+wbiw91g45oJ z(S+=D>T`*(I8GKN0R;drvm*>p#}IK(z9UX~Lrq`AJ6dzf2imb1Rbck%4opz7TP3&E zaLTc~VN%Nl(Hke}7n!pQ<$%qWF;b$6hb@{$g^f`1#yDALX*J&^Q{OT=6$_J7Lod43 zP=}ZTbc)hPmWq_@MEq5PvL{9Y3{Ff_pXil-G+YXHU}bOCgY-rQL_5PLr*7?sCi2mo2IBfFDt^oaenP)x{ z$w767{8xJR<50n5LJZ2U^!&#mbK=s@fP5PeWyxin1^JM-;7rJ2z46#*%@N9_oC`U0 zw(4xiA-4tRLk^|Q&xj<@t^j^fY%8JRC++k#MPUKuawSLPBQ>)tH0kyz>O!2p5rPRPoeLQ9@^Q;1ZZOc?h{g zBEWDqL%ptBD7*_NE6xU+k5@c)sNfJvj-Ut-TX#F~`t-MGpr@s2!%^hN5tJ$PJ8Dz_ zFUbo~6jpIcppsC?eHUV33^T+@_o2+OaWTSmL@Z|2x1lJq)fdSu!L~1#u}(s_X`pc&JJ0^^YMj zW~ggH2%4|pfE|wDY2-4cOq{>~);~UISo;@ArqY5$2s;Ayo&F+>!&-DnZV%GMO0XQf zD|&-S5mGRTBgG(kkb%hvBEoKC3=uj+$hmnXoty(nfimcSA=b~8Yi3ne^3LIwp9?3L z;7kY8;7n5XP*THlxv|tlyhm6`Bjq`ZXi6_y37x^1fRe(BqgQ!2cGgfX)3F}m2$D&0LMGcg0kbRMvp}RX|A}vi zNmHU$&As<}wGhMDi~jgmc55MzB?OL3Xw^bK8NhwubzCpFtRezld3tFKVn{P?2&>>P zZj!VFIk@n2sw#63r<=8;cZ)41XHrvh_+yn^b{q$G;^2(w@^2wHo0F$ObIgR6Ffq;> z1&*1MWpfp01IYhGm~=OnuM{ZwvS{81yhj*{v}I{2UMLuvYg`(_M6AG}HawYrqYHG4 z4S1W`D4{}_UP2v2VkoM+-i!U?&uuVT04)i$B+!yTO9Cwkv?S1yKuZEG3A7~8l0ZuW jEeW(F(2_t)0xb!&B+!yTO9Cwkv?S1yKuZGess#QIOq&L! diff --git a/gradle-5/java-exec/build/distributions/java-exec-0.0.1.zip b/gradle-5/java-exec/build/distributions/java-exec-0.0.1.zip deleted file mode 100644 index 71369c77a0e8d991cfc45f7c0c707b2843876cab..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5080 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 rhVWNff1>_8Vg3h&3HZ;+{DpcsZ \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/.." >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="java-exec" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and JAVA_EXEC_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/lib/java-exec-0.0.1.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $JAVA_EXEC_OPTS -classpath "\"$CLASSPATH\"" com.baeldung.gradle.exec.MainClass "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/gradle-5/java-exec/build/scripts/java-exec.bat b/gradle-5/java-exec/build/scripts/java-exec.bat deleted file mode 100644 index d72b659657..0000000000 --- a/gradle-5/java-exec/build/scripts/java-exec.bat +++ /dev/null @@ -1,100 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem java-exec startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME%.. - -@rem Add default JVM options here. You can also use JAVA_OPTS and JAVA_EXEC_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\lib\java-exec-0.0.1.jar - -@rem Execute java-exec -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %JAVA_EXEC_OPTS% -classpath "%CLASSPATH%" com.baeldung.gradle.exec.MainClass %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable JAVA_EXEC_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%JAVA_EXEC_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega From b018d2c6cd955d51fead1007494258a8421dcd98 Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Sun, 21 Jun 2020 03:06:32 +0530 Subject: [PATCH 18/44] review comments --- .../circularbuffer/CircularBuffer.java | 4 +- .../ProducerConsumerLiveTest.java | 63 ++++++++++--------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java index 271fc5f376..6b315265b4 100644 --- a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -25,7 +25,7 @@ public class CircularBuffer { int nextWriteSeq = writeSequence + 1; data[nextWriteSeq % capacity] = element; - writeSequence += 1; + writeSequence++; return true; } @@ -37,7 +37,7 @@ public class CircularBuffer { if (isNotEmpty()) { E nextValue = data[readSequence % capacity]; - readSequence += 1; + readSequence++; return nextValue; } diff --git a/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java b/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java index 06b1c5e4cf..83ce27043b 100644 --- a/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java +++ b/data-structures/src/test/java/com/baeldung/circularbuffer/ProducerConsumerLiveTest.java @@ -2,6 +2,11 @@ package com.baeldung.circularbuffer; import static org.junit.Assert.assertArrayEquals; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; import org.junit.jupiter.api.Test; @@ -11,38 +16,34 @@ public class ProducerConsumerLiveTest { private final String[] shapes = { "Circle", "Triangle", "Rectangle", "Square", "Rhombus", "Trapezoid", "Pentagon", "Pentagram", "Hexagon", "Hexagram" }; @Test - public void givenACircularBuffer_whenInterleavingProducerConsumer_thenElementsMatch() throws InterruptedException { + public void givenACircularBuffer_whenInterleavingProducerConsumer_thenElementsMatch() throws Exception { CircularBuffer buffer = new CircularBuffer(shapes.length); - String[] consumedShapes = new String[shapes.length]; - Thread producer = new Thread(new Producer(shapes, buffer)); - Thread consumer = new Thread(new Consumer(consumedShapes, buffer)); + ExecutorService executorService = Executors.newFixedThreadPool(2); - producer.start(); - consumer.start(); + executorService.submit(new Producer(buffer, shapes)); + Future consumed = executorService.submit(new Consumer(buffer, shapes.length)); - producer.join(); - consumer.join(); - - assertArrayEquals(shapes, consumedShapes); + String[] shapesConsumed = consumed.get(5L, TimeUnit.SECONDS); + assertArrayEquals(shapes, shapesConsumed); } - static class Producer implements Runnable { + static class Producer implements Runnable { - private String[] producerShapes; - private CircularBuffer buffer; + private CircularBuffer buffer; + private T[] items; - public Producer(String[] producerShapes, CircularBuffer buffer) { - this.producerShapes = producerShapes; + public Producer(CircularBuffer buffer, T[] items) { this.buffer = buffer; + this.items = items; } @Override public void run() { - for (int i = 0; i < producerShapes.length;) { - if (buffer.offer(producerShapes[i])) { - System.out.println("Produced: " + producerShapes[i]); + for (int i = 0; i < items.length;) { + if (buffer.offer(items[i])) { + System.out.println("Produced: " + items[i]); i++; LockSupport.parkNanos(5); } @@ -50,28 +51,30 @@ public class ProducerConsumerLiveTest { } } - static class Consumer implements Runnable { + @SuppressWarnings("unchecked") + static class Consumer implements Callable { - private CircularBuffer buffer; - private String[] consumedShapes; + private CircularBuffer buffer; + private int expectedCount; - public Consumer(String[] consumedShapes, CircularBuffer buffer) { - this.consumedShapes = consumedShapes; + public Consumer(CircularBuffer buffer, int expectedCount) { this.buffer = buffer; + this.expectedCount = expectedCount; } @Override - public void run() { - - for (int i = 0; i < consumedShapes.length;) { - String shape = buffer.poll(); - if (shape != null) { - consumedShapes[i++] = shape; + public T[] call() throws Exception { + T[] items = (T[]) new Object[expectedCount]; + for (int i = 0; i < items.length;) { + T item = buffer.poll(); + if (item != null) { + items[i++] = item; LockSupport.parkNanos(5); - System.out.println("Consumed: " + shape); + System.out.println("Consumed: " + item); } } + return items; } } } From bc19610dc76a65a4f49c78880c3c036bf5b1064e Mon Sep 17 00:00:00 2001 From: Sorin Zamfir Date: Sun, 21 Jun 2020 19:24:56 +0300 Subject: [PATCH 19/44] BAEL-4090: Cleaned up sources --- gradle-5/unused-dependencies/build.gradle | 8 -------- .../main/java/com/baeldung/unused/UnusedDependencies.java | 3 --- 2 files changed, 11 deletions(-) diff --git a/gradle-5/unused-dependencies/build.gradle b/gradle-5/unused-dependencies/build.gradle index 78cf53843e..d848cd0e0d 100644 --- a/gradle-5/unused-dependencies/build.gradle +++ b/gradle-5/unused-dependencies/build.gradle @@ -2,15 +2,7 @@ description = "Gradle Unused Dependencies example" dependencies { - // unused dependency sample implementation('com.google.guava:guava:29.0-jre') - // indirect dependency sample implementation('org.apache.httpcomponents:httpclient:4.5.12') - // webjars sample - implementation('org.webjars:jquery:3.1.1') - // empty jars - implementation('org.codehaus.cargo:empty-jar:1.7.13') - // family jar - implementation('org.apache.openjpa:openjpa:3.1.1') testImplementation('junit:junit:4.12') } diff --git a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java index db557a1fa1..c2e221356c 100644 --- a/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java +++ b/gradle-5/unused-dependencies/src/main/java/com/baeldung/unused/UnusedDependencies.java @@ -4,7 +4,6 @@ import java.lang.reflect.Method; import java.util.List; import java.util.stream.Collectors; -import org.apache.http.HttpHeaders; import org.apache.http.ssl.SSLContextBuilder; import com.google.common.collect.ImmutableList; @@ -26,8 +25,6 @@ public class UnusedDependencies { private static void useHttpCore() { SSLContextBuilder.create(); - // does not trigger the direct dep violation - System.out.println(HttpHeaders.ACCEPT); } private static void useHttpClientWithReflection() { From 6d4b45e1aa6acd81f9dcfba6091d2bc95ac98145 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 21 Jun 2020 22:10:19 +0530 Subject: [PATCH 20/44] moved apache tiles related code in spring-mvc-views module --- spring-mvc-basics-2/README.md | 1 - spring-mvc-basics-2/pom.xml | 7 ---- .../spring/configuration/WebInitializer.java | 2 -- spring-mvc-views/README.md | 1 + spring-mvc-views/pom.xml | 7 ++++ .../TilesApplicationConfiguration.java | 4 +-- .../themes/config/WebInitializer.java | 1 + .../themes/controllers}/TilesController.java | 2 +- .../WEB-INF/views/pages/apachetiles.jsp | 0 .../main/webapp/WEB-INF/views/pages/home.jsp | 12 +++++++ .../webapp/WEB-INF/views/pages/springmvc.jsp | 12 +++++++ .../views/tiles/layouts/defaultLayout.jsp | 0 .../views/tiles/templates/defaultFooter.jsp | 0 .../views/tiles/templates/defaultHeader.jsp | 0 .../views/tiles/templates/defaultMenu.jsp | 0 .../main/webapp/WEB-INF/views/tiles/tiles.xml | 0 .../src/main/webapp/static/css/app.css | 36 +++++++++++++++++++ 17 files changed, 72 insertions(+), 13 deletions(-) rename {spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration => spring-mvc-views/src/main/java/com/baeldung/themes/config}/TilesApplicationConfiguration.java (93%) rename {spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles => spring-mvc-views/src/main/java/com/baeldung/themes/controllers}/TilesController.java (94%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp (100%) create mode 100644 spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp create mode 100644 spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp (100%) rename {spring-mvc-basics-2 => spring-mvc-views}/src/main/webapp/WEB-INF/views/tiles/tiles.xml (100%) create mode 100644 spring-mvc-views/src/main/webapp/static/css/app.css diff --git a/spring-mvc-basics-2/README.md b/spring-mvc-basics-2/README.md index 5c1c671f73..cbc9f93e93 100644 --- a/spring-mvc-basics-2/README.md +++ b/spring-mvc-basics-2/README.md @@ -7,7 +7,6 @@ This module contains articles about Spring MVC - [Template Engines for Spring](https://www.baeldung.com/spring-template-engines) - [Spring 5 and Servlet 4 – The PushBuilder](https://www.baeldung.com/spring-5-push) - [Servlet Redirect vs Forward](https://www.baeldung.com/servlet-redirect-forward) -- [Apache Tiles Integration with Spring MVC](https://www.baeldung.com/spring-mvc-apache-tiles) - [Guide to Spring Email](https://www.baeldung.com/spring-email) - [Using ThymeLeaf and FreeMarker Emails Templates with Spring](https://www.baeldung.com/spring-email-templates) - [Request Method Not Supported (405) in Spring](https://www.baeldung.com/spring-request-method-not-supported-405) diff --git a/spring-mvc-basics-2/pom.xml b/spring-mvc-basics-2/pom.xml index 4c3041a209..026ddf8e72 100644 --- a/spring-mvc-basics-2/pom.xml +++ b/spring-mvc-basics-2/pom.xml @@ -99,12 +99,6 @@ ${jade.version} - - org.apache.tiles - tiles-jsp - ${apache-tiles.version} - - org.springframework @@ -178,7 +172,6 @@ 1.4.9 5.1.0 20180130 - 3.0.8 1.6.1 diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java index 4d43549440..aaa2443105 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java +++ b/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/WebInitializer.java @@ -23,8 +23,6 @@ public class WebInitializer implements WebApplicationInitializer { ctx.register(EmailConfiguration.class); // ctx.setServletContext(container); - //ctx.register(TilesApplicationConfiguration.class); - // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(ctx)); diff --git a/spring-mvc-views/README.md b/spring-mvc-views/README.md index 7aa05699f3..0323349130 100644 --- a/spring-mvc-views/README.md +++ b/spring-mvc-views/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Spring MVC Themes](https://www.baeldung.com/spring-mvc-themes) +- [Apache Tiles Integration with Spring MVC](https://www.baeldung.com/spring-mvc-apache-tiles) diff --git a/spring-mvc-views/pom.xml b/spring-mvc-views/pom.xml index b23403fe31..452805bd53 100644 --- a/spring-mvc-views/pom.xml +++ b/spring-mvc-views/pom.xml @@ -74,6 +74,12 @@ spring-security-taglibs ${spring.security.version} + + + org.apache.tiles + tiles-jsp + ${apache-tiles.version} + @@ -115,6 +121,7 @@ 2.5.0 5.4.9.Final enter-location-of-server + 3.0.8 \ No newline at end of file diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java b/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java similarity index 93% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java rename to spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java index de2b7fe68f..886c8987e8 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/configuration/TilesApplicationConfiguration.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/config/TilesApplicationConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.configuration; +package com.baeldung.themes.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -12,7 +12,7 @@ import org.springframework.web.servlet.view.tiles3.TilesViewResolver; @Configuration @EnableWebMvc -@ComponentScan(basePackages = "com.baeldung.spring.controller.tiles") +@ComponentScan(basePackages = "com.baeldung.themes") public class TilesApplicationConfiguration implements WebMvcConfigurer { /** diff --git a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java b/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java index 3fbe8d043d..3333d664d7 100644 --- a/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/config/WebInitializer.java @@ -14,6 +14,7 @@ public class WebInitializer implements WebApplicationInitializer { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(DataSourceConfig.class); context.register(ThemeMVCConfig.class); + //context.register(TilesApplicationConfiguration.class); servletContext.addListener(new ContextLoaderListener(context)); diff --git a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java b/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java similarity index 94% rename from spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java rename to spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java index 319340b886..11a3d3d197 100644 --- a/spring-mvc-basics-2/src/main/java/com/baeldung/spring/controller/tiles/TilesController.java +++ b/spring-mvc-views/src/main/java/com/baeldung/themes/controllers/TilesController.java @@ -1,4 +1,4 @@ -package com.baeldung.spring.controller.tiles; +package com.baeldung.themes.controllers; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/pages/apachetiles.jsp diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp new file mode 100644 index 0000000000..47157a5d2a --- /dev/null +++ b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/home.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Home + + +

Welcome to Apache Tiles integration with Spring MVC

+ + \ No newline at end of file diff --git a/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp new file mode 100644 index 0000000000..497e04901a --- /dev/null +++ b/spring-mvc-views/src/main/webapp/WEB-INF/views/pages/springmvc.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Spring MVC + + +

Spring MVC configured to work with Apache Tiles

+ + \ No newline at end of file diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/layouts/defaultLayout.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultFooter.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultHeader.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/templates/defaultMenu.jsp diff --git a/spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/tiles.xml b/spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml similarity index 100% rename from spring-mvc-basics-2/src/main/webapp/WEB-INF/views/tiles/tiles.xml rename to spring-mvc-views/src/main/webapp/WEB-INF/views/tiles/tiles.xml diff --git a/spring-mvc-views/src/main/webapp/static/css/app.css b/spring-mvc-views/src/main/webapp/static/css/app.css new file mode 100644 index 0000000000..9976e5406e --- /dev/null +++ b/spring-mvc-views/src/main/webapp/static/css/app.css @@ -0,0 +1,36 @@ +.flex-container { + display: -webkit-flex; + display: flex; + -webkit-flex-flow: row wrap; + flex-flow: row wrap; + text-align: center; +} + +.flex-container > * { + padding: 15px; + -webkit-flex: 1 100%; + flex: 1 100%; +} + +.article { + text-align: left; +} + +header {background: black;color:white;} +footer {background: #aaa;color:white;} +.nav {background:#eee;} + +.nav ul { + list-style-type: none; + padding: 0; +} + +.nav ul a { + text-decoration: none; +} + +@media all and (min-width: 768px) { + .nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;} + .article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;} + footer {-webkit-order:3;order:3;} +} \ No newline at end of file From 02ec5e5a8db525f37e4eb9c53f147f2564d083eb Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Mon, 22 Jun 2020 01:38:45 +0430 Subject: [PATCH 21/44] Invoke Operator --- .../src/main/kotlin/com/baeldung/operators/Page.kt | 1 + .../src/test/kotlin/com/baeldung/operators/PageTest.kt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt index 1077eb94f9..8a0ee48a36 100644 --- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt +++ b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt @@ -6,6 +6,7 @@ interface Page { fun elements(): MutableList } +operator fun Page.invoke(index: Int): T = elements()[index] operator fun Page.get(index: Int): T = elements()[index] operator fun Page.get(start: Int, endExclusive: Int): List = elements().subList(start, endExclusive) operator fun Page.set(index: Int, value: T) { diff --git a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt index 4217fc0c08..fa6e1773bd 100644 --- a/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt +++ b/core-kotlin-modules/core-kotlin-lang/src/test/kotlin/com/baeldung/operators/PageTest.kt @@ -14,6 +14,11 @@ class PageTest { assertEquals(page[1, 3], listOf("Kotlin", "Scala")) } + @Test + fun `Invoke convention should work as expected`() { + assertEquals(page(1), "Kotlin") + } + @Test fun `In convention should work on a page as expected`() { assertTrue("Kotlin" in page) From 1e3c2b2a75fb275ae10b6f983d9ab3f2fa4099f4 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 22 Jun 2020 12:50:14 +0300 Subject: [PATCH 22/44] Update .gitignore --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index d3a5dae06d..78125cc3ee 100644 --- a/.gitignore +++ b/.gitignore @@ -85,7 +85,3 @@ transaction.log *-shell.log apache-cxf/cxf-aegis/baeldung.xml -apache-fop/src/test/resources/input.xml -apache-fop/src/test/resources/output_herold.pdf -apache-fop/src/test/resources/output_html2fo.pdf -apache-fop/src/test/resources/output_jtidy.pdf \ No newline at end of file From 70672e1e0d4a081949248979ee86516057ace4fe Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Mon, 22 Jun 2020 15:06:29 +0200 Subject: [PATCH 23/44] KTLN-137 --- .../java/com/baeldung/observer/IObservable.kt | 18 ++++++++++++++++++ .../java/com/baeldung/observer/IObserver.kt | 5 +++++ .../observer/delegates/BaeldungNewsletter.kt | 10 ++++++++++ .../observer/delegates/BaeldungReader.kt | 8 ++++++++ .../observer/standard/BaeldungNewsletter.kt | 14 ++++++++++++++ .../observer/standard/BaeldungReader.kt | 9 +++++++++ 6 files changed, 64 insertions(+) create mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt create mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt create mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt create mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt create mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt create mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt new file mode 100644 index 0000000000..e896d55cf2 --- /dev/null +++ b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt @@ -0,0 +1,18 @@ +package com.baeldung.observer + +import java.util.ArrayList + +interface IObservable { + val observers: ArrayList + fun add(observer: IObserver) { + observers.add(observer) + } + + fun remove(observer: IObserver) { + observers.remove(observer) + } + + fun sendUpdateEvent() { + observers.forEach { it.update() } + } +} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt new file mode 100644 index 0000000000..e2187a9fcb --- /dev/null +++ b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt @@ -0,0 +1,5 @@ +package com.baeldung.observer + +interface IObserver { + fun update() +} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt new file mode 100644 index 0000000000..748c1064ff --- /dev/null +++ b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt @@ -0,0 +1,10 @@ +package com.baeldung.observer.delegates + +import kotlin.properties.Delegates + +class BaeldungNewsletter { + val newestArticleObservers = mutableListOf<(String) -> Unit>() + var newestArticleUrl: String by Delegates.observable("") { _, _, newValue -> + newestArticleObservers.forEach { it(newValue) } + } +} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt new file mode 100644 index 0000000000..f275648549 --- /dev/null +++ b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt @@ -0,0 +1,8 @@ +package com.baeldung.observer.delegates + +fun main() { + val newsletter = BaeldungNewsletter() + newsletter.newestArticleObservers.add { newestArticleUrl -> + println("New Baeldung article: ${newestArticleUrl}") + } +} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt new file mode 100644 index 0000000000..0ec4796edb --- /dev/null +++ b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt @@ -0,0 +1,14 @@ +package com.baeldung.observer.standard + +import com.baeldung.observer.IObservable +import com.baeldung.observer.IObserver +import java.util.ArrayList + +class BaeldungNewsletter : IObservable { + override val observers: ArrayList = ArrayList() + var newestArticleUrl = "" + set(value) { + field = value + sendUpdateEvent() + } +} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt new file mode 100644 index 0000000000..14e686f2f8 --- /dev/null +++ b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt @@ -0,0 +1,9 @@ +package com.baeldung.observer.standard + +import com.baeldung.observer.IObserver + +class BaeldungReader(private var newsletter: BaeldungNewsletter) : IObserver { + override fun update() { + println("New Baeldung article: ${newsletter.newestArticleUrl}") + } +} \ No newline at end of file From 7acbc61340997f171ce0203c5cbe137253275ef3 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Tue, 23 Jun 2020 22:14:30 +0200 Subject: [PATCH 24/44] [BAEL-4131] division by zero unit tests --- .../DivisionByZeroUnitTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java diff --git a/java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java new file mode 100644 index 0000000000..0e0e099d91 --- /dev/null +++ b/java-numbers-3/src/test/java/com/baeldung/divisionbyzero/DivisionByZeroUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.divisionbyzero; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class DivisionByZeroUnitTest { + + @Test + void givenInt_whenDividedByZero_thenThrowException() { + assertThrows(ArithmeticException.class, () -> { + int result = 12 / 0; + }); + } + + @Test + void whenDividingIntZeroByZero_thenThrowException() { + assertThrows(ArithmeticException.class, () -> { + int result = 0 / 0; + }); + } + + @Test + void whenDividingFloatingNumberByZero_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> { + float result = 0f / 0; + }); + assertDoesNotThrow(() -> { + double result = 0d / 0; + }); + } + + @Test + void givenPositiveFloatingNumber_whenDividedByZero_thenReturnPositiveInfinity() { + assertEquals(Float.POSITIVE_INFINITY, 12f / 0); + assertEquals(Double.POSITIVE_INFINITY, 12d / 0); + } + + @Test + void givenNegativeFloatingNumber_whenDividedByZero_thenReturnNegativeInfinity() { + assertEquals(Float.NEGATIVE_INFINITY, -12f / 0); + assertEquals(Double.NEGATIVE_INFINITY, -12d / 0); + } + + @Test + void givenPositiveFloatingNumber_whenDividedByNegativeZero_thenReturnNegativeInfinity() { + assertEquals(Float.NEGATIVE_INFINITY, 12f / -0f); + assertEquals(Double.NEGATIVE_INFINITY, 12f / -0f); + } + + @Test + void whenDividingFloatingNumberZeroByZero_thenReturnNaN() { + assertEquals(Float.NaN, 0f / 0); + assertEquals(Double.NaN, 0d / 0); + } + + @Test + void givenABitRepresentationWithAllExponentBitsZeroesAndAllFractionBitsZeroes_whenTransformingItToFloat_thenReturnPositiveZero() { + assertEquals(0f, Float.intBitsToFloat(0b00000000000000000000000000000000)); + assertEquals(-0f, Float.intBitsToFloat(0b10000000000000000000000000000000)); + } + + @Test + void givenABitRepresentationWithAllExponentBitsOnesAndAllFractionBitsZeroes_whenTransformingItToFloat_thenReturnInfinity() { + assertEquals(Float.POSITIVE_INFINITY, Float.intBitsToFloat(0b01111111100000000000000000000000)); + assertEquals(Float.NEGATIVE_INFINITY, Float.intBitsToFloat(0b11111111100000000000000000000000)); + } + + @Test + void givenABitRepresentationWithAllExponentBitsOnesAndNotAllFractionBitsZeroes_whenTransformingItToFloat_thenReturnNan() { + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000010000000000000000)); + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000011000000000100000)); + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000011100000000000000)); + assertEquals(Float.NaN, Float.intBitsToFloat(0b11111111100000011110000000000000)); + } +} From 4df44e18c52bb4ec25cca75575804b0874f89ad5 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 24 Jun 2020 15:19:35 +0430 Subject: [PATCH 25/44] Move the Memory Layout Codebase to a new Module --- core-java-modules/core-java-jvm-2/README.md | 5 +++ core-java-modules/core-java-jvm-2/pom.xml | 43 +++++++++++++++++++ .../memlayout/MemoryLayoutUnitTest.java | 0 core-java-modules/pom.xml | 1 + 4 files changed, 49 insertions(+) create mode 100644 core-java-modules/core-java-jvm-2/README.md create mode 100644 core-java-modules/core-java-jvm-2/pom.xml rename core-java-modules/{core-java-jvm => core-java-jvm-2}/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java (100%) diff --git a/core-java-modules/core-java-jvm-2/README.md b/core-java-modules/core-java-jvm-2/README.md new file mode 100644 index 0000000000..4925a268a9 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/README.md @@ -0,0 +1,5 @@ +## Core Java JVM Cookbooks and Examples + +This module contains articles about working with the Java Virtual Machine (JVM). + +### Relevant Articles: \ No newline at end of file diff --git a/core-java-modules/core-java-jvm-2/pom.xml b/core-java-modules/core-java-jvm-2/pom.xml new file mode 100644 index 0000000000..71dca18094 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + core-java-jvm-2 + 0.1.0-SNAPSHOT + core-java-jvm-2 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + junit + junit + ${junit.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + org.openjdk.jol + jol-core + ${jol-core.version} + + + + + 3.6.1 + 0.10 + + + diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java similarity index 100% rename from core-java-modules/core-java-jvm/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java rename to core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 26c374b51d..76fed91251 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -80,6 +80,7 @@ core-java-jndi core-java-jvm + core-java-jvm-2 core-java-lambdas core-java-lang From 9f224670a60cd46a76afa4fdeee7a157ed109372 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 24 Jun 2020 15:21:53 +0430 Subject: [PATCH 26/44] Fixed a typo --- .../test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java index 005ece0195..2f226d7657 100644 --- a/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java +++ b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java @@ -91,7 +91,7 @@ public class MemoryLayoutUnitTest { private boolean first; private char second; private double third; - private int forth; + private int fourth; private boolean fifth; } From dbf302c6ba1215c1af2163b0a596961e53dfa53f Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 24 Jun 2020 15:42:46 +0200 Subject: [PATCH 27/44] JAVA-1642: Get rid of the overriden spring-boot.version property --- spring-soap/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spring-soap/pom.xml b/spring-soap/pom.xml index d0987329c0..137ff03c31 100644 --- a/spring-soap/pom.xml +++ b/spring-soap/pom.xml @@ -83,8 +83,4 @@ - - 2.1.2.RELEASE - - From 39c55876c9e2c6f0f716f11c5d8659c2eb8f5ad4 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 24 Jun 2020 21:07:15 +0430 Subject: [PATCH 28/44] Added Custom Health Groups --- .../src/main/resources/application.properties | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-5-reactive-security/src/main/resources/application.properties b/spring-5-reactive-security/src/main/resources/application.properties index 234834b894..d13007ded7 100644 --- a/spring-5-reactive-security/src/main/resources/application.properties +++ b/spring-5-reactive-security/src/main/resources/application.properties @@ -1,5 +1,9 @@ logging.level.root=INFO -management.endpoints.web.exposure.include.=* +management.endpoints.web.exposure.include=* info.app.name=Spring Boot 2 actuator Application +management.endpoint.health.group.custom.include=diskSpace,ping +management.endpoint.health.group.custom.show-components=always +management.endpoint.health.group.custom.show-details=always +management.endpoint.health.group.custom.status.http-mapping.up=207 \ No newline at end of file From 1ff99dfea75a5b41eb0f607e6e491e0ab10f198c Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 24 Jun 2020 21:55:56 +0430 Subject: [PATCH 29/44] Default Serial Version UID --- .../baeldung/deserialization/DefaultSerial.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java new file mode 100644 index 0000000000..ddfef9a1d2 --- /dev/null +++ b/core-java-modules/core-java/src/main/java/com/baeldung/deserialization/DefaultSerial.java @@ -0,0 +1,15 @@ +package com.baeldung.deserialization; + +import java.io.IOException; +import java.io.Serializable; + +public class DefaultSerial implements Serializable { + + private String name; + + public static void main(String[] args) throws IOException, ClassNotFoundException { + String digest = "rO0ABXNyACpjb20uYmFlbGR1bmcuZGVzZXJpY" + + "WxpemF0aW9uLkRlZmF1bHRTZXJpYWx9iVz3Lz/mdAIAAHhw"; + DefaultSerial instance = (DefaultSerial) DeserializationUtility.deSerializeObjectFromString(digest); + } +} From bb2060ee782eeb0c05e18fe68c39f7d82c93411e Mon Sep 17 00:00:00 2001 From: developerDiv Date: Wed, 24 Jun 2020 22:07:48 +0100 Subject: [PATCH 30/44] Move to java-core-networking-2 --- .../macaddress/GetAllMacAddressesDemo.java | 23 +++++++++++++++++++ .../macaddress/MacAddressUnitTest.java | 21 +++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java create mode 100644 core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java diff --git a/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java new file mode 100644 index 0000000000..8f07d4133e --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/main/java/com/baeldung/macaddress/GetAllMacAddressesDemo.java @@ -0,0 +1,23 @@ +package com.baeldung.macaddress; + +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + +public class GetAllMacAddressesDemo { + + public static void main(String[] args) throws SocketException { + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface ni = networkInterfaces.nextElement(); + byte[] hardwareAddress = ni.getHardwareAddress(); + if (hardwareAddress != null) { + String[] hexadecimalFormat = new String[hardwareAddress.length]; + for (int i = 0; i < hardwareAddress.length; i++) { + hexadecimalFormat[i] = String.format("%02X", hardwareAddress[i]); + } + System.out.println(String.join("-", hexadecimalFormat)); + } + } + } +} diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java new file mode 100644 index 0000000000..3786fdcfdd --- /dev/null +++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.macaddress; + +import org.junit.Test; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; + +import static org.junit.Assert.assertNotNull; + +public class MacAddressUnitTest { + + @Test + public void givenNetworkInterface_whenUsingLocalHost_thenGetMacAddress() throws UnknownHostException, SocketException { + InetAddress localHost = InetAddress.getLocalHost(); + NetworkInterface ni = NetworkInterface.getByInetAddress(localHost); + byte[] macAddress = ni.getHardwareAddress(); + assertNotNull(macAddress); + } +} From c52d618baad3c1f884de9495392c96a06135beac Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:41:47 +0800 Subject: [PATCH 31/44] Update README.md --- persistence-modules/hibernate5/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index bd437c80eb..8793e2e9c7 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -4,7 +4,7 @@ This module contains articles about Hibernate 5. Let's not add more articles her ### Relevant articles: -- [An Overview of Identifiers in Hibernate](https://www.baeldung.com/hibernate-identifiers) +- [An Overview of Identifiers in Hibernate/JPA](https://www.baeldung.com/hibernate-identifiers) - [Hibernate Interceptors](https://www.baeldung.com/hibernate-interceptor) - [Hibernate Entity Lifecycle](https://www.baeldung.com/hibernate-entity-lifecycle) - [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy) @@ -12,4 +12,4 @@ This module contains articles about Hibernate 5. Let's not add more articles her - [Hibernate 5 Bootstrapping API](https://www.baeldung.com/hibernate-5-bootstrapping-api) - [Guide to the Hibernate EntityManager](https://www.baeldung.com/hibernate-entitymanager) - [Using c3p0 with Hibernate](https://www.baeldung.com/hibernate-c3p0) -- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) \ No newline at end of file +- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) From 13a37ab18bfe6f8ad7ee1172caafa7c6d3327c16 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:44:34 +0800 Subject: [PATCH 32/44] Update README.md --- libraries-testing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries-testing/README.md b/libraries-testing/README.md index ffdefe4b19..43d7673e2d 100644 --- a/libraries-testing/README.md +++ b/libraries-testing/README.md @@ -8,7 +8,7 @@ This module contains articles about test libraries. - [Introduction to JSONassert](https://www.baeldung.com/jsonassert) - [Serenity BDD and Screenplay](https://www.baeldung.com/serenity-screenplay) - [Serenity BDD with Spring and JBehave](https://www.baeldung.com/serenity-spring-jbehave) -- [Introduction to Awaitlity](https://www.baeldung.com/awaitlity-testing) +- [Introduction to Awaitility](https://www.baeldung.com/awaitlity-testing) - [Introduction to Hoverfly in Java](https://www.baeldung.com/hoverfly) - [Testing with Hamcrest](https://www.baeldung.com/java-junit-hamcrest-guide) - [Introduction To DBUnit](https://www.baeldung.com/java-dbunit) From fb70309f0fbe71b98cc305e84d6c963e58aa3277 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:49:18 +0800 Subject: [PATCH 33/44] Update README.md --- .../spring-security-sso/spring-security-sso-kerberos/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md index 4bb0eea16c..a6244ec0ad 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md @@ -1,4 +1,4 @@ ## Relevant articles: -- [Spring Security Kerberos Integration](https://www.baeldung.com/spring-security-kerberos-integration) +- [Spring Security Kerberos Integration With MiniKdc](https://www.baeldung.com/spring-security-kerberos-integration) - [Introduction to SPNEGO/Kerberos Authentication in Spring](https://www.baeldung.com/spring-security-kerberos) From 912f0c64034af0332d009d744a76f8f3ecf3617e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 26 Jun 2020 17:51:18 +0800 Subject: [PATCH 34/44] Update README.md --- persistence-modules/spring-data-elasticsearch/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-elasticsearch/README.md b/persistence-modules/spring-data-elasticsearch/README.md index 63f1185732..9f68a25243 100644 --- a/persistence-modules/spring-data-elasticsearch/README.md +++ b/persistence-modules/spring-data-elasticsearch/README.md @@ -6,7 +6,7 @@ - [Guide to Elasticsearch in Java](https://www.baeldung.com/elasticsearch-java) - [Geospatial Support in ElasticSearch](https://www.baeldung.com/elasticsearch-geo-spatial) - [A Simple Tagging Implementation with Elasticsearch](https://www.baeldung.com/elasticsearch-tagging) -- [Introduction to Spring Data Elasticsearch – test 2](https://www.baeldung.com/spring-data-elasticsearch-test-2) +- [Introduction to Spring Data Elasticsearch (evaluation)](https://www.baeldung.com/spring-data-elasticsearch-test-2) ### Build the Project with Tests Running ``` From 785e85477cf401eb6f9c7f0295edf02c6614543c Mon Sep 17 00:00:00 2001 From: Vikas Rajput Date: Fri, 26 Jun 2020 21:59:30 +0530 Subject: [PATCH 35/44] Bael 4085 (#9580) * BAEL-4085: First Draft completed * BAEL-4085: used ternary operator for if condition * BAEL-4085: renamed unit test class as per the review comment * BAEL-4085: deleted old file Co-authored-by: Vikas Ramsingh Rajput --- ...nitTest.java => MultipartPostRequestControllerUnitTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/{MultipartPostRequestUnitTest.java => MultipartPostRequestControllerUnitTest.java} (96%) diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestUnitTest.java b/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java similarity index 96% rename from spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestUnitTest.java rename to spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java index 2e88935c1b..e75990e0b0 100644 --- a/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestUnitTest.java +++ b/spring-mvc-java-2/src/test/java/com/baeldung/multiparttesting/MultipartPostRequestControllerUnitTest.java @@ -20,7 +20,7 @@ import com.baeldung.matrix.config.MatrixWebConfig; @WebAppConfiguration @ContextConfiguration(classes = { MatrixWebConfig.class, MultipartPostRequestController.class }) @RunWith(SpringJUnit4ClassRunner.class) -public class MultipartPostRequestUnitTest { +public class MultipartPostRequestControllerUnitTest { @Autowired private WebApplicationContext webApplicationContext; From 3b3013bfb0409b209dba5f05e41662344ee67a9a Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Sat, 27 Jun 2020 02:55:48 +0530 Subject: [PATCH 36/44] BAEL-3977: Upgrade Guava modules/articles to newest Guava version (#9587) * BAEL-3977: Upgrade Guava modules/articles to newest Guava version * BAEL-3977: Guava version upgrade --- .../java/com/baeldung/size/JavaFolderSizeUnitTest.java | 2 +- .../com/baeldung/guava/joinsplit/GuavaStringUnitTest.java | 8 ++++---- parent-java/pom.xml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java b/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java index 467da4f76a..7fd7641a61 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java +++ b/core-java-modules/core-java-io/src/test/java/com/baeldung/size/JavaFolderSizeUnitTest.java @@ -72,7 +72,7 @@ public class JavaFolderSizeUnitTest { public void whenGetFolderSizeUsingGuava_thenCorrect() { final File folder = new File(path); - final Iterable files = com.google.common.io.Files.fileTreeTraverser().breadthFirstTraversal(folder); + final Iterable files = com.google.common.io.Files.fileTraverser().breadthFirst(folder); final long size = StreamSupport.stream(files.spliterator(), false).filter(File::isFile).mapToLong(File::length).sum(); assertEquals(EXPECTED_SIZE, size); diff --git a/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java b/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java index 73c4c3291e..0c480d02a0 100644 --- a/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java +++ b/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java @@ -117,7 +117,7 @@ public class GuavaStringUnitTest { @Test public void whenRemoveSpecialCharacters_thenRemoved() { final String input = "H*el.lo,}12"; - final CharMatcher matcher = CharMatcher.JAVA_LETTER_OR_DIGIT; + final CharMatcher matcher = CharMatcher.javaLetterOrDigit(); final String result = matcher.retainFrom(input); assertEquals("Hello12", result); @@ -127,7 +127,7 @@ public class GuavaStringUnitTest { public void whenRemoveNonASCIIChars_thenRemoved() { final String input = "あhello₤"; - String result = CharMatcher.ASCII.retainFrom(input); + String result = CharMatcher.ascii().retainFrom(input); assertEquals("hello", result); result = CharMatcher.inRange('0', 'z').retainFrom(input); @@ -138,13 +138,13 @@ public class GuavaStringUnitTest { public void whenValidateString_thenValid() { final String input = "hello"; - boolean result = CharMatcher.JAVA_LOWER_CASE.matchesAllOf(input); + boolean result = CharMatcher.javaLowerCase().matchesAllOf(input); assertTrue(result); result = CharMatcher.is('e').matchesAnyOf(input); assertTrue(result); - result = CharMatcher.JAVA_DIGIT.matchesNoneOf(input); + result = CharMatcher.javaDigit().matchesNoneOf(input); assertTrue(result); } diff --git a/parent-java/pom.xml b/parent-java/pom.xml index f56ffbd7f7..d251adcdd3 100644 --- a/parent-java/pom.xml +++ b/parent-java/pom.xml @@ -42,7 +42,7 @@ - 23.0 + 29.0-jre 2.6 1.19 2.3.7 From b0a88534e56635442a05b920242e18df12de4335 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sat, 27 Jun 2020 09:45:28 +0430 Subject: [PATCH 37/44] Moved the Array Length Example to the new Module --- .../test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/{core-java-jvm => core-java-jvm-2}/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java (100%) diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java similarity index 100% rename from core-java-modules/core-java-jvm/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java rename to core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/arraylength/ArrayLengthUnitTest.java From 8fbfc35782ddfbb516d22a76f12c020db98dd266 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 27 Jun 2020 12:57:09 +0300 Subject: [PATCH 38/44] Update README.md --- guava-collections/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava-collections/README.md b/guava-collections/README.md index 51731d7db7..17cdb91ef5 100644 --- a/guava-collections/README.md +++ b/guava-collections/README.md @@ -14,3 +14,4 @@ This module contains articles about Google Guava collections - [Guava – Lists](https://www.baeldung.com/guava-lists) - [Guide to Guava MinMaxPriorityQueue and EvictingQueue](https://www.baeldung.com/guava-minmax-priority-queue-and-evicting-queue) - [Guide to Guava Table](https://www.baeldung.com/guava-table) +- [Guava CharMatcher](https://www.baeldung.com/guava-string-charmatcher) From ef41e8caa191faf4ce4c2348366e6ca7e6ca9e17 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Sat, 27 Jun 2020 18:05:37 +0200 Subject: [PATCH 39/44] BAEL-4312: Add Java Stream example (#9559) --- .../com/baeldung/inttoenum/PizzaStatus.java | 7 ++--- .../baeldung/inttoenum/IntToEnumUnitTest.java | 31 +++++++++++++++---- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/inttoenum/PizzaStatus.java b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/inttoenum/PizzaStatus.java index 8d7c626521..ef8e712a59 100644 --- a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/inttoenum/PizzaStatus.java +++ b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/inttoenum/PizzaStatus.java @@ -21,11 +21,10 @@ public enum PizzaStatus { private static Map timeToDeliveryToEnumValuesMapping = new HashMap<>(); static { - PizzaStatus[] pizzaStatuses = PizzaStatus.values(); - for (int pizzaStatusIndex = 0; pizzaStatusIndex < pizzaStatuses.length; pizzaStatusIndex++) { + for (PizzaStatus pizzaStatus : PizzaStatus.values()) { timeToDeliveryToEnumValuesMapping.put( - pizzaStatuses[pizzaStatusIndex].getTimeToDelivery(), - pizzaStatuses[pizzaStatusIndex] + pizzaStatus.getTimeToDelivery(), + pizzaStatus ); } } diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java index 876c230827..aed8ce0a2b 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/inttoenum/IntToEnumUnitTest.java @@ -1,7 +1,12 @@ package com.baeldung.inttoenum; +import org.assertj.core.api.Assertions; import org.junit.Test; +import java.util.Arrays; +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; public class IntToEnumUnitTest { @@ -9,19 +14,33 @@ public class IntToEnumUnitTest { @Test public void whenIntToEnumUsingValuesMethod_thenReturnEnumObject() { int timeToDeliveryForOrderedPizzaStatus = 5; - PizzaStatus[] pizzaStatuses = PizzaStatus.values(); + PizzaStatus pizzaOrderedStatus = null; - for (int pizzaStatusIndex = 0; pizzaStatusIndex < pizzaStatuses.length; pizzaStatusIndex++) { - if (pizzaStatuses[pizzaStatusIndex].getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) { - pizzaOrderedStatus = pizzaStatuses[pizzaStatusIndex]; + + for (PizzaStatus pizzaStatus : PizzaStatus.values()) { + if (pizzaStatus.getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) { + pizzaOrderedStatus = pizzaStatus; } } - assertEquals(pizzaOrderedStatus, PizzaStatus.ORDERED); + + assertThat(pizzaOrderedStatus).isEqualTo(PizzaStatus.ORDERED); } @Test public void whenIntToEnumUsingMap_thenReturnEnumObject() { int timeToDeliveryForOrderedPizzaStatus = 5; - assertEquals(PizzaStatus.castIntToEnum(timeToDeliveryForOrderedPizzaStatus), PizzaStatus.ORDERED); + + assertThat(PizzaStatus.castIntToEnum(timeToDeliveryForOrderedPizzaStatus)).isEqualTo(PizzaStatus.ORDERED); + } + + @Test + public void whenIntToEnumUsingStream_thenReturnEnumObject() { + int timeToDeliveryForOrderedPizzaStatus = 5; + + Optional pizzaStatus = Arrays.stream(PizzaStatus.values()) + .filter(p -> p.getTimeToDelivery() == timeToDeliveryForOrderedPizzaStatus) + .findFirst(); + + assertThat(pizzaStatus).hasValue(PizzaStatus.ORDERED); } } \ No newline at end of file From 96e48fed8110c7f1d6721a2cf768c49b27d6ebca Mon Sep 17 00:00:00 2001 From: kwoyke Date: Sat, 27 Jun 2020 18:20:22 +0200 Subject: [PATCH 40/44] BAEL-4323: Rename getters to follow Java Beans convention (#9569) --- .../com/baeldung/comparing/PersonWithEquals.java | 6 +++--- .../comparing/PersonWithEqualsAndComparable.java | 12 ++++++++++++ ...PersonWithEqualsAndComparableUsingComparator.java | 12 ++++++------ .../PersonWithEqualsAndWrongComparable.java | 12 ++++++++++++ .../com/baeldung/comparing/PersonWithoutEquals.java | 8 ++++++++ .../comparing/ComparatorInterfaceUnitTest.java | 4 ++-- .../java/com/baeldung/comparing/GuavaUnitTest.java | 4 ++-- 7 files changed, 45 insertions(+), 13 deletions(-) diff --git a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java index e3a61fc05a..1358393538 100644 --- a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java +++ b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEquals.java @@ -22,15 +22,15 @@ public class PersonWithEquals { this.birthDate = birthDate; } - public String firstName() { + public String getFirstName() { return firstName; } - public String lastName() { + public String getLastName() { return lastName; } - public LocalDate birthDate() { + public LocalDate getBirthDate() { return birthDate; } diff --git a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java index 5611ce8a09..b358271cae 100644 --- a/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java +++ b/core-java-modules/core-java-lang-2/src/main/java/com/baeldung/comparing/PersonWithEqualsAndComparable.java @@ -22,6 +22,18 @@ public class PersonWithEqualsAndComparable implements Comparable compareByFirstNames = new Comparator() { @Override public int compare(PersonWithEquals o1, PersonWithEquals o2) { - return o1.firstName().compareTo(o2.firstName()); + return o1.getFirstName().compareTo(o2.getFirstName()); } }; people.sort(compareByFirstNames); @@ -37,7 +37,7 @@ class ComparatorInterfaceUnitTest { people.add(joe); people.add(allan); - Comparator compareByFirstNames = Comparator.comparing(PersonWithEquals::firstName); + Comparator compareByFirstNames = Comparator.comparing(PersonWithEquals::getFirstName); people.sort(compareByFirstNames); assertThat(people).containsExactly(allan, joe); diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java index 5c8591e134..129efd54ea 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparing/GuavaUnitTest.java @@ -63,8 +63,8 @@ class GuavaUnitTest { PersonWithEquals joe = new PersonWithEquals("Joe", "Portman"); int comparisonResult = ComparisonChain.start() - .compare(natalie.lastName(), joe.lastName()) - .compare(natalie.firstName(), joe.firstName()) + .compare(natalie.getLastName(), joe.getLastName()) + .compare(natalie.getFirstName(), joe.getFirstName()) .result(); assertThat(comparisonResult).isPositive(); From 68d0783c374be09b1146464ecf787c5d2fdf9de6 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Sun, 28 Jun 2020 06:57:16 +0200 Subject: [PATCH 41/44] BAEL-4325: Upgrade reddison to 3.13.1 (#9588) * BAEL-4325: Upgrade reddison to 3.13.1 * BAEL-4325: Add jedis.version property --- persistence-modules/redis/pom.xml | 13 ++++++++++--- .../src/main/java/com/baeldung/CustomMessage.java | 4 +++- .../redis/src/main/java/com/baeldung/Ledger.java | 4 +++- .../src/main/resources/singleNodeConfig.json | 7 +------ .../src/main/resources/singleNodeConfig.yaml | 7 +------ .../RedissonConfigurationIntegrationTest.java | 2 +- .../com/baeldung/RedissonIntegrationTest.java | 15 +++++++++------ 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/persistence-modules/redis/pom.xml b/persistence-modules/redis/pom.xml index b8f76c09c4..e4c5eb4002 100644 --- a/persistence-modules/redis/pom.xml +++ b/persistence-modules/redis/pom.xml @@ -33,7 +33,7 @@ redis.clients jedis - ${redisson.version} + ${jedis.version} com.github.kstyrc @@ -48,12 +48,19 @@ io.lettuce lettuce-core - + + + io.netty + netty-transport-native-epoll + ${epoll.version} + 0.6 - 3.3.0 + 3.13.1 + 3.3.0 + 4.1.50.Final diff --git a/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java b/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java index 1d6a7e4e13..26ebe46f64 100644 --- a/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java +++ b/persistence-modules/redis/src/main/java/com/baeldung/CustomMessage.java @@ -1,9 +1,11 @@ package com.baeldung; +import java.io.Serializable; + /** * Created by johnson on 3/9/17. */ -public class CustomMessage { +public class CustomMessage implements Serializable { private String message; public CustomMessage() { diff --git a/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java b/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java index da72791f7e..c9fb81979e 100644 --- a/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java +++ b/persistence-modules/redis/src/main/java/com/baeldung/Ledger.java @@ -1,6 +1,8 @@ package com.baeldung; -public class Ledger { +import java.io.Serializable; + +public class Ledger implements Serializable { public Ledger() { } diff --git a/persistence-modules/redis/src/main/resources/singleNodeConfig.json b/persistence-modules/redis/src/main/resources/singleNodeConfig.json index f56e13dcfc..c46a542b46 100644 --- a/persistence-modules/redis/src/main/resources/singleNodeConfig.json +++ b/persistence-modules/redis/src/main/resources/singleNodeConfig.json @@ -1,13 +1,10 @@ { "singleServerConfig": { "idleConnectionTimeout": 10000, - "pingTimeout": 1000, "connectTimeout": 10000, "timeout": 3000, "retryAttempts": 3, "retryInterval": 1500, - "reconnectionTimeout": 3000, - "failedAttempts": 3, "password": null, "subscriptionsPerConnection": 5, "clientName": null, @@ -17,11 +14,9 @@ "connectionMinimumIdleSize": 10, "connectionPoolSize": 64, "database": 0, - "dnsMonitoring": false, "dnsMonitoringInterval": 5000 }, "threads": 0, "nettyThreads": 0, - "codec": null, - "useLinuxNativeEpoll": false + "codec": null } \ No newline at end of file diff --git a/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml b/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml index 1b05c46be2..9074434bd1 100644 --- a/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml +++ b/persistence-modules/redis/src/main/resources/singleNodeConfig.yaml @@ -1,12 +1,9 @@ singleServerConfig: idleConnectionTimeout: 10000 - pingTimeout: 1000 connectTimeout: 10000 timeout: 3000 retryAttempts: 3 retryInterval: 1500 - reconnectionTimeout: 3000 - failedAttempts: 3 password: null subscriptionsPerConnection: 5 clientName: null @@ -16,9 +13,7 @@ singleServerConfig: connectionMinimumIdleSize: 10 connectionPoolSize: 64 database: 0 - dnsMonitoring: false dnsMonitoringInterval: 5000 threads: 0 nettyThreads: 0 -codec: ! {} -useLinuxNativeEpoll: false \ No newline at end of file +codec: ! {} \ No newline at end of file diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java index 66f61ae5dd..c2e771d7b8 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java @@ -48,7 +48,7 @@ public class RedissonConfigurationIntegrationTest { public void givenJavaConfig_thenRedissonConnectToRedis() { Config config = new Config(); config.useSingleServer() - .setAddress(String.format("127.0.0.1:%s", port)); + .setAddress(String.format("redis://127.0.0.1:%s", port)); client = Redisson.create(config); diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java index 53d77c2699..8c8e6a02dd 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java @@ -7,6 +7,7 @@ import org.redisson.Redisson; import org.redisson.RedissonMultiLock; import org.redisson.api.*; import org.redisson.client.RedisClient; +import org.redisson.client.RedisClientConfig; import org.redisson.client.RedisConnection; import org.redisson.client.codec.StringCodec; import org.redisson.client.protocol.RedisCommands; @@ -103,10 +104,10 @@ public class RedissonIntegrationTest { public void givenTopicSubscribedToAChannel_thenReceiveMessageFromChannel() throws ExecutionException, InterruptedException { CompletableFuture future = new CompletableFuture<>(); - RTopic subscribeTopic = client.getTopic("baeldung"); - subscribeTopic.addListener((channel, customMessage) -> future.complete(customMessage.getMessage())); + RTopic subscribeTopic = client.getTopic("baeldung"); + subscribeTopic.addListener(CustomMessage.class, (channel, customMessage) -> future.complete(customMessage.getMessage())); - RTopic publishTopic = client.getTopic("baeldung"); + RTopic publishTopic = client.getTopic("baeldung"); long clientsReceivedMessage = publishTopic.publish(new CustomMessage("This is a message")); @@ -203,10 +204,10 @@ public class RedissonIntegrationTest { batch.getMap("ledgerMap").fastPutAsync("1", "2"); batch.getMap("ledgerMap").putAsync("2", "5"); - List result = batch.execute(); + BatchResult batchResult = batch.execute(); RMap map = client.getMap("ledgerMap"); - assertTrue(result.size() > 0 && map.get("1").equals("2")); + assertTrue(batchResult.getResponses().size() > 0 && map.get("1").equals("2")); } @Test @@ -220,7 +221,9 @@ public class RedissonIntegrationTest { @Test public void givenLowLevelRedisCommands_thenExecuteLowLevelCommandsOnRedis(){ - RedisClient client = new RedisClient("localhost", 6379); + RedisClientConfig redisClientConfig = new RedisClientConfig(); + redisClientConfig.setAddress("localhost", 6379); + RedisClient client = RedisClient.create(redisClientConfig); RedisConnection conn = client.connect(); conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "test", 0); From 64a6cd08f7a7c393beba55eb6f9ed03590a992be Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 28 Jun 2020 21:23:57 +0300 Subject: [PATCH 42/44] KTLN-137 move kotlin article --- .../java/com/baeldung/observer/IObservable.kt | 18 ------------------ .../java/com/baeldung/observer/IObserver.kt | 5 ----- .../observer/delegates/BaeldungNewsletter.kt | 10 ---------- .../observer/delegates/BaeldungReader.kt | 8 -------- .../observer/standard/BaeldungNewsletter.kt | 14 -------------- .../observer/standard/BaeldungReader.kt | 9 --------- 6 files changed, 64 deletions(-) delete mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt delete mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt delete mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt delete mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt delete mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt delete mode 100644 patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt deleted file mode 100644 index e896d55cf2..0000000000 --- a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObservable.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.observer - -import java.util.ArrayList - -interface IObservable { - val observers: ArrayList - fun add(observer: IObserver) { - observers.add(observer) - } - - fun remove(observer: IObserver) { - observers.remove(observer) - } - - fun sendUpdateEvent() { - observers.forEach { it.update() } - } -} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt deleted file mode 100644 index e2187a9fcb..0000000000 --- a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/IObserver.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.observer - -interface IObserver { - fun update() -} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt deleted file mode 100644 index 748c1064ff..0000000000 --- a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungNewsletter.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.observer.delegates - -import kotlin.properties.Delegates - -class BaeldungNewsletter { - val newestArticleObservers = mutableListOf<(String) -> Unit>() - var newestArticleUrl: String by Delegates.observable("") { _, _, newValue -> - newestArticleObservers.forEach { it(newValue) } - } -} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt deleted file mode 100644 index f275648549..0000000000 --- a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/delegates/BaeldungReader.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.observer.delegates - -fun main() { - val newsletter = BaeldungNewsletter() - newsletter.newestArticleObservers.add { newestArticleUrl -> - println("New Baeldung article: ${newestArticleUrl}") - } -} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt deleted file mode 100644 index 0ec4796edb..0000000000 --- a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungNewsletter.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.observer.standard - -import com.baeldung.observer.IObservable -import com.baeldung.observer.IObserver -import java.util.ArrayList - -class BaeldungNewsletter : IObservable { - override val observers: ArrayList = ArrayList() - var newestArticleUrl = "" - set(value) { - field = value - sendUpdateEvent() - } -} \ No newline at end of file diff --git a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt b/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt deleted file mode 100644 index 14e686f2f8..0000000000 --- a/patterns/design-patterns-behavioral-2/src/main/java/com/baeldung/observer/standard/BaeldungReader.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.observer.standard - -import com.baeldung.observer.IObserver - -class BaeldungReader(private var newsletter: BaeldungNewsletter) : IObserver { - override fun update() { - println("New Baeldung article: ${newsletter.newestArticleUrl}") - } -} \ No newline at end of file From 00973ce2014632745fcc37fcf7fbdcf7f26e376a Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 28 Jun 2020 20:46:29 +0200 Subject: [PATCH 43/44] JAVA-1766 Update core-groovy-2 module --- core-groovy-2/determine-datatype/pom.xml | 44 --------------- .../groovy/determine/datatype/Person.groovy | 14 ----- .../determine/datatype/PersonTest.groovy | 55 ------------------- 3 files changed, 113 deletions(-) delete mode 100644 core-groovy-2/determine-datatype/pom.xml delete mode 100644 core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy delete mode 100644 core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy diff --git a/core-groovy-2/determine-datatype/pom.xml b/core-groovy-2/determine-datatype/pom.xml deleted file mode 100644 index e03cb58ead..0000000000 --- a/core-groovy-2/determine-datatype/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - 4.0.0 - com.baeldung.groovy - determine-datatype - 0.0.1-SNAPSHOT - - src - - - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - - - org.codehaus.gmaven - groovy-maven-plugin - - - org.codehaus.groovy - groovy-all - 2.0.6 - - - - - - - - - org.junit - junit5-engine - ${junit5.version} - - - - - 5.0.0-ALPHA - - \ No newline at end of file diff --git a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy b/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy deleted file mode 100644 index 1a89dce435..0000000000 --- a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/Person.groovy +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.groovy.determine.datatype - -class Person { - - private int ageAsInt - private Double ageAsDouble - private String ageAsString - - Person() {} - Person(int ageAsInt) { this.ageAsInt = ageAsInt} - Person(Double ageAsDouble) { this.ageAsDouble = ageAsDouble} - Person(String ageAsString) { this.ageAsString = ageAsString} -} -class Student extends Person {} diff --git a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy b/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy deleted file mode 100644 index 56095a3f1b..0000000000 --- a/core-groovy-2/determine-datatype/src/com/baeldung/groovy/determine/datatype/PersonTest.groovy +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.groovy.determine.datatype; - -import org.junit.Assert -import org.junit.Test; - -public class PersonTest { - - @Test - public void givenWhenParameterTypeIsInteger_thenReturnTrue() { - Person personObj = new Person(10) - Assert.assertTrue(personObj.ageAsInt instanceof Integer); - } - - @Test - public void givenWhenParameterTypeIsDouble_thenReturnTrue() { - Person personObj = new Person(10.0) - Assert.assertTrue((personObj.ageAsDouble).getClass() == Double) - } - - @Test - public void givenWhenParameterTypeIsString_thenReturnTrue() { - Person personObj = new Person("10 years") - Assert.assertTrue(personObj.ageAsString.class == String) - } - - @Test - public void givenClassName_WhenParameterIsInteger_thenReturnTrue() { - Assert.assertTrue(Person.class.getDeclaredField('ageAsInt').type == int.class) - } - - @Test - public void givenWhenObjectIsInstanceOfType_thenReturnTrue() { - Person personObj = new Person() - Assert.assertTrue(personObj instanceof Person) - } - - @Test - public void givenWhenInstanceIsOfSubtype_thenReturnTrue() { - Student studentObj = new Student() - Assert.assertTrue(studentObj in Person) - } - - @Test - public void givenGroovyList_WhenFindClassName_thenReturnTrue() { - def ageList = ['ageAsString','ageAsDouble', 10] - Assert.assertTrue(ageList.class == ArrayList) - Assert.assertTrue(ageList.getClass() == ArrayList) - } - - @Test - public void givenGrooyMap_WhenFindClassName_thenReturnTrue() { - def ageMap = [ageAsString: '10 years', ageAsDouble: 10.0] - Assert.assertFalse(ageMap.class == LinkedHashMap) - } -} \ No newline at end of file From 80b55f35a5e4f5e7d6ecab5d282dea0d1d5b50b5 Mon Sep 17 00:00:00 2001 From: developerDiv Date: Sun, 28 Jun 2020 21:28:10 +0100 Subject: [PATCH 44/44] Update test to be more specific --- .../test/java/com/baeldung/macaddress/MacAddressUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java index 3786fdcfdd..293e92c690 100644 --- a/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java +++ b/core-java-modules/core-java-networking-2/src/test/java/com/baeldung/macaddress/MacAddressUnitTest.java @@ -7,7 +7,7 @@ import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; public class MacAddressUnitTest { @@ -16,6 +16,6 @@ public class MacAddressUnitTest { InetAddress localHost = InetAddress.getLocalHost(); NetworkInterface ni = NetworkInterface.getByInetAddress(localHost); byte[] macAddress = ni.getHardwareAddress(); - assertNotNull(macAddress); + assertEquals(6, macAddress.length); } }