Package com.yummynoodlebar.core.domain

Examples of com.yummynoodlebar.core.domain.Order


public class OrdersFixtures {

  public static final String YUMMY_ITEM = "yummy_core";

  public static Order standardOrder() {
    Order order = new Order(new Date());

    order.setExpectedCompletionTime(new Date(order.getDateTimeOfSubmission().getTime() + 300000));
    order.setMenuItems(standardMenu());
    order.setTotalCost(new BigDecimal("12.99"));

    return order;
  }
View Full Code Here


    this.ordersRepository = ordersRepository;
  }

  @Override
  public OrderCreatedEvent createOrder(CreateOrderEvent createOrderEvent) {
    Order order = Order.fromOrderDetails(createOrderEvent.getDetails());

    order.addStatus(new OrderStatus(new Date(), "Order Created"));

    order = ordersRepository.save(order);

    return new OrderCreatedEvent(order.getKey(), order.toOrderDetails());
  }
View Full Code Here

  }

  @Override
  public OrderDetailsEvent requestOrderDetails(RequestOrderDetailsEvent requestOrderDetailsEvent) {

    Order order = ordersRepository.findById(requestOrderDetailsEvent.getKey());

    if (order == null) {
      return OrderDetailsEvent.notFound(requestOrderDetailsEvent.getKey());
    }

    return new OrderDetailsEvent(
            requestOrderDetailsEvent.getKey(),
            order.toOrderDetails());
  }
View Full Code Here

  }

  @Override
  public OrderDeletedEvent deleteOrder(DeleteOrderEvent deleteOrderEvent) {

    Order order = ordersRepository.findById(deleteOrderEvent.getKey());

    if (order == null) {
      return OrderDeletedEvent.notFound(deleteOrderEvent.getKey());
    }

    OrderDetails details = order.toOrderDetails();

    //TODOCUMENT This contains some specific domain logic, not exposed to the outside world, and not part of the
    //persistence rules.

    if (!order.canBeDeleted()) {
      return OrderDeletedEvent.deletionForbidden(deleteOrderEvent.getKey(), details);
    }

    ordersRepository.delete(deleteOrderEvent.getKey());
    return new OrderDeletedEvent(deleteOrderEvent.getKey(), details);
View Full Code Here

    return new OrderDeletedEvent(deleteOrderEvent.getKey(), details);
  }

  @Override
  public OrderStatusEvent requestOrderStatus(RequestOrderStatusEvent requestOrderDetailsEvent) {
    Order order = ordersRepository.findById(requestOrderDetailsEvent.getKey());

    if (order == null) {
      return OrderStatusEvent.notFound(requestOrderDetailsEvent.getKey());
    }

    return new OrderStatusEvent(requestOrderDetailsEvent.getKey(), order.getStatus().toStatusDetails());
  }
View Full Code Here

  }

  @Test
  public void addANewOrderToTheSystem() {

    when(mockOrdersMemoryRepository.save(any(Order.class))).thenReturn(new Order(new Date()));

    CreateOrderEvent ev = new CreateOrderEvent(new OrderDetails());

    uut.createOrder(ev);
View Full Code Here

  }

  @Test
  public void addTwoNewOrdersToTheSystem() {

    when(mockOrdersMemoryRepository.save(any(Order.class))).thenReturn(new Order(new Date()));

    CreateOrderEvent ev = new CreateOrderEvent(new OrderDetails());

    uut.createOrder(ev);
    uut.createOrder(ev);
View Full Code Here

  @Test
  public void removeAnOrderFromTheSystemFailsIfNotPermitted() {
    UUID key = UUID.randomUUID();

    Order order = new Order(new Date()) {
      @Override
      public boolean canBeDeleted() {
        return false;
      }
    };

    when(mockOrdersMemoryRepository.findById(key)).thenReturn(order);

    DeleteOrderEvent ev = new DeleteOrderEvent(key);

    OrderDeletedEvent orderDeletedEvent = uut.deleteOrder(ev);

    verify(mockOrdersMemoryRepository, never()).delete(ev.getKey());

    assertTrue(orderDeletedEvent.isEntityFound());
    assertFalse(orderDeletedEvent.isDeletionCompleted());
    assertEquals(order.getDateTimeOfSubmission(), orderDeletedEvent.getDetails().getDateTimeOfSubmission());
  }
View Full Code Here

  @Test
  public void removeAnOrderFromTheSystemWorksIfExists() {

    UUID key = UUID.randomUUID();
    Order order = new Order(new Date());

    when(mockOrdersMemoryRepository.findById(key)).thenReturn(order);

    DeleteOrderEvent ev = new DeleteOrderEvent(key);

    OrderDeletedEvent orderDeletedEvent = uut.deleteOrder(ev);

    verify(mockOrdersMemoryRepository).delete(ev.getKey());

    assertTrue(orderDeletedEvent.isEntityFound());
    assertTrue(orderDeletedEvent.isDeletionCompleted());
    assertEquals(order.getDateTimeOfSubmission(), orderDeletedEvent.getDetails().getDateTimeOfSubmission());
  }
View Full Code Here

public class OrdersFixtures {

  public static final String YUMMY_ITEM = "yummy_core";

  public static Order standardOrder() {
    Order order = new Order(new Date());

    order.setOrderItems(Collections.singletonMap(YUMMY_ITEM, 12));

    return order;
  }
View Full Code Here

TOP

Related Classes of com.yummynoodlebar.core.domain.Order

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.