mirror of https://github.com/apache/archiva.git
Additional tests for groups and fix for repository remove action
This commit is contained in:
parent
0f1a03e086
commit
084b9efccf
|
@ -245,7 +245,7 @@ public interface RepositoryGroupService
|
|||
),
|
||||
@ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to delete the group",
|
||||
content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
|
||||
@ApiResponse( responseCode = "404", description = "The group with the given id does not exist, or the repository was not part of the group.",
|
||||
@ApiResponse( responseCode = "404", description = "Either the group with the given id does not exist, or the repository was not part of the group.",
|
||||
content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) ),
|
||||
}
|
||||
)
|
||||
|
|
|
@ -279,15 +279,15 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
|
|||
}
|
||||
|
||||
@Override
|
||||
public RepositoryGroup deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId ) throws org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException
|
||||
public RepositoryGroup deleteRepositoryFromGroup( final String repositoryGroupId, final String repositoryId ) throws org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException
|
||||
{
|
||||
if ( StringUtils.isEmpty( repositoryGroupId ) )
|
||||
{
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, "" ), 404 );
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, repositoryGroupId ), 404 );
|
||||
}
|
||||
if ( StringUtils.isEmpty( repositoryId ) )
|
||||
{
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, "" ), 404 );
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId ), 404 );
|
||||
}
|
||||
try
|
||||
{
|
||||
|
@ -295,12 +295,14 @@ public class DefaultRepositoryGroupService implements RepositoryGroupService
|
|||
if (repositoryGroup==null) {
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, "" ), 404 );
|
||||
}
|
||||
if (repositoryGroup.getRepositories().stream().noneMatch( r -> repositoryId.equals( r.getId() ) )) {
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId ), 404 );
|
||||
}
|
||||
if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
|
||||
log.error( "This group instance is not editable: {}", repositoryGroupId );
|
||||
throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, "" ), 500 );
|
||||
}
|
||||
EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
|
||||
|
||||
editableRepositoryGroup.removeRepository( repositoryId );
|
||||
org.apache.archiva.repository.RepositoryGroup newGroup = repositoryRegistry.putRepositoryGroup( editableRepositoryGroup );
|
||||
return RepositoryGroup.of( newGroup );
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.archiva.rest.services.v2;
|
|||
import io.restassured.response.Response;
|
||||
import org.apache.archiva.components.rest.model.PagedResult;
|
||||
import org.apache.archiva.rest.api.model.v2.RepositoryGroup;
|
||||
import org.apache.archiva.rest.api.services.v2.ArchivaRestError;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
@ -191,6 +192,73 @@ public class NativeRepositoryGroupServiceTest extends AbstractNativeRestServices
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveRepositoryGroup( )
|
||||
{
|
||||
String token = getAdminToken( );
|
||||
List<String> groups = new ArrayList<>( );
|
||||
try
|
||||
{
|
||||
for ( int i=0; i<10; i++)
|
||||
{
|
||||
String groupName = String.format( "group_%03d", i );
|
||||
groups.add( groupName );
|
||||
Map<String, Object> jsonAsMap = new HashMap<>( );
|
||||
jsonAsMap.put( "id", groupName );
|
||||
Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.body( jsonAsMap )
|
||||
.post( "" )
|
||||
.then( ).statusCode( 201 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
RepositoryGroup result = response.getBody( ).jsonPath( ).getObject( "", RepositoryGroup.class );
|
||||
assertNotNull( result );
|
||||
}
|
||||
Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.delete( "group_001" )
|
||||
.then( ).statusCode( 200 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
|
||||
response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.get( "" )
|
||||
.then( ).statusCode( 200 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
PagedResult resultList = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
|
||||
assertEquals( 9, resultList.getPagination( ).getTotalCount( ) );
|
||||
|
||||
|
||||
response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.delete( "group_005" )
|
||||
.then( ).statusCode( 200 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
|
||||
response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.get( "" )
|
||||
.then( ).statusCode( 200 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
resultList = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
|
||||
assertEquals( 8, resultList.getPagination( ).getTotalCount( ) );
|
||||
|
||||
} finally
|
||||
{
|
||||
for (String groupName : groups)
|
||||
{
|
||||
if (!("group_001".equals(groupName) || "group_005".equals(groupName) ) )
|
||||
{
|
||||
given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.delete( groupName )
|
||||
.then( ).statusCode( 200 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testAddRepositoryToGroup( )
|
||||
{
|
||||
|
@ -347,4 +415,54 @@ public class NativeRepositoryGroupServiceTest extends AbstractNativeRestServices
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveRepositoryFromGroup404( )
|
||||
{
|
||||
String token = getAdminToken( );
|
||||
try
|
||||
{
|
||||
Map<String, Object> jsonAsMap = new HashMap<>( );
|
||||
jsonAsMap.put( "id", "group_001" );
|
||||
jsonAsMap.put( "repositories", Arrays.asList( "internal" ) );
|
||||
Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.body( jsonAsMap )
|
||||
.post( "" )
|
||||
.prettyPeek()
|
||||
.then( ).statusCode( 201 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
RepositoryGroup result = response.getBody( ).jsonPath( ).getObject( "", RepositoryGroup.class );
|
||||
assertNotNull( result );
|
||||
|
||||
response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.get( "" )
|
||||
.then( ).statusCode( 200 ).extract( ).response( );
|
||||
assertNotNull( response );
|
||||
PagedResult resultList = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
|
||||
assertEquals( 1, resultList.getPagination( ).getTotalCount( ) );
|
||||
|
||||
assertNotNull( result.getRepositories( ) );
|
||||
assertEquals( 1, result.getRepositories( ).size( ) );
|
||||
assertTrue( result.getRepositories( ).contains( "internal" ) );
|
||||
|
||||
response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.body( jsonAsMap )
|
||||
.delete( "group_001/repositories/internalxx" )
|
||||
.prettyPeek()
|
||||
.then( ).statusCode( 404 ).extract( ).response( );
|
||||
|
||||
assertNotNull( response );
|
||||
ArchivaRestError error = response.getBody( ).jsonPath( ).getObject( "", ArchivaRestError.class );
|
||||
assertNotNull( error );
|
||||
} finally
|
||||
{
|
||||
given( ).spec( getRequestSpec( token ) ).contentType( JSON )
|
||||
.when( )
|
||||
.delete( "group_001" )
|
||||
.then( ).statusCode( 200 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue