-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathPaymentControllerTest.java
More file actions
79 lines (60 loc) · 2.7 KB
/
PaymentControllerTest.java
File metadata and controls
79 lines (60 loc) · 2.7 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.bravo.user.controller;
import com.bravo.user.App;
import com.bravo.user.service.PaymentService;
import com.bravo.user.util.TestUtil;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ContextConfiguration(classes = {App.class})
@ExtendWith(SpringExtension.class)
@SpringBootTest()
@AutoConfigureMockMvc
class PaymentControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private PaymentService paymentService;
@Test
void retrievePaymentsByUser() throws Exception {
final String userId = "user-id";
when(paymentService.retrieveByUserId(userId)).thenReturn(TestUtil.getPaymentsDto());
final MvcResult result = this.mockMvc
.perform(get("/payment/retrieve/" + userId))
.andExpect(status().isOk())
.andReturn();
String responseBody = result.getResponse().getContentAsString();
assertNotNull(result);
assertNotNull(responseBody);
assertTrue(responseBody.contains("\"id\" : \"15040055-a640-4cea-cfb7-357669fcdefe\""));
}
@Test
void retrievePaymentsByUserEmptyPayments() throws Exception {
final String userId = "user-id";
when(paymentService.retrieveByUserId(userId)).thenReturn(Collections.emptyList());
final MvcResult result = this.mockMvc
.perform(get("/payment/retrieve/" + userId))
.andExpect(status().isOk())
.andReturn();
String responseBody = result.getResponse().getContentAsString();
assertNotNull(result);
assertEquals(responseBody, "[ ]");
}
@Test
void retrievePaymentsByUserNotFound() throws Exception {
this.mockMvc.perform(get("/payment/retrieve/")).andExpect(status().isNotFound());
}
}