Search in sources :

Example 1 with ProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceTest method searchProductsSuccess.

@Test
public void searchProductsSuccess() {
    Pageable pageable = PageRequest.of(0, 2);
    Page<Product> productPage = ProductUtils.createPageWithMilkProducts(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.searchProducts(perfectPhrase, warehouseId, pageable)).thenReturn(productPage);
    SearchProductDTO searchDTO = createSearchProductDTO(requestSearchPhrase);
    List<ProductDTO> resultList = productService.searchProducts(searchDTO, pageable);
    List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productPage);
    verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
    verify(productRepoMock, times(1)).searchProducts(perfectPhrase, warehouseId, pageable);
    assertEquals(resultList, perfectList);
}
Also used : Pageable(org.springframework.data.domain.Pageable) Product(com.ncedu.fooddelivery.api.v1.entities.Product) Point(com.vividsolutions.jts.geom.Point) SearchProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO) ProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO) WarehouseInfoDTO(com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO) SearchProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceTest method getProductDTOByIDSuccess.

@Test
public void getProductDTOByIDSuccess() {
    Long productId = 1L;
    Product product = ProductUtils.createMilkInShowcase(productId);
    when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
    ProductDTO resultDTO = productService.getProductDTOById(productId);
    ProductDTO perfectDTO = createProductDTO(product);
    verify(productRepoMock, times(1)).findById(productId);
    assertEquals(perfectDTO, resultDTO);
}
Also used : Product(com.ncedu.fooddelivery.api.v1.entities.Product) SearchProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO) ProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.

the class ProductUtils method createProductCreateDTO.

public static ProductCreateDTO createProductCreateDTO(Product p) {
    ProductCreateDTO productDTO = new ProductCreateDTO();
    productDTO.setDescription(p.getDescription());
    productDTO.setPrice(p.getPrice());
    productDTO.setName(p.getName());
    productDTO.setInShowcase(p.getInShowcase());
    productDTO.setWeight(p.getWeight());
    productDTO.setExpirationDays(p.getExpirationDays());
    return productDTO;
}
Also used : ProductCreateDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductCreateDTO)

Example 4 with ProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.

the class ProductUtils method createProductDTOListFromPage.

public static List<ProductDTO> createProductDTOListFromPage(Page<Product> page) {
    List<Product> products = page.getContent();
    List<ProductDTO> productsDTO = new ArrayList<>();
    for (Product p : products) {
        productsDTO.add(createProductDTO(p));
    }
    return productsDTO;
}
Also used : ArrayList(java.util.ArrayList) Product(com.ncedu.fooddelivery.api.v1.entities.Product) ProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)

Example 5 with ProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceImpl1 method convertToOrderInfoDTO.

public OrderInfoDTO convertToOrderInfoDTO(Order order) {
    List<OrderProductPosition> orderProductPositions = orderProductPositionRepo.findAllByOrder(order);
    List<OrderInfoDTO.ProductAmountPair> products = new ArrayList<>();
    for (OrderProductPosition orderProductPosition : orderProductPositions) {
        ProductDTO p = productMapper.mapToDTO(orderProductPosition.getProductPosition().getProduct());
        Integer amount = orderProductPosition.getAmount();
        products.add(new OrderInfoDTO.ProductAmountPair(p, amount));
    }
    return new OrderInfoDTO(order.getId(), order.getClient(), order.getAddress(), order.getCoordinates(), order.getWarehouse(), order.getCourier(), order.getStatus(), order.getDateStart(), order.getDateEnd(), order.getOverallCost(), order.getHighDemandCoeff(), order.getDiscount(), order.getPromoCodeId(), order.getClientRating(), order.getDeliveryRating(), products);
}
Also used : OrderProductPosition(com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition) ProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)

Aggregations

ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)9 Product (com.ncedu.fooddelivery.api.v1.entities.Product)8 SearchProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO)7 Test (org.junit.jupiter.api.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)5 Point (com.vividsolutions.jts.geom.Point)5 Pageable (org.springframework.data.domain.Pageable)5 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)3 ArrayList (java.util.ArrayList)2 ProductCreateDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductCreateDTO)1 ProductUpdateDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductUpdateDTO)1 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)1 PageImpl (org.springframework.data.domain.PageImpl)1