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.mock.MockAuditListener;
23 import org.apache.archiva.admin.model.AuditInformation;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.admin.model.beans.RemoteRepository;
26 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
27 import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin;
28 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
29 import org.apache.archiva.redback.users.User;
30 import org.apache.commons.io.FileUtils;
31 import org.apache.commons.lang.StringUtils;
32 import org.apache.archiva.redback.role.RoleManager;
33 import org.apache.archiva.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;
39 import javax.inject.Inject;
41 import java.util.List;
42 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
45 * @author Olivier Lamy
47 @RunWith( ArchivaSpringJUnit4ClassRunner.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 = AbstractRepositoryAdminTest.fixPath( 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 // make a nice repo path to allow unit test to run
78 private static String fixPath ( String path )
81 if ( path.contains( SPACE ) )
83 LoggerFactory.getLogger( AbstractRepositoryAdminTest.class.getName() ).error(
84 "You are building and testing with {appserver.base}: \n " + path + " containing space. Consider relocating." );
86 return path.replaceAll( SPACE, "&20");
89 protected User getFakeUser()
91 SimpleUser user = new SimpleUser()
94 public Object getPrincipal()
101 user.setUsername( "root" );
102 user.setFullName( "The top user" );
106 protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
108 return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
109 repoLocation + "/.index", false, 1, 2, true, false );
112 protected File clearRepoLocation( String path )
115 File repoDir = new File( path );
116 if ( repoDir.exists() )
118 FileUtils.deleteDirectory( repoDir );
120 assertFalse( repoDir.exists() );
124 protected ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
126 for ( ManagedRepository repo : repos )
128 if ( StringUtils.equals( id, repo.getId() ) )
136 protected RemoteRepository getRemoteRepository()
138 return getRemoteRepository( "foo" );
141 protected RemoteRepository getRemoteRepository(String id)
143 RemoteRepository remoteRepository = new RemoteRepository();
144 remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
145 remoteRepository.setTimeout( 10 );
146 remoteRepository.setName( "maven foo" );
147 remoteRepository.setUserName( "foo-name" );
148 remoteRepository.setPassword( "toto" );
149 remoteRepository.setId( id );
150 remoteRepository.setRemoteDownloadNetworkProxyId( "foo" );
151 remoteRepository.setDescription( "cool apache repo" );
152 return remoteRepository;