Fix for group and additional tests

This commit is contained in:
Martin Stockhammer 2021-06-29 22:16:34 +02:00
parent 478c60608d
commit 0f1a03e086
2 changed files with 160 additions and 3 deletions

View 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;
}

View 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 );
}
}
}