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.rest.api.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.junit.After;
36 import org.junit.AfterClass;
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
42 import java.util.Arrays;
43 import java.util.List;
44 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
47 * @author Olivier Lamy
49 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
50 public class DownloadMergedIndexTest
51 extends AbstractDownloadTest
55 public static void setAppServerBase()
57 previousAppServerBase = System.getProperty( "appserver.base" );
58 System.setProperty( "appserver.base", "target/" + DownloadMergedIndexTest.class.getName() );
62 public static void resetAppServerBase()
64 System.setProperty( "appserver.base", previousAppServerBase );
67 protected String getSpringConfigLocation()
69 return "classpath*:META-INF/spring-context.xml classpath*:spring-context-merge-index-download.xml";
77 File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
78 if ( tmpIndexDir.exists() )
80 FileUtils.deleteDirectory( tmpIndexDir );
86 public void downloadMergedIndex()
89 File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" );
90 if ( tmpIndexDir.exists() )
92 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( "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 RepositoryGroup repositoryGroup = new RepositoryGroup();
125 repositoryGroup.setId( "test-group" );
126 repositoryGroup.setRepositories( Arrays.asList( id ) );
128 repositoryGroupService.addRepositoryGroup( repositoryGroup );
130 // create a repo with a remote on the one with index
131 id = Long.toString( System.currentTimeMillis() );
132 managedRepository = new ManagedRepository();
133 managedRepository.setId( id );
134 managedRepository.setName( "name of " + id );
135 managedRepository.setLocation( "src/test/repositories/test-repo" );
136 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id );
138 if ( managedRepositoriesService.getManagedRepository( id ) != null )
140 managedRepositoriesService.deleteManagedRepository( id, false );
143 getManagedRepositoriesService().addManagedRepository( managedRepository );
145 RemoteRepository remoteRepository = new RemoteRepository();
146 remoteRepository.setId( "all-merged" );
147 remoteRepository.setName( "all-merged" );
148 remoteRepository.setDownloadRemoteIndex( true );
149 remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" );
150 remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/.indexer" );
151 remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME );
152 remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD );
154 getRemoteRepositoriesService().addRemoteRepository( remoteRepository );
156 ProxyConnectorService proxyConnectorService = getProxyConnectorService();
157 ProxyConnector proxyConnector = new ProxyConnector();
158 proxyConnector.setProxyId( "foo-bar" );
159 proxyConnector.setSourceRepoId( id );
160 proxyConnector.setTargetRepoId( "all-merged" );
161 proxyConnectorService.addProxyConnector( proxyConnector );
163 repositoriesService.scheduleDownloadRemoteIndex( "all-merged", true, true );
167 while ( timeout > 0 )
173 SearchService searchService = getSearchService();
175 SearchRequest request = new SearchRequest();
176 request.setRepositories( Arrays.asList( id ) );
177 request.setGroupId( "org.apache.felix" );
179 List<Artifact> artifacts = searchService.searchArtifacts( request );
180 assertFalse( artifacts.isEmpty() );
181 assertEquals( 1, artifacts.size() );