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.proxyconnector.ProxyConnectorAdmin;
27 import org.apache.archiva.admin.repository.remote.RemoteRepository;
28 import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin;
29 import org.apache.commons.io.FileUtils;
30 import org.apache.commons.lang.StringUtils;
31 import org.codehaus.plexus.redback.role.RoleManager;
32 import org.codehaus.plexus.redback.users.User;
33 import org.codehaus.plexus.redback.users.memory.SimpleUser;
34 import org.junit.runner.RunWith;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
40 import javax.inject.Inject;
42 import java.util.List;
45 * @author Olivier Lamy
47 @RunWith( SpringJUnit4ClassRunner.class )
48 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
49 public abstract class AbstractRepositoryAdminTest
52 protected Logger log = LoggerFactory.getLogger( getClass() );
54 public static final String APPSERVER_BASE_PATH = System.getProperty( "appserver.base" );
57 protected MockAuditListener mockAuditListener;
60 protected RoleManager roleManager;
63 protected RemoteRepositoryAdmin remoteRepositoryAdmin;
66 protected ManagedRepositoryAdmin managedRepositoryAdmin;
69 protected ProxyConnectorAdmin proxyConnectorAdmin;
71 protected AuditInformation getFakeAuditInformation()
73 AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
74 return auditInformation;
77 protected User getFakeUser()
79 SimpleUser user = new SimpleUser()
82 public Object getPrincipal()
89 user.setUsername( "root" );
90 user.setFullName( "The top user" );
94 protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
96 return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
97 repoLocation + "/.index", false, 1, 2, true );
100 protected File clearRepoLocation( String path )
103 File repoDir = new File( path );
104 if ( repoDir.exists() )
106 FileUtils.deleteDirectory( repoDir );
108 assertFalse( repoDir.exists() );
112 protected ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
114 for ( ManagedRepository repo : repos )
116 if ( StringUtils.equals( id, repo.getId() ) )
124 protected RemoteRepository getRemoteRepository()
126 return getRemoteRepository( "foo" );
129 protected RemoteRepository getRemoteRepository(String id)
131 RemoteRepository remoteRepository = new RemoteRepository();
132 remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
133 remoteRepository.setTimeout( 10 );
134 remoteRepository.setName( "maven foo" );
135 remoteRepository.setUserName( "foo-name" );
136 remoteRepository.setPassword( "toto" );
137 remoteRepository.setId( id );
138 return remoteRepository;