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