* Moved Controller vs RestController article code from spring-mvc-java to spring-mvc-basics
* now using jupiter tests for the tests involved * fixed error in involved test
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
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;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import com.baeldung.web.controller.SimpleBookController;
|
||||
|
||||
public class SimpleBookControllerIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(new SimpleBookController()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookId_whenMockMVC_thenVerifyResponse() throws Exception {
|
||||
this.mockMvc
|
||||
.perform(get("/books/42"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(CONTENT_TYPE))
|
||||
.andExpect(jsonPath("$.id").value(42));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.baeldung.web.controller;
|
||||
|
||||
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;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import com.baeldung.web.controller.SimpleBookController;
|
||||
|
||||
public class SimpleBookRestControllerIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(new SimpleBookController()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBookId_whenMockMVC_thenVerifyResponse() throws Exception {
|
||||
this.mockMvc
|
||||
.perform(get("/books/42"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(CONTENT_TYPE))
|
||||
.andExpect(jsonPath("$.id").value(42));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user