Skip to content

Commit

Permalink
Fixing Tests. closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
springframeworkguru committed May 26, 2019
1 parent 9f8cce7 commit 4be5b9c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import guru.springframework.msscbeerservice.web.model.BeerDto;
import guru.springframework.msscbeerservice.web.model.BeerStyleEnum;
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.math.BigDecimal;
import java.util.UUID;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
Expand All @@ -33,7 +35,7 @@ void getBeerById() throws Exception {
@Test
void saveNewBeer() throws Exception {

BeerDto beerDto = BeerDto.builder().build();
BeerDto beerDto = getValidBeerDto();
String beerDtoJson = objectMapper.writeValueAsString(beerDto);

mockMvc.perform(post("/api/v1/beer/")
Expand All @@ -44,12 +46,21 @@ void saveNewBeer() throws Exception {

@Test
void updateBeerById() throws Exception {
BeerDto beerDto = BeerDto.builder().build();
BeerDto beerDto = getValidBeerDto();
String beerDtoJson = objectMapper.writeValueAsString(beerDto);

mockMvc.perform(put("/api/v1/beer/" + UUID.randomUUID().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(beerDtoJson))
.andExpect(status().isNoContent());
}

BeerDto getValidBeerDto(){
return BeerDto.builder()
.beerName("My Beer")
.beerStyle(BeerStyleEnum.ALE)
.price(new BigDecimal("2.99"))
.upc(123123123123L)
.build();
}
}

0 comments on commit 4be5b9c

Please sign in to comment.