Currently for creating a new Order we use below code,
public record OrderRequest(
@Positive(message = "CustomerId should be positive") Long customerId,
@NotEmpty(message = "Order without items not valid") List<OrderItemRequest> items) {}
we have validation set up at the Order (parent) level. However, we need to extend this validation to the OrderItem level (child) to ensure that all key attributes are properly validated.
Specifically, we need to enforce the following validation rules for OrderItemRequest:
- Quantity should not be zero.
- Price should not be zero.
- A valid product code must be provided.
To implement this enhancement, the following tasks need to be completed:
- Modify
OrderItemRequest.java
: Add validation logic to the OrderItemRequest class to enforce the above-mentioned rules.
- Create a New JUnit : Develop a new test case in the
OrderControllerIT.java
class to demonstrate that the extended validation at the child level is functioning correctly. This test case should cover various scenarios to ensure thorough testing.