JAVA-31190: Preparation for migrating spring-boot-modules to version 3. (#15834)
This commit is contained in:
@@ -49,4 +49,8 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<start-class>com.baeldung.Application</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package com.baeldung.application.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
+18
-11
@@ -1,5 +1,22 @@
|
||||
package com.baeldung.ecommerce.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import com.baeldung.ecommerce.dto.OrderProductDto;
|
||||
import com.baeldung.ecommerce.exception.ResourceNotFoundException;
|
||||
import com.baeldung.ecommerce.model.Order;
|
||||
@@ -8,18 +25,8 @@ import com.baeldung.ecommerce.model.OrderStatus;
|
||||
import com.baeldung.ecommerce.service.OrderProductService;
|
||||
import com.baeldung.ecommerce.service.OrderService;
|
||||
import com.baeldung.ecommerce.service.ProductService;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/orders")
|
||||
|
||||
+4
-3
@@ -1,12 +1,13 @@
|
||||
package com.baeldung.ecommerce.controller;
|
||||
|
||||
import com.baeldung.ecommerce.model.Product;
|
||||
import com.baeldung.ecommerce.service.ProductService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.baeldung.ecommerce.model.Product;
|
||||
import com.baeldung.ecommerce.service.ProductService;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/products")
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+13
-7
@@ -1,16 +1,22 @@
|
||||
package com.baeldung.ecommerce.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Transient;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
@Entity
|
||||
@Table(name = "orders")
|
||||
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="orderProducts")
|
||||
|
||||
+4
-4
@@ -2,10 +2,10 @@ package com.baeldung.ecommerce.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Transient;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EmbeddedId;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Transient;
|
||||
|
||||
@Entity
|
||||
public class OrderProduct {
|
||||
|
||||
+6
-5
@@ -1,13 +1,14 @@
|
||||
package com.baeldung.ecommerce.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import java.io.Serializable;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
@Embeddable
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "order")
|
||||
|
||||
+6
-2
@@ -1,7 +1,11 @@
|
||||
package com.baeldung.ecommerce.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
public class Product {
|
||||
|
||||
+4
-3
@@ -1,10 +1,11 @@
|
||||
package com.baeldung.ecommerce.service;
|
||||
|
||||
import com.baeldung.ecommerce.model.OrderProduct;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.baeldung.ecommerce.model.OrderProduct;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Validated
|
||||
public interface OrderProductService {
|
||||
|
||||
+4
-3
@@ -1,10 +1,11 @@
|
||||
package com.baeldung.ecommerce.service;
|
||||
|
||||
import com.baeldung.ecommerce.model.Order;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.baeldung.ecommerce.model.Order;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Validated
|
||||
public interface OrderService {
|
||||
|
||||
+4
-3
@@ -1,10 +1,11 @@
|
||||
package com.baeldung.ecommerce.service;
|
||||
|
||||
import com.baeldung.ecommerce.model.Product;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import com.baeldung.ecommerce.model.Product;
|
||||
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@Validated
|
||||
public interface ProductService {
|
||||
|
||||
+22
-24
@@ -1,37 +1,37 @@
|
||||
package com.baeldung.ecommerce;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import com.baeldung.ecommerce.controller.OrderController;
|
||||
import com.baeldung.ecommerce.controller.ProductController;
|
||||
import com.baeldung.ecommerce.dto.OrderProductDto;
|
||||
import com.baeldung.ecommerce.model.Order;
|
||||
import com.baeldung.ecommerce.model.Product;
|
||||
import org.assertj.core.api.Assertions;
|
||||
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.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasProperty;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = { EcommerceApplication.class }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class EcommerceApplicationIntegrationTest {
|
||||
|
||||
@Autowired private TestRestTemplate restTemplate;
|
||||
|
||||
@LocalServerPort private int port;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired private ProductController productController;
|
||||
|
||||
@@ -80,9 +80,7 @@ public class EcommerceApplicationIntegrationTest {
|
||||
public void givenPostOrder_whenBodyRequestMatcherJson_thenResponseContainsEqualObjectProperties() {
|
||||
final ResponseEntity<Order> postResponse = restTemplate.postForEntity("http://localhost:" + port + "/api/orders", prepareOrderForm(), Order.class);
|
||||
Order order = postResponse.getBody();
|
||||
Assertions
|
||||
.assertThat(postResponse.getStatusCode())
|
||||
.isEqualByComparingTo(HttpStatus.CREATED);
|
||||
assertEquals(HttpStatus.CREATED, postResponse.getStatusCode());
|
||||
|
||||
assertThat(order, hasProperty("status", is("PAID")));
|
||||
assertThat(order.getOrderProducts(), hasItem(hasProperty("quantity", is(2))));
|
||||
|
||||
Reference in New Issue
Block a user