Search in sources :

Example 6 with Product

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

the class ProductServiceTest method getProductByIdSuccess.

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

Example 7 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product 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 8 with Product

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

the class ProductUtils method createPageProductsInShowcase.

public static Page<Product> createPageProductsInShowcase(Pageable pageable) {
    Product milk = createMilkInShowcase(1L);
    Product bread = createBreadInShowcase(2L);
    List<Product> products = new ArrayList<>();
    products.add(milk);
    products.add(bread);
    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)

Example 9 with Product

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

the class ProductUtils method createProduct.

public static Product createProduct(Long id, String name, String description, boolean inShowcase, Double price) {
    Product product = new Product();
    product.setId(id);
    product.setName(name);
    product.setDescription(description);
    product.setExpirationDays(Short.valueOf("5"));
    product.setWeight(400);
    product.setPrice(price);
    product.setInShowcase(inShowcase);
    return product;
}
Also used : Product(com.ncedu.fooddelivery.api.v1.entities.Product)

Example 10 with Product

use of com.ncedu.fooddelivery.api.v1.entities.Product 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)

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