1 package org.apache.archiva;
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.rest.api.model.SearchRequest;
27 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
28 import org.apache.archiva.rest.api.services.ProxyConnectorService;
29 import org.apache.archiva.rest.api.services.RepositoriesService;
30 import org.apache.archiva.rest.api.services.RepositoryGroupService;
31 import org.apache.archiva.rest.api.services.SearchService;
32 import org.apache.commons.io.FileUtils;
33 import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
34 import org.apache.archiva.redback.rest.services.FakeCreateAdminService;
35 import org.fest.assertions.api.Assertions;
36 import org.junit.After;
37 import org.junit.AfterClass;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
43 import java.util.Arrays;
44 import java.util.List;
46 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
49 * @author Olivier Lamy
51 @RunWith(ArchivaBlockJUnit4ClassRunner.class)
52 public class DownloadMergedIndexTest
53 extends AbstractDownloadTest
57 public static void setAppServerBase()
59 previousAppServerBase = System.getProperty( "appserver.base" );
60 System.setProperty( "appserver.base", "target/" + DownloadMergedIndexTest.class.getName() );
64 public static void resetAppServerBase()
66 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 downloadMergedIndex()
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 repositoryGroup.setRepositories( Arrays.asList( id ) );
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 RemoteRepository remoteRepository = new RemoteRepository();
155 remoteRepository.setId( "all-merged" );
156 remoteRepository.setName( "all-merged" );
157 remoteRepository.setDownloadRemoteIndex( true );
158 remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" );
159 remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/.indexer" );
160 remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME );
161 remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD );
163 getRemoteRepositoriesService().addRemoteRepository( remoteRepository );
165 ProxyConnectorService proxyConnectorService = getProxyConnectorService();
166 ProxyConnector proxyConnector = new ProxyConnector();
167 proxyConnector.setProxyId( "foo-bar1" );
168 proxyConnector.setSourceRepoId( id );
169 proxyConnector.setTargetRepoId( "all-merged" );
170 proxyConnectorService.addProxyConnector( proxyConnector );
172 repositoriesService.scheduleDownloadRemoteIndex( "all-merged", true, true );
176 while ( timeout > 0 )
182 SearchService searchService = getSearchService();
184 SearchRequest request = new SearchRequest();
185 request.setRepositories( Arrays.asList( id ) );
186 request.setGroupId( "org.apache.felix" );
188 List<Artifact> artifacts = searchService.searchArtifacts( request );
189 Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );