-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef20d41
commit fa9009e
Showing
3 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
src/test/java/guru/springframework/msscbeerservice/MsscBeerServiceApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/guru/springframework/msscbeerservice/web/controller/BeerControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package guru.springframework.msscbeerservice.web.controller; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import guru.springframework.msscbeerservice.web.model.BeerDto; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest(BeerController.class) | ||
class BeerControllerTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@Test | ||
void getBeerById() throws Exception { | ||
|
||
mockMvc.perform(get("/api/v1/beer/" + UUID.randomUUID().toString()).accept(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
|
||
} | ||
|
||
@Test | ||
void saveNewBeer() throws Exception { | ||
|
||
BeerDto beerDto = BeerDto.builder().build(); | ||
String beerDtoJson = objectMapper.writeValueAsString(beerDto); | ||
|
||
mockMvc.perform(post("/api/v1/beer/") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(beerDtoJson)) | ||
.andExpect(status().isCreated()); | ||
} | ||
|
||
@Test | ||
void updateBeerById() throws Exception { | ||
BeerDto beerDto = BeerDto.builder().build(); | ||
String beerDtoJson = objectMapper.writeValueAsString(beerDto); | ||
|
||
mockMvc.perform(put("/api/v1/beer/" + UUID.randomUUID().toString()) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(beerDtoJson)) | ||
.andExpect(status().isNoContent()); | ||
} | ||
} |