JAVA-31190: Preparation for migrating spring-boot-modules to version 3. (#15834)

This commit is contained in:
Harry9656
2024-02-27 02:49:02 +01:00
committed by GitHub
parent 74da22b9c4
commit aefd833c3b
190 changed files with 1052 additions and 832 deletions
@@ -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))));