1 package org.apache.archiva.rest.services.v2;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import io.restassured.response.Response;
22 import org.apache.archiva.components.rest.model.PagedResult;
23 import org.apache.archiva.rest.api.model.v2.Repository;
24 import org.junit.jupiter.api.AfterAll;
25 import org.junit.jupiter.api.BeforeAll;
26 import org.junit.jupiter.api.DisplayName;
27 import org.junit.jupiter.api.MethodOrderer;
28 import org.junit.jupiter.api.Tag;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.TestInstance;
31 import org.junit.jupiter.api.TestMethodOrder;
33 import java.util.List;
35 import static io.restassured.RestAssured.given;
36 import static io.restassured.http.ContentType.JSON;
37 import static org.junit.jupiter.api.Assertions.*;
40 * @author Martin Stockhammer <martin_s@apache.org>
42 @TestInstance( TestInstance.Lifecycle.PER_CLASS )
44 @TestMethodOrder( MethodOrderer.Random.class )
45 @DisplayName( "Native REST tests for V2 RepositoryService" )
46 public class NativeRepositoryServiceTest extends AbstractNativeRestServices
49 protected String getServicePath( )
51 return "/repositories";
55 void setup( ) throws Exception
61 void destroy( ) throws Exception
63 super.shutdownNative( );
67 void testGetRepositories() {
68 String token = getAdminToken( );
69 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
73 .then( ).statusCode( 200 ).extract( ).response( );
74 assertNotNull( response );
75 PagedResult<Repository> repositoryPagedResult = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
76 assertEquals( 3, repositoryPagedResult.getPagination( ).getTotalCount( ) );
77 List<Repository> data = response.getBody( ).jsonPath( ).getList( "data", Repository.class );
78 assertTrue( data.stream( ).anyMatch( p -> "central".equals( p.getId( ) ) ) );
79 assertTrue( data.stream( ).anyMatch( p -> "internal".equals( p.getId( ) ) ) );
80 assertTrue( data.stream( ).anyMatch( p -> "snapshots".equals( p.getId( ) ) ) );
81 Repository snapshotRepo = data.stream( ).filter( p -> "snapshots".equals( p.getId( ) ) ).findFirst( ).get( );
82 assertEquals( "Archiva Managed Snapshot Repository", snapshotRepo.getName( ) );
83 assertEquals( "MAVEN", snapshotRepo.getType() );
84 assertEquals( "managed", snapshotRepo.getCharacteristic() );
85 assertEquals( "default", snapshotRepo.getLayout() );
86 assertTrue( snapshotRepo.isScanned( ) );
87 assertTrue( snapshotRepo.isIndex( ) );
89 Repository centralRepo = data.stream( ).filter( p -> "central".equals( p.getId( ) ) ).findFirst( ).get( );
90 assertEquals( "Central Repository", centralRepo.getName( ) );
91 assertEquals( "MAVEN", centralRepo.getType() );
92 assertEquals( "remote", centralRepo.getCharacteristic() );
93 assertEquals( "default", centralRepo.getLayout() );
99 void testGetFilteredRepositories() {
100 String token = getAdminToken( );
101 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
103 .queryParam( "q", "central" )
106 .then( ).statusCode( 200 ).extract( ).response( );
107 assertNotNull( response );
108 PagedResult<Repository> repositoryPagedResult = response.getBody( ).jsonPath( ).getObject( "", PagedResult.class );
109 assertEquals( 1, repositoryPagedResult.getPagination( ).getTotalCount( ) );
110 List<Repository> data = response.getBody( ).jsonPath( ).getList( "data", Repository.class );
111 assertTrue( data.stream( ).anyMatch( p -> "central".equals( p.getId( ) ) ) );
116 void getStatistics() {
117 String token = getAdminToken( );
118 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
120 .get( "managed/internal/statistics" )
122 .then( ).statusCode( 200 ).extract( ).response( );
123 assertNotNull( response );
128 void scheduleScan() {
129 String token = getAdminToken( );
130 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
132 .post( "managed/internal/scan/schedule" )
134 .then( ).statusCode( 200 ).extract( ).response( );
135 assertNotNull( response );
140 void immediateScan() {
141 String token = getAdminToken( );
142 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
144 .post( "managed/internal/scan/now" )
146 .then( ).statusCode( 200 ).extract( ).response( );
147 assertNotNull( response );
153 String token = getAdminToken( );
154 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
156 .get( "managed/internal/scan/status" )
158 .then( ).statusCode( 200 ).extract( ).response( );
159 assertNotNull( response );
164 void scheduleIndexDownload() {
165 String token = getAdminToken( );
166 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
168 .post( "remote/central/index/download/start" )
169 .then( ).statusCode( 200 ).extract( ).response( );
170 assertNotNull( response );
174 void getIndexDownloadList() {
175 String token = getAdminToken( );
176 given( ).spec( getRequestSpec( token ) ).contentType( JSON )
178 .queryParam( "immediate", "true" )
179 .post( "remote/central/index/download/start" )
180 .then( ).statusCode( 200 ).extract( ).response( );
181 Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
183 .get( "remote/index/downloads" )
184 .then( ).statusCode( 200 ).extract( ).response( );
185 assertNotNull( response );
186 List<String> downloads = response.getBody( ).jsonPath( ).getList( "", String.class );
187 assertEquals( 1, downloads.size() );
188 assertEquals( "central", downloads.get( 0 ) );