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 service.deleteManagedRepository( repo.getId(), true );
54 assertNull( service.getManagedRepository( repo.getId() ) );
58 public void updateManagedRepo()
61 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
63 ManagedRepository repo = getTestManagedRepository();
64 if ( service.getManagedRepository( repo.getId() ) != null )
66 service.deleteManagedRepository( repo.getId(), true );
67 assertNull( service.getManagedRepository( repo.getId() ) );
69 service.addManagedRepository( repo );
70 repo = service.getManagedRepository( repo.getId() );
71 assertNotNull( repo );
72 assertEquals( "test", repo.getName() );
73 // toto is foo in French :-)
74 repo.setName( "toto" );
76 service.updateManagedRepository( repo );
78 repo = service.getManagedRepository( repo.getId() );
79 assertNotNull( repo );
80 assertEquals( "toto", repo.getName() );
82 service.deleteManagedRepository( repo.getId(), true );
83 assertNull( service.getManagedRepository( repo.getId() ) );
88 public void fileLocationExists()
91 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
92 File target = new File( "target" );
94 assertTrue( service.fileLocationExists( target.getCanonicalPath() ) );
96 // normally should not exists :-)
97 assertFalse( service.fileLocationExists( "/fooofofof/foddfdofd/dedede/kdeo" ) );
102 public void getManagedRepositoryStatistics()
106 String testRepoId = "test-repo";
107 // force guest user creation if not exists
108 if ( getUserService( authorizationHeader ).getGuestUser() == null )
110 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
113 createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
115 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
117 ArchivaRepositoryStatistics archivaRepositoryStatistics = service.getManagedRepositoryStatistics( testRepoId );
119 assertNotNull( archivaRepositoryStatistics );
121 log.info( "archivaRepositoryStatistics:" + archivaRepositoryStatistics.toString() );
123 assertEquals( 92, archivaRepositoryStatistics.getNewFileCount() );
124 assertEquals( 92, archivaRepositoryStatistics.getTotalFileCount() );
126 deleteTestRepo( testRepoId );