forked from rehmanmuradali/springboot-java8
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGreetingAndHelloControllerTest.java
More file actions
60 lines (51 loc) · 2.34 KB
/
Copy pathGreetingAndHelloControllerTest.java
File metadata and controls
60 lines (51 loc) · 2.34 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
package hello.controller;
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.test.web.servlet.MockMvc;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
class GreetingAndHelloControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
void greetingDefaultsToWorld() throws Exception {
mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.content").value("Hello, World!"));
}
@Test
void greetingUsesNameParam() throws Exception {
mockMvc.perform(get("/").param("name", "Devin"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.content").value("Hello, Devin!"));
}
@Test
void datetimeEndpoint() throws Exception {
mockMvc.perform(get("/datetime"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Greetings from Spring Boot!")))
.andExpect(content().string(containsString("Time in California:")));
}
@Test
void stringOperationEndpoint() throws Exception {
mockMvc.perform(get("/topic/string/operation"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("spring:java:javascript")))
.andExpect(content().string(containsString("java:javascript")))
.andExpect(content().string(containsString("[spring]")));
}
@Test
void fileOperationEndpoint() throws Exception {
mockMvc.perform(get("/topic/file/operation"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Read \"temp.txt\"")))
.andExpect(content().string(containsString(" Hello, this, is, Rehman")));
}
}