|
2 | 2 |
|
3 | 3 | import org.junit.Test; |
4 | 4 | import org.junit.runner.RunWith; |
| 5 | +import org.springframework.beans.factory.annotation.Autowired; |
| 6 | +import org.springframework.beans.factory.annotation.Value; |
| 7 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
5 | 8 | import org.springframework.boot.test.context.SpringBootTest; |
6 | 9 | import org.springframework.test.context.junit4.SpringRunner; |
| 10 | +import org.springframework.test.web.servlet.MockMvc; |
| 11 | +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; |
| 12 | + |
| 13 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 14 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
| 15 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
7 | 16 |
|
8 | 17 | @RunWith(SpringRunner.class) |
9 | 18 | @SpringBootTest |
| 19 | +@AutoConfigureMockMvc |
10 | 20 | public class HacksterServiceApplicationTests { |
| 21 | + @Value("${maxAllowedApartmentsPerRealtor}") |
| 22 | + private int maxAllowedApartmentsPerRealtor; |
| 23 | + |
| 24 | + @Autowired |
| 25 | + private MockMvc mockMvc; |
| 26 | + |
| 27 | + @Test |
| 28 | + public void checkIfNewPhoneNumberIsNotHakster() throws Exception { |
| 29 | + mockMvc.perform(get("/hackster/123123123")) |
| 30 | + .andDo(MockMvcResultHandlers.print()) |
| 31 | + .andExpect(status().isOk()) |
| 32 | + .andExpect(content().string("false")); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void checkIfOldPhoneNumberIsNotHakster() throws Exception { |
| 37 | + mockMvc.perform(get("/hackster/321321")) |
| 38 | + .andDo(MockMvcResultHandlers.print()) |
| 39 | + .andExpect(status().isOk()) |
| 40 | + .andExpect(content().string("false")); |
| 41 | + |
| 42 | + for (int i = 0; i < maxAllowedApartmentsPerRealtor - 1; i++) { |
| 43 | + mockMvc.perform(get("/hackster/321321")); |
| 44 | + } |
11 | 45 |
|
12 | | - @Test |
13 | | - public void contextLoads() { |
14 | | - } |
| 46 | + mockMvc.perform(get("/hackster/321321")) |
| 47 | + .andDo(MockMvcResultHandlers.print()) |
| 48 | + .andExpect(status().isOk()) |
| 49 | + .andExpect(content().string("true")); |
| 50 | + } |
15 | 51 | } |
0 commit comments