Author: olamy
Date: Fri Feb  1 15:30:59 2013
New Revision: 1441488

URL: http://svn.apache.org/viewvc?rev=1441488&view=rev
Log:
more unit tests

Modified:
    
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/LdapGroupMapping.java
    
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java
    
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java

Modified: 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/LdapGroupMapping.java
URL: 
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/LdapGroupMapping.java?rev=1441488&r1=1441487&r2=1441488&view=diff
==============================================================================
--- 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/LdapGroupMapping.java
 (original)
+++ 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/model/LdapGroupMapping.java
 Fri Feb  1 15:30:59 2013
@@ -76,4 +76,32 @@ public class LdapGroupMapping
         sb.append( '}' );
         return sb.toString();
     }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( o == null || getClass() != o.getClass() )
+        {
+            return false;
+        }
+
+        LdapGroupMapping that = (LdapGroupMapping) o;
+
+        if ( !group.equals( that.group ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return group.hashCode();
+    }
 }

Modified: 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java
URL: 
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java?rev=1441488&r1=1441487&r2=1441488&view=diff
==============================================================================
--- 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java
 (original)
+++ 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java
 Fri Feb  1 15:30:59 2013
@@ -29,6 +29,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
@@ -64,10 +65,11 @@ public interface LdapGroupMappingService
         throws RedbackServiceException;
 
     @DELETE
+    @Path( "{group}" )
     @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( permissions = 
RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
-    Boolean removeLdapGroupMapping( String group )
+    Boolean removeLdapGroupMapping( @PathParam( "group" ) String group )
         throws RedbackServiceException;
 
     @POST

Modified: 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
URL: 
http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java?rev=1441488&r1=1441487&r2=1441488&view=diff
==============================================================================
--- 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
 (original)
+++ 
archiva/redback/redback-core/trunk/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LdapGroupMappingServiceTest.java
 Fri Feb  1 15:30:59 2013
@@ -22,7 +22,9 @@ import org.apache.archiva.redback.compon
 import org.apache.archiva.redback.rest.api.model.LdapGroupMapping;
 import org.apache.archiva.redback.rest.api.services.LdapGroupMappingService;
 import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
+import org.apache.commons.lang.StringUtils;
 import org.fest.assertions.Assertions;
+import org.fest.assertions.Condition;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.annotation.DirtiesContext;
@@ -102,12 +104,9 @@ public class LdapGroupMappingServiceTest
         throws Exception
     {
 
-
         // cleanup ldap entries
         InitialDirContext context = apacheDs.getAdminContext();
 
-
-
         for ( String group : this.groups )
         {
             context.unbind( createGroupDn( group ) );
@@ -178,7 +177,27 @@ public class LdapGroupMappingServiceTest
     }
 
     @Test
-    public void getLdapGroupMappings() throws Exception
+    public void getLdapGroupMappings()
+        throws Exception
+    {
+        try
+        {
+            LdapGroupMappingService service = getLdapGroupMappingService( 
authorizationHeader );
+
+            List<LdapGroupMapping> mappings = service.getLdapGroupMappings();
+
+            Assertions.assertThat( mappings 
).isNotNull().isNotEmpty().hasSize( 3 );
+        }
+        catch ( Exception e )
+        {
+            log.error( e.getMessage(), e );
+            throw e;
+        }
+    }
+
+    @Test
+    public void addThenRemove()
+        throws Exception
     {
         try
         {
@@ -187,6 +206,41 @@ public class LdapGroupMappingServiceTest
             List<LdapGroupMapping> mappings = service.getLdapGroupMappings();
 
             Assertions.assertThat( mappings 
).isNotNull().isNotEmpty().hasSize( 3 );
+
+            LdapGroupMapping ldapGroupMapping = new LdapGroupMapping( "ldap 
group", Arrays.asList( "redback role" ) );
+
+            service.addLdapGroupMapping( ldapGroupMapping );
+
+            mappings = service.getLdapGroupMappings();
+
+            Assertions.assertThat( mappings 
).isNotNull().isNotEmpty().hasSize( 4 ).satisfies( new Condition<List<?>>()
+            {
+                @Override
+                public boolean matches( List<?> objects )
+                {
+                    boolean res = false;
+
+                    List<LdapGroupMapping> mappingList = 
(List<LdapGroupMapping>) objects;
+
+                    for ( LdapGroupMapping mapping : mappingList )
+                    {
+                        if ( StringUtils.equals( "ldap group", 
mapping.getGroup() ) )
+                        {
+                            Assertions.assertThat( mapping.getRoleNames() 
).isNotNull().isNotEmpty().containsOnly(
+                                "redback role" );
+                            return true;
+                        }
+                    }
+
+                    return res;
+                }
+            } );
+
+            service.removeLdapGroupMapping( "ldap group" );
+
+            mappings = service.getLdapGroupMappings();
+
+            Assertions.assertThat( mappings 
).isNotNull().isNotEmpty().hasSize( 3 );
         }
         catch ( Exception e )
         {


Reply via email to