Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
- public ResponseEntity<Shop> createShop(@ModelAttribute Shop newShop) {
- long newShopId = shopService.add(newShop);
- Shop shop = shopService.get(newShopId);
- return new ResponseEntity<Shop>(shop, HttpStatus.CREATED);
- }
- @Test
- public void testCreateShop() throws Exception {
- Shop returnShop = Shop.builder().id(0L).name("shop1").latitude(1.0).latitude(1.0).build();
- Shop shop = Shop.builder().id(1L).name("shop1").latitude(1.0).latitude(1.0).build();
- when(shopServiceMock.add(returnShop)).thenReturn(1L);
- when(shopServiceMock.get(1L)).thenReturn(shop);
- ObjectMapper objectMapper = new ObjectMapper();
- byte[] jsonShop = objectMapper.writeValueAsBytes(returnShop);
- mockMvc.perform(post("/api/shops/add").contentType(TestUtil.APPLICATION_JSON_UTF8).content(jsonShop))
- .andExpect(status().isCreated())
- .andExpect(jsonPath("$.id", is(1)))
- .andExpect(jsonPath("$.name", is("shop1")));
- }
Advertisement
Add Comment
Please, Sign In to add comment