/** * Get locations that have any of specified set of tags among its child tags. * * @see Location#isInHierarchy(Location,Location) */ @Test public void isInHierarchy_shouldShouldFindLocationInHierarchy() { Location locationGrandParent = new Location(); Location locationParent = new Location(); Location locationChild = new Location(); locationGrandParent.addChildLocation(locationParent); locationParent.addChildLocation(locationChild); assertTrue(Location.isInHierarchy(locationChild, locationParent)); assertTrue(Location.isInHierarchy(locationChild, locationGrandParent)); }
childA.setName("level A child"); childA.setDescription("is a child"); location.addChildLocation(childA); childB.setName("level B child"); childB.setDescription("is a child"); childA.addChildLocation(childB);
@Test public void shouldIncludeTheListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); Assert.assertEquals(0, location.getChildLocations().size()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location); MockHttpServletRequest httpReq = request(RequestMethod.GET, getURI() + "/" + getUuid()); httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = deserialize(handle(httpReq)); Assert.assertEquals(1, ((Collection) PropertyUtils.getProperty(result, "childLocations")).size()); }
@Test public void shouldOverwriteAListOfChildLocations() throws Exception { Location location = service.getLocationByUuid(getUuid()); location.addChildLocation(service.getLocation(2)); service.saveLocation(location); String json = "{ \"childLocations\": [] }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Location updatedLocation = service.getLocationByUuid(getUuid()); Assert.assertNotNull(updatedLocation); Assert.assertTrue(updatedLocation.getChildLocations().isEmpty()); }