Examples of CustomerWithOrdersAndOrderLines


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

    @Test
    public void testFromDtoWithTwoLevelsOfReferences() throws Exception {
        /**
         * Create a customer dto with orders and orderlines to be translated to a DO.
         */
        CustomerWithOrdersAndOrderLines dto = createCustomerDto(new String[] { "1", "2" },
                new String[] { "3", "4" });
        /**
         * Save it and check.
         */
        Long customerId = customerServiceModelService.createCustomer(dto);
        CustomerWithOrdersAndOrderLines created = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);
        checkCustomer(created, new String[] { "1", "2" }, new String[] { "3", "4" });

        /**
         * Delete one orderline from each order and check.
         */
        List<OrderWithOrderLinesDto> orderList = new ArrayList<OrderWithOrderLinesDto>(created
                .getOrders());
        Collections.sort(orderList, new OrderDtoComparator());
        orderList.get(0).removeFromOrderLines(0);
        orderList.get(1).removeFromOrderLines(0);
        customerServiceModelService.updateCustomer(created);
        CustomerWithOrdersAndOrderLines updated = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);
        checkCustomer(updated, new String[] { "1", "2" }, new String[] { "4" });
        /**
         * Add a new orderline to each order and check.
         */
        orderList = new ArrayList<OrderWithOrderLinesDto>(updated.getOrders());
        orderList.get(0).addToOrderLines(createOrderLine(5, "5"));
        orderList.get(1).addToOrderLines(createOrderLine(5, "5"));
        customerServiceModelService.updateCustomer(updated);
        updated = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);
        checkCustomer(updated, new String[] { "1", "2" }, new String[] { "4", "5" });

        /**
         * Update the productnumber in the orderlines of both orders from 4 to 6. So leave the one
         * with productnumber 5 alone.
         */
        orderList = new ArrayList<OrderWithOrderLinesDto>(updated.getOrders());
        assertEquals("4", orderList.get(0).getOrderLines().get(0).getProduct().getProductNumber());
        orderList.get(0).getOrderLines().get(0).getProduct().setProductNumber("6");
        assertEquals("4", orderList.get(1).getOrderLines().get(0).getProduct().getProductNumber());
        orderList.get(1).getOrderLines().get(0).getProduct().setProductNumber("6");
        customerServiceModelService.updateCustomer(updated);
View Full Code Here

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

        }
    }

    private CustomerWithOrdersAndOrderLines createCustomerDto(String[] orderNumbers,
            String[] productNumbers) {
        CustomerWithOrdersAndOrderLines result = new CustomerWithOrdersAndOrderLines();
        result.setBirthDate(new DateTime("1955-10-17"));
        result.setFirstName("Piet");
        result.setLastName("Heijn");
        result.setCustomerNr(1);

        for (String orderNumber : orderNumbers) {
            result.addToOrders(createOrder(orderNumber, productNumbers));
        }
        return result;
    }
