1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.index; 20 21 import java.io.File; 22 import java.util.ArrayList; 23 import java.util.Collection; 24 import java.util.List; 25 26 import org.apache.lucene.search.Query; 27 import org.junit.Test; 28 29 import static org.junit.Assert.assertEquals; 30 31 /** http://issues.sonatype.org/browse/NEXUS-13 */ 32 public class Nexus658NexusIndexerTest extends AbstractNexusIndexerTest { 33 protected File repo = new File(getBasedir(), "src/test/nexus-658"); 34 35 @Override 36 protected void prepareNexusIndexer(NexusIndexer nexusIndexer) throws Exception { 37 context = 38 nexusIndexer.addIndexingContext("nexus-658", "nexus-658", repo, indexDir, null, null, DEFAULT_CREATORS); 39 nexusIndexer.scan(context); 40 } 41 42 @Test 43 public void testSearchFlat() throws Exception { 44 Query q = nexusIndexer.constructQuery(MAVEN.GROUP_ID, "org.sonatype.nexus", SearchType.SCORED); 45 FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(q)); 46 Collection<ArtifactInfo> r = response.getResults(); 47 assertEquals(r.toString(), 4, r.size()); 48 49 List<ArtifactInfo> list = new ArrayList<>(r); 50 51 // g a v p c #1 52 ArtifactInfo ai1 = list.get(0); 53 assertEquals("org.sonatype.nexus", ai1.getGroupId()); 54 assertEquals("nexus-webapp", ai1.getArtifactId()); 55 assertEquals("1.0.0-SNAPSHOT", ai1.getVersion()); 56 assertEquals("jar", ai1.getPackaging()); 57 assertEquals(null, ai1.getClassifier()); 58 assertEquals(ArtifactAvailability.PRESENT, ai1.getSourcesExists()); 59 assertEquals("nexus-658", ai1.getRepository()); 60 61 // g a v p c #2 62 ArtifactInfo ai2 = list.get(1); 63 assertEquals("org.sonatype.nexus", ai2.getGroupId()); 64 assertEquals("nexus-webapp", ai2.getArtifactId()); 65 assertEquals("1.0.0-SNAPSHOT", ai2.getVersion()); 66 assertEquals("tar.gz", ai2.getPackaging()); 67 assertEquals("bundle", ai2.getClassifier()); 68 assertEquals(ArtifactAvailability.NOT_AVAILABLE, ai2.getSourcesExists()); 69 assertEquals("nexus-658", ai2.getRepository()); 70 71 // g a v p c #3 72 ArtifactInfo ai3 = list.get(2); 73 assertEquals("org.sonatype.nexus", ai3.getGroupId()); 74 assertEquals("nexus-webapp", ai3.getArtifactId()); 75 assertEquals("1.0.0-SNAPSHOT", ai3.getVersion()); 76 assertEquals("zip", ai3.getPackaging()); 77 assertEquals("bundle", ai3.getClassifier()); 78 assertEquals(ArtifactAvailability.NOT_AVAILABLE, ai3.getSourcesExists()); 79 assertEquals("nexus-658", ai3.getRepository()); 80 81 // g a v p c #3 82 ArtifactInfo ai4 = list.get(3); 83 assertEquals("org.sonatype.nexus", ai4.getGroupId()); 84 assertEquals("nexus-webapp", ai4.getArtifactId()); 85 assertEquals("1.0.0-SNAPSHOT", ai4.getVersion()); 86 assertEquals("jar", ai4.getPackaging()); 87 assertEquals("sources", ai4.getClassifier()); 88 assertEquals(ArtifactAvailability.NOT_AVAILABLE, ai4.getSourcesExists()); 89 assertEquals("nexus-658", ai4.getRepository()); 90 } 91 }