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.codehaus.redback.integration.security.role.RedbackRoleConstants;
33 import org.codehaus.redback.rest.services.FakeCreateAdminService;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.JUnit4;
40 import java.util.Arrays;
41 import java.util.List;
44 * @author Olivier Lamy
46 @RunWith( JUnit4.class )
47 public class DownloadMergedIndexTest
48 extends AbstractDownloadTest
52 public static void setAppServerBase()
54 previousAppServerBase = System.getProperty( "appserver.base" );
55 System.setProperty( "appserver.base", "target/" + DownloadMergedIndexTest.class.getName() );
59 public static void resetAppServerBase()
61 System.setProperty( "appserver.base", previousAppServerBase );
64 protected String getSpringConfigLocation()
66 return "classpath*:META-INF/spring-context.xml classpath*:spring-context-merge-index-download.xml";
70 public void downloadMergedIndex()
73 String id = Long.toString( System.currentTimeMillis() );
74 ManagedRepository managedRepository = new ManagedRepository();
75 managedRepository.setId( id );
76 managedRepository.setName( "name of " + id );
77 managedRepository.setLocation( "src/test/repositories/test-repo" );
78 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/target/tmpIndex/" + id );
80 ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
82 if ( managedRepositoriesService.getManagedRepository( id ) != null )
84 managedRepositoriesService.deleteManagedRepository( id, false );
87 getManagedRepositoriesService().addManagedRepository( managedRepository );
89 RepositoriesService repositoriesService = getRepositoriesService();
91 repositoriesService.scanRepositoryNow( id, true );
93 // wait a bit to ensure index is finished
95 while ( timeout > 0 && repositoriesService.alreadyScanning( id ) )
101 RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
103 RepositoryGroup repositoryGroup = new RepositoryGroup();
104 repositoryGroup.setId( "test-group" );
105 repositoryGroup.setRepositories( Arrays.asList( id ) );
107 repositoryGroupService.addRepositoryGroup( repositoryGroup );
109 // create a repo with a remote on the one with index
110 id = Long.toString( System.currentTimeMillis() );
111 managedRepository = new ManagedRepository();
112 managedRepository.setId( id );
113 managedRepository.setName( "name of " + id );
114 managedRepository.setLocation( "src/test/repositories/test-repo" );
115 managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/target/tmpIndex/" + id );
117 if ( managedRepositoriesService.getManagedRepository( id ) != null )
119 managedRepositoriesService.deleteManagedRepository( id, false );
122 getManagedRepositoriesService().addManagedRepository( managedRepository );
124 RemoteRepository remoteRepository = new RemoteRepository();
125 remoteRepository.setId( "all-merged" );
126 remoteRepository.setName( "all-merged" );
127 remoteRepository.setDownloadRemoteIndex( true );
128 remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" );
129 remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/.indexer" );
130 remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME );
131 remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD );
133 getRemoteRepositoriesService().addRemoteRepository( remoteRepository );
135 ProxyConnectorService proxyConnectorService = getProxyConnectorService();
136 ProxyConnector proxyConnector = new ProxyConnector();
137 proxyConnector.setProxyId( "foo-bar" );
138 proxyConnector.setSourceRepoId( id );
139 proxyConnector.setTargetRepoId( "all-merged" );
140 proxyConnectorService.addProxyConnector( proxyConnector );
142 repositoriesService.scheduleDownloadRemoteIndex( "all-merged", true, true );
146 while ( timeout > 0 )
152 SearchService searchService = getSearchService();
154 SearchRequest request = new SearchRequest();
155 request.setRepositories( Arrays.asList( id ) );
156 request.setGroupId( "org.apache.felix" );
158 List<Artifact> artifacts = searchService.searchArtifacts( request );
159 assertFalse( artifacts.isEmpty() );
160 assertEquals( 1, artifacts.size() );