1 package org.apache.archiva.remotedownload;
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 org.apache.archiva.admin.model.beans.ManagedRepository;
22 import org.apache.archiva.admin.model.beans.ProxyConnector;
23 import org.apache.archiva.admin.model.beans.RemoteRepository;
24 import org.apache.archiva.admin.model.beans.RepositoryGroup;
25 import org.apache.archiva.maven2.model.Artifact;
26 import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
27 import org.apache.archiva.redback.rest.services.FakeCreateAdminService;
28 import org.apache.archiva.rest.api.model.SearchRequest;
29 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
30 import org.apache.archiva.rest.api.services.ProxyConnectorService;
31 import org.apache.archiva.rest.api.services.RepositoriesService;
32 import org.apache.archiva.rest.api.services.RepositoryGroupService;
33 import org.apache.archiva.rest.api.services.SearchService;
34 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
35 import org.apache.commons.io.FileUtils;
36 import static org.assertj.core.api.Assertions.assertThat;
37 import org.junit.After;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
44 import java.util.Arrays;
45 import java.util.List;
48 * @author Olivier Lamy
50 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
51 public class DownloadMergedIndexNonDefaultPathTest
52 extends AbstractDownloadTest
56 public static void setAppServerBase()
58 previousAppServerBase = System.getProperty( "appserver.base" );
59 System.setProperty( "appserver.base", System.getProperty( "basedir" ) + "/target/" + DownloadMergedIndexNonDefaultPathTest.class.getName() );
63 public static void resetAppServerBase()
65 System.setProperty( "appserver.base", previousAppServerBase );
69 protected String getSpringConfigLocation()
71 return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-merge-index-download.xml";
79 File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
80 if ( tmpIndexDir.exists() )
82 FileUtils.deleteDirectory( tmpIndexDir );
88 public void downloadMergedIndexWithNonDefaultPath()
91 File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
92 if ( tmpIndexDir.exists() )
94 FileUtils.deleteDirectory( tmpIndexDir );
96 String id = Long.toString( System.currentTimeMillis() );
97 ManagedRepository managedRepository = new ManagedRepository();
98 managedRepository.setId( id );
99 managedRepository.setName( "name of " + id );
100 managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" );
101 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
103 ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
105 if ( managedRepositoriesService.getManagedRepository( id ) != null )
107 managedRepositoriesService.deleteManagedRepository( id, false );
110 getManagedRepositoriesService().addManagedRepository( managedRepository );
112 RepositoriesService repositoriesService = getRepositoriesService();
114 repositoriesService.scanRepositoryNow( id, true );
116 // wait a bit to ensure index is finished
118 while ( timeout > 0 && repositoriesService.alreadyScanning( id ) )
124 RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
126 String repoGroupId = "test-group";
128 if ( repositoryGroupService.getRepositoryGroup( repoGroupId ) != null )
130 repositoryGroupService.deleteRepositoryGroup( repoGroupId );
133 RepositoryGroup repositoryGroup = new RepositoryGroup();
134 repositoryGroup.setId( repoGroupId );
135 String path = ".fooooo";
136 repositoryGroup.setRepositories( Arrays.asList( id ) );
137 repositoryGroup.setMergedIndexPath( path );
139 repositoryGroupService.addRepositoryGroup( repositoryGroup );
141 // create a repo with a remote on the one with index
142 id = Long.toString( System.currentTimeMillis() );
143 managedRepository = new ManagedRepository();
144 managedRepository.setId( id );
145 managedRepository.setName( "name of " + id );
146 managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" );
147 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
149 if ( managedRepositoriesService.getManagedRepository( id ) != null )
151 managedRepositoriesService.deleteManagedRepository( id, false );
154 getManagedRepositoriesService().addManagedRepository( managedRepository );
156 String remoteId = Long.toString( System.currentTimeMillis() );
158 RemoteRepository remoteRepository = new RemoteRepository();
159 remoteRepository.setId( remoteId );
160 remoteRepository.setName( remoteId );
161 remoteRepository.setDownloadRemoteIndex( true );
162 remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" );
163 remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/" + path );
164 remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME );
165 remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD );
167 getRemoteRepositoriesService().addRemoteRepository( remoteRepository );
169 ProxyConnectorService proxyConnectorService = getProxyConnectorService();
170 ProxyConnector proxyConnector = new ProxyConnector();
171 proxyConnector.setProxyId( "foo-bar2" );
172 proxyConnector.setSourceRepoId( id );
173 proxyConnector.setTargetRepoId( remoteId );
174 proxyConnectorService.addProxyConnector( proxyConnector );
176 repositoriesService.scheduleDownloadRemoteIndex( remoteId, true, true );
181 while ( timeout > 0 )
187 while ( !repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty() )
190 log.debug( "still running remote download" );
193 SearchService searchService = getSearchService();
195 SearchRequest request = new SearchRequest();
196 request.setRepositories( Arrays.asList( id ) );
197 request.setGroupId( "org.apache.felix" );
199 List<Artifact> artifacts = searchService.searchArtifacts( request );
200 assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );