dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21307
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10042: FRED-API: tests for putting to a invalid id
------------------------------------------------------------
revno: 10042
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-03-07 15:59:06 +0300
message:
FRED-API: tests for putting to a invalid id
modified:
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/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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 09:24:35 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java 2013-03-07 12:59:06 +0000
@@ -549,6 +549,23 @@
HttpHeaders headers = new HttpHeaders();
headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+ OrganisationUnit organisationUnit;
+
+ if ( id.length() == 11 )
+ {
+ organisationUnit = organisationUnitService.getOrganisationUnit( id );
+ }
+ else
+ {
+ organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id );
+ }
+
+ if ( organisationUnit == null )
+ {
+ return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( HttpStatus.NOT_FOUND.toString(),
+ "Facility with that ID not found" ), headers, HttpStatus.NOT_FOUND );
+ }
+
// getId == null is not legal, but will be catched by bean validation
if ( facility.getId() != null )
{
@@ -572,23 +589,6 @@
if ( constraintViolations.isEmpty() )
{
OrganisationUnit organisationUnitUpdate = conversionService.convert( facility, OrganisationUnit.class );
- OrganisationUnit organisationUnit;
-
- if ( id.length() == 11 )
- {
- organisationUnit = organisationUnitService.getOrganisationUnit( id );
- }
- else
- {
- organisationUnit = organisationUnitService.getOrganisationUnitByUuid( id );
- }
-
- if ( organisationUnit == null )
- {
- return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( HttpStatus.NOT_FOUND.toString(),
- "Facility with that ID not found" ), headers, HttpStatus.NOT_FOUND );
- }
-
checkIdentifier( facility, organisationUnit.getUid() );
if ( request.getHeader( "If-Match" ) != null )
=== 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 09:31:13 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java 2013-03-07 12:59:06 +0000
@@ -137,4 +137,13 @@
.andExpect( jsonPath( "$.name" ).value( "OrgUnitA" ) )
.andExpect( status().isOk() );
}
+
+ @Test
+ public void testPutFacility404() throws Exception
+ {
+ MockHttpSession session = getSession( "ALL" );
+
+ mvc.perform( put( "/v1/facilities/abc123" ).content( "{}" ).session( session ).contentType( MediaType.APPLICATION_JSON ) )
+ .andExpect( status().isNotFound() );
+ }
}