]> source.dussan.org Git - archiva.git/blob
41296cb2b6246ea17904f0f35f5318f0332f3519
[archiva.git] /
1 package org.apache.archiva.rest.services;
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  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics;
24 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
25 import org.apache.archiva.rest.api.services.RepositoriesService;
26 import org.junit.Test;
27
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30
31
32 /**
33  * @author Olivier Lamy
34  */
35 public class ManagedRepositoriesServiceTest
36     extends AbstractArchivaRestTest
37 {
38
39
40     @Test
41     public void addManagedRepo()
42         throws Exception
43     {
44         ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
45
46         ManagedRepository repo = getTestManagedRepository();
47         if ( service.getManagedRepository( repo.getId() ) != null )
48         {
49             service.deleteManagedRepository( repo.getId(), true );
50             assertNull( service.getManagedRepository( repo.getId() ) );
51         }
52         service.addManagedRepository( repo );
53         repo = service.getManagedRepository( repo.getId() );
54         assertNotNull( repo );
55
56         assertEquals( getTestManagedRepository().getDescription(), repo.getDescription() );
57
58         RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
59
60         int timeout = 20000;
61         while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
62         {
63             Thread.sleep( 500 );
64             timeout -= 500;
65         }
66
67         service.deleteManagedRepository( repo.getId(), true );
68         assertNull( service.getManagedRepository( repo.getId() ) );
69     }
70
71     @Test
72     public void updateManagedRepo()
73         throws Exception
74     {
75         ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
76
77         ManagedRepository repo = getTestManagedRepository();
78         if ( service.getManagedRepository( repo.getId() ) != null )
79         {
80             service.deleteManagedRepository( repo.getId(), true );
81             assertNull( service.getManagedRepository( repo.getId() ) );
82         }
83         service.addManagedRepository( repo );
84
85         RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
86
87         int timeout = 20000;
88         while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
89         {
90             Thread.sleep( 500 );
91             timeout -= 500;
92         }
93
94         repo = service.getManagedRepository( repo.getId() );
95         assertNotNull( repo );
96         assertEquals( "test", repo.getName() );
97         // toto is foo in French :-)
98         repo.setName( "toto" );
99
100         service.updateManagedRepository( repo );
101
102         repo = service.getManagedRepository( repo.getId() );
103         assertNotNull( repo );
104         assertEquals( "toto", repo.getName() );
105
106         timeout = 20000;
107         while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
108         {
109             Thread.sleep( 500 );
110             timeout -= 500;
111         }
112
113         service.deleteManagedRepository( repo.getId(), true );
114         assertNull( service.getManagedRepository( repo.getId() ) );
115
116     }
117
118     //@Test
119     public void fileLocationExists()
120         throws Exception
121     {
122         ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
123         Path target = getProjectDirectory().resolve( "target" );
124
125         assertTrue( service.fileLocationExists( target.toAbsolutePath().toString() ) );
126
127         // normally should not exists :-)
128         assertFalse( service.fileLocationExists( "/fooofofof/foddfdofd/dedede/kdeo" ) );
129
130     }
131
132     @Test
133     public void getManagedRepositoryStatistics()
134         throws Exception
135     {
136
137         getArchivaAdministrationService().addFileTypePattern("ignored", ".index-*/**");
138         getArchivaAdministrationService().addFileTypePattern("ignored", ".indexer-*/**");
139         String testRepoId = "test-repo";
140         // force guest user creation if not exists
141         if ( getUserService( authorizationHeader ).getGuestUser() == null )
142         {
143             assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
144         }
145
146         RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
147
148         createAndIndexRepo( testRepoId,
149                             getProjectDirectory().resolve("src/test/repo-with-osgi" ) );
150
151         repositoriesService.scanRepositoryDirectoriesNow( testRepoId );
152
153         int timeout = 20000;
154         while ( timeout > 0 && repositoriesService.alreadyScanning( testRepoId ) )
155         {
156             Thread.sleep( 500 );
157             timeout -= 500;
158         }
159
160         ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
161
162         ArchivaRepositoryStatistics archivaRepositoryStatistics =
163             service.getManagedRepositoryStatistics( testRepoId, "en" );
164
165         assertNotNull( archivaRepositoryStatistics );
166
167         log.info( "archivaRepositoryStatistics: {}", archivaRepositoryStatistics.toString() );
168
169         assertEquals( 92, archivaRepositoryStatistics.getNewFileCount() );
170         assertEquals( 92, archivaRepositoryStatistics.getTotalFileCount() );
171
172         deleteTestRepo( testRepoId );
173     }
174
175
176 }