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:
parent
75fa37a3de
commit
b949895ed7
|
@ -76,4 +76,32 @@ public class LdapGroupMapping
|
||||||
sb.append( '}' );
|
sb.append( '}' );
|
||||||
return sb.toString();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
@ -64,10 +65,11 @@ public interface LdapGroupMappingService
|
||||||
throws RedbackServiceException;
|
throws RedbackServiceException;
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
|
@Path( "{group}" )
|
||||||
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
|
||||||
@RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
|
@RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION )
|
||||||
Boolean removeLdapGroupMapping( String group )
|
Boolean removeLdapGroupMapping( @PathParam( "group" ) String group )
|
||||||
throws RedbackServiceException;
|
throws RedbackServiceException;
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|
|
@ -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.model.LdapGroupMapping;
|
||||||
import org.apache.archiva.redback.rest.api.services.LdapGroupMappingService;
|
import org.apache.archiva.redback.rest.api.services.LdapGroupMappingService;
|
||||||
import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
|
import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.fest.assertions.Assertions;
|
import org.fest.assertions.Assertions;
|
||||||
|
import org.fest.assertions.Condition;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.test.annotation.DirtiesContext;
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
@ -102,12 +104,9 @@ public class LdapGroupMappingServiceTest
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// cleanup ldap entries
|
// cleanup ldap entries
|
||||||
InitialDirContext context = apacheDs.getAdminContext();
|
InitialDirContext context = apacheDs.getAdminContext();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for ( String group : this.groups )
|
for ( String group : this.groups )
|
||||||
{
|
{
|
||||||
context.unbind( createGroupDn( group ) );
|
context.unbind( createGroupDn( group ) );
|
||||||
|
@ -178,7 +177,8 @@ public class LdapGroupMappingServiceTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getLdapGroupMappings() throws Exception
|
public void getLdapGroupMappings()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -194,4 +194,58 @@ public class LdapGroupMappingServiceTest
|
||||||
throw e;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue