Updated formatting.
This commit is contained in:
		
							parent
							
								
									6fb230546d
								
							
						
					
					
						commit
						c996f8ccd5
					
				| @ -12,14 +12,14 @@ import org.springframework.web.servlet.view.JstlView; | |||||||
| 
 | 
 | ||||||
| @EnableWebMvc | @EnableWebMvc | ||||||
| @Configuration | @Configuration | ||||||
| @ComponentScan(basePackages = {"com.baeldung.spring.controller"}) | @ComponentScan(basePackages = { "com.baeldung.spring.controller" }) | ||||||
| public class ApplicationConfig extends WebMvcConfigurerAdapter { | public class ApplicationConfig extends WebMvcConfigurerAdapter { | ||||||
| 
 | 
 | ||||||
| 	public ApplicationConfig() { |     public ApplicationConfig() { | ||||||
| 		super(); |         super(); | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@Override |     @Override | ||||||
|     public void addViewControllers(final ViewControllerRegistry registry) { |     public void addViewControllers(final ViewControllerRegistry registry) { | ||||||
|         super.addViewControllers(registry); |         super.addViewControllers(registry); | ||||||
|         registry.addViewController("/").setViewName("index"); |         registry.addViewController("/").setViewName("index"); | ||||||
| @ -27,7 +27,7 @@ public class ApplicationConfig extends WebMvcConfigurerAdapter { | |||||||
| 
 | 
 | ||||||
|     @Bean |     @Bean | ||||||
|     public ViewResolver viewResolver() { |     public ViewResolver viewResolver() { | ||||||
|     	final InternalResourceViewResolver bean = new InternalResourceViewResolver(); |         final InternalResourceViewResolver bean = new InternalResourceViewResolver(); | ||||||
|         bean.setViewClass(JstlView.class); |         bean.setViewClass(JstlView.class); | ||||||
|         bean.setPrefix("/WEB-INF/jsp/"); |         bean.setPrefix("/WEB-INF/jsp/"); | ||||||
|         bean.setSuffix(".jsp"); |         bean.setSuffix(".jsp"); | ||||||
|  | |||||||
| @ -1,19 +1,22 @@ | |||||||
| package com.baeldung.spring.bean; | package com.baeldung.spring.bean; | ||||||
| 
 | 
 | ||||||
| public class Greeting { | public class Greeting { | ||||||
| 	private int id; |     private int id; | ||||||
| 	private String message; |     private String message; | ||||||
| 
 | 
 | ||||||
| 	public int getId() { |     public int getId() { | ||||||
| 		return id; |         return id; | ||||||
| 	} |     } | ||||||
| 	public void setId(int id) { | 
 | ||||||
| 		this.id = id; |     public void setId(int id) { | ||||||
| 	} |         this.id = id; | ||||||
| 	public String getMessage() { |     } | ||||||
| 		return message; | 
 | ||||||
| 	} |     public String getMessage() { | ||||||
| 	public void setMessage(String message) { |         return message; | ||||||
| 		this.message = message; |     } | ||||||
| 	} | 
 | ||||||
|  |     public void setMessage(String message) { | ||||||
|  |         this.message = message; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -12,53 +12,53 @@ import com.baeldung.spring.bean.Greeting; | |||||||
| @Controller | @Controller | ||||||
| public class GreetController { | public class GreetController { | ||||||
| 
 | 
 | ||||||
| 	@RequestMapping(value = "/homePage", method = RequestMethod.GET) |     @RequestMapping(value = "/homePage", method = RequestMethod.GET) | ||||||
| 	public String index() { |     public String index() { | ||||||
| 		return "index"; |         return "index"; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@RequestMapping(value = "/greet", method = RequestMethod.GET, produces = "application/json") |     @RequestMapping(value = "/greet", method = RequestMethod.GET, produces = "application/json") | ||||||
| 	@ResponseBody |     @ResponseBody | ||||||
| 	public Greeting greet() { |     public Greeting greet() { | ||||||
| 		Greeting greeting = new Greeting(); |         Greeting greeting = new Greeting(); | ||||||
| 		greeting.setId(1); |         greeting.setId(1); | ||||||
| 		greeting.setMessage("Hello World!!!"); |         greeting.setMessage("Hello World!!!"); | ||||||
| 		return greeting; |         return greeting; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@RequestMapping(value = "/greetWithPathVariable/{name}", method = RequestMethod.GET, produces = "application/json") |     @RequestMapping(value = "/greetWithPathVariable/{name}", method = RequestMethod.GET, produces = "application/json") | ||||||
| 	@ResponseBody |     @ResponseBody | ||||||
| 	public Greeting greetWithPathVariable(@PathVariable("name") String name) { |     public Greeting greetWithPathVariable(@PathVariable("name") String name) { | ||||||
| 		Greeting greeting = new Greeting(); |         Greeting greeting = new Greeting(); | ||||||
| 		greeting.setId(1); |         greeting.setId(1); | ||||||
| 		greeting.setMessage("Hello World " + name + "!!!"); |         greeting.setMessage("Hello World " + name + "!!!"); | ||||||
| 		return greeting; |         return greeting; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@RequestMapping(value = "/greetWithQueryVariable", method = RequestMethod.GET, produces = "application/json") |     @RequestMapping(value = "/greetWithQueryVariable", method = RequestMethod.GET, produces = "application/json") | ||||||
| 	@ResponseBody |     @ResponseBody | ||||||
| 	public Greeting greetWithQueryVariable(@RequestParam("name") String name) { |     public Greeting greetWithQueryVariable(@RequestParam("name") String name) { | ||||||
| 		Greeting greeting = new Greeting(); |         Greeting greeting = new Greeting(); | ||||||
| 		greeting.setId(1); |         greeting.setId(1); | ||||||
| 		greeting.setMessage("Hello World " + name + "!!!"); |         greeting.setMessage("Hello World " + name + "!!!"); | ||||||
| 		return greeting; |         return greeting; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@RequestMapping(value = "/greetWithPost", method = RequestMethod.POST, produces = "application/json") |     @RequestMapping(value = "/greetWithPost", method = RequestMethod.POST, produces = "application/json") | ||||||
| 	@ResponseBody |     @ResponseBody | ||||||
| 	public Greeting greetWithPost() { |     public Greeting greetWithPost() { | ||||||
| 		Greeting greeting = new Greeting(); |         Greeting greeting = new Greeting(); | ||||||
| 		greeting.setId(1); |         greeting.setId(1); | ||||||
| 		greeting.setMessage("Hello World!!!"); |         greeting.setMessage("Hello World!!!"); | ||||||
| 		return greeting; |         return greeting; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@RequestMapping(value = "/greetWithPostAndFormData", method = RequestMethod.POST, produces = "application/json") |     @RequestMapping(value = "/greetWithPostAndFormData", method = RequestMethod.POST, produces = "application/json") | ||||||
| 	@ResponseBody |     @ResponseBody | ||||||
| 	public Greeting greetWithPostAndFormData(@RequestParam("id") int id, @RequestParam("name") String name) { |     public Greeting greetWithPostAndFormData(@RequestParam("id") int id, @RequestParam("name") String name) { | ||||||
| 		Greeting greeting = new Greeting(); |         Greeting greeting = new Greeting(); | ||||||
| 		greeting.setId(id); |         greeting.setId(id); | ||||||
| 		greeting.setMessage("Hello World " + name + "!!!"); |         greeting.setMessage("Hello World " + name + "!!!"); | ||||||
| 		return greeting; |         return greeting; | ||||||
| 	} |     } | ||||||
| } | } | ||||||
| @ -1,5 +1,5 @@ | |||||||
| <html> | <html> | ||||||
| 	<body> | <body> | ||||||
| 		<h1>Spring MVC - Integration Testing</h1> | 	<h1>Spring MVC - Integration Testing</h1> | ||||||
| 	</body> | </body> | ||||||
| </html> | </html> | ||||||
| @ -1,5 +1,5 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <beans xmlns="http://www.springframework.org/schema/beans" | <beans xmlns="http://www.springframework.org/schema/beans" | ||||||
| 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd" > | 	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd"> | ||||||
| </beans> | </beans> | ||||||
| @ -1,34 +1,33 @@ | |||||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" | <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | 	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||||||
|          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | 	version="3.1"> | ||||||
|          version="3.1"> |  | ||||||
| 
 | 
 | ||||||
|     <display-name>Spring MVC - Integration Testing</display-name> | 	<display-name>Spring MVC - Integration Testing</display-name> | ||||||
| 
 | 
 | ||||||
|     <context-param> | 	<context-param> | ||||||
|         <param-name>contextClass</param-name> | 		<param-name>contextClass</param-name> | ||||||
|         <param-value> | 		<param-value> | ||||||
|         	org.springframework.web.context.support.AnnotationConfigWebApplicationContext |         	org.springframework.web.context.support.AnnotationConfigWebApplicationContext | ||||||
|       	</param-value> |       	</param-value> | ||||||
|     </context-param> | 	</context-param> | ||||||
|     <context-param> | 	<context-param> | ||||||
|         <param-name>contextConfigLocation</param-name> | 		<param-name>contextConfigLocation</param-name> | ||||||
|         <param-value>com.baeldung.spring</param-value> | 		<param-value>com.baeldung.spring</param-value> | ||||||
|     </context-param> | 	</context-param> | ||||||
| 
 | 
 | ||||||
|     <listener> | 	<listener> | ||||||
|         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | 		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | ||||||
|     </listener> | 	</listener> | ||||||
| 
 | 
 | ||||||
|     <servlet> | 	<servlet> | ||||||
|         <servlet-name>spring</servlet-name> | 		<servlet-name>spring</servlet-name> | ||||||
|         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | 		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | ||||||
|         <load-on-startup>1</load-on-startup> | 		<load-on-startup>1</load-on-startup> | ||||||
|     </servlet> | 	</servlet> | ||||||
| 
 | 
 | ||||||
|     <servlet-mapping> | 	<servlet-mapping> | ||||||
|         <servlet-name>spring</servlet-name> | 		<servlet-name>spring</servlet-name> | ||||||
|         <url-pattern>/</url-pattern> | 		<url-pattern>/</url-pattern> | ||||||
|     </servlet-mapping> | 	</servlet-mapping> | ||||||
| </web-app> | </web-app> | ||||||
| @ -28,87 +28,62 @@ import javax.servlet.ServletContext; | |||||||
| @ContextConfiguration(classes = { ApplicationConfig.class }) | @ContextConfiguration(classes = { ApplicationConfig.class }) | ||||||
| public class GreetControllerIntegrationTest { | public class GreetControllerIntegrationTest { | ||||||
| 
 | 
 | ||||||
| 	@Autowired |     @Autowired | ||||||
| 	private WebApplicationContext wac; |     private WebApplicationContext wac; | ||||||
| 
 | 
 | ||||||
| 	private MockMvc mockMvc; |     private MockMvc mockMvc; | ||||||
| 
 | 
 | ||||||
| 	@Before |     @Before | ||||||
| 	public void setup() throws Exception { |     public void setup() throws Exception { | ||||||
| 		this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) |         this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); | ||||||
| //				.alwaysExpect(MockMvcResultMatchers.status().isOk()) |     } | ||||||
| 				.build(); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyWac() { |     public void verifyWac() { | ||||||
| 		ServletContext servletContext = wac.getServletContext(); |         ServletContext servletContext = wac.getServletContext(); | ||||||
| 		Assert.assertNotNull(servletContext); |         Assert.assertNotNull(servletContext); | ||||||
| 		Assert.assertTrue(servletContext instanceof MockServletContext); |         Assert.assertTrue(servletContext instanceof MockServletContext); | ||||||
| 		Assert.assertNotNull(wac.getBean("greetController")); |         Assert.assertNotNull(wac.getBean("greetController")); | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyIndexJspViewName() throws Exception { |     public void verifyIndexJspViewName() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.get("/homePage")).andDo(print()).andExpect(MockMvcResultMatchers.view().name("index")); | ||||||
| 					.perform(MockMvcRequestBuilders.get("/homePage")) |     } | ||||||
| 					.andDo(print()) |  | ||||||
| 					.andExpect(MockMvcResultMatchers.view().name("index")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreet() throws Exception { |     public void verifyGreet() throws Exception { | ||||||
| 		MvcResult mvcResult = this.mockMvc |         MvcResult mvcResult = this.mockMvc.perform(MockMvcRequestBuilders.get("/greet")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")).andReturn(); | ||||||
| 										.perform(MockMvcRequestBuilders.get("/greet")) |         Assert.assertEquals("application/json;charset=UTF-8", mvcResult.getResponse().getContentType()); | ||||||
| 										.andDo(print()) |     } | ||||||
| 										.andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
| 										.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")) |  | ||||||
| 										.andReturn(); |  | ||||||
| 		Assert.assertEquals("application/json;charset=UTF-8", mvcResult.getResponse().getContentType()); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPathVariable() throws Exception { |     public void verifyGreetWithPathVariable() throws Exception { | ||||||
| 		this.mockMvc.perform(MockMvcRequestBuilders.get("/greetWithPathVariable/John")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) |         this.mockMvc.perform(MockMvcRequestBuilders.get("/greetWithPathVariable/John")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) | ||||||
| 				.andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |                 .andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John!!!")); | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John!!!")); |     } | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPathVariable_2() throws Exception { |     public void verifyGreetWithPathVariable_2() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.get("/greetWithPathVariable/{name}", "Doe")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) | ||||||
| 				.perform(MockMvcRequestBuilders.get("/greetWithPathVariable/{name}", "Doe")) |                 .andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World Doe!!!")); | ||||||
| 				.andDo(print()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World Doe!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithQueryVariable() throws Exception { |     public void verifyGreetWithQueryVariable() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.get("/greetWithQueryVariable").param("name", "John Doe")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) | ||||||
| 				.perform(MockMvcRequestBuilders.get("/greetWithQueryVariable").param("name", "John Doe")) |                 .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")); | ||||||
| 				.andDo(print()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPost() throws Exception { |     public void verifyGreetWithPost() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.post("/greetWithPost")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) | ||||||
| 				.perform(MockMvcRequestBuilders.post("/greetWithPost")) |                 .andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")); | ||||||
| 				.andDo(print()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPostAndFormData() throws Exception { |     public void verifyGreetWithPostAndFormData() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.post("/greetWithPostAndFormData").param("id", "1").param("name", "John Doe")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) | ||||||
| 				.perform(MockMvcRequestBuilders.post("/greetWithPostAndFormData").param("id", "1").param("name", "John Doe")) |                 .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")).andExpect(MockMvcResultMatchers.jsonPath("$.id").value(1)); | ||||||
| 				.andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")).andExpect(MockMvcResultMatchers.jsonPath("$.id").value(1)); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| @ -16,68 +16,48 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. | |||||||
| 
 | 
 | ||||||
| public class GreetControllerTest { | public class GreetControllerTest { | ||||||
| 
 | 
 | ||||||
| 	private MockMvc mockMvc; |     private MockMvc mockMvc; | ||||||
| 
 | 
 | ||||||
| 	@Before |     @Before | ||||||
| 	public void setup() { |     public void setup() { | ||||||
| 		this.mockMvc = MockMvcBuilders.standaloneSetup(new GreetController()).build(); |         this.mockMvc = MockMvcBuilders.standaloneSetup(new GreetController()).build(); | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyIndexJspViewName() throws Exception { |     public void verifyIndexJspViewName() throws Exception { | ||||||
| 		this.mockMvc.perform(get("/homePage")) |         this.mockMvc.perform(get("/homePage")).andExpect(view().name("index")); | ||||||
| 				.andExpect(view().name("index")); |     } | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreet() throws Exception { |     public void verifyGreet() throws Exception { | ||||||
| 		this.mockMvc.perform(get("/greet")) |         this.mockMvc.perform(get("/greet")).andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.message").value("Hello World!!!")); | ||||||
| 				.andExpect(status().isOk()) |     } | ||||||
| 				.andExpect(content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(jsonPath("$.message").value("Hello World!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPathVariable() throws Exception { |     public void verifyGreetWithPathVariable() throws Exception { | ||||||
| 		this.mockMvc.perform(get("/greetWithPathVariable/John")) |         this.mockMvc.perform(get("/greetWithPathVariable/John")).andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.message").value("Hello World John!!!")); | ||||||
| 				.andExpect(status().isOk()) |     } | ||||||
| 				.andExpect(content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(jsonPath("$.message").value("Hello World John!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPathVariable_2() throws Exception { |     public void verifyGreetWithPathVariable_2() throws Exception { | ||||||
| 		this.mockMvc.perform(get("/greetWithPathVariable/{name}","Doe")) |         this.mockMvc.perform(get("/greetWithPathVariable/{name}", "Doe")).andExpect(status().isOk()).andExpect(content().contentType("application/json;charset=UTF-8")).andExpect(jsonPath("$.message").value("Hello World Doe!!!")); | ||||||
| 				.andExpect(status().isOk()) |     } | ||||||
| 				.andExpect(content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(jsonPath("$.message").value("Hello World Doe!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithQueryVariable() throws Exception { |     public void verifyGreetWithQueryVariable() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.get("/greetWithQueryVariable").param("name", "John Doe")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) | ||||||
| 				.perform(MockMvcRequestBuilders.get("/greetWithQueryVariable").param("name", "John Doe")) |                 .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")); | ||||||
| 				.andDo(print()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPost() throws Exception { |     public void verifyGreetWithPost() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.post("/greetWithPost")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) | ||||||
| 				.perform(MockMvcRequestBuilders.post("/greetWithPost")) |                 .andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")); | ||||||
| 				.andDo(print()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.status().isOk()) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")); |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	@Test |     @Test | ||||||
| 	public void verifyGreetWithPostAndFormData() throws Exception { |     public void verifyGreetWithPostAndFormData() throws Exception { | ||||||
| 		this.mockMvc |         this.mockMvc.perform(MockMvcRequestBuilders.post("/greetWithPostAndFormData").param("id", "1").param("name", "John Doe")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) | ||||||
| 				.perform(MockMvcRequestBuilders.post("/greetWithPostAndFormData").param("id", "1").param("name", "John Doe")) |                 .andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")).andExpect(MockMvcResultMatchers.jsonPath("$.id").value(1)); | ||||||
| 				.andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()) |     } | ||||||
| 				.andExpect(MockMvcResultMatchers.content().contentType("application/json;charset=UTF-8")) |  | ||||||
| 				.andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World John Doe!!!")).andExpect(MockMvcResultMatchers.jsonPath("$.id").value(1)); |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user