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;
31 * @author Olivier Lamy
33 public class ManagedRepositoriesServiceTest
34 extends AbstractArchivaRestTest
39 public void addManagedRepo()
42 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
44 ManagedRepository repo = getTestManagedRepository();
45 if ( service.getManagedRepository( repo.getId() ) != null )
47 service.deleteManagedRepository( repo.getId(), true );
48 assertNull( service.getManagedRepository( repo.getId() ) );
50 service.addManagedRepository( repo );
51 repo = service.getManagedRepository( repo.getId() );
52 assertNotNull( repo );
54 assertEquals( getTestManagedRepository().getDescription(), repo.getDescription() );
56 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
59 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
65 service.deleteManagedRepository( repo.getId(), true );
66 assertNull( service.getManagedRepository( repo.getId() ) );
70 public void updateManagedRepo()
73 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
75 ManagedRepository repo = getTestManagedRepository();
76 if ( service.getManagedRepository( repo.getId() ) != null )
78 service.deleteManagedRepository( repo.getId(), true );
79 assertNull( service.getManagedRepository( repo.getId() ) );
81 service.addManagedRepository( repo );
83 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
86 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
92 repo = service.getManagedRepository( repo.getId() );
93 assertNotNull( repo );
94 assertEquals( "test", repo.getName() );
95 // toto is foo in French :-)
96 repo.setName( "toto" );
98 service.updateManagedRepository( repo );
100 repo = service.getManagedRepository( repo.getId() );
101 assertNotNull( repo );
102 assertEquals( "toto", repo.getName() );
105 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
111 service.deleteManagedRepository( repo.getId(), true );
112 assertNull( service.getManagedRepository( repo.getId() ) );
117 public void fileLocationExists()
120 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
121 File target = new File( "target" );
123 assertTrue( service.fileLocationExists( target.getCanonicalPath() ) );
125 // normally should not exists :-)
126 assertFalse( service.fileLocationExists( "/fooofofof/foddfdofd/dedede/kdeo" ) );
131 public void getManagedRepositoryStatistics()
135 String testRepoId = "test-repo";
136 // force guest user creation if not exists
137 if ( getUserService( authorizationHeader ).getGuestUser() == null )
139 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
142 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
144 createAndIndexRepo( testRepoId,
145 new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ).getAbsolutePath() );
147 repositoriesService.scanRepositoryDirectoriesNow( testRepoId );
150 while ( timeout > 0 && repositoriesService.alreadyScanning( testRepoId ) )
156 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
158 ArchivaRepositoryStatistics archivaRepositoryStatistics =
159 service.getManagedRepositoryStatistics( testRepoId, "en" );
161 assertNotNull( archivaRepositoryStatistics );
163 log.info( "archivaRepositoryStatistics: {}", archivaRepositoryStatistics.toString() );
165 assertEquals( 92, archivaRepositoryStatistics.getNewFileCount() );
166 assertEquals( 92, archivaRepositoryStatistics.getTotalFileCount() );
168 deleteTestRepo( testRepoId );