Skip to content

Commit

Permalink
updating UPC, closes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
springframeworkguru committed Jun 7, 2019
1 parent f77647f commit 6edba6b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
@Component
public class BeerLoader implements CommandLineRunner {

public static final String BEER_1_UPC = "0631234200036";
public static final String BEER_2_UPC = "0631234300019";
public static final String BEER_3_UPC = "0083783375213";

private final BeerRepository beerRepository;

public BeerLoader(BeerRepository beerRepository) {
Expand All @@ -32,7 +36,7 @@ private void loadBeerObjects() {
.beerStyle("IPA")
.quantityToBrew(200)
.minOnHand(12)
.upc(337010000001L)
.upc(BEER_1_UPC)
.price(new BigDecimal("12.95"))
.build());

Expand All @@ -41,7 +45,16 @@ private void loadBeerObjects() {
.beerStyle("PALE_ALE")
.quantityToBrew(200)
.minOnHand(12)
.upc(337010000002L)
.upc(BEER_2_UPC)
.price(new BigDecimal("11.95"))
.build());

beerRepository.save(Beer.builder()
.beerName("No Hammers On The Bar")
.beerStyle("PALE_ALE")
.quantityToBrew(200)
.minOnHand(12)
.upc(BEER_3_UPC)
.price(new BigDecimal("11.95"))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Beer {
private String beerStyle;

@Column(unique = true)
private Long upc;
private String upc;

private BigDecimal price;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ public class BeerDto {
@NotNull
private BeerStyleEnum beerStyle;

@Positive
@NotNull
private Long upc;
private String upc;

@JsonFormat(shape = JsonFormat.Shape.STRING)
@Positive
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package guru.springframework.msscbeerservice.web.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import guru.springframework.msscbeerservice.bootstrap.BeerLoader;
import guru.springframework.msscbeerservice.services.BeerService;
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.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import java.math.BigDecimal;
import java.util.UUID;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand All @@ -24,9 +29,14 @@ class BeerControllerTest {
@Autowired
ObjectMapper objectMapper;

@MockBean
BeerService beerService;

@Test
void getBeerById() throws Exception {

given(beerService.getById(any())).willReturn(getValidBeerDto());

mockMvc.perform(get("/api/v1/beer/" + UUID.randomUUID().toString()).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());

Expand All @@ -38,6 +48,8 @@ void saveNewBeer() throws Exception {
BeerDto beerDto = getValidBeerDto();
String beerDtoJson = objectMapper.writeValueAsString(beerDto);

given(beerService.saveNewBeer(any())).willReturn(getValidBeerDto());

mockMvc.perform(post("/api/v1/beer/")
.contentType(MediaType.APPLICATION_JSON)
.content(beerDtoJson))
Expand All @@ -46,6 +58,8 @@ void saveNewBeer() throws Exception {

@Test
void updateBeerById() throws Exception {
given(beerService.updateBeer(any(), any())).willReturn(getValidBeerDto());

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

Expand All @@ -60,7 +74,7 @@ BeerDto getValidBeerDto(){
.beerName("My Beer")
.beerStyle(BeerStyleEnum.ALE)
.price(new BigDecimal("2.99"))
.upc(123123123123L)
.upc(BeerLoader.BEER_1_UPC)
.build();
}
}

0 comments on commit 6edba6b

Please sign in to comment.