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.*;
30 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
31 import org.junit.After;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
37 import java.nio.file.Files;
38 import java.nio.file.Path;
39 import java.nio.file.Paths;
40 import java.util.Arrays;
41 import java.util.List;
43 import static org.assertj.core.api.Assertions.assertThat;
46 * @author Olivier Lamy
48 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
49 public class DownloadMergedIndexNonDefaultPathTest
50 extends AbstractDownloadTest
54 public static void setAppServerBase()
56 previousAppServerBase = System.getProperty( "appserver.base" );
57 System.setProperty( "appserver.base", System.getProperty( "basedir" ) + "/target/" + DownloadMergedIndexNonDefaultPathTest.class.getName() );
61 public static void resetAppServerBase()
63 System.setProperty( "appserver.base", previousAppServerBase );
67 protected String getSpringConfigLocation()
69 return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-merge-index-download.xml";
77 Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ), "tmpIndex" );
78 if ( Files.exists(tmpIndexDir) )
80 org.apache.archiva.common.utils.FileUtils.deleteDirectory( tmpIndexDir );
86 public void downloadMergedIndexWithNonDefaultPath()
89 Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ), "tmpIndex" );
90 if ( Files.exists(tmpIndexDir) )
92 org.apache.archiva.common.utils.FileUtils.deleteDirectory( tmpIndexDir );
94 String id = Long.toString( System.currentTimeMillis() );
95 ManagedRepository managedRepository = new ManagedRepository();
96 managedRepository.setId( id );
97 managedRepository.setName( "name of " + id );
98 managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" );
99 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
101 ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
103 if ( managedRepositoriesService.getManagedRepository( id ) != null )
105 managedRepositoriesService.deleteManagedRepository( id, false );
108 getManagedRepositoriesService().addManagedRepository( managedRepository );
110 RepositoriesService repositoriesService = getRepositoriesService();
112 repositoriesService.scanRepositoryNow( id, true );
114 // wait a bit to ensure index is finished
116 while ( timeout > 0 && repositoriesService.alreadyScanning( id ) )
122 RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
124 String repoGroupId = "test-group";
126 if ( repositoryGroupService.getRepositoryGroup( repoGroupId ) != null )
128 repositoryGroupService.deleteRepositoryGroup( repoGroupId );
131 RepositoryGroup repositoryGroup = new RepositoryGroup();
132 repositoryGroup.setId( repoGroupId );
133 String path = ".fooooo";
134 repositoryGroup.setRepositories( Arrays.asList( id ) );
135 repositoryGroup.setMergedIndexPath( path );
137 repositoryGroupService.addRepositoryGroup( repositoryGroup );
139 // create a repo with a remote on the one with index
140 id = Long.toString( System.currentTimeMillis() );
141 managedRepository = new ManagedRepository();
142 managedRepository.setId( id );
143 managedRepository.setName( "name of " + id );
144 managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" );
145 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
147 if ( managedRepositoriesService.getManagedRepository( id ) != null )
149 managedRepositoriesService.deleteManagedRepository( id, false );
152 getManagedRepositoriesService().addManagedRepository( managedRepository );
154 String remoteId = Long.toString( System.currentTimeMillis() );
156 RemoteRepository remoteRepository = new RemoteRepository();
157 remoteRepository.setId( remoteId );
158 remoteRepository.setName( remoteId );
159 remoteRepository.setDownloadRemoteIndex( true );
160 remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" );
161 remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/" + path );
162 remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME );
163 remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD );
165 getRemoteRepositoriesService().addRemoteRepository( remoteRepository );
167 ProxyConnectorService proxyConnectorService = getProxyConnectorService();
168 ProxyConnector proxyConnector = new ProxyConnector();
169 proxyConnector.setProxyId( "foo-bar2" );
170 proxyConnector.setSourceRepoId( id );
171 proxyConnector.setTargetRepoId( remoteId );
172 proxyConnectorService.addProxyConnector( proxyConnector );
174 repositoriesService.scheduleDownloadRemoteIndex( remoteId, true, true );
179 while ( timeout > 0 )
185 while ( !repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty() )
188 log.debug( "still running remote download" );
191 SearchService searchService = getSearchService();
193 SearchRequest request = new SearchRequest();
194 request.setRepositories( Arrays.asList( id ) );
195 request.setGroupId( "org.apache.felix" );
197 List<Artifact> artifacts = searchService.searchArtifacts( request );
198 assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );