public void testMapManufacuringFacilityToDTSMerge() {
Map<String, Object> betriebsstaetteMap =
getManufacturingFacility(4L,"Manufacturing Facility Description.");
ManufacturingFacility manufacturingFacility = (ManufacturingFacility)betriebsstaetteMap.get(BaseManufacturingFacilityTest.MANUFACTURINGFACILITY_KEY);
ManufacturingFacilityDTS manufacturingFacilityDTS = (ManufacturingFacilityDTS)betriebsstaetteMap.get(BaseManufacturingFacilityTest.MANUFACTURINGFACILITYDTS_KEY);
addAddressToManufacturingFacility(betriebsstaetteMap, 10L, "StreetA", 815L, "This is a comment. 10", 'D');
addAddressToManufacturingFacility(betriebsstaetteMap, 11L, "StreetB", 816L, "This is a comment. 11", 'E');
addAddressToManufacturingFacility(betriebsstaetteMap, 12L, "StreetC", 817L, "This is a comment. 12", 'F');
// Edit some values on "orginal" bean.
// This is because we want to see if values are kept which are not mapped.
// With the AddressMergingMapper this variable does not contain any addresses after merge.
// The entity mapped from contains 3 addresses.
// Without the AddressMergingMapper there are contained 3 adresses.
// But then the check for the land value fails.
ManufacturingFacilityDTS manufacturingFacilityDTSServer = mapper.map(manufacturingFacility, ManufacturingFacilityDTS.class);
manufacturingFacilityDTSServer.setIdNumber(4L);
Character vLand = 'D';
for(AddressDTO currAnschrift: manufacturingFacilityDTSServer.getAddressL()){
currAnschrift.setLand(vLand);
}
ManufacturingFacility manufacturingFacilityToEdit = mapper.map(manufacturingFacilityDTSServer,ManufacturingFacility.class);
manufacturingFacilityToEdit.putPrototype(manufacturingFacilityDTSServer);
// Now the bean will be edited to see if the mapped values are correctly merged.
List<Address> anschriftenGUI = manufacturingFacilityToEdit.getAddresses();
anschriftenGUI.remove(1);
manufacturingFacilityToEdit.setDescription("Description after merge.");
Address firstAdr = anschriftenGUI.get(0);
firstAdr.setStreet("Street new");
// merge
ManufacturingFacilityDTS prototype = manufacturingFacilityToEdit.returnPrototype();
mapper.map(manufacturingFacilityToEdit, prototype);
// Do some checks.
assertTrue("IdNumber was not kept after merge.",
4L == prototype.getIdNumber());
// Check name of street
assertTrue("Street new".equals(prototype.getAddressL().get(0).getStreet()));
// Amount of addresses
List<AddressDTO> addressesFromPrototype = prototype.getAddressL();
assertTrue("An address was removed. In the merged DS this address does still exist.",
addressesFromPrototype.size() == 2);
// land check
List<AddressDTO> addressesAfterMerge = prototype.getAddressL();
AddressDTO addressOne = addressesAfterMerge.get(0);
AddressDTO addressTwo = addressesAfterMerge.get(1);
assertTrue("Land after merge is wrong.", Character.valueOf('D').equals(addressOne.getLand()));
assertTrue("Land after merge is wrong.", Character.valueOf('D').equals(addressTwo.getLand()));