You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/09/19 17:05:47 UTC

[2/5] git commit: Test partial update via PUT with both /users/ and /users/ forms of URL

Test partial update via PUT with both /users/<username> and /users/<uuid> forms of URL


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/6ae1a668
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/6ae1a668
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/6ae1a668

Branch: refs/heads/two-dot-o
Commit: 6ae1a668f6b18d42ccf9109ddae747cf0b97efda
Parents: 138ead7
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Sep 18 10:27:25 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Sep 18 10:27:25 2014 -0400

----------------------------------------------------------------------
 .../apache/usergrid/rest/PartialUpdateTest.java | 47 ++++++++++++++++++--
 1 file changed, 43 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ae1a668/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
index 366df14..7e6e364 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/PartialUpdateTest.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import javax.ws.rs.core.MediaType;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 import org.junit.Rule;
@@ -61,18 +62,18 @@ public class PartialUpdateTest extends AbstractRestIT {
         assertNotNull( userNode );
         String uuid = userNode.withArray("entities").get(0).get("uuid").asText();
         assertNotNull( uuid );
-
         refreshIndex( "test-organization", "test-app" );
 
-        // update user bart passing only an update to his employer
+        // Update bart's employer without specifying any required fields 
+        // (with uuid specified in URL)
 
         Map<String, Object> updateProperties = new LinkedHashMap<String, Object>() {{
             put( "employer", "Initech" );
         }};
 
         try {
-            JsonNode updatedNode = mapper.readTree( 
-                resource().path( "/test-organization/test-app/user/" + uuid )
+            mapper.readTree( 
+                resource().path( "/test-organization/test-app/user/" + uuid ) 
                     .queryParam( "access_token", adminAccessToken )
                     .accept( MediaType.APPLICATION_JSON )
                     .type( MediaType.APPLICATION_JSON )
@@ -81,5 +82,43 @@ public class PartialUpdateTest extends AbstractRestIT {
         } catch ( UniformInterfaceException uie ) {
             fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
         }
+        refreshIndex( "test-organization", "test-app" );
+
+        userNode = mapper.readTree( 
+            resource().path( "/test-organization/test-app/users/" + uuid )
+                .queryParam( "access_token", adminAccessToken )
+                .accept( MediaType.APPLICATION_JSON )
+                .get( String.class ));
+        assertNotNull( userNode );
+        assertEquals( "Initech", userNode.withArray("entities").get(0).get("employer").asText());
+
+
+        // Update bart's employer without specifying any required fields 
+        // (this time with username specified in URL)
+
+        updateProperties = new LinkedHashMap<String, Object>() {{
+            put( "employer", "ACME Corporation" );
+        }};
+
+        try {
+            mapper.readTree( 
+                resource().path( "/test-organization/test-app/users/bart")
+                    .queryParam( "access_token", adminAccessToken )
+                    .accept( MediaType.APPLICATION_JSON )
+                    .type( MediaType.APPLICATION_JSON )
+                    .put( String.class, updateProperties ));
+
+        } catch ( UniformInterfaceException uie ) {
+            fail("Update failed due to: " + uie.getResponse().getEntity(String.class));
+        }
+        refreshIndex( "test-organization", "test-app" );
+
+        userNode = mapper.readTree( 
+            resource().path( "/test-organization/test-app/users/bart" )
+                .queryParam( "access_token", adminAccessToken )
+                .accept( MediaType.APPLICATION_JSON )
+                .get( String.class ));
+        assertNotNull( userNode );
+        assertEquals( "ACME Corporation", userNode.withArray("entities").get(0).get("employer").asText());
     }
 }