Package org.company.recordshop.service.dto

Examples of org.company.recordshop.service.dto.SimpleCustomerDto


  }

  @Test
  public void testCreateNewFromDtoSucceed() {

    SimpleCustomerDto simpleCust = new SimpleCustomerDto();
    simpleCust.setFirstName("Vincent");
    simpleCust.setLastName("Van Gogh");
    simpleCust.setCustomerNr(1234);
    simpleCust.setSexe(SexeEnumDto.MALE);
    simpleCust.setBirthDate(new DateTime(2008, 1, 1, 1, 1, 0, 0));

    OrderNumberAndDateDto orderDto = new OrderNumberAndDateDto();
    orderDto.setOrderNumber("1");
    orderDto.setCustomer(simpleCust);

    simpleCust.addToOrders(orderDto);

    Customer newCust = simpleCustomerDtoTranslator.fromDto(simpleCust);
    assertEquals("Vincent", newCust.getFirstName());
    assertEquals(1234, newCust.getCustomerNr().intValue());
    assertEquals(1, newCust.getOrders().size());
View Full Code Here


    Customer cust = new Customer("Herman", "Bread", new DateTime(
        "2009-11-06"), 4321);
    Order order = new Order("1111");
    cust.addToOrders(order);

    SimpleCustomerDto customerDto = simpleCustomerDtoTranslator.toDto(cust);

    assertEquals(Integer.valueOf(4321), customerDto.getCustomerNr());
    assertFalse(customerDto.getOrders().isEmpty());
    for (OrderNumberAndDateDto orderDto : customerDto.getOrders()) {
      assertEquals("1111", orderDto.getOrderNumber());
    }
  }
View Full Code Here

  public void testFromDtoBidirectionalSucceed() throws Exception {
    CustomerRepository repository = new CustomerRepository();
    /**
     * Create a customer dto with orders to be translated to a DO.
     */
    SimpleCustomerDto customerDto = createCustomerDto("1853-03-30",
        "Vincent", "van Gogh", 1, new String[] { "1", "2" });

    /**
     * Translate it to a DO and check.
     */
    Customer customer = simpleCustomerDtoTranslator.fromDto(customerDto);
    checkCustomer(customer, new String[] { "1", "2" });

    /**
     * "Save" the customer and retrieve. Id's will be added to all domain
     * objects. Then transform to a DTO again.
     */
    customer = repository.get(repository.save(customer));
    customerDto = simpleCustomerDtoTranslator.toDto(customer);

    /**
     * Remove an order from the DTO to see if it gets removed from the DO.
     */
    customerDto.removeFromOrders(customerDto.getFromOrders(1L));
    customer = simpleCustomerDtoTranslator.fromDto(customerDto, customer);
    checkCustomer(customer, new String[] { "2" });

    /**
     * Add another order to the DTO to see if it gets added to the DO.
     */
    OrderNumberAndDateDto orderDto = new OrderNumberAndDateDto();
    orderDto.setOrderNumber("3");
    orderDto.setCustomer(customerDto);
    customerDto.addToOrders(orderDto);
    customer = simpleCustomerDtoTranslator.fromDto(customerDto, customer);
    customer = repository.get(repository.save(customer));
    checkCustomer(customer, new String[] { "2", "3" });

    // TODO: Also update one or more orders.
View Full Code Here

    }
  }

  private SimpleCustomerDto createCustomerDto(String birth, String first,
      String last, int number, String[] orders) {
    SimpleCustomerDto customerDto = new SimpleCustomerDto();
    customerDto.setBirthDate(new DateTime(birth));
    customerDto.setFirstName(first);
    customerDto.setLastName(last);
    customerDto.setCustomerNr(number);

    for (int i = 0; i < orders.length; i++) {
      OrderNumberAndDateDto orderDto = new OrderNumberAndDateDto();
      orderDto.setOrderNumber(orders[i]);
      orderDto.setCustomer(customerDto);
      customerDto.addToOrders(orderDto);
    }
    return customerDto;
  }
View Full Code Here

    return result;
  }

  @Test(expected = BusinessRuleException.class)
  public void testFromDtoWithNullsFail() {
    SimpleCustomerDto custDto = new SimpleCustomerDto();
    simpleCustomerDtoTranslator.fromDto(custDto);
  }
View Full Code Here

    SimpleCustomerDto createdCustomer = null;

    OrderDto createdOrder = null;

    public SimpleCustomerDto createCustomer(String first, String last, int nr) {
        SimpleCustomerDto result = new SimpleCustomerDto();
        result.setFirstName(first);
        result.setLastName(last);
        result.setCustomerNr(nr);
        result.setBirthDate(new DateTime("2008-01-01"));
        result = customerService.readCustomer(customerService.createCustomer(result));
        return result;
    }
View Full Code Here

            List<OrderNumberAndDateDto> orders = customerService.getOrders(simpleCustomerDto);
            if (createdCustomer.getId() == simpleCustomerDto.getId()) {
                Assert.assertTrue(orders.size() == 3);
                for (OrderNumberAndDateDto order : orders) {
                    OrderDto orderDto = new OrderDto(order.getId(), order.getVersion());
                    SimpleCustomerDto customer = customerService.getCustomer(orderDto);
                    Assert.assertTrue(simpleCustomerDto.getId() == customer.getId());
                }
            } else {
                Assert.assertTrue(orders.size() == 0);
            }
        }
View Full Code Here

        Assert.assertEquals(all.size(), 3);
    }

    @Test
    public final void testFindByExample() {
        SimpleCustomerDto example = new SimpleCustomerDto();
        example.clear();
        List<SimpleCustomerDto> result = customerService.findCustomers(example);
        assertEquals(3, result.size());

        example.setBlackListed(false);
        result = customerService.findCustomers(example);
        assertEquals(3, result.size());

        example.setBlackListed(true);
        result = customerService.findCustomers(example);
        assertEquals(0, result.size());

        example.setBlackListed(null);
        example.setFirstName("Jo");
        result = customerService.findCustomers(example);
        assertEquals(2, result.size());
    }
View Full Code Here

        Long id = createdOrder.getId();
        customerService.addToOrders(createdCustomer, createdOrder);

        OrderNumberAndDateDto o = orderService.readOrderAsOrderNumberAndDateDto(createdOrder
                .getId());
        SimpleCustomerDto orderCustomer = o.getCustomer();
        Assert.assertEquals(o.getCustomer().getId(), createdCustomer.getId());
        Assert.assertTrue(o.getCustomer().getOrders().size() == 1);
    }
View Full Code Here

    @Test
    @ExpectedException(IllegalArgumentException.class)
    public final void testAddNonExistingOrder() {
        customerService.addToOrders(createdCustomer, new OrderDto(-1L, 0));
        customerService.addToOrders(new SimpleCustomerDto(-1L, 0), createdOrder);
    }
View Full Code Here

TOP

Related Classes of org.company.recordshop.service.dto.SimpleCustomerDto

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.