more unit tests

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1441488 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-02-01 15:30:59 +00:00
parent 75fa37a3de
commit b949895ed7
3 changed files with 89 additions and 5 deletions

View File

@ -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();
}
}

View File

@ -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

View File

@ -22,7 +22,9 @@ import org.apache.archiva.redback.components.apacheds.ApacheDs;
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,8 @@ public class LdapGroupMappingServiceTest
}
@Test
public void getLdapGroupMappings() throws Exception
public void getLdapGroupMappings()
throws Exception
{
try
{
@ -194,4 +194,58 @@ public class LdapGroupMappingServiceTest
throw e;
}
}
@Test
public void addThenRemove()
throws Exception
{
try
{
LdapGroupMappingService service = getLdapGroupMappingService( authorizationHeader );
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 )
{
log.error( e.getMessage(), e );
throw e;
}
}
}