]> source.dussan.org Git - archiva.git/blob
4e9cdbeb0914098366fadaa409d89d17c0601cdc
[archiva.git] /
1 package org.apache.archiva.rest.services.v2;
2
3 /*
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
11  *
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
18  * under the License.
19  */
20
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;
32
33 import java.util.List;
34
35 import static io.restassured.RestAssured.given;
36 import static io.restassured.http.ContentType.JSON;
37 import static org.junit.jupiter.api.Assertions.*;
38
39 /**
40  * @author Martin Stockhammer <martin_s@apache.org>
41  */
42 @TestInstance( TestInstance.Lifecycle.PER_CLASS )
43 @Tag( "rest-native" )
44 @TestMethodOrder( MethodOrderer.Random.class )
45 @DisplayName( "Native REST tests for V2 RepositoryService" )
46 public class NativeRepositoryServiceTest extends AbstractNativeRestServices
47 {
48     @Override
49     protected String getServicePath( )
50     {
51         return "/repositories";
52     }
53
54     @BeforeAll
55     void setup( ) throws Exception
56     {
57         super.setupNative( );
58     }
59
60     @AfterAll
61     void destroy( ) throws Exception
62     {
63         super.shutdownNative( );
64     }
65
66     @Test
67     void testGetRepositories() {
68         String token = getAdminToken( );
69             Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
70                 .when( )
71                 .get( "" )
72                 .prettyPeek()
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( ) );
88
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() );
94
95
96     }
97
98     @Test
99     void testGetFilteredRepositories() {
100         String token = getAdminToken( );
101         Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
102             .when( )
103             .queryParam( "q", "central" )
104             .get( "" )
105             .prettyPeek()
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( ) ) ) );
112     }
113
114
115     @Test
116     void getStatistics() {
117         String token = getAdminToken( );
118         Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
119             .when( )
120             .get( "managed/internal/statistics" )
121             .prettyPeek()
122             .then( ).statusCode( 200 ).extract( ).response( );
123         assertNotNull( response );
124
125     }
126
127     @Test
128     void scheduleScan() {
129         String token = getAdminToken( );
130         Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
131             .when( )
132             .post( "managed/internal/scan/schedule" )
133             .prettyPeek()
134             .then( ).statusCode( 200 ).extract( ).response( );
135         assertNotNull( response );
136
137     }
138
139     @Test
140     void immediateScan() {
141         String token = getAdminToken( );
142         Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
143             .when( )
144             .post( "managed/internal/scan/now" )
145             .prettyPeek()
146             .then( ).statusCode( 200 ).extract( ).response( );
147         assertNotNull( response );
148
149     }
150
151     @Test
152     void scanStatus() {
153         String token = getAdminToken( );
154         Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
155             .when( )
156             .get( "managed/internal/scan/status" )
157             .prettyPeek()
158             .then( ).statusCode( 200 ).extract( ).response( );
159         assertNotNull( response );
160
161     }
162
163     @Test
164     void scheduleIndexDownload() {
165         String token = getAdminToken( );
166         Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON )
167             .when( )
168             .post( "remote/central/index/download/start" )
169             .then( ).statusCode( 200 ).extract( ).response( );
170         assertNotNull( response );
171     }
172
173     @Test
174     void getIndexDownloadList() {
175         String token = getAdminToken( );
176         given( ).spec( getRequestSpec( token ) ).contentType( JSON )
177             .when( )
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 )
182             .when( )
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 ) );
189     }
190
191 }