42 lines
1.5 KiB
Java
42 lines
1.5 KiB
Java
package me.bvn13.test.spring.validation.atleastonegroup.web.product;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
@AutoConfigureMockMvc
|
|
@SpringBootTest
|
|
public class ProductControllerTest {
|
|
|
|
@Autowired
|
|
MockMvc mockMvc;
|
|
|
|
@Autowired
|
|
ObjectMapper objectMapper;
|
|
|
|
@Test
|
|
void testValidation() throws Exception {
|
|
mockMvc.perform(post("/api/products")
|
|
.contentType(MediaType.APPLICATION_JSON)
|
|
.content(objectMapper.writeValueAsString(aCreateCardRequest())))
|
|
.andDo(print())
|
|
.andExpect(status().isBadRequest())
|
|
.andExpect(jsonPath("$.status").value("VALIDATION_ERROR: Validation error"))
|
|
.andExpect(jsonPath("$.response").isMap())
|
|
.andExpect(jsonPath("$.response.createProductRequestDto").exists());
|
|
}
|
|
|
|
CreateProductRequestDto aCreateCardRequest() {
|
|
return CreateProductRequestDto.builder().build();
|
|
}
|
|
|
|
}
|