public void testRemove() { City city = newCity(); IAddressService service = AddressServiceFactory.createAddressService(); Address ad = new Address(); ad.setStreet("rua"); ad.setCity(city); service.persist(ad); Long id = city.getId(); assertNotNull(id); assertNotNull(ad.getId()); // must delete childs, but no other related instances, as javadoc // documentation explain try { service.remove(city); fail("Cant delete because there are related elements"); } catch (Exception e) { assertNotNull("must keep existing", service.findCityById(id)); } }
public void testRemoveCity() { City city = newCity(); IAddressService service = AddressServiceFactory.createAddressService(); service.persist(city); Long id = city.getId(); assertNotNull(id); service.remove(city); assertNull("Can't find anything. ", service.findCityById(id)); }