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 assertNotNull( service.getManagedRepository( repo.getId() ) );
53 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
56 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
62 service.deleteManagedRepository( repo.getId(), true );
63 assertNull( service.getManagedRepository( repo.getId() ) );
67 public void updateManagedRepo()
70 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
72 ManagedRepository repo = getTestManagedRepository();
73 if ( service.getManagedRepository( repo.getId() ) != null )
75 service.deleteManagedRepository( repo.getId(), true );
76 assertNull( service.getManagedRepository( repo.getId() ) );
78 service.addManagedRepository( repo );
80 RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
83 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
89 repo = service.getManagedRepository( repo.getId() );
90 assertNotNull( repo );
91 assertEquals( "test", repo.getName() );
92 // toto is foo in French :-)
93 repo.setName( "toto" );
95 service.updateManagedRepository( repo );
97 repo = service.getManagedRepository( repo.getId() );
98 assertNotNull( repo );
99 assertEquals( "toto", repo.getName() );
102 while ( timeout > 0 && repositoriesService.alreadyScanning( repo.getId() ) )
108 service.deleteManagedRepository( repo.getId(), true );
109 assertNull( service.getManagedRepository( repo.getId() ) );
114 public void fileLocationExists()
117 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
118 File target = new File( "target" );
120 assertTrue( service.fileLocationExists( target.getCanonicalPath() ) );
122 // normally should not exists :-)
123 assertFalse( service.fileLocationExists( "/fooofofof/foddfdofd/dedede/kdeo" ) );
128 public void getManagedRepositoryStatistics()
132 String testRepoId = "test-repo";
133 // force guest user creation if not exists
134 if ( getUserService( authorizationHeader ).getGuestUser() == null )
136 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
139 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
141 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
143 ArchivaRepositoryStatistics archivaRepositoryStatistics =
144 service.getManagedRepositoryStatistics( testRepoId, "en" );
146 assertNotNull( archivaRepositoryStatistics );
148 log.info( "archivaRepositoryStatistics:" + archivaRepositoryStatistics.toString() );
150 assertEquals( 92, archivaRepositoryStatistics.getNewFileCount() );
151 assertEquals( 92, archivaRepositoryStatistics.getTotalFileCount() );
153 deleteTestRepo( testRepoId );