* tries to add an existing Customer to a Product. Currently goes wrong !
*
*/
@Test
public final void testAddExistingCustomer() {
ProductWithCustomersDto p001 = new ProductWithCustomersDto();
p001.setProductNumber("p001");
p001.setPrice(new Float(8));
p001.setOrderable(true);
ProductWithCustomersDto createdP001 = customerService
.readProductAsProductWithCustomersDto(customerService.createProduct(p001));
// Comment the try below and uncomment the ones below that to get the
// real test.
// try {
// createdP001.addToBuyers(createdCustomer);
// ProductWithCustomersDto createdP002 =
// customerServiceModelService.updateProduct(createdP001);
// Assert.fail("Expecting Service Exception");
// } catch (TranslatorException e) {
// System.err.println("Expected exception: " + e.getMessage());
// }
// JOS: The above is incorrect (just not to break the build)
// The below should be run as a test and shows the error.
createdP001.addToBuyers(createdCustomer);
customerService.updateProduct(createdP001);
ProductWithCustomersDto stored = customerService
.readProductAsProductWithCustomersDto(createdP001.getId());
Assert.assertTrue("Number of customers should be one", stored.getBuyers().size() == 1);
SimpleCustomerDto storedCustomer = stored.getFromBuyers(createdCustomer.getId());
Assert.assertTrue("Customer should be there", storedCustomer != null);
storedCustomer.setCustomerNr(9101);
stored.addToBuyers(storedCustomer);
customerService.updateProduct(stored);
stored = customerService.readProductAsProductWithCustomersDto(createdP001.getId());
Assert.assertTrue("Number of customers should be one", stored.getBuyers().size() == 1);
storedCustomer = stored.getFromBuyers(createdCustomer.getId());
Assert.assertTrue("Customer should be there", storedCustomer != null);
Assert.assertTrue("Customer number inciiorrect", storedCustomer.getCustomerNr() == 9101);
}