← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10062: FRED-API: test POST/PUT of invalid JSON data

 

------------------------------------------------------------
revno: 10062
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-03-08 08:21:57 +0300
message:
  FRED-API: test POST/PUT of invalid JSON data
modified:
  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/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-08 05:11:33 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/test/java/org/hisp/dhis/web/webapi/v1/controller/FacilityControllerTest.java	2013-03-08 05:21:57 +0000
@@ -168,11 +168,37 @@
     {
         MockHttpSession session = getSession( "ALL" );
 
-        mvc.perform( put( "/v1/facilities/abc123" ).content( "{}" ).session( session ).contentType( MediaType.APPLICATION_JSON ) )
+        mvc.perform( put( "/v1/facilities/INVALID_IDENTIFIER" ).content( "{}" ).session( session ).contentType( MediaType.APPLICATION_JSON ) )
             .andExpect( status().isNotFound() );
     }
 
     @Test
+    public void testPutInvalidJsonUid() throws Exception
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        manager.save( organisationUnit );
+
+        MockHttpSession session = getSession( "ALL" );
+
+        mvc.perform( put( "/v1/facilities/" + organisationUnit.getUid() ).content( "INVALID JSON" )
+            .session( session ).contentType( MediaType.APPLICATION_JSON ) )
+            .andExpect( status().isBadRequest() );
+    }
+
+    @Test
+    public void testPutInvalidJsonUuid() throws Exception
+    {
+        OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
+        manager.save( organisationUnit );
+
+        MockHttpSession session = getSession( "ALL" );
+
+        mvc.perform( put( "/v1/facilities/" + organisationUnit.getUuid() ).content( "INVALID JSON" )
+            .session( session ).contentType( MediaType.APPLICATION_JSON ) )
+            .andExpect( status().isBadRequest() );
+    }
+
+    @Test
     public void testPutFacilityUid() throws Exception
     {
         OrganisationUnit organisationUnit = createOrganisationUnit( 'A' );
@@ -227,6 +253,7 @@
             .session( session ).contentType( MediaType.APPLICATION_JSON ) )
             .andExpect( content().contentType( MediaType.APPLICATION_JSON ) )
             .andExpect( jsonPath( "$.name" ).value( "FacilityA" ) )
+            .andExpect( jsonPath( "$.active" ).value( true ) )
             .andExpect( status().isCreated() );
     }
 
@@ -265,6 +292,15 @@
             .andExpect( status().isCreated() );
     }
 
+    @Test
+    public void testPostInvalidJson() throws Exception
+    {
+        MockHttpSession session = getSession( "ALL" );
+
+        mvc.perform( post( "/v1/facilities" ).content( "INVALID JSON" ).session( session ).contentType( MediaType.APPLICATION_JSON ) )
+            .andExpect( status().isBadRequest() );
+    }
+
     //---------------------------------------------------------------------------------------------
     // Test DELETE
     //---------------------------------------------------------------------------------------------
@@ -274,7 +310,7 @@
     {
         MockHttpSession session = getSession( "ALL" );
 
-        mvc.perform( delete( "/v1/facilities/abc123" ).session( session ) )
+        mvc.perform( delete( "/v1/facilities/INVALID_IDENTIFIER" ).session( session ) )
             .andExpect( status().isNotFound() );
     }