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.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 org.fest.assertions.api.Assertions;
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", "target/" + DownloadMergedIndexNonDefaultPathTest.class.getName() );
63 public static void resetAppServerBase()
65 System.setProperty( "appserver.base", previousAppServerBase );
68 protected String getSpringConfigLocation()
70 return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-merge-index-download.xml";
78 File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
79 if ( tmpIndexDir.exists() )
81 FileUtils.deleteDirectory( tmpIndexDir );
87 public void downloadMergedIndexWithNonDefaultPath()
90 File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
91 if ( tmpIndexDir.exists() )
93 FileUtils.deleteDirectory( tmpIndexDir );
95 String id = Long.toString( System.currentTimeMillis() );
96 ManagedRepository managedRepository = new ManagedRepository();
97 managedRepository.setId( id );
98 managedRepository.setName( "name of " + id );
99 managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" );
100 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
102 ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
104 if ( managedRepositoriesService.getManagedRepository( id ) != null )
106 managedRepositoriesService.deleteManagedRepository( id, false );
109 getManagedRepositoriesService().addManagedRepository( managedRepository );
111 RepositoriesService repositoriesService = getRepositoriesService();
113 repositoriesService.scanRepositoryNow( id, true );
115 // wait a bit to ensure index is finished
117 while ( timeout > 0 && repositoriesService.alreadyScanning( id ) )
123 RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
125 String repoGroupId = "test-group";
127 if ( repositoryGroupService.getRepositoryGroup( repoGroupId ) != null )
129 repositoryGroupService.deleteRepositoryGroup( repoGroupId );
132 RepositoryGroup repositoryGroup = new RepositoryGroup();
133 repositoryGroup.setId( repoGroupId );
134 String path = ".fooooo";
135 repositoryGroup.setRepositories( Arrays.asList( id ) );
136 repositoryGroup.setMergedIndexPath( path );
138 repositoryGroupService.addRepositoryGroup( repositoryGroup );
140 // create a repo with a remote on the one with index
141 id = Long.toString( System.currentTimeMillis() );
142 managedRepository = new ManagedRepository();
143 managedRepository.setId( id );
144 managedRepository.setName( "name of " + id );
145 managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" );
146 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
148 if ( managedRepositoriesService.getManagedRepository( id ) != null )
150 managedRepositoriesService.deleteManagedRepository( id, false );
153 getManagedRepositoriesService().addManagedRepository( managedRepository );
155 String remoteId = Long.toString( System.currentTimeMillis() );
157 RemoteRepository remoteRepository = new RemoteRepository();
158 remoteRepository.setId( remoteId );
159 remoteRepository.setName( remoteId );
160 remoteRepository.setDownloadRemoteIndex( true );
161 remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" );
162 remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/" + path );
163 remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME );
164 remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD );
166 getRemoteRepositoriesService().addRemoteRepository( remoteRepository );
168 ProxyConnectorService proxyConnectorService = getProxyConnectorService();
169 ProxyConnector proxyConnector = new ProxyConnector();
170 proxyConnector.setProxyId( "foo-bar2" );
171 proxyConnector.setSourceRepoId( id );
172 proxyConnector.setTargetRepoId( remoteId );
173 proxyConnectorService.addProxyConnector( proxyConnector );
175 repositoriesService.scheduleDownloadRemoteIndex( "all-merged", true, true );
179 while ( timeout > 0 )
185 SearchService searchService = getSearchService();
187 SearchRequest request = new SearchRequest();
188 request.setRepositories( Arrays.asList( id ) );
189 request.setGroupId( "org.apache.felix" );
191 List<Artifact> artifacts = searchService.searchArtifacts( request );
192 Assertions.assertThat( artifacts ).isNotNull().isNotEmpty().hasSize( 1 );