diff --git a/src/main/java/com/i8ai/training/store/api/ProductController.java b/src/main/java/com/i8ai/training/store/api/ProductController.java index e585f20..9d7f101 100644 --- a/src/main/java/com/i8ai/training/store/api/ProductController.java +++ b/src/main/java/com/i8ai/training/store/api/ProductController.java @@ -44,5 +44,4 @@ public Product replaceProduct(@PathVariable Long productId, @Valid @RequestBody public void deleteProduct(@PathVariable Long productId) { productService.deleteProduct(productId); } - } diff --git a/src/main/java/com/i8ai/training/store/api/ShopController.java b/src/main/java/com/i8ai/training/store/api/ShopController.java index 03596b3..66f8a5b 100644 --- a/src/main/java/com/i8ai/training/store/api/ShopController.java +++ b/src/main/java/com/i8ai/training/store/api/ShopController.java @@ -45,5 +45,4 @@ public Shop replaceShop(@PathVariable Long shopId, @Valid @RequestBody Shop modi public void deleteShop(@PathVariable Long shopId) { shopService.deleteShop(shopId); } - } diff --git a/src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java b/src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java index 3fa843a..55a6c18 100644 --- a/src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java +++ b/src/test/java/com/i8ai/training/store/api/BalanceControllerTest.java @@ -11,7 +11,7 @@ import java.util.List; import static com.i8ai.training.store.util.TestUtils.*; -import static org.mockito.Mockito.when; +import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -20,15 +20,15 @@ @WebMvcTest(BalanceController.class) class BalanceControllerTest { - @MockBean - BalanceService balanceService; - @Autowired MockMvc mockMvc; + @MockBean + BalanceService balanceService; + @Test void getNetBalance() throws Exception { - when(balanceService.getNetBalance(null, null)).thenReturn( + given(balanceService.getNetBalance(null, null)).willReturn( Balance.builder().spent(NET_SALES_EXPENSES).income(NET_SALES_INCOME).build() ); @@ -40,7 +40,7 @@ void getNetBalance() throws Exception { @Test void getBalancesPerProduct() throws Exception { - when(balanceService.getBalancesPerProduct(null, null)).thenReturn(List.of( + given(balanceService.getBalancesPerProduct(null, null)).willReturn(List.of( Balance.builder().spent(PRODUCT_A_EXPENSES).income(PRODUCT_A_INCOME).product(PRODUCT_A).build(), Balance.builder().spent(PRODUCT_B_EXPENSES).income(PRODUCT_B_INCOME).product(PRODUCT_B).build() )); @@ -57,7 +57,7 @@ void getBalancesPerProduct() throws Exception { @Test void getBalanceByProduct() throws Exception { - when(balanceService.getBalanceByProduct(PRODUCT_A.getId(), null, null)).thenReturn( + given(balanceService.getBalanceByProduct(PRODUCT_A.getId(), null, null)).willReturn( Balance.builder().spent(PRODUCT_A_EXPENSES).income(PRODUCT_A_INCOME).product(PRODUCT_A).build() ); @@ -70,7 +70,7 @@ void getBalanceByProduct() throws Exception { @Test void getBalancesByProductPerShop() throws Exception { - when(balanceService.getBalancesByProductPerShop(PRODUCT_B.getId(), null, null)).thenReturn(List.of( + given(balanceService.getBalancesByProductPerShop(PRODUCT_B.getId(), null, null)).willReturn(List.of( Balance.builder().spent(PACK1A_SALES_EXPENSES).income(PACK1A_SALES_INCOME).product(PRODUCT_A).shop(SHOP1).build(), Balance.builder().spent(PACK2B_SALES_EXPENSES).income(PACK2B_SALES_INCOME).product(PRODUCT_B).shop(SHOP2).build() )); @@ -89,7 +89,7 @@ void getBalancesByProductPerShop() throws Exception { @Test void getBalancesPerShop() throws Exception { - when(balanceService.getBalancesPerShop(null, null)).thenReturn(List.of( + given(balanceService.getBalancesPerShop(null, null)).willReturn(List.of( Balance.builder().spent(SHOP1_EXPENSES).income(SHOP1_INCOME).shop(SHOP1).build(), Balance.builder().spent(SHOP2_EXPENSES).income(SHOP2_INCOME).shop(SHOP2).build() )); @@ -106,8 +106,8 @@ void getBalancesPerShop() throws Exception { @Test void getBalanceByShop() throws Exception { - when(balanceService.getBalanceByShop(SHOP1.getId(), null, null)) - .thenReturn(Balance.builder().spent(SHOP1_EXPENSES).income(SHOP1_INCOME).shop(SHOP1).build()); + given(balanceService.getBalanceByShop(SHOP1.getId(), null, null)) + .willReturn(Balance.builder().spent(SHOP1_EXPENSES).income(SHOP1_INCOME).shop(SHOP1).build()); mockMvc.perform(get("/balance/shop/" + SHOP1.getId())) .andExpect(status().isOk()) @@ -118,7 +118,7 @@ void getBalanceByShop() throws Exception { @Test void getBalancesByShopPerProduct() throws Exception { - when(balanceService.getBalancesByShopPerProduct(SHOP2.getId(), null, null)).thenReturn( + given(balanceService.getBalancesByShopPerProduct(SHOP2.getId(), null, null)).willReturn( List.of( Balance.builder() .spent(PACK2A_SALES_EXPENSES) @@ -149,8 +149,8 @@ void getBalancesByShopPerProduct() throws Exception { @Test void getBalanceByProductAndShop() throws Exception { - when(balanceService.getBalanceByProductAndShop(PRODUCT_B.getId(), SHOP2.getId(), null, null)) - .thenReturn( + given(balanceService.getBalanceByProductAndShop(PRODUCT_B.getId(), SHOP2.getId(), null, null)) + .willReturn( Balance.builder() .spent(PACK2B_SALES_EXPENSES) .income(PACK2B_SALES_INCOME) @@ -169,7 +169,7 @@ void getBalanceByProductAndShop() throws Exception { @Test void getBalancesPerProductPerShop() throws Exception { - when(balanceService.getBalancesPerProductPerShop(null, null)).thenReturn( + given(balanceService.getBalancesPerProductPerShop(null, null)).willReturn( List.of( Balance.builder() .spent(PACK1A_SALES_EXPENSES) diff --git a/src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java b/src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java new file mode 100644 index 0000000..1391a33 --- /dev/null +++ b/src/test/java/com/i8ai/training/store/api/ExistenceControllerTest.java @@ -0,0 +1,76 @@ +package com.i8ai.training.store.api; + +import com.i8ai.training.store.service.ExistenceService; +import com.i8ai.training.store.service.data.Existence; +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.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(ExistenceController.class) +class ExistenceControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private ExistenceService existenceService; + + @Test + void testGetAllProductsExistenceInMain() throws Exception { + List existences = Arrays.asList(Existence.builder().build(), Existence.builder().build()); + given(existenceService.getAllProductsExistenceInMain()).willReturn(existences); + + mockMvc.perform(get("/existence")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testGetProductExistenceInMain() throws Exception { + Existence existence = Existence.builder().build(); + given(existenceService.getProductExistenceInMain(anyLong())).willReturn(existence); + + mockMvc.perform(get("/existence/1")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testGetProductExistenceInAllShops() throws Exception { + List existences = Arrays.asList(Existence.builder().build(), Existence.builder().build()); + given(existenceService.getProductExistenceInAllShops(anyLong())).willReturn(existences); + + mockMvc.perform(get("/existence/1/shop")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testGetProductExistenceInShop() throws Exception { + Existence existence = Existence.builder().build(); + given(existenceService.getProductExistenceInShop(anyLong(), anyLong())).willReturn(existence); + + mockMvc.perform(get("/existence/1/shop/1")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").exists()); + } +} diff --git a/src/test/java/com/i8ai/training/store/api/LotControllerTest.java b/src/test/java/com/i8ai/training/store/api/LotControllerTest.java new file mode 100644 index 0000000..74248a7 --- /dev/null +++ b/src/test/java/com/i8ai/training/store/api/LotControllerTest.java @@ -0,0 +1,67 @@ +package com.i8ai.training.store.api; + +import com.i8ai.training.store.model.Lot; +import com.i8ai.training.store.service.LotService; +import com.i8ai.training.store.util.TestUtils; +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.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(LotController.class) +class LotControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private LotService lotService; + + @Test + void testGetLots() throws Exception { + List lots = Arrays.asList(Lot.builder().build(), Lot.builder().build()); + + given(lotService.getLots(null, null, null)).willReturn(lots); + + mockMvc.perform(get("/lot")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testRegisterLot() throws Exception { + Lot newLot = Lot.builder().build(); + Lot savedLot = Lot.builder().build(); + given(lotService.registerLot(any(Lot.class))).willReturn(savedLot); + + mockMvc.perform(post("/lot") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.asJsonString(newLot))) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testDeleteLot() throws Exception { + doNothing().when(lotService).deleteLot(anyLong()); + + mockMvc.perform(delete("/lot/1")) + .andExpect(status().isOk()); + } +} diff --git a/src/test/java/com/i8ai/training/store/api/PackControllerTest.java b/src/test/java/com/i8ai/training/store/api/PackControllerTest.java new file mode 100644 index 0000000..eeef19e --- /dev/null +++ b/src/test/java/com/i8ai/training/store/api/PackControllerTest.java @@ -0,0 +1,66 @@ +package com.i8ai.training.store.api; + +import com.i8ai.training.store.model.Pack; +import com.i8ai.training.store.service.PackService; +import com.i8ai.training.store.util.TestUtils; +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.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(PackController.class) +class PackControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private PackService packService; + + @Test + void testGetPacks() throws Exception { + List packs = Arrays.asList(Pack.builder().build(), Pack.builder().build()); + given(packService.getPacks(null, null, null, null)).willReturn(packs); + + mockMvc.perform(get("/pack")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testRegisterPack() throws Exception { + Pack newPack = Pack.builder().build(); + Pack savedPack = Pack.builder().build(); + given(packService.registerPack(any(Pack.class))).willReturn(savedPack); + + mockMvc.perform(post("/pack") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.asJsonString(newPack))) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testDeletePack() throws Exception { + doNothing().when(packService).deletePack(anyLong()); + + mockMvc.perform(delete("/pack/1")) + .andExpect(status().isOk()); + } +} diff --git a/src/test/java/com/i8ai/training/store/api/ProductControllerTest.java b/src/test/java/com/i8ai/training/store/api/ProductControllerTest.java new file mode 100644 index 0000000..ad9d899 --- /dev/null +++ b/src/test/java/com/i8ai/training/store/api/ProductControllerTest.java @@ -0,0 +1,90 @@ +package com.i8ai.training.store.api; + +import com.i8ai.training.store.model.Product; +import com.i8ai.training.store.service.ProductService; +import com.i8ai.training.store.util.TestUtils; +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.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(ProductController.class) +class ProductControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private ProductService productService; + + @Test + void testGetAllProducts() throws Exception { + List products = Arrays.asList(Product.builder().build(), Product.builder().build()); + given(productService.getAllProducts()).willReturn(products); + + mockMvc.perform(get("/product")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testAddProduct() throws Exception { + Product newProduct = Product.builder().build(); + Product savedProduct = Product.builder().build(); + given(productService.addProduct(any(Product.class))).willReturn(savedProduct); + + mockMvc.perform(post("/product") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.asJsonString(newProduct))) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testGetProduct() throws Exception { + Product product = Product.builder().build(); + given(productService.getProduct(anyLong())).willReturn(product); + + mockMvc.perform(get("/product/1")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testReplaceProduct() throws Exception { + Product modifiedProduct = Product.builder().build(); + given(productService.replaceProduct(anyLong(), any(Product.class))).willReturn(modifiedProduct); + + mockMvc.perform(put("/product/1") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"someField\":\"someValue\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testDeleteProduct() throws Exception { + doNothing().when(productService).deleteProduct(anyLong()); + + mockMvc.perform(delete("/product/1")) + .andExpect(status().isOk()); + } +} diff --git a/src/test/java/com/i8ai/training/store/api/SaleControllerTest.java b/src/test/java/com/i8ai/training/store/api/SaleControllerTest.java new file mode 100644 index 0000000..f3cd149 --- /dev/null +++ b/src/test/java/com/i8ai/training/store/api/SaleControllerTest.java @@ -0,0 +1,66 @@ +package com.i8ai.training.store.api; + +import com.i8ai.training.store.model.Sale; +import com.i8ai.training.store.service.SaleService; +import com.i8ai.training.store.util.TestUtils; +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.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(SaleController.class) +class SaleControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private SaleService saleService; + + @Test + void testGetSales() throws Exception { + List sales = Arrays.asList(Sale.builder().build(), Sale.builder().build()); + given(saleService.getSales(null, null, null, null)).willReturn(sales); + + mockMvc.perform(get("/sale")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testRegisterSale() throws Exception { + Sale newSale = Sale.builder().build(); + Sale savedSale = Sale.builder().build(); + given(saleService.registerSale(any(Sale.class))).willReturn(savedSale); + + mockMvc.perform(post("/sale") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.asJsonString(newSale))) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testDeleteSale() throws Exception { + doNothing().when(saleService).deleteSale(anyLong()); + + mockMvc.perform(delete("/sale/1")) + .andExpect(status().isOk()); + } +} diff --git a/src/test/java/com/i8ai/training/store/api/ShopControllerTest.java b/src/test/java/com/i8ai/training/store/api/ShopControllerTest.java new file mode 100644 index 0000000..ee2ebac --- /dev/null +++ b/src/test/java/com/i8ai/training/store/api/ShopControllerTest.java @@ -0,0 +1,90 @@ +package com.i8ai.training.store.api; + +import com.i8ai.training.store.model.Shop; +import com.i8ai.training.store.service.ShopService; +import com.i8ai.training.store.util.TestUtils; +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.util.Arrays; +import java.util.List; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doNothing; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@WebMvcTest(ShopController.class) +class ShopControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private ShopService shopService; + + @Test + void testGetAllShops() throws Exception { + List shops = Arrays.asList(Shop.builder().build(), Shop.builder().build()); + given(shopService.getAllShops()).willReturn(shops); + + mockMvc.perform(get("/shop")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").isArray()) + .andExpect(jsonPath("$[0]").exists()) + .andExpect(jsonPath("$[1]").exists()); + } + + @Test + void testAddShop() throws Exception { + Shop newShop = Shop.builder().build(); + Shop savedShop = Shop.builder().build(); + given(shopService.addShop(any(Shop.class))).willReturn(savedShop); + + mockMvc.perform(post("/shop") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.asJsonString(newShop))) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testGetShop() throws Exception { + Shop shop = Shop.builder().build(); + given(shopService.getShop(anyLong())).willReturn(shop); + + mockMvc.perform(get("/shop/1")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testReplaceShop() throws Exception { + Shop modifiedShop = Shop.builder().build(); + given(shopService.replaceShop(anyLong(), any(Shop.class))).willReturn(modifiedShop); + + mockMvc.perform(put("/shop/1") + .contentType(MediaType.APPLICATION_JSON) + .content(TestUtils.asJsonString(modifiedShop))) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json")) + .andExpect(jsonPath("$").exists()); + } + + @Test + void testDeleteShop() throws Exception { + doNothing().when(shopService).deleteShop(anyLong()); + + mockMvc.perform(delete("/shop/1")) + .andExpect(status().isOk()); + } +} diff --git a/src/test/java/com/i8ai/training/store/util/TestUtils.java b/src/test/java/com/i8ai/training/store/util/TestUtils.java index 6761e40..2c83461 100644 --- a/src/test/java/com/i8ai/training/store/util/TestUtils.java +++ b/src/test/java/com/i8ai/training/store/util/TestUtils.java @@ -1,5 +1,6 @@ package com.i8ai.training.store.util; +import com.fasterxml.jackson.databind.ObjectMapper; import com.i8ai.training.store.model.*; import java.util.Date; @@ -118,4 +119,13 @@ public class TestUtils { .id(0x1A35L).registered(new Date(65)).amount(SALE_2B65_AMOUNT).price(PRODUCT_B_PRICE).pack(PACK2B).build(); public static final Sale SALE_2B70 = Sale.builder() .id(0x1A35L).registered(new Date(70)).amount(SALE_2B70_AMOUNT).price(PRODUCT_B_PRICE).pack(PACK2B).build(); + + + public static String asJsonString(final Object obj) { + try { + return new ObjectMapper().writeValueAsString(obj); + } catch (Exception e) { + throw new RuntimeException(e); + } + } }