From 0f1a03e0863031e781b129f81f068c9bc4b12ff9 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Tue, 29 Jun 2021 22:16:34 +0200 Subject: [PATCH] Fix for group and additional tests --- .../base/RepositoryGroupHandler.java | 3 +- .../v2/NativeRepositoryGroupServiceTest.java | 160 +++++++++++++++++- 2 files changed, 160 insertions(+), 3 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java index 6783f7467..8604ba9d1 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java @@ -401,6 +401,7 @@ public class RepositoryGroupHandler implements RepositoryHandler @@ -191,4 +191,160 @@ public class NativeRepositoryGroupServiceTest extends AbstractNativeRestServices } } + @Test + void testAddRepositoryToGroup( ) + { + String token = getAdminToken( ); + try + { + Map jsonAsMap = new HashMap<>( ); + jsonAsMap.put( "id", "group_001" ); + 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( ) ); + + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonAsMap ) + .put( "group_001/repositories/internal" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + + assertNotNull( response ); + result = response.getBody( ).jsonPath( ).getObject( "", RepositoryGroup.class ); + assertNotNull( result ); + assertEquals( 1, result.getRepositories( ).size( ) ); + assertTrue( result.getRepositories( ).contains( "internal" ) ); + + } finally + { + given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .delete( "group_001" ) + .then( ).statusCode( 200 ); + } + } + + @Test + void testAddRepositoryToGroupIdempotency( ) + { + String token = getAdminToken( ); + try + { + Map jsonAsMap = new HashMap<>( ); + jsonAsMap.put( "id", "group_001" ); + 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( ) ); + + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonAsMap ) + .put( "group_001/repositories/internal" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonAsMap ) + .put( "group_001/repositories/internal" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + + assertNotNull( response ); + result = response.getBody( ).jsonPath( ).getObject( "", RepositoryGroup.class ); + assertNotNull( result ); + assertEquals( 1, result.getRepositories( ).size( ) ); + assertTrue( result.getRepositories( ).contains( "internal" ) ); + + } finally + { + given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .delete( "group_001" ) + .then( ).statusCode( 200 ); + } + } + + + @Test + void testRemoveRepositoryFromGroup( ) + { + String token = getAdminToken( ); + try + { + Map 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/internal" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + + assertNotNull( response ); + result = response.getBody( ).jsonPath( ).getObject( "", RepositoryGroup.class ); + assertNotNull( result ); + assertEquals( 0, result.getRepositories( ).size( ) ); + + } finally + { + given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .delete( "group_001" ) + .then( ).statusCode( 200 ); + } + } + } -- 2.39.5