=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-07 18:52:55 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-08 04:56:18 +0000 @@ -663,18 +663,28 @@ @RequestMapping( value = "/{id}", method = RequestMethod.DELETE ) @PreAuthorize( "hasRole('F_FRED_DELETE') or hasRole('ALL')" ) - public ResponseEntity deleteFacility( @PathVariable String id ) throws HierarchyViolationException + public ResponseEntity deleteFacility( @PathVariable String id ) throws HierarchyViolationException, IOException { - OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( id ); - - if ( organisationUnit != null ) - { - organisationUnitService.deleteOrganisationUnit( organisationUnit ); - - return new ResponseEntity( HttpStatus.OK ); - } - - return new ResponseEntity( HttpStatus.NOT_FOUND ); + OrganisationUnit organisationUnit; + + if ( id.length() == 11 ) + { + organisationUnit = organisationUnitService.getOrganisationUnit( id ); + } + else + { + organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id ); + } + + if ( organisationUnit == null ) + { + return new ResponseEntity( MessageResponseUtils.jsonMessage( HttpStatus.NOT_FOUND.toString(), + "Facility with that ID not found" ), HttpStatus.NOT_FOUND ); + } + + organisationUnitService.deleteOrganisationUnit( organisationUnit ); + + return new ResponseEntity( HttpStatus.OK ); } //-------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java' --- dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-07 15:50:24 +0000 +++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-08 04:56:18 +0000 @@ -57,6 +57,10 @@ mvc.perform( get( "/api-fred/" ).session( session ) ).andExpect( redirectedUrl( "/api-fred/v1" ) ); } + //--------------------------------------------------------------------------------------------- + // Test GET + //--------------------------------------------------------------------------------------------- + @Test public void testGetFacilitiesWithALL() throws Exception { @@ -154,6 +158,10 @@ .andExpect( status().isOk() ); } + //--------------------------------------------------------------------------------------------- + // Test PUT + //--------------------------------------------------------------------------------------------- + @Test public void testPutFacility404() throws Exception { @@ -163,6 +171,10 @@ .andExpect( status().isNotFound() ); } + //--------------------------------------------------------------------------------------------- + // Test POST + //--------------------------------------------------------------------------------------------- + @Test public void testPostName() throws Exception { @@ -211,4 +223,41 @@ .andExpect( jsonPath( "$.name" ).value( "FacilityA" ) ) .andExpect( status().isCreated() ); } + + //--------------------------------------------------------------------------------------------- + // Test DELETE + //--------------------------------------------------------------------------------------------- + + @Test + public void testDeleteFacility404() throws Exception + { + MockHttpSession session = getSession( "ALL" ); + + mvc.perform( delete( "/v1/facilities/abc123" ).session( session ) ) + .andExpect( status().isNotFound() ); + } + + @Test + public void testDeleteFacilityUid() throws Exception + { + OrganisationUnit organisationUnit = createOrganisationUnit( 'A' ); + manager.save( organisationUnit ); + + MockHttpSession session = getSession( "ALL" ); + + mvc.perform( delete( "/v1/facilities/" + organisationUnit.getUid() ).session( session ) ) + .andExpect( status().isOk() ); + } + + @Test + public void testDeleteFacilityUuid() throws Exception + { + OrganisationUnit organisationUnit = createOrganisationUnit( 'A' ); + manager.save( organisationUnit ); + + MockHttpSession session = getSession( "ALL" ); + + mvc.perform( delete( "/v1/facilities/" + organisationUnit.getUuid() ).session( session ) ) + .andExpect( status().isOk() ); + } }