View Full Code Here

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

     * Create a customer dto with orders and orderlines to be translated to a DO.
     */
    @Before
    public void setUp() {

        customerDto = new CustomerWithOrdersAndOrderLines();
        customerDto.setCustomerNr(1234);
        customerDto.setFirstName("Buyer");
        customerDto.setLastName("TheCustomer");
        customerDto.setBirthDate(new DateTime("1970-01-01"));

View Full Code Here

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

        /**
         * Save, flush and check.
         */

        CustomerWithOrdersAndOrderLines createdCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerServiceModelService
                        .createCustomer(customerDto));
        flush();

        assertEquals(2, createdCustomer.getOrders().size());
        for (OrderWithOrderLinesDto orderDto : createdCustomer.getOrders()) {
            assertTrue(orderDto.getId() > 0);
            assertEquals(2, orderDto.getOrderLines().size());
            for (OrderLineDto orderLineDto : orderDto.getOrderLines()) {
                assertTrue(orderLineDto.getId() > 0);
                assertTrue(orderLineDto.getProduct().getId() > 0);
View Full Code Here

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

     * Delete one orderline from each order, Update and check.
     */
    @Test
    public void testUpdateRemovedOrderLines() {

        CustomerWithOrdersAndOrderLines createdCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerServiceModelService
                        .createCustomer(customerDto));
        flush();

        for (OrderWithOrderLinesDto orderDto : createdCustomer.getOrders()) {
            OrderLineDto toBeRemoved = null;
            for (OrderLineDto orderLineDto : orderDto.getOrderLines()) {
                if (orderLineDto.getLineNumber() == 1) {
                    toBeRemoved = orderLineDto;
                }
            }
            orderDto.removeFromOrderLines(toBeRemoved);
        }

        for (OrderWithOrderLinesDto orderDto : createdCustomer.getOrders()) {
            assertEquals(1, orderDto.getOrderLines().size());
        }

        // Update the complete customer structure in one service call.
        customerServiceModelService.updateCustomer(createdCustomer);
        flush();
        CustomerWithOrdersAndOrderLines updatedCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(createdCustomer.getId());

        assertEquals(2, updatedCustomer.getOrders().size());
        for (OrderWithOrderLinesDto updatedOrderDto : updatedCustomer.getOrders()) {
            assertEquals(1, updatedOrderDto.getOrderLines().size());
            for (OrderLineDto orderLineDto : updatedOrderDto.getOrderLines()) {
                assertTrue(2 == orderLineDto.getLineNumber());
            }
        }
View Full Code Here

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

     */
    @Test
    public void testUpdateOrdersWithNewOrderLine() throws Exception {

        Long customerId = customerServiceModelService.createCustomer(customerDto);
        CustomerWithOrdersAndOrderLines createdCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);
        flush();
        // createdCustomer =
        // customerServiceModelService.readCustomerAsCustomerWithOrdersAndOrderLines(createdCustomer.getId());

        OrderLineDto orderLineDtoNew = new OrderLineDto();
        orderLineDtoNew.setLineNumber(3);
        orderLineDtoNew.setDescription("ORDER-NEW-ORDERLINE-3");

        for (OrderWithOrderLinesDto orderDto : createdCustomer.getOrders()) {
            orderDto.addToOrderLines(orderLineDtoNew);
        }

        // Update the complete customer structure in one service call.
        customerServiceModelService.updateCustomer(createdCustomer);
        CustomerWithOrdersAndOrderLines updatedCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);
        flush();
        // JOS: Added to make the test succeed, but it should not be needed.
        updatedCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(updatedCustomer.getId());

        assertEquals(2, updatedCustomer.getOrders().size());
        for (OrderWithOrderLinesDto updatedOrderDto : updatedCustomer.getOrders()) {
            assertEquals(3, updatedOrderDto.getOrderLines().size());
            for (OrderLineDto orderLineDto : updatedOrderDto.getOrderLines()) {
                if (orderLineDto.getLineNumber() == 3) {
                    assertTrue(orderLineDto.getId() > 0);
                    assertTrue("ORDER-NEW-ORDERLINE-3".equals(orderLineDto.getDescription()));
View Full Code Here

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

     */
    @Test
    public void testChangeValueInOrderLine() throws Exception {

        Long customerId = customerServiceModelService.createCustomer(customerDto);
        CustomerWithOrdersAndOrderLines createdCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);
        flush();

        createdCustomer.setLastName("-CHICKEN-IN-");
        for (OrderWithOrderLinesDto orderDto : createdCustomer.getOrders()) {
            for (OrderLineDto orderLine : orderDto.getOrderLines()) {
                orderLine.setDescription("-THE-BASKET-");
                orderLine.getProduct().setPrice(10f);
            }
        }

        // Update the complete customer structure in one service call.
        customerServiceModelService.updateCustomer(createdCustomer);
        flush();
        CustomerWithOrdersAndOrderLines updatedCustomer = customerServiceModelService
                .readCustomerAsCustomerWithOrdersAndOrderLines(customerId);

        assertTrue(updatedCustomer.getLastName().equals("-CHICKEN-IN-"));
        for (OrderWithOrderLinesDto orderDto : updatedCustomer.getOrders()) {
            for (OrderLineDto orderLine : orderDto.getOrderLines()) {
                assertTrue(orderLine.getDescription().equals("-THE-BASKET-"));
                assertTrue(orderLine.getProduct().getPrice() == 10f);
            }
        }
View Full Code Here

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

      final Map<Object, Object> translated) {
    if (translated.containsKey((source))) {
      return (CustomerWithOrdersAndOrderLines) translated.get(source);
    }
    Assert.notNull(source, "argument [source] may not be null");
    CustomerWithOrdersAndOrderLines result = new CustomerWithOrdersAndOrderLines(
        source.getId(), source.getVersion());
    result.setFirstName(source.getFirstName());
    result.setLastName(source.getLastName());
    result.setBirthDate(source.getBirthDate());
    result.setCustomerNr(source.getCustomerNr());

    translated.put(source, result);

    for (Order element : source.getOrders()) {
      result.addToOrders(orderWithOrderLinesDtoTranslator.toDto(element,
          translated));
    }

    return result;
  }
View Full Code Here

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

    }
    return customerDto;
  }

  private CustomerWithOrdersAndOrderLines createCustomerDto() {
    CustomerWithOrdersAndOrderLines result = new CustomerWithOrdersAndOrderLines();
    return result;
  }
View Full Code Here

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

    public void testFromDtoWithTwoLevelsOfReferences() throws Exception {
        CustomerRepository repository = new CustomerRepository();
        /**
         * Create a customer dto with orders and orderlines to be translated to a DO.
         */
        CustomerWithOrdersAndOrderLines dto = createCustomerDto(new String[] { "1", "2" }, new String[] { "3", "4" });
        /**
         * Translate it to a DO and check.
         */
        Customer created = customerWithOrdersAndOrderLinesTranslator.fromDto(dto);
        checkCustomer(created, new String[] { "1", "2" }, new String[] { "3", "4" });
        /**
         * "Save" the customer and retrieve. Id's will be added to all domain objects. Then transform to a DTO again.
         */
        Customer saved = repository.get(repository.save(created));
        dto = customerWithOrdersAndOrderLinesTranslator.toDto(saved);
        customerWithOrdersAndOrderLinesTranslator.fromDto(dto, saved);
        checkCustomer(saved, new String[] { "1", "2" }, new String[] { "3", "4" });

        /**
         * Delete one orderline from each order and check.
         */
        List<OrderWithOrderLinesDto> orderList = new ArrayList<OrderWithOrderLinesDto>(dto.getOrders());
        Collections.sort(orderList, new OrderDtoComparator());
        orderList.get(0).removeFromOrderLines(0);
        orderList.get(1).removeFromOrderLines(0);
        customerWithOrdersAndOrderLinesTranslator.fromDto(dto, saved);
        checkCustomer(saved, new String[] { "1", "2" }, new String[] { "4" });
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.