1 package org.apache.archiva.rest.services;
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.rest.api.model.Artifact;
22 import org.apache.archiva.rest.api.model.ManagedRepository;
23 import org.apache.archiva.rest.api.services.ManagedRepositoriesService;
24 import org.apache.archiva.rest.api.services.SearchService;
25 import org.apache.commons.io.FileUtils;
26 import org.junit.Test;
29 import java.util.List;
32 * @author Olivier Lamy
34 public class SearchServiceTest
35 extends AbstractArchivaRestTest
38 public void quickSearchOnArtifactId()
42 // olamy temporary disabled due to huge refactoring
48 String testRepoId = "test-repo";
49 // force guest user creation if not exists
50 if ( getUserService( authorizationHeader ).getGuestUser() == null )
52 assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
55 File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
57 if ( targetRepo.exists() )
59 FileUtils.deleteDirectory( targetRepo );
62 File sourceRepo = new File( "src/test/repo-with-osgi" );
64 FileUtils.copyDirectory( sourceRepo, targetRepo );
66 ManagedRepository managedRepository = new ManagedRepository();
67 managedRepository.setId( testRepoId );
68 managedRepository.setName( "test repo" );
69 managedRepository.setCronExpression( "* * * * * ?" );
71 managedRepository.setLocation( targetRepo.getPath() );
73 ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
74 service.addManagedRepository( managedRepository );
76 getRepositoriesService( authorizationHeader ).scanRepository( testRepoId, true );
78 while ( getRepositoriesService( authorizationHeader ).alreadyScanning( testRepoId ) )
83 SearchService searchService = getSearchService( authorizationHeader );
85 List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
87 assertNotNull( artifacts );
88 assertTrue( " empty results for commons-logging search", artifacts.size() > 0 );
89 log.info( "artifacts for commons-logginf search {}", artifacts );
91 deleteTestRepo( testRepoId );
94 private void deleteTestRepo( String id )
97 if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( id ) != null )
99 getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( id, true );