Skip to content

Commit

Permalink
#294 - added version for preventing extra call
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Sep 2, 2023
1 parent a5e3fbc commit 6e389d4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
Expand All @@ -38,6 +39,8 @@ public class Order {

private String source;

@Version private Long version;

@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderItem> items = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</column>
<column name="source" type="${string.type}" />
<column name="status" type="${string.type}" />
<column name="version" type="bigint" />
</createTable>

<createTable tableName="order_items">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,27 @@ void setUp() {
orderRepository.deleteAll();

orderList = new ArrayList<>();
Order order1 = new Order(null, 1L, "NEW", null, new ArrayList<>());
Order order1 = new Order();
order1.setCustomerId(1L);
order1.setStatus("NEW");
OrderItem orderItem = new OrderItem();
orderItem.setProductId("Product1");
orderItem.setQuantity(10);
orderItem.setProductPrice(BigDecimal.TEN);
order1.addOrderItem(orderItem);
this.orderList.add(order1);
Order order2 = new Order(null, 1L, "NEW", null, new ArrayList<>());
Order order2 = new Order();
order2.setCustomerId(1L);
order2.setStatus("NEW");
OrderItem orderItem1 = new OrderItem();
orderItem1.setProductId("Product2");
orderItem1.setQuantity(100);
orderItem1.setProductPrice(BigDecimal.ONE);
order2.addOrderItem(orderItem1);
this.orderList.add(order2);
Order order3 = new Order(null, 1L, "NEW", null, new ArrayList<>());
Order order3 = new Order();
order3.setCustomerId(1L);
order3.setStatus("NEW");
OrderItem orderItem2 = new OrderItem();
orderItem2.setProductId("Product2");
orderItem2.setQuantity(100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void shouldUpdateOrder() throws Exception {
void shouldReturn404WhenUpdatingNonExistingOrder() throws Exception {
Long orderId = 1L;
given(orderService.findOrderById(orderId)).willReturn(Optional.empty());
Order order = new Order(1L, 1L, "CONFIRMED", null, new ArrayList<>());
OrderRequest order = new OrderRequest(1L, new ArrayList<>());

this.mockMvc
.perform(
Expand Down

0 comments on commit 6e389d4

Please sign in to comment.