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.proxyconnectorrule.ProxyConnectorRuleAdmin;
29 import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
30 import org.apache.archiva.redback.role.RoleManager;
31 import org.apache.archiva.redback.users.User;
32 import org.apache.archiva.redback.users.memory.SimpleUser;
33 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
34 import org.apache.commons.io.FileUtils;
35 import org.apache.commons.lang.StringUtils;
36 import org.junit.runner.RunWith;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.test.context.ContextConfiguration;
41 import javax.inject.Inject;
42 import javax.inject.Named;
44 import java.util.HashMap;
45 import java.util.List;
49 * @author Olivier Lamy
51 @RunWith (ArchivaSpringJUnit4ClassRunner.class)
52 @ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
53 public abstract class AbstractRepositoryAdminTest
56 protected Logger log = LoggerFactory.getLogger( getClass() );
58 public static final String APPSERVER_BASE_PATH =
59 AbstractRepositoryAdminTest.fixPath( System.getProperty( "appserver.base" ) );
62 protected MockAuditListener mockAuditListener;
65 protected RoleManager roleManager;
68 protected RemoteRepositoryAdmin remoteRepositoryAdmin;
71 protected ManagedRepositoryAdmin managedRepositoryAdmin;
74 protected ProxyConnectorAdmin proxyConnectorAdmin;
77 protected ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;
79 protected AuditInformation getFakeAuditInformation()
81 AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
82 return auditInformation;
85 // make a nice repo path to allow unit test to run
86 private static String fixPath( String path )
89 if ( path.contains( SPACE ) )
91 LoggerFactory.getLogger( AbstractRepositoryAdminTest.class.getName() ).error(
92 "You are building and testing with {appserver.base}: \n {}"
93 + " containing space. Consider relocating.", path );
95 return path.replaceAll( SPACE, "&20" );
98 protected User getFakeUser()
100 SimpleUser user = new SimpleUser();
102 user.setUsername( "root" );
103 user.setFullName( "The top user" );
107 protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
109 return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
110 repoLocation + "/.index", false, 1, 2, true, false );
113 protected File clearRepoLocation( String path )
116 File repoDir = new File( path );
117 if ( repoDir.exists() )
119 FileUtils.deleteDirectory( repoDir );
121 assertFalse( repoDir.exists() );
125 protected ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
127 for ( ManagedRepository repo : repos )
129 if ( StringUtils.equals( id, repo.getId() ) )
137 protected RemoteRepository getRemoteRepository()
139 return getRemoteRepository( "foo" );
142 protected RemoteRepository getRemoteRepository( String id )
144 RemoteRepository remoteRepository = new RemoteRepository();
145 remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
146 remoteRepository.setTimeout( 10 );
147 remoteRepository.setName( "maven foo" );
148 remoteRepository.setUserName( "foo-name" );
149 remoteRepository.setPassword( "toto" );
150 remoteRepository.setId( id );
151 remoteRepository.setRemoteDownloadNetworkProxyId( "foo" );
152 remoteRepository.setDescription( "cool apache repo" );
153 Map<String, String> extraParameters = new HashMap<>();
154 extraParameters.put( "foo", "bar" );
155 remoteRepository.setExtraParameters( extraParameters );
156 Map<String, String> extraHeaders = new HashMap<>();
157 extraHeaders.put( "beer", "wine" );
158 remoteRepository.setExtraHeaders( extraHeaders );
159 return remoteRepository;