/
OutputControllerTest.java
56 lines (46 loc) · 2.13 KB
/
OutputControllerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pro.jaitl.spring.examples.validation.controller;
import org.junit.jupiter.api.Test;
import pro.jaitl.spring.examples.validation.dto.OutputDto;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
class OutputControllerTest extends BaseApiTest {
@Test
public void testOutput_Create_Valid() throws Exception {
OutputDto outputDto = new OutputDto();
outputDto.setName("test");
outputDto.setOutputId(1);
mockMvc.perform(doPost("/v1/outputs", outputDto))
.andExpect(status().isOk());
}
@Test
public void testOutput_Create_Invalid() throws Exception {
OutputDto outputDto = new OutputDto();
outputDto.setName(null);
outputDto.setOutputId(null);
mockMvc.perform(doPost("/v1/outputs", outputDto))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code", equalTo(400)))
.andExpect(jsonPath("$.error", containsString("outputId: must not be null")))
.andExpect(jsonPath("$.error", containsString("name: must not be null")));
}
@Test
public void testOutput_Update_Valid() throws Exception {
OutputDto outputDto = new OutputDto();
outputDto.setName(null);
outputDto.setOutputId(null);
mockMvc.perform(doPut("/v1/outputs", outputDto))
.andExpect(status().isOk());
}
@Test
public void testOutput_Update_Invalid() throws Exception {
OutputDto outputDto = new OutputDto();
outputDto.setName("it's longer than 20 characters");
outputDto.setOutputId(-1);
mockMvc.perform(doPut("/v1/outputs", outputDto))
.andExpect(jsonPath("$.code", equalTo(400)))
.andExpect(jsonPath("$.error", containsString("outputId: must be greater than or equal to 0")))
.andExpect(jsonPath("$.error", containsString("name: size must be between 0 and 20")));
}
}