1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.test.web.servlet.samples.standalone;
17
18 import org.junit.Test;
19
20 import org.springframework.http.MediaType;
21 import org.springframework.stereotype.Controller;
22 import org.springframework.test.web.Person;
23 import org.springframework.web.bind.annotation.RequestMapping;
24 import org.springframework.web.bind.annotation.RequestParam;
25 import org.springframework.web.bind.annotation.ResponseBody;
26
27 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
28 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
29 import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
30
31
32
33
34
35
36 public class RequestParameterTests {
37
38 @Test
39 public void queryParameter() throws Exception {
40
41 standaloneSetup(new PersonController()).build()
42 .perform(get("/search?name=George").accept(MediaType.APPLICATION_JSON))
43 .andExpect(status().isOk())
44 .andExpect(content().contentType("application/json;charset=UTF-8"))
45 .andExpect(jsonPath("$.name").value("George"));
46 }
47
48
49 @Controller
50 private class PersonController {
51
52 @RequestMapping(value="/search")
53 @ResponseBody
54 public Person get(@RequestParam String name) {
55 Person person = new Person(name);
56 return person;
57 }
58 }
59
60 }