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.