directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1534933 - in /directory/escimo/trunk: server/src/main/java/org/apache/directory/scim/rest/GroupService.java tests/src/test/java/org/apache/directory/scim/UserResourceTest.java
Date Wed, 23 Oct 2013 07:16:06 GMT
Author: kayyagari
Date: Wed Oct 23 07:16:05 2013
New Revision: 1534933

URL: http://svn.apache.org/r1534933
Log:
path service for Groups

Modified:
    directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
    directory/escimo/trunk/tests/src/test/java/org/apache/directory/scim/UserResourceTest.java

Modified: directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java?rev=1534933&r1=1534932&r2=1534933&view=diff
==============================================================================
--- directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
(original)
+++ directory/escimo/trunk/server/src/main/java/org/apache/directory/scim/rest/GroupService.java
Wed Oct 23 07:16:05 2013
@@ -39,6 +39,7 @@ import javax.ws.rs.core.Response.Respons
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.directory.scim.AttributeNotFoundException;
 import org.apache.directory.scim.GroupResource;
 import org.apache.directory.scim.ProviderService;
 import org.apache.directory.scim.RequestContext;
@@ -174,4 +175,46 @@ public class GroupService
         return rb.build();
     }
 
+    @PATCH
+    @Produces({MediaType.APPLICATION_JSON})
+    public Response patchGroup( String jsonData, @Context UriInfo uriInfo, @Context HttpHeaders
headers )
+    {
+        ResponseBuilder rb = null;
+
+        if( ( jsonData == null ) || ( jsonData.trim().length() == 0 ) )
+        {
+            rb = Response.status( Status.BAD_REQUEST ).entity( "No data is present with the
call to " + uriInfo.getAbsolutePath() );
+            return rb.build();
+        }
+        
+        LOG.debug( "Data received at the URI {}\n{}", uriInfo.getAbsolutePath(), jsonData
);
+        
+        try
+        {
+            RequestContext ctx = new RequestContext( provider, uriInfo, headers );
+            
+            ServerResource resource = provider.patchGroup( jsonData, ctx );
+            
+            if( resource == null )
+            {
+                rb = Response.status( Status.NO_CONTENT );
+            }
+            else
+            {
+                String json = ResourceSerializer.serialize( resource );
+                rb = Response.ok().entity( json );
+            }
+        }
+        catch( AttributeNotFoundException e )
+        {
+            rb = Response.status( Status.NOT_FOUND ).entity( exceptionToStr( e ) );
+        }
+        catch( Exception e )
+        {
+            rb = Response.status( Status.INTERNAL_SERVER_ERROR ).entity( exceptionToStr(
e ) );
+        }
+        
+        return rb.build();
+    }
+
 }

Modified: directory/escimo/trunk/tests/src/test/java/org/apache/directory/scim/UserResourceTest.java
URL: http://svn.apache.org/viewvc/directory/escimo/trunk/tests/src/test/java/org/apache/directory/scim/UserResourceTest.java?rev=1534933&r1=1534932&r2=1534933&view=diff
==============================================================================
--- directory/escimo/trunk/tests/src/test/java/org/apache/directory/scim/UserResourceTest.java
(original)
+++ directory/escimo/trunk/tests/src/test/java/org/apache/directory/scim/UserResourceTest.java
Wed Oct 23 07:16:05 2013
@@ -22,7 +22,7 @@ package org.apache.directory.scim;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -30,11 +30,15 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.directory.api.ldap.model.constants.SchemaConstants;
+import org.apache.directory.api.ldap.model.cursor.EntryCursor;
 import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.message.SearchScope;
 import org.apache.directory.api.ldap.model.name.Dn;
 import org.apache.directory.scim.User.Email;
 import org.apache.directory.scim.User.Name;
 import org.apache.directory.scim.schema.CoreResource;
+import org.apache.directory.server.core.api.CoreSession;
+import org.apache.directory.server.core.api.LdapCoreSessionConnection;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -203,20 +207,54 @@ public class UserResourceTest
         List<Group.Member> members = new ArrayList<Group.Member>();
         group.setMembers( members );
         
-        Entry entry = JettyServer.getAdminSession().lookup( new Dn( "uid=admin,ou=system"
), SchemaConstants.ENTRY_UUID_AT );
+        CoreSession session = JettyServer.getAdminSession();
+        LdapCoreSessionConnection conn = new LdapCoreSessionConnection( session );
         
-        Group.Member m1 = new Group.Member();
+        EntryCursor cursor = conn.search( "ou=system", "(objectClass=*)", SearchScope.SUBTREE,
SchemaConstants.ALL_ATTRIBUTES_ARRAY );
         
-        String value = entry.get( SchemaConstants.ENTRY_UUID_AT ).getString();
-        
-        m1.setValue( value );
-        m1.set$ref( baseUrl + "/Users/" + value );
-        
-        members.add( m1 );
+        int count = 0;
+        while( cursor.next() )
+        {
+            Entry entry = cursor.get();
+            
+            Group.Member m1 = new Group.Member();
+            
+            String value = entry.get( SchemaConstants.ENTRY_UUID_AT ).getString();
+            
+            m1.setValue( value );
+            m1.set$ref( baseUrl + "/Users/" + value );
+            
+            members.add( m1 );
+            count++;
+        }
         
         Group addedGroup = ( Group ) client.addGroup( group );
         assertNotNull( addedGroup );
         assertEquals( group.getDisplayName(), addedGroup.getDisplayName() );
         assertNotNull( addedGroup.getId() );
+        assertEquals( count, addedGroup.getMembers().size() );
+        
+        Group.Member deletedMember = members.get( 0 );
+        
+        Group tobePatchedGroup = new Group();
+        tobePatchedGroup.setId( addedGroup.getId() );
+        
+        List<Group.Member> patchedMembers = new ArrayList<Group.Member>();
+        tobePatchedGroup.setMembers( patchedMembers );
+        
+        deletedMember.setOperation( "delete" );
+        patchedMembers.add( deletedMember );
+        
+        client.patchGroup( tobePatchedGroup );
+        Group patchedGroup = ( Group ) client.getGroup( addedGroup.getId() );
+        assertEquals( ( count - 1 ), patchedGroup.getMembers().size() );
+        
+        for( Group.Member gm : patchedGroup.getMembers() )
+        {
+            if( gm.getValue().equals( deletedMember.getValue() ) )
+            {
+                fail( "This member shouldn't present" );
+            }
+        }
     }
 }



Mime
View raw message