32 lines
1017 B
Java
32 lines
1017 B
Java
package com.baeldung.web.controller;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
public class SimpleBookRestControllerIntegrationTest {
|
|
|
|
private MockMvc mockMvc;
|
|
|
|
@BeforeEach
|
|
public void setup() {
|
|
this.mockMvc = MockMvcBuilders.standaloneSetup(new SimpleBookRestController()).build();
|
|
}
|
|
|
|
@Test
|
|
public void givenBookId_whenMockMVC_thenVerifyResponse() throws Exception {
|
|
this.mockMvc
|
|
.perform(get("/books-rest/42"))
|
|
.andExpect(status().isOk())
|
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
|
.andExpect(jsonPath("$.id").value(42));
|
|
}
|
|
|
|
}
|
|
|