1 package org.apache.archiva.admin.repository;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import junit.framework.TestCase;
22 import org.apache.archiva.admin.AuditInformation;
23 import org.apache.archiva.admin.mock.MockAuditListener;
24 import org.apache.archiva.admin.repository.managed.ManagedRepository;
25 import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
26 import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin;
27 import org.apache.commons.io.FileUtils;
28 import org.apache.commons.lang.StringUtils;
29 import org.codehaus.plexus.redback.role.RoleManager;
30 import org.codehaus.plexus.redback.users.User;
31 import org.codehaus.plexus.redback.users.memory.SimpleUser;
32 import org.junit.runner.RunWith;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.test.context.ContextConfiguration;
36 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38 import javax.inject.Inject;
40 import java.util.List;
43 * @author Olivier Lamy
45 @RunWith( SpringJUnit4ClassRunner.class )
46 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
47 public abstract class AbstractRepositoryAdminTest
50 protected Logger log = LoggerFactory.getLogger( getClass() );
52 public static final String APPSERVER_BASE_PATH = System.getProperty( "appserver.base" );
55 protected MockAuditListener mockAuditListener;
58 protected RoleManager roleManager;
61 protected RemoteRepositoryAdmin remoteRepositoryAdmin;
64 protected ManagedRepositoryAdmin managedRepositoryAdmin;
66 protected AuditInformation getFakeAuditInformation()
68 AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
69 return auditInformation;
72 protected User getFakeUser()
74 SimpleUser user = new SimpleUser()
77 public Object getPrincipal()
84 user.setUsername( "root" );
85 user.setFullName( "The top user" );
89 protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
91 return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
92 repoLocation + "/.index", false, 1, 2, true );
95 protected File clearRepoLocation( String path )
98 File repoDir = new File( path );
99 if ( repoDir.exists() )
101 FileUtils.deleteDirectory( repoDir );
103 assertFalse( repoDir.exists() );
107 protected ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
109 for ( ManagedRepository repo : repos )
111 if ( StringUtils.equals( id, repo.getId() ) )