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 @Named("proxyConnectorAdmin#default")
75 protected ProxyConnectorAdmin proxyConnectorAdmin;
78 protected ProxyConnectorRuleAdmin proxyConnectorRuleAdmin;
80 protected AuditInformation getFakeAuditInformation()
82 AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" );
83 return auditInformation;
86 // make a nice repo path to allow unit test to run
87 private static String fixPath( String path )
90 if ( path.contains( SPACE ) )
92 LoggerFactory.getLogger( AbstractRepositoryAdminTest.class.getName() ).error(
93 "You are building and testing with {appserver.base}: \n " + path
94 + " containing space. Consider relocating." );
96 return path.replaceAll( SPACE, "&20" );
99 protected User getFakeUser()
101 SimpleUser user = new SimpleUser();
103 user.setUsername( "root" );
104 user.setFullName( "The top user" );
108 protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation )
110 return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?",
111 repoLocation + "/.index", false, 1, 2, true, false );
114 protected File clearRepoLocation( String path )
117 File repoDir = new File( path );
118 if ( repoDir.exists() )
120 FileUtils.deleteDirectory( repoDir );
122 assertFalse( repoDir.exists() );
126 protected ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
128 for ( ManagedRepository repo : repos )
130 if ( StringUtils.equals( id, repo.getId() ) )
138 protected RemoteRepository getRemoteRepository()
140 return getRemoteRepository( "foo" );
143 protected RemoteRepository getRemoteRepository( String id )
145 RemoteRepository remoteRepository = new RemoteRepository();
146 remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
147 remoteRepository.setTimeout( 10 );
148 remoteRepository.setName( "maven foo" );
149 remoteRepository.setUserName( "foo-name" );
150 remoteRepository.setPassword( "toto" );
151 remoteRepository.setId( id );
152 remoteRepository.setRemoteDownloadNetworkProxyId( "foo" );
153 remoteRepository.setDescription( "cool apache repo" );
154 Map<String, String> extraParameters = new HashMap<>();
155 extraParameters.put( "foo", "bar" );
156 remoteRepository.setExtraParameters( extraParameters );
157 Map<String, String> extraHeaders = new HashMap<>();
158 extraHeaders.put( "beer", "wine" );
159 remoteRepository.setExtraHeaders( extraHeaders );
160 return remoteRepository;