Search in sources :

Example 1 with SearchProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO 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 SearchProductDTO

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

the class ProductServiceImpl method searchCountProducts.

@Override
public CountDTO searchCountProducts(SearchProductDTO searchDTO) {
    Long warehouseId = getWarehouseIdByCoordinates(searchDTO.getGeo());
    String resultPhrase = preparePhraseToSearch(searchDTO.getPhrase());
    int count = productRepo.searchProductsCount(resultPhrase, warehouseId);
    return new CountDTO(count);
}
Also used : CountDTO(com.ncedu.fooddelivery.api.v1.dto.CountDTO) Point(com.vividsolutions.jts.geom.Point)

Example 3 with SearchProductDTO

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

the class ProductServiceImpl method searchProductsCountInShowcase.

@Override
public CountDTO searchProductsCountInShowcase(SearchProductDTO searchDTO) {
    Long warehouseId = getWarehouseIdByCoordinates(searchDTO.getGeo());
    String resultPhrase = preparePhraseToSearch(searchDTO.getPhrase());
    int countInShowcase = productRepo.searchProductsCountInShowcase(resultPhrase, warehouseId);
    return new CountDTO(countInShowcase);
}
Also used : CountDTO(com.ncedu.fooddelivery.api.v1.dto.CountDTO) Point(com.vividsolutions.jts.geom.Point)

Example 4 with SearchProductDTO

use of com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO 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);
}
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)

Aggregations

Point (com.vividsolutions.jts.geom.Point)4 CountDTO (com.ncedu.fooddelivery.api.v1.dto.CountDTO)2 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)2 SearchProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.SearchProductDTO)2 WarehouseInfoDTO (com.ncedu.fooddelivery.api.v1.dto.warehouseDTOs.WarehouseInfoDTO)2 Product (com.ncedu.fooddelivery.api.v1.entities.Product)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Pageable (org.springframework.data.domain.Pageable)2