-
Notifications
You must be signed in to change notification settings - Fork 1
/
HelloControllerTests.java
38 lines (32 loc) · 1.42 KB
/
HelloControllerTests.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
package org.acme.externalconfig.rest;
import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
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;
@SpringBootTest(properties = { "spring.cloud.kubernetes.config.enabled=false" })
@AutoConfigureMockMvc
class HelloControllerTests {
@Autowired
MockMvc mockMvc;
@Test
public void helloNoSubPath() throws Exception {
this.mockMvc.perform(get("/hello").accept(TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(TEXT_PLAIN))
.andExpect(content().string("Hello World"));
}
@ParameterizedTest
@ValueSource(strings = { "Yoda", "Darth Vader" })
public void helloSubPath(String subpath) throws Exception {
this.mockMvc.perform(get("/hello/{name}", subpath).accept(TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(TEXT_PLAIN))
.andExpect(content().string("Hello " + subpath));
}
}