1 package org.apache.archiva.rest.services;
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
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
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;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
33 * @author Olivier Lamy
35 public class ManagedRepositoriesServiceTest
36 extends AbstractArchivaRestTest
41 public void addManagedRepo()
44 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
46 ManagedRepository repo = getTestManagedRepository();
47 if ( service.getManagedRepository( repo.getId() ) != null )
49 service.deleteManagedRepository( repo.getId(), true );
50 assertNull( service.getManagedRepository( repo.getId() ) );
52 service.addManagedRepository( repo );
53 repo = service.getManagedRepository( repo.getId() );
54 assertNotNull( repo );
56 assertEquals( getTestManagedRepository().getDescription(), repo.getDescription() );
58 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
61 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
67 service.deleteManagedRepository( repo.getId(), true );
68 assertNull( service.getManagedRepository( repo.getId() ) );
72 public void updateManagedRepo()
75 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
77 ManagedRepository repo = getTestManagedRepository();
78 if ( service.getManagedRepository( repo.getId() ) != null )
80 service.deleteManagedRepository( repo.getId(), true );
81 assertNull( service.getManagedRepository( repo.getId() ) );
83 service.addManagedRepository( repo );
85 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
88 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
94 repo = service.getManagedRepository( repo.getId() );
95 assertNotNull( repo );
96 assertEquals( "test", repo.getName() );
97 // toto is foo in French :-)
98 repo.setName( "toto" );
100 service.updateManagedRepository( repo );
102 repo = service.getManagedRepository( repo.getId() );
103 assertNotNull( repo );
104 assertEquals( "toto", repo.getName() );
107 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
113 service.deleteManagedRepository( repo.getId(), true );
114 assertNull( service.getManagedRepository( repo.getId() ) );
119 public void fileLocationExists()
122 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
123 Path target = getProjectDirectory().resolve( "target" );
125 assertTrue( service.fileLocationExists( target.toAbsolutePath().toString() ) );
127 // normally should not exists :-)
128 assertFalse( service.fileLocationExists( "/fooofofof/foddfdofd/dedede/kdeo" ) );
133 public void getManagedRepositoryStatistics()
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 )
143 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
146 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
148 createAndIndexRepo( testRepoId,
149 getProjectDirectory().resolve("src/test/repo-with-osgi" ) );
151 repositoriesService.scanRepositoryDirectoriesNow( testRepoId );
154 while ( timeout > 0 && repositoriesService.alreadyScanning( testRepoId ) )
160 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
162 ArchivaRepositoryStatistics archivaRepositoryStatistics =
163 service.getManagedRepositoryStatistics( testRepoId, "en" );
165 assertNotNull( archivaRepositoryStatistics );
167 log.info( "archivaRepositoryStatistics: {}", archivaRepositoryStatistics.toString() );
169 assertEquals( 92, archivaRepositoryStatistics.getNewFileCount() );
170 assertEquals( 92, archivaRepositoryStatistics.getTotalFileCount() );
172 deleteTestRepo( testRepoId );