Search in sources :

Example 21 with Order

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

the class OrderServiceTest method changeOrderStatusSuccessTest.

@Test
public void changeOrderStatusSuccessTest() {
    ChangeOrderStatusDTO dto = new ChangeOrderStatusDTO();
    dto.setNewStatus(OrderStatus.DELIVERED);
    Order fakeOrder = getFakeOrder();
    Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(fakeOrder);
    orderService.changeOrderStatus(fakeOrder, getFakeUserClient(), dto);
    Assertions.assertTrue(fakeOrder.getStatus() == OrderStatus.DELIVERED);
    Mockito.verify(orderRepo, Mockito.times(1)).save(fakeOrder);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ChangeOrderStatusDTO(com.ncedu.fooddelivery.api.v1.dto.order.ChangeOrderStatusDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with Order

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

the class OrderServiceTest method replaceCourierAccessExTest.

@Test
public void replaceCourierAccessExTest() {
    User fakeUser = getFakeUserModerator();
    Courier mockCourier = Mockito.mock(Courier.class);
    Order fakeOrder = getFakeOrder();
    fakeOrder.setWarehouse(getFakeWarehouse2());
    Assertions.assertThrows(CustomAccessDeniedException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            orderService.replaceCourier(fakeOrder, fakeUser);
        }
    });
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with Order

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

the class ProductPositionServiceTest method shipProductPositionsNotUniqueTest.

@Test
public void shipProductPositionsNotUniqueTest() {
    ProductPositionsShipmentDTO mockDTO = Mockito.mock(ProductPositionsShipmentDTO.class);
    List<ProductPositionsShipmentDTO.ProductPositionAmountPair> mockPairs;
    ProductPositionsShipmentDTO.ProductPositionAmountPair mockPair1 = new ProductPositionsShipmentDTO.ProductPositionAmountPair(), mockPair2 = new ProductPositionsShipmentDTO.ProductPositionAmountPair();
    mockPair1.setId(12L);
    mockPair1.setAmount(10);
    mockPair2.setId(13L);
    mockPair2.setAmount(20);
    mockPairs = new ArrayList<>(Arrays.asList(mockPair1, mockPair2, mockPair1));
    Long mockOrderId = 110L;
    Order mockOrder = new Order();
    Warehouse mockWarehouse = Mockito.mock(Warehouse.class);
    mockOrder.setWarehouse(mockWarehouse);
    Mockito.when(mockWarehouse.getId()).thenReturn(1L);
    Mockito.when(mockDTO.getPositionAmountPairs()).thenReturn(mockPairs);
    Mockito.when(orderRepo.findById(Mockito.any(Long.class))).thenReturn(Optional.of(mockOrder));
    assertThrows(NotUniqueIdException.class, new Executable() {

        @Override
        public void execute() {
            productPositionService.shipProductPositions(mockOrderId, mockDTO);
        }
    });
    Mockito.verify(orderRepo, times(1)).findById(110L);
    Mockito.verify(mockDTO, times(1)).getPositionAmountPairs();
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Warehouse(com.ncedu.fooddelivery.api.v1.entities.Warehouse) Executable(org.junit.jupiter.api.function.Executable) ProductPositionsShipmentDTO(com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsShipmentDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with Order

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

the class ProductPositionServiceTest method shipProductPositionsNotEnoughTest.

@Test
public void shipProductPositionsNotEnoughTest() {
    Long mockOrderId = 110L;
    Order mockOrder = Mockito.mock(Order.class);
    ProductPositionsShipmentDTO mockDTO = Mockito.mock(ProductPositionsShipmentDTO.class);
    ProductPositionsShipmentDTO.ProductPositionAmountPair mockPair = new ProductPositionsShipmentDTO.ProductPositionAmountPair();
    mockPair.setId(10L);
    mockPair.setAmount(1000);
    ProductPosition mockPosition = Mockito.mock(ProductPosition.class);
    mockPosition.setCurrentAmount(1);
    Warehouse mockWarehouse = Mockito.mock(Warehouse.class);
    Mockito.when(mockWarehouse.getId()).thenReturn(1L);
    Mockito.when(mockOrder.getWarehouse()).thenReturn(mockWarehouse);
    Mockito.when(mockDTO.getPositionAmountPairs()).thenReturn(new ArrayList<>(Arrays.asList(mockPair)));
    Mockito.when(orderRepo.findById(Mockito.any(Long.class))).thenReturn(Optional.of(mockOrder));
    Mockito.when(productPositionRepo.findById(Mockito.any(Long.class))).thenReturn(Optional.of(mockPosition));
    Mockito.when(mockPosition.getWarehouse()).thenReturn(mockWarehouse);
    assertThrows(ProductPositionNotEnoughException.class, new Executable() {

        @Override
        public void execute() {
            productPositionService.shipProductPositions(mockOrderId, mockDTO);
        }
    });
    verify(mockDTO, times(1)).getPositionAmountPairs();
    verify(orderRepo, times(1)).findById(110L);
    verify(productPositionRepo, times(2)).findById(10L);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Warehouse(com.ncedu.fooddelivery.api.v1.entities.Warehouse) Executable(org.junit.jupiter.api.function.Executable) ProductPosition(com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition) ProductPositionsShipmentDTO(com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsShipmentDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with Order

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

the class DeliverySessionServiceTest method finishSessionActiveOrderExceptionTest.

@Test
public void finishSessionActiveOrderExceptionTest() {
    Order order = Mockito.mock(Order.class);
    Mockito.when(order.getId()).thenReturn(1L);
    Mockito.when(deliverySessionRepo.getActiveSession(targetUser.getId())).thenReturn(deliverySession);
    Mockito.when(orderService.findCouriersActiveOrder(targetCourier)).thenReturn(order);
    Assertions.assertThrows(DeliverySessionFinishException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            deliverySessionService.finishSession(targetUser);
        }
    });
    Mockito.verify(deliverySessionRepo, Mockito.times(1)).getActiveSession(targetUser.getId());
    Mockito.verify(orderService, Mockito.times(1)).findCouriersActiveOrder(targetCourier);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)19 Test (org.junit.jupiter.api.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)7 Executable (org.junit.jupiter.api.function.Executable)7 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)6 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)4 ProductPositionsShipmentDTO (com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsShipmentDTO)2 com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO)2 ChangeOrderStatusDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeOrderStatusDTO)2 ChangeRatingDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO)2 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)2 Warehouse (com.ncedu.fooddelivery.api.v1.entities.Warehouse)2 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)2 CourierAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.CourierAvailabilityEx)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)1 ProductPositionsFromOrderDTO (com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsFromOrderDTO)1 com.ncedu.fooddelivery.api.v1.dto.order (com.ncedu.fooddelivery.api.v1.dto.order)1