use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceImpl method updateProduct.
@Override
public void updateProduct(Long id, ProductUpdateDTO updatedProduct) {
Product product = getProductById(id);
productMapper.updateToEntity(product, updatedProduct);
productRepo.save(product);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method countOrderCostNotAvailableExTest.
@Test
public void countOrderCostNotAvailableExTest() {
WarehouseInfoDTO fakeWarehouseInfoDTO = getFakeWarehouseInfoDTO();
List<Product> fakeProducts = getFakeProducts();
List<ProductPosition> fakePositions = getFakeProductPositions();
Mockito.when(courierRepo.countWorkingCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 100);
Mockito.when(courierRepo.countDeliveringCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 100);
Mockito.when(warehouseService.getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class))).thenReturn(fakeWarehouseInfoDTO);
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(1L, 1L)).thenReturn(Arrays.asList(fakePositions.get(0), fakePositions.get(1)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(2L, 1L)).thenReturn(Arrays.asList(fakePositions.get(2), fakePositions.get(3)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(3L, 1L)).thenReturn(Arrays.asList(fakePositions.get(4), fakePositions.get(5)));
Mockito.when(productRepo.findById(1l)).thenReturn(Optional.of(fakeProducts.get(0)));
Mockito.when(productRepo.findById(2l)).thenReturn(Optional.of(fakeProducts.get(1)));
Mockito.when(productRepo.findById(3l)).thenReturn(Optional.of(fakeProducts.get(2)));
HashMap<Long, Integer> fakeHashMap = new HashMap<>();
fakeHashMap.put(1L, 4);
fakeHashMap.put(2L, 3);
fakeHashMap.put(3L, 5);
Assertions.assertThrows(ProductAvailabilityEx.class, new Executable() {
@Override
public void execute() throws Throwable {
orderService.countOrderCost(getFakeCoordsDTO(), fakeHashMap, 1L);
}
});
Mockito.verify(productPositionRepo, Mockito.times(3)).findByProductIdAndWarehouseIdWithLock(Mockito.any(Long.class), Mockito.eq(1L));
Mockito.verify(warehouseService, Mockito.times(1)).getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class));
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method createOrderTest.
@Test
public void createOrderTest() {
CreateOrderDTO fakeDTO = new CreateOrderDTO();
User fakeUser = getFakeUserClient();
HashMap<Long, Integer> fakeHashMap = new HashMap<>();
fakeHashMap.put(1L, 2);
fakeHashMap.put(2L, 3);
fakeHashMap.put(3L, 5);
fakeDTO.setProductAmountPairs(fakeHashMap);
fakeDTO.setOverallCost(380.0);
fakeDTO.setHighDemandCoeff(1.0);
fakeDTO.setDiscount(20.0);
fakeDTO.setAddress("address");
fakeDTO.setGeo(getFakeCoordsDTO());
fakeDTO.setWarehouseId(1L);
WarehouseInfoDTO fakeWarehouseInfoDTO = getFakeWarehouseInfoDTO();
List<Product> fakeProducts = getFakeProducts();
List<ProductPosition> fakePositions = getFakeProductPositions();
Mockito.when(courierRepo.countWorkingCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 100);
Mockito.when(courierRepo.countDeliveringCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 50);
Mockito.when(warehouseService.getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class))).thenReturn(fakeWarehouseInfoDTO);
Mockito.when(warehouseService.findById(1L)).thenReturn(getFakeWarehouse1());
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(1L, 1L)).thenReturn(Arrays.asList(fakePositions.get(0), fakePositions.get(1)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(2L, 1L)).thenReturn(Arrays.asList(fakePositions.get(2), fakePositions.get(3)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(3L, 1L)).thenReturn(Arrays.asList(fakePositions.get(4), fakePositions.get(5)));
Mockito.when(productPositionRepo.findById(1L)).thenReturn(Optional.of(fakePositions.get(0)));
Mockito.when(productPositionRepo.findById(2L)).thenReturn(Optional.of(fakePositions.get(1)));
Mockito.when(productPositionRepo.findById(3L)).thenReturn(Optional.of(fakePositions.get(2)));
Mockito.when(productPositionRepo.findById(4L)).thenReturn(Optional.of(fakePositions.get(3)));
Mockito.when(productPositionRepo.findById(5L)).thenReturn(Optional.of(fakePositions.get(4)));
Mockito.when(productPositionRepo.findById(6L)).thenReturn(Optional.of(fakePositions.get(5)));
Mockito.when(productRepo.findById(1l)).thenReturn(Optional.of(fakeProducts.get(0)));
Mockito.when(productRepo.findById(2l)).thenReturn(Optional.of(fakeProducts.get(1)));
Mockito.when(productRepo.findById(3l)).thenReturn(Optional.of(fakeProducts.get(2)));
Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(getFakeOrder());
Mockito.when(courierRepo.getWaitingCourierByWarehouse(1L)).thenReturn(Mockito.mock(Courier.class));
Mockito.when(orderProductPositionRepo.save(Mockito.any(OrderProductPosition.class))).thenReturn(Mockito.mock(OrderProductPosition.class));
orderService.createOrder(fakeDTO, fakeUser);
Mockito.verify(courierRepo, Mockito.times(1)).countWorkingCouriersByWarehouse(1L);
Mockito.verify(courierRepo, Mockito.times(1)).countDeliveringCouriersByWarehouse(1L);
Mockito.verify(productPositionRepo, Mockito.times(6)).findByProductIdAndWarehouseIdWithLock(Mockito.any(Long.class), Mockito.eq(1L));
Mockito.verify(warehouseService, Mockito.times(1)).getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class));
Mockito.verify(orderProductPositionRepo, Mockito.times(3)).save(Mockito.any(OrderProductPosition.class));
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method searchProductInShowcaseSuccess.
@Test
public void searchProductInShowcaseSuccess() {
Pageable pageable = PageRequest.of(0, 2);
Page<Product> productPage = ProductUtils.createPageProductsInShowcase(pageable);
String requestSearchPhrase = "Milk taste";
String perfectPhrase = "Milk:* & taste:*";
Long warehouseId = 4L;
Point geo = makeGeo();
WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
when(productRepoMock.searchProductsInShowcase(perfectPhrase, warehouseId, pageable)).thenReturn(productPage);
SearchProductDTO searchDTO = createSearchProductDTO(requestSearchPhrase);
List<ProductDTO> resultList = productService.searchProductsInShowcase(searchDTO, pageable);
List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productPage);
verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
verify(productRepoMock, times(1)).searchProductsInShowcase(perfectPhrase, warehouseId, pageable);
assertEquals(perfectList, resultList);
}
use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.
the class ProductServiceTest method getProductsInShowcaseSuccess.
@Test
public void getProductsInShowcaseSuccess() {
Pageable pageable = PageRequest.of(0, 2);
Page<Product> productPage = ProductUtils.createPageProductsInShowcase(pageable);
Long warehouseId = 4L;
Point geo = makeGeo();
WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
when(productRepoMock.findAllByInShowcase(warehouseId, pageable)).thenReturn(productPage);
CoordsDTO coordsDTO = makeCoordsDTO();
List<ProductDTO> resultList = productService.getProductsInShowcase(coordsDTO, pageable);
List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productPage);
verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
verify(productRepoMock, times(1)).findAllByInShowcase(warehouseId, pageable);
assertEquals(perfectList, resultList);
}
Aggregations