diff options
author | Martin Stockhammer <martin_s@apache.org> | 2021-01-27 20:16:26 +0100 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2021-01-27 20:16:26 +0100 |
commit | b32d75a85b4f5805d6d251ea2237f838087aa2bf (patch) | |
tree | 162037148959d4bddb68ef7a7aa22ea89a69759f /archiva-modules/archiva-web/archiva-rest/archiva-rest-services | |
parent | 7eef53d7c5145de75ecb6734169bacb53b02f5a0 (diff) | |
download | archiva-b32d75a85b4f5805d6d251ea2237f838087aa2bf.tar.gz archiva-b32d75a85b4f5805d6d251ea2237f838087aa2bf.zip |
Adding task admin implementation
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest/archiva-rest-services')
6 files changed, 220 insertions, 140 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java index 3c9c3a654..e380a24d9 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultMavenManagedRepositoryService.java @@ -24,6 +24,7 @@ import org.apache.archiva.components.rest.util.QueryHelper; import org.apache.archiva.rest.api.model.v2.FileInfo; import org.apache.archiva.rest.api.model.v2.MavenManagedRepository; import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException; +import org.apache.archiva.rest.api.services.v2.ErrorKeys; import org.apache.archiva.rest.api.services.v2.ErrorMessage; import org.apache.archiva.rest.api.services.v2.MavenManagedRepositoryService; import org.slf4j.Logger; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java index 42b719306..9290873d6 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryGroupService.java @@ -46,6 +46,7 @@ import org.apache.archiva.redback.rest.services.RedbackRequestInformation; import org.apache.archiva.redback.users.User; import org.apache.archiva.rest.api.model.v2.RepositoryGroup; import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException; +import org.apache.archiva.rest.api.services.v2.ErrorKeys; import org.apache.archiva.rest.api.services.v2.ErrorMessage; import org.apache.archiva.rest.api.services.v2.RepositoryGroupService; import org.apache.commons.lang3.StringUtils; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryService.java index 4f34cd135..7e41b093b 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultRepositoryService.java @@ -17,11 +17,10 @@ package org.apache.archiva.rest.services.v2; * under the License. */ +import org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.admin.RepositoryTaskAdministration; import org.apache.archiva.components.rest.model.PagedResult; import org.apache.archiva.components.rest.util.QueryHelper; -import org.apache.archiva.components.taskqueue.Task; -import org.apache.archiva.components.taskqueue.TaskQueueException; -import org.apache.archiva.components.taskqueue.execution.TaskQueueExecutor; import org.apache.archiva.metadata.repository.MetadataRepositoryException; import org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager; import org.apache.archiva.repository.RepositoryRegistry; @@ -33,19 +32,14 @@ import org.apache.archiva.rest.api.model.v2.Repository; import org.apache.archiva.rest.api.model.v2.RepositoryStatistics; import org.apache.archiva.rest.api.model.v2.ScanStatus; import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException; +import org.apache.archiva.rest.api.services.v2.ErrorKeys; import org.apache.archiva.rest.api.services.v2.ErrorMessage; import org.apache.archiva.rest.api.services.v2.RepositoryService; -import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; -import org.apache.archiva.scheduler.indexing.IndexingArchivaTaskScheduler; -import org.apache.archiva.scheduler.indexing.maven.ArchivaIndexingTaskExecutor; -import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler; -import org.apache.archiva.scheduler.repository.model.RepositoryTask; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import javax.inject.Inject; import javax.inject.Named; import javax.ws.rs.core.Response; import java.util.Comparator; @@ -58,49 +52,64 @@ import java.util.stream.Collectors; * @author Martin Stockhammer <martin_s@apache.org> * @since 3.0 */ -@Service("v2.repositoryService#rest") +@Service( "v2.repositoryService#rest" ) public class DefaultRepositoryService implements RepositoryService { - @Inject + final RepositoryRegistry repositoryRegistry; - @Inject + final RepositoryStatisticsManager repositoryStatisticsManager; - @Inject - @Named(value="taskQueueExecutor#indexing") - TaskQueueExecutor<ArtifactIndexingTask> indexingTaskExecutor; + private final RepositoryTaskAdministration repositoryTaskAdministration; - @Inject - @Named(value="taskQueueExecutor#repository-scanning") - TaskQueueExecutor<RepositoryTask> scanningTaskExecutor; - - @Inject - @Named(value = "archivaTaskScheduler#repository") - private RepositoryArchivaTaskScheduler repositoryArchivaTaskScheduler; - - @Inject - @Named( value = "archivaTaskScheduler#indexing" ) - private IndexingArchivaTaskScheduler indexingArchivaTaskScheduler; - - @Inject - private RepositoryScanner repoScanner; + private final RepositoryScanner repoScanner; private static final Logger log = LoggerFactory.getLogger( DefaultRepositoryService.class ); private static final QueryHelper<org.apache.archiva.repository.Repository> QUERY_HELPER = new QueryHelper<>( new String[]{"id", "name"} ); + static { QUERY_HELPER.addStringFilter( "id", org.apache.archiva.repository.Repository::getId ); QUERY_HELPER.addStringFilter( "name", org.apache.archiva.repository.Repository::getName ); + QUERY_HELPER.addStringFilter( "description", org.apache.archiva.repository.Repository::getDescription ); + QUERY_HELPER.addStringFilter( "type", repo -> repo.getType( ).name( ) ); + QUERY_HELPER.addBooleanFilter( "scanned", org.apache.archiva.repository.Repository::isScanned ); QUERY_HELPER.addNullsafeFieldComparator( "id", org.apache.archiva.repository.Repository::getId ); QUERY_HELPER.addNullsafeFieldComparator( "name", org.apache.archiva.repository.Repository::getName ); + QUERY_HELPER.addNullsafeFieldComparator( "type", repo -> repo.getType( ).name( ) ); + QUERY_HELPER.addNullsafeFieldComparator( "boolean", org.apache.archiva.repository.Repository::isScanned ); + } + + public DefaultRepositoryService( RepositoryRegistry repositoryRegistry, RepositoryStatisticsManager repositoryStatisticsManager, + @Named( value = "repositoryTaskAdministration#default") RepositoryTaskAdministration repositoryTaskAdministration, + RepositoryScanner repoScanner ) + { + this.repositoryRegistry = repositoryRegistry; + this.repositoryStatisticsManager = repositoryStatisticsManager; + this.repoScanner = repoScanner; + this.repositoryTaskAdministration = repositoryTaskAdministration; + } + + private void handleAdminException( RepositoryAdminException e ) throws ArchivaRestServiceException + { + log.error( "Repository admin error: {}", e.getMessage( ), e ); + if ( e.keyExists( ) ) + { + throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.PREFIX + e.getKey( ), e.getParameters( ) ) ); + } + else + { + throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) ); + } } + @Override public PagedResult<Repository> getRepositories( String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order, - String localeString) throws ArchivaRestServiceException + String localeString ) throws ArchivaRestServiceException { final Locale locale = StringUtils.isNotEmpty( localeString ) ? Locale.forLanguageTag( localeString ) : Locale.getDefault( ); boolean isAscending = QUERY_HELPER.isAscending( order ); @@ -123,7 +132,8 @@ public class DefaultRepositoryService implements RepositoryService @Override public RepositoryStatistics getManagedRepositoryStatistics( String repositoryId ) throws ArchivaRestServiceException { - if (repositoryRegistry.getManagedRepository( repositoryId )==null) { + if ( repositoryRegistry.getManagedRepository( repositoryId ) == null ) + { throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_MANAGED_NOT_FOUND, repositoryId ), 404 ); } try @@ -142,17 +152,13 @@ public class DefaultRepositoryService implements RepositoryService { try { - org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository( repositoryId ); - ArtifactIndexingTask task = - new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, repository.getIndexingContext() ); - task.setExecuteOnEntireRepo( true ); - task.setOnlyUpdate( !fullScan ); - indexingArchivaTaskScheduler.queueTask( task ); - repositoryArchivaTaskScheduler.queueTask( new RepositoryTask( repositoryId, fullScan ) ); + repositoryTaskAdministration.scheduleFullScan( repositoryId ); return Response.ok( ).build( ); - } catch ( TaskQueueException e ) { - log.error( "Could not queue the task: {}", e.getMessage( ), e ); - throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.TASK_QUEUE_FAILED, e.getMessage( ) ) ); + } + catch ( RepositoryAdminException e ) + { + handleAdminException( e ); + return Response.serverError( ).build( ); } } @@ -166,34 +172,22 @@ public class DefaultRepositoryService implements RepositoryService } catch ( RepositoryScannerException e ) { - log.error( e.getMessage(), e ); - throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_SCAN_FAILED, e.getMessage() )); + log.error( e.getMessage( ), e ); + throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.REPOSITORY_SCAN_FAILED, e.getMessage( ) ) ); } } @Override public ScanStatus getScanStatus( String repositoryId ) throws ArchivaRestServiceException { - ScanStatus status = new ScanStatus( ); try { - RepositoryTask scanTask = scanningTaskExecutor.getCurrentTask( ); - if ( !repositoryId.equals( scanTask.getRepositoryId( ) ) ) - { - scanTask=null; - } - ArtifactIndexingTask indexTask = indexingTaskExecutor.getCurrentTask( ); - if (!repositoryId.equals(indexTask.getRepository().getId())) { - indexTask = null; - } - status.updateScanInfo( scanTask, scanningTaskExecutor.getQueue( ).getQueueSnapshot( ).stream( ).filter( task -> repositoryId.equals(task.getRepositoryId()) ).collect( Collectors.toList() ) ); - status.updateIndexInfo( indexTask, indexingTaskExecutor.getQueue( ).getQueueSnapshot( ).stream().filter( task -> repositoryId.equals(task.getRepository().getId())).collect( Collectors.toList()) ); - return status; + return ScanStatus.of( repositoryTaskAdministration.getCurrentScanStatus( ) ); } - catch ( TaskQueueException e ) + catch ( RepositoryAdminException e ) { - log.error( "Could not get task information: {}", e.getMessage( ), e ); - throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.TASK_QUEUE_FAILED, e.getMessage( ) ) ); + handleAdminException( e ); + return null; } } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java index 990207486..360d03ebc 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java @@ -56,6 +56,7 @@ import org.apache.archiva.rest.api.model.v2.CacheConfiguration; import org.apache.archiva.rest.api.model.v2.LdapConfiguration; import org.apache.archiva.rest.api.model.v2.SecurityConfiguration; import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException; +import org.apache.archiva.rest.api.services.v2.ErrorKeys; import org.apache.archiva.rest.api.services.v2.ErrorMessage; import org.apache.archiva.rest.api.services.v2.SecurityConfigurationService; import org.apache.commons.collections4.CollectionUtils; @@ -87,8 +88,8 @@ import java.util.ResourceBundle; import java.util.function.Predicate; import java.util.stream.Collectors; -import static org.apache.archiva.rest.services.v2.ErrorKeys.INVALID_RESULT_SET_ERROR; -import static org.apache.archiva.rest.services.v2.ErrorKeys.REPOSITORY_ADMIN_ERROR; +import static org.apache.archiva.rest.api.services.v2.ErrorKeys.INVALID_RESULT_SET_ERROR; +import static org.apache.archiva.rest.api.services.v2.ErrorKeys.REPOSITORY_ADMIN_ERROR; /** * @author Martin Stockhammer <martin_s@apache.org> diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java deleted file mode 100644 index 5544ff315..000000000 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.apache.archiva.rest.services.v2;/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.archiva.rest.api.services.v2.ErrorMessage; - -import java.util.List; - -/** - * @author Martin Stockhammer <martin_s@apache.org> - */ -public interface ErrorKeys -{ - - String PREFIX = "archiva."; - String REPOSITORY_GROUP_PREFIX = PREFIX + "repository_group."; - String REPOSITORY_PREFIX = PREFIX + "repository."; - - String INVALID_RESULT_SET_ERROR = "archiva.result_set.invalid"; - String REPOSITORY_ADMIN_ERROR = "archiva.repositoryadmin.error"; - String LDAP_CF_INIT_FAILED = "archiva.ldap.cf.init.failed"; - String LDAP_USER_MAPPER_INIT_FAILED = "archiva.ldap.usermapper.init.failed"; - String LDAP_COMMUNICATION_ERROR = "archiva.ldap.communication_error"; - String LDAP_INVALID_NAME = "archiva.ldap.invalid_name"; - String LDAP_GENERIC_ERROR = "archiva.ldap.generic_error"; - String LDAP_SERVICE_UNAVAILABLE = "archiva.ldap.service_unavailable"; - String LDAP_SERVICE_AUTHENTICATION_FAILED = "archiva.ldap.authentication.failed"; - String LDAP_SERVICE_AUTHENTICATION_NOT_SUPPORTED = "archiva.ldap.authentication.not_supported"; - String LDAP_SERVICE_NO_PERMISSION = "archiva.ldap.no_permissions"; - - String PROPERTY_NOT_FOUND = "archiva.property.not.found"; - - String MISSING_DATA = "archiva.missing.data"; - - String REPOSITORY_GROUP_NOT_FOUND = REPOSITORY_GROUP_PREFIX+"notfound"; - String REPOSITORY_GROUP_ADD_FAILED = REPOSITORY_GROUP_PREFIX+"add.failed" ; - String REPOSITORY_GROUP_EXIST = REPOSITORY_GROUP_PREFIX+"exists"; - - String REPOSITORY_GROUP_DELETE_FAILED = REPOSITORY_GROUP_PREFIX + "delete.failed"; - String REPOSITORY_NOT_FOUND = REPOSITORY_PREFIX + "notfound"; - String REPOSITORY_MANAGED_NOT_FOUND = REPOSITORY_PREFIX + ".managed.notfound"; - - String REPOSITORY_METADATA_ERROR = REPOSITORY_PREFIX + "metadata_error"; - - String TASK_QUEUE_FAILED = PREFIX + "task.queue_failed"; - String REPOSITORY_SCAN_FAILED = REPOSITORY_PREFIX + "scan.failed"; -} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryServiceTest.java new file mode 100644 index 000000000..0c74d3a8c --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeRepositoryServiceTest.java @@ -0,0 +1,162 @@ +package org.apache.archiva.rest.services.v2; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import io.restassured.response.Response; +import org.apache.archiva.components.rest.model.PagedResult; +import org.apache.archiva.rest.api.model.v2.Repository; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestMethodOrder; + +import java.util.List; + +import static io.restassured.RestAssured.given; +import static io.restassured.http.ContentType.JSON; +import static org.junit.jupiter.api.Assertions.*; + +/** + * @author Martin Stockhammer <martin_s@apache.org> + */ +@TestInstance( TestInstance.Lifecycle.PER_CLASS ) +@Tag( "rest-native" ) +@TestMethodOrder( MethodOrderer.Random.class ) +@DisplayName( "Native REST tests for V2 RepositoryService" ) +public class NativeRepositoryServiceTest extends AbstractNativeRestServices +{ + @Override + protected String getServicePath( ) + { + return "/repositories"; + } + + @BeforeAll + void setup( ) throws Exception + { + super.setupNative( ); + } + + @AfterAll + void destroy( ) throws Exception + { + super.shutdownNative( ); + } + + @Test + void testGetRepositories() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + PagedResult<Repository> repositoryPagedResult = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class ); + assertEquals( 3, repositoryPagedResult.getPagination( ).getTotalCount( ) ); + List<Repository> data = response.getBody( ).jsonPath( ).getList( "data", Repository.class ); + assertTrue( data.stream( ).anyMatch( p -> "central".equals( p.getId( ) ) ) ); + assertTrue( data.stream( ).anyMatch( p -> "internal".equals( p.getId( ) ) ) ); + assertTrue( data.stream( ).anyMatch( p -> "snapshots".equals( p.getId( ) ) ) ); + Repository snapshotRepo = data.stream( ).filter( p -> "snapshots".equals( p.getId( ) ) ).findFirst( ).get( ); + assertEquals( "Archiva Managed Snapshot Repository", snapshotRepo.getName( ) ); + assertEquals( "MAVEN", snapshotRepo.getType() ); + assertEquals( "managed", snapshotRepo.getCharacteristic() ); + assertEquals( "default", snapshotRepo.getLayout() ); + assertTrue( snapshotRepo.isScanned( ) ); + assertTrue( snapshotRepo.isIndex( ) ); + + Repository centralRepo = data.stream( ).filter( p -> "central".equals( p.getId( ) ) ).findFirst( ).get( ); + assertEquals( "Central Repository", centralRepo.getName( ) ); + assertEquals( "MAVEN", centralRepo.getType() ); + assertEquals( "remote", centralRepo.getCharacteristic() ); + assertEquals( "default", centralRepo.getLayout() ); + + + } + + @Test + void testGetFilteredRepositories() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .queryParam( "q", "central" ) + .get( "" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + PagedResult<Repository> repositoryPagedResult = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class ); + assertEquals( 1, repositoryPagedResult.getPagination( ).getTotalCount( ) ); + List<Repository> data = response.getBody( ).jsonPath( ).getList( "data", Repository.class ); + assertTrue( data.stream( ).anyMatch( p -> "central".equals( p.getId( ) ) ) ); + } + + + @Test + void getStatistics() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "managed/internal/statistics" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + } + + @Test + void scheduleScan() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .post( "managed/internal/scan/schedule" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + } + + @Test + void immediateScan() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .post( "managed/internal/scan/now" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + } + + @Test + void scanStatus() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "managed/internal/scan/status" ) + .prettyPeek() + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + } +} |