]> source.dussan.org Git - archiva.git/commitdiff
Fix for group and additional tests
authorMartin Stockhammer <martin_s@apache.org>
Tue, 29 Jun 2021 20:16:34 +0000 (22:16 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Tue, 29 Jun 2021 20:16:34 +0000 (22:16 +0200)
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/RepositoryGroupHandler.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryGroupServiceTest.java

index 6783f74677bab030c9e33bcbe380e0029d2766e4..8604ba9d128171bf3a2a58f2266d83b74aaabbee 100644 (file)
@@ -401,6 +401,7 @@ public class RepositoryGroupHandler implements RepositoryHandler<RepositoryGroup
             repo = repositoryRegistry.getProvider( repoType ).createRepositoryGroup( repositoryGroupConfiguration );
         }
         replaceOrAddRepositoryConfig( repositoryGroupConfiguration, configuration );
+        updateReferences( repo, repositoryGroupConfiguration );
         return repo;
     }
 
@@ -422,7 +423,7 @@ public class RepositoryGroupHandler implements RepositoryHandler<RepositoryGroup
         }
         if ( result.isValid( ) )
         {
-            put( repositoryConfiguration );
+            put( result.getRepository() );
         }
         return result;
     }
index 226c5a8ed05811ace2cf33019e97d903dd32022c..594b79c15966c01d62744d3735f886e142c9f0f5 100644 (file)
@@ -31,6 +31,7 @@ import org.junit.jupiter.api.TestInstance;
 import org.junit.jupiter.api.TestMethodOrder;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -39,8 +40,7 @@ import static io.restassured.RestAssured.given;
 import static io.restassured.http.ContentType.JSON;
 import static org.easymock.EasyMock.contains;
 import static org.hamcrest.Matchers.endsWith;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * @author Martin Stockhammer <martin_s@apache.org>
@@ -191,4 +191,160 @@ public class NativeRepositoryGroupServiceTest extends AbstractNativeRestServices
         }
     }
 
+    @Test
+    void testAddRepositoryToGroup( )
+    {
+        String token = getAdminToken( );
+        try
+        {
+            Map<String, Object> 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<String, Object> 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<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/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 );
+        }
+    }
+
 }