-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : fix issue with mapping child in parent
- Loading branch information
1 parent
bd960e6
commit 0a17713
Showing
5 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
import com.example.hibernatecache.repositories.OrderItemRepository; | ||
import com.example.hibernatecache.repositories.OrderRepository; | ||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -51,26 +50,31 @@ void setUp() { | |
.setFirstName("firstName 1") | ||
.setLastName("lastName 1") | ||
.setEmail("[email protected]") | ||
.setPhone("9876543211")); | ||
savedOrder = | ||
orderRepository.persist( | ||
new Order() | ||
.setName("First Order") | ||
.setPrice(BigDecimal.TEN) | ||
.setCustomer(savedCustomer)); | ||
|
||
orderItemList = new ArrayList<>(); | ||
orderItemList.add(new OrderItem().setText("First OrderItem").setOrder(savedOrder)); | ||
orderItemList.add(new OrderItem().setText("Second OrderItem").setOrder(savedOrder)); | ||
orderItemList.add(new OrderItem().setText("Third OrderItem").setOrder(savedOrder)); | ||
orderItemList = orderItemRepository.persistAll(orderItemList); | ||
.setPhone("9876543211") | ||
.addOrder( | ||
new Order() | ||
.setName("First Order") | ||
.setPrice(BigDecimal.TEN) | ||
.addOrderItem( | ||
new OrderItem().setText("First OrderItem")) | ||
.addOrderItem( | ||
new OrderItem().setText("Second OrderItem")) | ||
.addOrderItem( | ||
new OrderItem() | ||
.setText("Third OrderItem")))); | ||
savedOrder = savedCustomer.getOrders().getFirst(); | ||
orderItemList = savedOrder.getOrderItems(); | ||
} | ||
|
||
@Test | ||
void shouldFetchAllOrderItems() throws Exception { | ||
this.mockMvc | ||
.perform(get("/api/order/items")) | ||
.andExpect(status().isOk()) | ||
.andExpect( | ||
header().string( | ||
HttpHeaders.CONTENT_TYPE, | ||
is(MediaType.APPLICATION_JSON_VALUE))) | ||
.andExpect(jsonPath("$.data.size()", is(orderItemList.size()))) | ||
.andExpect(jsonPath("$.totalElements", is(3))) | ||
.andExpect(jsonPath("$.pageNumber", is(1))) | ||
|
@@ -89,6 +93,10 @@ void shouldFindOrderItemById() throws Exception { | |
this.mockMvc | ||
.perform(get("/api/order/items/{id}", orderItemId)) | ||
.andExpect(status().isOk()) | ||
.andExpect( | ||
header().string( | ||
HttpHeaders.CONTENT_TYPE, | ||
is(MediaType.APPLICATION_JSON_VALUE))) | ||
.andExpect(jsonPath("$.orderItemId", is(orderItem.getId()), Long.class)) | ||
.andExpect(jsonPath("$.text", is(orderItem.getText()))); | ||
} | ||
|
@@ -104,6 +112,10 @@ void shouldCreateNewOrderItem() throws Exception { | |
.content(objectMapper.writeValueAsString(orderItemRequest))) | ||
.andExpect(status().isCreated()) | ||
.andExpect(header().exists(HttpHeaders.LOCATION)) | ||
.andExpect( | ||
header().string( | ||
HttpHeaders.CONTENT_TYPE, | ||
is(MediaType.APPLICATION_JSON_VALUE))) | ||
.andExpect(jsonPath("$.orderItemId", notNullValue())) | ||
.andExpect(jsonPath("$.text", is(orderItemRequest.text()))); | ||
} | ||
|
@@ -118,7 +130,10 @@ void shouldReturn400WhenCreateNewOrderItemWithoutText() throws Exception { | |
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(orderItemRequest))) | ||
.andExpect(status().isBadRequest()) | ||
.andExpect(header().string("Content-Type", is("application/problem+json"))) | ||
.andExpect( | ||
header().string( | ||
HttpHeaders.CONTENT_TYPE, | ||
is(MediaType.APPLICATION_PROBLEM_JSON_VALUE))) | ||
.andExpect(jsonPath("$.type", is("about:blank"))) | ||
.andExpect(jsonPath("$.title", is("Constraint Violation"))) | ||
.andExpect(jsonPath("$.status", is(400))) | ||
|
@@ -142,6 +157,10 @@ void shouldUpdateOrderItem() throws Exception { | |
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(orderItemRequest))) | ||
.andExpect(status().isOk()) | ||
.andExpect( | ||
header().string( | ||
HttpHeaders.CONTENT_TYPE, | ||
is(MediaType.APPLICATION_JSON_VALUE))) | ||
.andExpect(jsonPath("$.orderItemId", is(orderItemId), Long.class)) | ||
.andExpect(jsonPath("$.text", is(orderItemRequest.text()))); | ||
} | ||
|
@@ -153,6 +172,10 @@ void shouldDeleteOrderItem() throws Exception { | |
this.mockMvc | ||
.perform(delete("/api/order/items/{id}", orderItem.getId())) | ||
.andExpect(status().isOk()) | ||
.andExpect( | ||
header().string( | ||
HttpHeaders.CONTENT_TYPE, | ||
is(MediaType.APPLICATION_JSON_VALUE))) | ||
.andExpect(jsonPath("$.orderItemId", is(orderItem.getId()), Long.class)) | ||
.andExpect(jsonPath("$.text", is(orderItem.getText()))); | ||
} | ||
|