Search in sources :

Example 31 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceTest method getProductDTOByIdInShowCaseSuccess.

@Test
public void getProductDTOByIdInShowCaseSuccess() {
    Long productId = 1L;
    Product product = ProductUtils.createMilkInShowcase(productId);
    when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
    ProductDTO resultDTO = productService.getProductDTOByIdInShowcase(productId);
    ProductDTO perfectDTO = ProductUtils.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 32 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceTest method getProductsNullResult.

@Test
public void getProductsNullResult() {
    Pageable pageable = PageRequest.of(0, 2);
    Page<Product> productsPage = new PageImpl<>(new ArrayList<Product>(), pageable, 0);
    Long warehouseId = 4L;
    Point geo = makeGeo();
    WarehouseInfoDTO warehouseInfoDTO = new WarehouseInfoDTO(warehouseId, null, null, null, null, false);
    when(warehouseServiceMock.getNearestWarehouse(geo)).thenReturn(warehouseInfoDTO);
    when(productRepoMock.findAll(warehouseId, pageable)).thenReturn(productsPage);
    CoordsDTO coordsDTO = makeCoordsDTO();
    List<ProductDTO> resultList = productService.getProducts(coordsDTO, pageable);
    List<ProductDTO> perfectList = new ArrayList<>();
    verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
    verify(productRepoMock, times(1)).findAll(warehouseId, pageable);
    assertEquals(perfectList, resultList);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) 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) CoordsDTO(com.ncedu.fooddelivery.api.v1.dto.CoordsDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceTest method getProductDTOByIdInShowCaseError.

@Test
public void getProductDTOByIdInShowCaseError() {
    Long productId = 1L;
    Product product = ProductUtils.createMilkNOTinShowcase(productId);
    when(productRepoMock.findById(productId)).thenReturn(Optional.of(product));
    Exception exception = assertThrows(NotFoundEx.class, () -> {
        productService.getProductDTOByIdInShowcase(productId);
    });
    String resultMessage = exception.getMessage();
    String perfectMessage = new NotFoundEx(productId.toString()).getMessage();
    verify(productRepoMock, times(1)).findById(productId);
    assertEquals(perfectMessage, resultMessage);
}
Also used : NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) Product(com.ncedu.fooddelivery.api.v1.entities.Product) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductServiceTest method getProductsSuccess.

// TODO: rewrite tests!!!
@Test
public void getProductsSuccess() {
    Pageable pageable = PageRequest.of(0, 2);
    Page<Product> productsPage = ProductUtils.createPageWithMilkProducts(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.findAll(warehouseId, pageable)).thenReturn(productsPage);
    CoordsDTO coordsDTO = makeCoordsDTO();
    List<ProductDTO> resultList = productService.getProducts(coordsDTO, pageable);
    List<ProductDTO> perfectList = ProductUtils.createProductDTOListFromPage(productsPage);
    verify(warehouseServiceMock, times(1)).getNearestWarehouse(geo);
    verify(productRepoMock, times(1)).findAll(warehouseId, pageable);
    assertEquals(perfectList, resultList);
}
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) CoordsDTO(com.ncedu.fooddelivery.api.v1.dto.CoordsDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product in project 2021-msk-food-delivery by netcracker-edu.

the class ProductUtils method createPageWithMilkProducts.

public static Page<Product> createPageWithMilkProducts(Pageable pageable) {
    Product milk = createMilkInShowcase(1L);
    Product milkElite = createMilkNOTinShowcase(2L);
    List<Product> products = new ArrayList<>();
    products.add(milkElite);
    products.add(milk);
    return new PageImpl<Product>(products, pageable, products.size());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ArrayList(java.util.ArrayList) Product(com.ncedu.fooddelivery.api.v1.entities.Product)

Aggregations

Product (com.ncedu.fooddelivery.api.v1.entities.Product)17 Test (org.junit.jupiter.api.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)10 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)9 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)9 Product (entities.Product)9 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)8 SearchProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 Point (com.vividsolutions.jts.geom.Point)5 Pageable (org.springframework.data.domain.Pageable)5 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)3 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)3 PageImpl (org.springframework.data.domain.PageImpl)3 com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)2 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)2 ProductAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.ProductAvailabilityEx)2