maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject svn commit: r1030748 [10/21] - in /maven/indexer: branches/ tags/ trunk/ trunk/indexer-artifact/ trunk/indexer-artifact/src/ trunk/indexer-artifact/src/main/ trunk/indexer-artifact/src/main/java/ trunk/indexer-artifact/src/main/java/org/ trunk/indexer-...
Date Wed, 03 Nov 2010 22:51:35 GMT
Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.PrefixQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexingContext;
+
+public abstract class AbstractNexusIndexerTest
+    extends AbstractIndexCreatorHelper
+{
+    protected NexusIndexer nexusIndexer;
+
+    protected Directory indexDir = new RAMDirectory();
+
+    protected IndexingContext context;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        // FileUtils.deleteDirectory( indexDir );
+        nexusIndexer = lookup( NexusIndexer.class );
+        prepareNexusIndexer( nexusIndexer );
+    }
+
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+        unprepareNexusIndexer( nexusIndexer );
+        // TODO: Brian reported, does not work on Windows because of left open files?
+        // FileUtils.deleteDirectory( indexDir );
+    }
+
+    protected abstract void prepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception;
+
+    protected void unprepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception
+    {
+        nexusIndexer.removeIndexingContext( context, false );
+    }
+
+    protected void assertGroup( int expected, String group, IndexingContext context )
+        throws IOException
+    {
+        // ArtifactInfo.UINFO - UN_TOKENIZED
+        // ArtifactInfo.GROUP_ID - TOKENIZED
+
+        Term term = new Term( ArtifactInfo.GROUP_ID, group );
+        PrefixQuery pq = new PrefixQuery( term );
+        
+        // new WildcardQuery( //
+        // SpanTermQuery pq = new SpanTermQuery( term );
+        // PhraseQuery pq = new PhraseQuery();
+        // pq.add( new Term( ArtifactInfo.UINFO, group + "*" ) );
+        
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( pq, context ) );
+        Collection<ArtifactInfo> artifacts = response.getResults();
+        assertEquals( artifacts.toString(), expected, artifacts.size() );
+    }
+
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,507 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.ArtifactInfoGroup;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.GroupedSearchRequest;
+import org.apache.maven.index.GroupedSearchResponse;
+import org.apache.maven.index.search.grouping.GAGrouping;
+
+public abstract class AbstractRepoNexusIndexerTest
+    extends AbstractNexusIndexerTest
+{
+
+    protected File repo = new File( getBasedir(), "src/test/repo" );
+
+    public void testRootGroups()
+        throws Exception
+    {
+        Set<String> rootGroups = context.getRootGroups();
+        assertEquals( rootGroups.toString(), 12, rootGroups.size() );
+
+        assertGroup( 1, "com.adobe", context );
+        assertGroup( 1, "com.adobe.flexunit", context );
+
+        assertGroup( 2, "qdox", context );
+
+        assertGroup( 1, "proptest", context );
+
+        assertGroup( 3, "junit", context );
+
+        assertGroup( 13, "commons-logging", context );
+
+        assertGroup( 1, "regexp", context );
+
+        assertGroup( 2, "commons-cli", context );
+
+        assertGroup( 22, "org", context );
+
+        assertGroup( 10, "org.slf4j", context );
+
+        assertGroup( 4, "org.testng", context );
+
+        assertGroup( 5, "org.apache", context );
+
+        assertGroup( 1, "org.apache.directory", context );
+        assertGroup( 1, "org.apache.directory.server", context );
+
+        assertGroup( 3, "org.apache.maven", context );
+        assertGroup( 3, "org.apache.maven.plugins", context );
+        assertGroup( 0, "org.apache.maven.plugins.maven-core-it-plugin", context );
+    }
+
+    public void testSearchFlatPaged()
+        throws Exception
+    {
+        FlatSearchRequest request = new FlatSearchRequest( nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org" ) );
+
+        request.setStart( 0 );
+
+        request.setCount( 50 );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( request );
+
+        assertEquals( response.getResults().toString(), 22, response.getTotalHits() );
+    }
+
+    public void testSearchFlat()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "qdox" );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( 2, r.size() );
+
+        List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
+
+        assertEquals( 2, list.size() );
+
+        {
+            ArtifactInfo ai = list.get( 0 );
+            assertEquals( "1.6.1", ai.version );
+        }
+        {
+            ArtifactInfo ai = list.get( 1 );
+            assertEquals( "1.5", ai.version );
+            assertEquals( "test", ai.repository );
+        }
+    }
+
+    public void testSearchGrouped()
+        throws Exception
+    {
+        // ----------------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------------
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "qdox" );
+
+        GroupedSearchResponse response = nexusIndexer.searchGrouped( new GroupedSearchRequest( q, new GAGrouping() ) );
+
+        Map<String, ArtifactInfoGroup> r = response.getResults();
+
+        assertEquals( 1, r.size() );
+
+        ArtifactInfoGroup ig = r.values().iterator().next();
+
+        assertEquals( "qdox : qdox", ig.getGroupKey() );
+
+        assertEquals( 2, ig.getArtifactInfos().size() );
+
+        List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( ig.getArtifactInfos() );
+
+        assertEquals( 2, list.size() );
+
+        ArtifactInfo ai = list.get( 0 );
+
+        assertEquals( "1.6.1", ai.version );
+
+        ai = list.get( 1 );
+
+        assertEquals( "1.5", ai.version );
+
+        assertEquals( "test", ai.repository );
+    }
+
+    public void testSearchGroupedProblematicNames()
+        throws Exception
+    {
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "commons-logg*" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 1, r.size() );
+
+            ArtifactInfoGroup ig = r.values().iterator().next();
+
+            assertEquals( "commons-logging : commons-logging", ig.getGroupKey() );
+
+            assertEquals( ig.getArtifactInfos().toString(), 13, ig.getArtifactInfos().size() );
+        }
+
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "*logging" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 1, r.size() );
+
+            ArtifactInfoGroup ig = r.values().iterator().next();
+
+            assertEquals( "commons-logging : commons-logging", ig.getGroupKey() );
+
+            assertEquals( ig.getArtifactInfos().toString(), 13, ig.getArtifactInfos().size() );
+        }
+
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "*-logging" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 1, r.size() );
+
+            ArtifactInfoGroup ig = r.values().iterator().next();
+
+            assertEquals( "commons-logging : commons-logging", ig.getGroupKey() );
+
+            assertEquals( ig.getArtifactInfos().toString(), 13, ig.getArtifactInfos().size() );
+        }
+
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "comm*-logg*" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 1, r.size() );
+
+            ArtifactInfoGroup ig = r.values().iterator().next();
+
+            assertEquals( "commons-logging : commons-logging", ig.getGroupKey() );
+
+            assertEquals( ig.getArtifactInfos().toString(), 13, ig.getArtifactInfos().size() );
+        }
+
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "*mmons-log*" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 1, r.size() );
+
+            ArtifactInfoGroup ig = r.values().iterator().next();
+
+            assertEquals( "commons-logging : commons-logging", ig.getGroupKey() );
+
+            assertEquals( ig.getArtifactInfos().toString(), 13, ig.getArtifactInfos().size() );
+        }
+
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "commons-" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 2, r.size() );
+
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( "commons-cli : commons-cli", ig1.getGroupKey() );
+            assertEquals( ig1.getArtifactInfos().toString(), 2, ig1.getArtifactInfos().size() );
+
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( "commons-logging : commons-logging", ig2.getGroupKey() );
+            assertEquals( ig2.getArtifactInfos().toString(), 13, ig2.getArtifactInfos().size() );
+        }
+
+        {
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "logging-commons" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 0, r.size() );
+        }
+
+        {
+            // numbers and "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "*slf4*" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 3, r.size() );
+
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( ig1.getArtifactInfos().toString(), 2, ig1.getArtifactInfos().size() );
+            assertEquals( "org.slf4j : jcl104-over-slf4j", ig1.getGroupKey() );
+
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( ig2.getArtifactInfos().toString(), 4, ig2.getArtifactInfos().size() );
+            assertEquals( "org.slf4j : slf4j-api", ig2.getGroupKey() );
+
+            ArtifactInfoGroup ig3 = it.next();
+            assertEquals( ig3.getArtifactInfos().toString(), 4, ig3.getArtifactInfos().size() );
+            assertEquals( "org.slf4j : slf4j-log4j12", ig3.getGroupKey() );
+        }
+        {
+            // numbers and "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "jcl104-over-slf4*" );
+
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 1, r.size() );
+
+            ArtifactInfoGroup ig = r.values().iterator().next();
+
+            assertEquals( ig.getArtifactInfos().toString(), 2, ig.getArtifactInfos().size() );
+
+            assertEquals( "org.slf4j : jcl104-over-slf4j", ig.getGroupKey() );
+        }
+    }
+
+    // public void testConstructQuery()
+    // {
+    // Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "jcl104-over-slf4*" );
+    //
+    // assertEquals( "+a:jcl104 +a:over +a:slf4*", q.toString() );
+    //
+    // }
+
+    public void testIdentify()
+        throws Exception
+    {
+        ArtifactInfo ai = nexusIndexer.identify( ArtifactInfo.SHA1, "4d2db265eddf1576cb9d896abc90c7ba46b48d87" );
+
+        assertNotNull( ai );
+
+        assertEquals( "qdox", ai.groupId );
+
+        assertEquals( "qdox", ai.artifactId );
+
+        assertEquals( "1.5", ai.version );
+
+        // Using a file
+
+        File artifact = new File( repo, "qdox/qdox/1.5/qdox-1.5.jar" );
+
+        ai = nexusIndexer.identify( artifact );
+
+        assertNotNull( "Can't identify qdox-1.5.jar", ai );
+
+        assertEquals( "qdox", ai.groupId );
+
+        assertEquals( "qdox", ai.artifactId );
+
+        assertEquals( "1.5", ai.version );
+    }
+
+    // Paging is currently disabled
+    public void donttestPaging()
+        throws Exception
+    {
+        // we have 22 artifact for this search
+        int total = 22;
+
+        int pageSize = 4;
+
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org" );
+
+        FlatSearchRequest req = new FlatSearchRequest( q );
+
+        // have page size of 4, that will make us 4 pages
+        req.setCount( pageSize );
+
+        List<ArtifactInfo> constructedPageList = new ArrayList<ArtifactInfo>();
+
+        int offset = 0;
+
+        while ( true )
+        {
+            req.setStart( offset );
+
+            FlatSearchResponse resp = nexusIndexer.searchFlat( req );
+
+            Collection<ArtifactInfo> p = resp.getResults();
+
+            assertEquals( p.toString(), total, resp.getTotalHits() );
+
+            assertEquals( Math.min( pageSize, total - offset ), p.size() );
+
+            constructedPageList.addAll( p );
+
+            offset += pageSize;
+
+            if ( offset > total )
+            {
+                break;
+            }
+        }
+
+        // 
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+        Collection<ArtifactInfo> onePage = response.getResults();
+
+        List<ArtifactInfo> onePageList = new ArrayList<ArtifactInfo>( onePage );
+
+        // onePage and constructedPage should hold equal elems in the same order
+        assertTrue( resultsAreEqual( onePageList, constructedPageList ) );
+    }
+
+    public void testPurge()
+        throws Exception
+    {
+        // we have 14 artifact for this search
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org" );
+        FlatSearchRequest request = new FlatSearchRequest( q );
+
+        FlatSearchResponse response1 = nexusIndexer.searchFlat( request );
+        Collection<ArtifactInfo> p1 = response1.getResults();
+
+        assertEquals( 22, p1.size() );
+
+        context.purge();
+
+        FlatSearchResponse response2 = nexusIndexer.searchFlat( request );
+        Collection<ArtifactInfo> p2 = response2.getResults();
+
+        assertEquals( 0, p2.size() );
+    }
+
+    protected boolean resultsAreEqual( List<ArtifactInfo> left, List<ArtifactInfo> right )
+    {
+        assertEquals( left.size(), right.size() );
+
+        for ( int i = 0; i < left.size(); i++ )
+        {
+            if ( ArtifactInfo.VERSION_COMPARATOR.compare( left.get( i ), right.get( i ) ) != 0 )
+            {
+                // TODO: we are FAKING here!
+                // return false;
+            }
+        }
+
+        return true;
+    }
+
+    public void testPackaging()
+        throws Exception
+    {
+        IndexReader reader = context.getIndexReader();
+
+        for ( int i = 0; i < reader.maxDoc(); i++ )
+        {
+            if ( !reader.isDeleted( i ) )
+            {
+                Document document = reader.document( i );
+
+                String uinfo = document.get( ArtifactInfo.UINFO );
+
+                if ( uinfo != null )
+                {
+                    String info = document.get( ArtifactInfo.INFO );
+                    assertFalse( info.startsWith( "null" ) );
+                }
+            }
+        }
+
+        // {
+        // Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "jar" ) );
+        // FlatSearchResponse response = nexusIndexer.searchFlat(new FlatSearchRequest(query));
+        // assertEquals(response.getResults().toString(), 22, response.getTotalHits());
+        // }
+        {
+            Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "tar.gz" ) );
+            FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+            assertEquals( response.getResults().toString(), 1, response.getTotalHits() );
+
+            ArtifactInfo ai = response.getResults().iterator().next();
+            assertEquals( "tar.gz", ai.packaging );
+            assertEquals( "tar.gz", ai.fextension );
+        }
+        {
+            Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "zip" ) );
+            FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+            assertEquals( response.getResults().toString(), 1, response.getTotalHits() );
+
+            ArtifactInfo ai = response.getResults().iterator().next();
+            assertEquals( "zip", ai.packaging );
+            assertEquals( "zip", ai.fextension );
+        }
+    }
+
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,292 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FilteredQuery;
+import org.apache.lucene.search.PrefixQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.QueryWrapperFilter;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.packer.DefaultIndexPacker;
+import org.apache.maven.index.updater.DefaultIndexUpdater;
+
+public class DefaultIndexNexusIndexerTest
+    extends MinimalIndexNexusIndexerTest
+{
+    @Override
+    protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception
+    {
+        context =
+            nexusIndexer.addIndexingContext( "test-default", "test", repo, indexDir, null, null, DEFAULT_CREATORS );
+
+        assertNull( context.getTimestamp() ); // unknown upon creation
+
+        nexusIndexer.scan( context );
+
+        assertNotNull( context.getTimestamp() );
+    }
+
+    public void testPlugin()
+        throws Exception
+    {
+        // String term = "plugin";
+        // String term = "maven-core-it-plugin";
+        String term = "org.apache.maven.plugins";
+
+        // Query bq = new TermQuery(new Term(ArtifactInfo.GROUP_ID, "org.apache.maven.plugins"));
+        // Query bq = new TermQuery(new Term(ArtifactInfo.ARTIFACT_ID, term));
+        Query bq = new PrefixQuery( new Term( ArtifactInfo.GROUP_ID, term ) );
+        // BooleanQuery bq = new BooleanQuery();
+        // bq.add(new PrefixQuery(new Term(ArtifactInfo.GROUP_ID, term + "*")), Occur.SHOULD);
+        // bq.add(new PrefixQuery(new Term(ArtifactInfo.ARTIFACT_ID, term + "*")), Occur.SHOULD);
+        TermQuery tq = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-plugin" ) );
+        Query query = new FilteredQuery( tq, new QueryWrapperFilter( bq ) );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+
+        ArtifactInfo ai = r.iterator().next();
+
+        assertEquals( "org.apache.maven.plugins", ai.groupId );
+        assertEquals( "maven-core-it-plugin", ai.artifactId );
+        assertEquals( "core-it", ai.prefix );
+
+        List<String> goals = ai.goals;
+        assertEquals( 14, goals.size() );
+        assertEquals( "catch", goals.get( 0 ) );
+        assertEquals( "fork", goals.get( 1 ) );
+        assertEquals( "fork-goal", goals.get( 2 ) );
+        assertEquals( "touch", goals.get( 3 ) );
+        assertEquals( "setter-touch", goals.get( 4 ) );
+        assertEquals( "generate-envar-properties", goals.get( 5 ) );
+        assertEquals( "generate-properties", goals.get( 6 ) );
+        assertEquals( "loadable", goals.get( 7 ) );
+        assertEquals( "light-touch", goals.get( 8 ) );
+        assertEquals( "package", goals.get( 9 ) );
+        assertEquals( "reachable", goals.get( 10 ) );
+        assertEquals( "runnable", goals.get( 11 ) );
+        assertEquals( "throw", goals.get( 12 ) );
+        assertEquals( "tricky-params", goals.get( 13 ) );
+    }
+
+    public void testPluginPackaging()
+        throws Exception
+    {
+        Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-plugin" ) );
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+        // repo contains 3 artifacts with packaging "maven-plugin", but one of the is actually an archetype!
+        assertEquals( response.getResults().toString(), 2, response.getTotalHits() );
+    }
+
+    public void testSearchArchetypes()
+        throws Exception
+    {
+        // TermQuery tq = new TermQuery(new Term(ArtifactInfo.PACKAGING, "maven-archetype"));
+        // BooleanQuery bq = new BooleanQuery();
+        // bq.add(new WildcardQuery(new Term(ArtifactInfo.GROUP_ID, term + "*")), Occur.SHOULD);
+        // bq.add(new WildcardQuery(new Term(ArtifactInfo.ARTIFACT_ID, term + "*")), Occur.SHOULD);
+        // FilteredQuery query = new FilteredQuery(tq, new QueryWrapperFilter(bq));
+
+        Query q = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-archetype" ) );
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( 4, r.size() );
+
+        Iterator<ArtifactInfo> it = r.iterator();
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "org.apache.directory.server", ai.groupId );
+            assertEquals( "apacheds-schema-archetype", ai.artifactId );
+            assertEquals( "1.0.2", ai.version );
+        }
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "org.apache.servicemix.tooling", ai.groupId );
+            assertEquals( "servicemix-service-engine", ai.artifactId );
+            assertEquals( "3.1", ai.version );
+        }
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "org.terracotta.maven.archetypes", ai.groupId );
+            assertEquals( "pojo-archetype", ai.artifactId );
+            assertEquals( "1.0.3", ai.version );
+        }
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "proptest", ai.groupId );
+            assertEquals( "proptest-archetype", ai.artifactId );
+            assertEquals( "1.0", ai.version );
+        }
+    }
+
+    public void testIndexTimestamp()
+        throws Exception
+    {
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+        DefaultIndexPacker.packIndexArchive( context, os );
+
+        Thread.sleep( 1000L );
+
+        File newIndex = new File( getBasedir(), "target/test-new" );
+
+        Directory newIndexDir = FSDirectory.getDirectory( newIndex );
+
+        DefaultIndexUpdater.unpackIndexArchive( new ByteArrayInputStream( os.toByteArray() ), newIndexDir, context );
+
+        IndexingContext newContext =
+            nexusIndexer.addIndexingContext( "test-new", "test", null, newIndexDir, null, null, DEFAULT_CREATORS );
+
+        assertEquals( context.getTimestamp().getTime(), newContext.getTimestamp().getTime() );
+
+        assertEquals( context.getTimestamp(), newContext.getTimestamp() );
+
+        // make sure context has the same artifacts
+
+        Query query = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "qdox" );
+
+        FlatSearchRequest request = new FlatSearchRequest( query, newContext );
+        FlatSearchResponse response = nexusIndexer.searchFlat( request );
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( 2, r.size() );
+
+        List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
+
+        assertEquals( 2, list.size() );
+
+        ArtifactInfo ai = list.get( 0 );
+
+        assertEquals( "1.6.1", ai.version );
+
+        ai = list.get( 1 );
+
+        assertEquals( "1.5", ai.version );
+
+        assertEquals( "test", ai.repository );
+
+        Date timestamp = newContext.getTimestamp();
+
+        newContext.close( false );
+
+        newIndexDir = FSDirectory.getDirectory( newIndex );
+
+        DefaultIndexUpdater.unpackIndexArchive( new ByteArrayInputStream( os.toByteArray() ), newIndexDir, context );
+
+        newContext =
+            nexusIndexer.addIndexingContext( "test-new", "test", null, newIndexDir, null, null, DEFAULT_CREATORS );
+
+        assertEquals( timestamp, newContext.getTimestamp() );
+
+        newContext.close( true );
+
+        assertFalse( new File( newIndex, "timestamp" ).exists() );
+    }
+
+    public void testArchetype()
+        throws Exception
+    {
+        String term = "proptest";
+
+        Query bq = new PrefixQuery( new Term( ArtifactInfo.GROUP_ID, term ) );
+        TermQuery tq = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-archetype" ) );
+        Query query = new FilteredQuery( tq, new QueryWrapperFilter( bq ) );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+    }
+
+    public void testArchetypePackaging()
+        throws Exception
+    {
+        Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-archetype" ) );
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+        assertEquals( response.getResults().toString(), 4, response.getTotalHits() );
+    }
+
+    public void testBrokenJar()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "brokenjar" );
+
+        FlatSearchRequest searchRequest = new FlatSearchRequest( q );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( searchRequest );
+
+        Set<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+
+        ArtifactInfo ai = r.iterator().next();
+
+        assertEquals( "brokenjar", ai.groupId );
+        assertEquals( "brokenjar", ai.artifactId );
+        assertEquals( "1.0", ai.version );
+        assertEquals( null, ai.classNames );
+    }
+
+    public void testMissingPom()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "missingpom" );
+
+        FlatSearchRequest searchRequest = new FlatSearchRequest( q );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( searchRequest );
+
+        Set<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+
+        ArtifactInfo ai = r.iterator().next();
+
+        assertEquals( "missingpom", ai.groupId );
+        assertEquals( "missingpom", ai.artifactId );
+        assertEquals( "1.0", ai.version );
+        // See Nexus 2318. It should be null for a jar without classes
+        assertNull( ai.classNames );
+    }
+
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,105 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.File;
+
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexingContext;
+import org.codehaus.plexus.util.FileUtils;
+
+public class FSDirectoryDeleteTest
+    extends AbstractIndexCreatorHelper
+{
+    protected NexusIndexer nexusIndexer;
+    
+    protected File repo = new File( getBasedir(), "src/test/nexus-13" );
+    
+    protected IndexingContext context;
+    protected File indexDirFile = super.getDirectory("fsdirectorytest/one" ); 
+    protected Directory indexDir;
+    
+    protected IndexingContext otherContext;
+    protected File otherIndexDirFile = super.getDirectory("fsdirectorytest/other" ); 
+    protected Directory otherIndexDir;
+    
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        
+        nexusIndexer = lookup( NexusIndexer.class );
+        
+        indexDir = FSDirectory.getDirectory( indexDirFile );
+        
+        context = nexusIndexer.addIndexingContext(
+            "one",
+            "nexus-13",
+            repo,
+            indexDir,
+            null,
+            null,
+            DEFAULT_CREATORS );
+        
+        nexusIndexer.scan( context );
+        
+        otherIndexDir = FSDirectory.getDirectory( otherIndexDirFile );
+        
+        otherContext = nexusIndexer.addIndexingContext(
+            "other",
+            "nexus-13",
+            repo,
+            otherIndexDir,
+            null,
+            null,
+            DEFAULT_CREATORS );
+        
+        nexusIndexer.scan( otherContext );
+    }
+    
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+        
+        nexusIndexer.removeIndexingContext( context, true );
+        
+        nexusIndexer.removeIndexingContext( otherContext, true );
+        
+        super.deleteDirectory( indexDirFile );
+        
+        super.deleteDirectory( otherIndexDirFile );
+    }
+    
+    public void testIndexAndDelete()
+        throws Exception
+    {
+        context.getIndexReader().maxDoc();
+        
+        otherContext.getIndexReader().maxDoc();
+        
+        context.replace( otherIndexDir );
+        
+        context.merge( otherIndexDir );
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,516 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FilteredQuery;
+import org.apache.lucene.search.PrefixQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.QueryWrapperFilter;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.ArtifactInfoGroup;
+import org.apache.maven.index.Field;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.GroupedSearchRequest;
+import org.apache.maven.index.GroupedSearchResponse;
+import org.apache.maven.index.IteratorSearchRequest;
+import org.apache.maven.index.IteratorSearchResponse;
+import org.apache.maven.index.MAVEN;
+import org.apache.maven.index.MatchHighlight;
+import org.apache.maven.index.MatchHighlightMode;
+import org.apache.maven.index.MatchHighlightRequest;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.SearchType;
+import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.packer.DefaultIndexPacker;
+import org.apache.maven.index.search.grouping.GAGrouping;
+import org.apache.maven.index.search.grouping.GGrouping;
+import org.apache.maven.index.updater.DefaultIndexUpdater;
+
+public class FullIndexNexusIndexerTest
+    extends DefaultIndexNexusIndexerTest
+{
+    @Override
+    protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception
+    {
+        context = nexusIndexer.addIndexingContext( "test-default", "test", repo, indexDir, null, null, FULL_CREATORS );
+
+        assertNull( context.getTimestamp() ); // unknown upon creation
+
+        nexusIndexer.scan( context );
+
+        assertNotNull( context.getTimestamp() );
+    }
+
+    public void testSearchGroupedClasses()
+        throws Exception
+    {
+        {
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "com/thoughtworks/qdox" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+
+            assertEquals( r.toString(), 2, r.size() ); // qdox and testng
+
+            assertTrue( r.containsKey( "qdox : qdox" ) );
+            assertTrue( r.containsKey( "org.testng : testng" ) );
+            assertEquals( "qdox : qdox", r.get( "qdox : qdox" ).getGroupKey() );
+            assertEquals( "org.testng : testng", r.get( "org.testng : testng" ).getGroupKey() );
+        }
+
+        {
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "com.thoughtworks.qdox" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+
+            assertTrue( r.containsKey( "qdox : qdox" ) );
+            assertTrue( r.containsKey( "org.testng : testng" ) );
+            assertEquals( "qdox : qdox", r.get( "qdox : qdox" ).getGroupKey() );
+            assertEquals( "org.testng : testng", r.get( "org.testng : testng" ).getGroupKey() );
+        }
+
+        {
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "thoughtworks" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+            assertTrue( r.containsKey( "qdox : qdox" ) );
+            assertTrue( r.containsKey( "org.testng : testng" ) );
+            assertEquals( "qdox : qdox", r.get( "qdox : qdox" ).getGroupKey() );
+            assertEquals( "org.testng : testng", r.get( "org.testng : testng" ).getGroupKey() );
+        }
+
+        {
+            // an implicit class name wildcard
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "Logger" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( r.toString(), "org.slf4j", ig1.getGroupKey() );
+
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( r.toString(), "org.testng", ig2.getGroupKey() );
+        }
+
+        {
+            // a lower case search
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "logger" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( r.toString(), "org.slf4j", ig1.getGroupKey() );
+
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( r.toString(), "org.testng", ig2.getGroupKey() );
+        }
+
+        {
+            // explicit class name wildcard without terminator
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "*.Logger" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( r.toString(), "org.slf4j", ig1.getGroupKey() );
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( r.toString(), "org.testng", ig2.getGroupKey() );
+        }
+
+        {
+            // explicit class name wildcard with terminator
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "*.Logger " );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( r.toString(), "org.slf4j", ig1.getGroupKey() );
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( r.toString(), "org.testng", ig2.getGroupKey() );
+        }
+
+        {
+            // a class name wildcard
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "*Logger" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 3, r.size() );
+
+            Iterator<ArtifactInfoGroup> it = r.values().iterator();
+
+            ArtifactInfoGroup ig1 = it.next();
+            assertEquals( r.toString(), "commons-logging", ig1.getGroupKey() ); // Jdk14Logger and LogKitLogger
+
+            ArtifactInfoGroup ig2 = it.next();
+            assertEquals( r.toString(), "org.slf4j", ig2.getGroupKey() );
+
+            ArtifactInfoGroup ig3 = it.next();
+            assertEquals( r.toString(), "org.testng", ig3.getGroupKey() );
+        }
+
+        {
+            // exact class name
+            Query q =
+                nexusIndexer.constructQuery( ArtifactInfo.NAMES, "org/apache/commons/logging/LogConfigurationException" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() ); // jcl104-over-slf4j and commons-logging
+        }
+
+        {
+            // implicit class name pattern
+            Query q =
+                nexusIndexer.constructQuery( ArtifactInfo.NAMES, "org.apache.commons.logging.LogConfigurationException" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() ); // jcl104-over-slf4j and commons-logging
+        }
+
+        {
+            // exact class name
+            Query q =
+                nexusIndexer.constructQuery( ArtifactInfo.NAMES,
+                    "^org.apache.commons.logging.LogConfigurationException$" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() ); // jcl104-over-slf4j and commons-logging
+        }
+
+        {
+            // package name prefix
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "^org.apache.commons.logging" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() ); // jcl104-over-slf4j and commons-logging
+        }
+
+        {
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.NAMES, "*slf4j*Logg*" );
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+            assertEquals( r.toString(), 2, r.size() );
+
+            {
+                ArtifactInfoGroup ig = r.values().iterator().next();
+                ArrayList<ArtifactInfo> list1 = new ArrayList<ArtifactInfo>( ig.getArtifactInfos() );
+                assertEquals( r.toString(), 2, list1.size() );
+
+                ArtifactInfo ai1 = list1.get( 0 );
+                assertEquals( "org.slf4j", ai1.groupId );
+                assertEquals( "slf4j-api", ai1.artifactId );
+                assertEquals( "1.4.2", ai1.version );
+                ArtifactInfo ai2 = list1.get( 1 );
+                assertEquals( "org.slf4j", ai2.groupId );
+                assertEquals( "slf4j-api", ai2.artifactId );
+                assertEquals( "1.4.1", ai2.version );
+            }
+
+            {
+                // This was error, since slf4j-log4j12 DOES NOT HAVE any class for this search!
+                ArtifactInfoGroup ig = r.get( "org.slf4j : slf4j-log4j12" );
+                ArrayList<ArtifactInfo> list = new ArrayList<ArtifactInfo>( ig.getArtifactInfos() );
+                assertEquals( list.toString(), 1, list.size() );
+
+                ArtifactInfo ai = list.get( 0 );
+                assertEquals( "org.slf4j", ai.groupId );
+                assertEquals( "slf4j-log4j12", ai.artifactId );
+                assertEquals( "1.4.1", ai.version );
+            }
+        }
+    }
+
+    public void testSearchArchetypes()
+        throws Exception
+    {
+        // TermQuery tq = new TermQuery(new Term(ArtifactInfo.PACKAGING, "maven-archetype"));
+        // BooleanQuery bq = new BooleanQuery();
+        // bq.add(new WildcardQuery(new Term(ArtifactInfo.GROUP_ID, term + "*")), Occur.SHOULD);
+        // bq.add(new WildcardQuery(new Term(ArtifactInfo.ARTIFACT_ID, term + "*")), Occur.SHOULD);
+        // FilteredQuery query = new FilteredQuery(tq, new QueryWrapperFilter(bq));
+
+        Query q = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-archetype" ) );
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( 4, r.size() );
+
+        Iterator<ArtifactInfo> it = r.iterator();
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "org.apache.directory.server", ai.groupId );
+            assertEquals( "apacheds-schema-archetype", ai.artifactId );
+            assertEquals( "1.0.2", ai.version );
+        }
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "org.apache.servicemix.tooling", ai.groupId );
+            assertEquals( "servicemix-service-engine", ai.artifactId );
+            assertEquals( "3.1", ai.version );
+        }
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "org.terracotta.maven.archetypes", ai.groupId );
+            assertEquals( "pojo-archetype", ai.artifactId );
+            assertEquals( "1.0.3", ai.version );
+        }
+        {
+            ArtifactInfo ai = it.next();
+            assertEquals( "proptest", ai.groupId );
+            assertEquals( "proptest-archetype", ai.artifactId );
+            assertEquals( "1.0", ai.version );
+        }
+    }
+
+    public void testIndexTimestamp()
+        throws Exception
+    {
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+        DefaultIndexPacker.packIndexArchive( context, os );
+
+        Thread.sleep( 1000L );
+
+        File newIndex = new File( getBasedir(), "target/test-new" );
+
+        Directory newIndexDir = FSDirectory.getDirectory( newIndex );
+
+        DefaultIndexUpdater.unpackIndexArchive( new ByteArrayInputStream( os.toByteArray() ), newIndexDir, context );
+
+        IndexingContext newContext =
+            nexusIndexer.addIndexingContext( "test-new", "test", null, newIndexDir, null, null, DEFAULT_CREATORS );
+
+        assertEquals( context.getTimestamp().getTime(), newContext.getTimestamp().getTime() );
+
+        assertEquals( context.getTimestamp(), newContext.getTimestamp() );
+
+        // make sure context has the same artifacts
+
+        Query query = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "qdox" );
+
+        FlatSearchRequest request = new FlatSearchRequest( query, newContext );
+        FlatSearchResponse response = nexusIndexer.searchFlat( request );
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( 2, r.size() );
+
+        List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
+
+        assertEquals( 2, list.size() );
+
+        ArtifactInfo ai = list.get( 0 );
+
+        assertEquals( "1.6.1", ai.version );
+
+        ai = list.get( 1 );
+
+        assertEquals( "1.5", ai.version );
+
+        assertEquals( "test", ai.repository );
+
+        Date timestamp = newContext.getTimestamp();
+
+        newContext.close( false );
+
+        newIndexDir = FSDirectory.getDirectory( newIndex );
+
+        DefaultIndexUpdater.unpackIndexArchive( new ByteArrayInputStream( os.toByteArray() ), newIndexDir, context );
+
+        newContext =
+            nexusIndexer.addIndexingContext( "test-new", "test", null, newIndexDir, null, null, DEFAULT_CREATORS );
+
+        assertEquals( timestamp, newContext.getTimestamp() );
+
+        newContext.close( true );
+
+        assertFalse( new File( newIndex, "timestamp" ).exists() );
+    }
+
+    public void testArchetype()
+        throws Exception
+    {
+        String term = "proptest";
+
+        Query bq = new PrefixQuery( new Term( ArtifactInfo.GROUP_ID, term ) );
+        TermQuery tq = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-archetype" ) );
+        Query query = new FilteredQuery( tq, new QueryWrapperFilter( bq ) );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+
+        Collection<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+    }
+
+    public void testArchetypePackaging()
+        throws Exception
+    {
+        Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "maven-archetype" ) );
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+        assertEquals( response.getResults().toString(), 4, response.getTotalHits() );
+    }
+
+    public void testBrokenJar()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "brokenjar" );
+
+        FlatSearchRequest searchRequest = new FlatSearchRequest( q );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( searchRequest );
+
+        Set<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+
+        ArtifactInfo ai = r.iterator().next();
+
+        assertEquals( "brokenjar", ai.groupId );
+        assertEquals( "brokenjar", ai.artifactId );
+        assertEquals( "1.0", ai.version );
+        assertEquals( null, ai.classNames );
+    }
+
+    public void testMissingPom()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "missingpom" );
+
+        FlatSearchRequest searchRequest = new FlatSearchRequest( q );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( searchRequest );
+
+        Set<ArtifactInfo> r = response.getResults();
+
+        assertEquals( r.toString(), 1, r.size() );
+
+        ArtifactInfo ai = r.iterator().next();
+
+        assertEquals( "missingpom", ai.groupId );
+        assertEquals( "missingpom", ai.artifactId );
+        assertEquals( "1.0", ai.version );
+        // See Nexus 2318. It should be null for a jar without classes
+        assertNull( ai.classNames );
+    }
+
+    // ==
+
+    protected IteratorSearchRequest createHighlightedRequest( Field field, String text, SearchType type )
+    {
+        Query q = nexusIndexer.constructQuery( field, text, type );
+
+        IteratorSearchRequest request = new IteratorSearchRequest( q );
+
+        request.getMatchHighlightRequests().add( new MatchHighlightRequest( field, q, MatchHighlightMode.HTML ) );
+
+        return request;
+    }
+
+    public void testClassnameSearchNgWithHighlighting()
+        throws Exception
+    {
+        IteratorSearchRequest request = createHighlightedRequest( MAVEN.CLASSNAMES, "Logger", SearchType.SCORED );
+
+        IteratorSearchResponse response = nexusIndexer.searchIterator( request );
+
+        for ( ArtifactInfo ai : response )
+        {
+            // These are _all_ classnames
+            String classnames = ai.classNames;
+
+            for ( MatchHighlight mh : ai.getMatchHighlights() )
+            {
+                for ( String highlighted : mh.getHighlightedMatch() )
+                {
+                    // Logger and LoggerFactory
+                    assertTrue( "Class name should be highlighted", highlighted.contains( "<B>Logger" ) );
+                    assertFalse( "Class name should not contain \"/\" alone (but okay within HTML, see above!)", highlighted.matches( "\\p{Lower}/\\p{Upper}" ) );
+                    assertFalse( "Class name should not begin with \".\" or \"/\"", highlighted.startsWith( "." )
+                        || highlighted.startsWith( "/" ) );
+                }
+            }
+        }
+
+        assertEquals( "found in jcl104-over-slf4j and commons-logging", 5, response.getTotalHits() );
+    }
+
+    public void testGAVSearchNgWithHighlighting()
+        throws Exception
+    {
+        IteratorSearchRequest request = createHighlightedRequest( MAVEN.GROUP_ID, "commons", SearchType.SCORED );
+
+        IteratorSearchResponse response = nexusIndexer.searchIterator( request );
+
+        for ( ArtifactInfo ai : response )
+        {
+            for ( MatchHighlight mh : ai.getMatchHighlights() )
+            {
+                assertTrue( "Group ID should be highlighted", mh.getHighlightedMatch().contains(
+                    "<B>commons</B>-logging" )
+                    || mh.getHighlightedMatch().contains( "<B>commons</B>-cli" ) );
+            }
+        }
+
+        assertEquals( "found in commons-logging and commons-cli", 15, response.getTotalHits() );
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,294 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.ArtifactInfoGroup;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.GroupedSearchRequest;
+import org.apache.maven.index.GroupedSearchResponse;
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.search.grouping.GAGrouping;
+import org.apache.maven.index.updater.DefaultIndexUpdater;
+
+/** 
+ * @author Eugene Kuleshov
+ */
+public class Index20081108RegressionTest
+    extends AbstractRepoNexusIndexerTest
+{
+    @Override
+    protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception
+    {
+        context = nexusIndexer.addIndexingContextForced(
+            "test",
+            "test",
+            null,
+            indexDir,
+            null,
+            null,
+            DEFAULT_CREATORS );
+        
+        InputStream is = new FileInputStream( getBasedir() +  //
+            File.separator + "src" +  // 
+            File.separator + "test" + //
+            File.separator  + "nexus-maven-repository-index.20081108.zip" );
+        
+        Directory tempDir = new RAMDirectory();
+        DefaultIndexUpdater.unpackIndexArchive( is, tempDir, context );
+        context.replace( tempDir );
+    }
+    
+    public void testExtension() throws Exception 
+    {
+        assertEquals( 31, context.getIndexReader().numDocs() );
+        
+        {
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "qdox" );
+            FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+            assertEquals( response.getResults().toString(), 2, response.getTotalHits() );
+  
+            List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( response.getResults() );
+            assertEquals( 2, list.size() );
+  
+            {
+                ArtifactInfo ai = list.get( 0 );
+                assertEquals( "1.6.1", ai.version );
+                assertEquals( "jar", ai.fextension );
+                assertEquals( "jar", ai.packaging );
+            }
+            {
+                ArtifactInfo ai = list.get( 1 );
+                assertEquals( "1.5", ai.version );
+                assertEquals( "jar", ai.fextension );
+                assertEquals( "jar", ai.packaging );
+            }
+        }
+        {
+          Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "tar.gz" ) );
+          FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+          assertEquals( response.getResults().toString(), 1, response.getTotalHits() );
+          
+          ArtifactInfo ai = response.getResults().iterator().next();
+          assertEquals( "tar.gz", ai.packaging );
+          assertEquals( "tar.gz", ai.fextension );
+        }
+        {
+            Query query = new TermQuery( new Term( ArtifactInfo.PACKAGING, "zip" ) );
+            FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( query ) );
+            assertEquals( response.getResults().toString(), 1, response.getTotalHits() );
+            
+            ArtifactInfo ai = response.getResults().iterator().next();
+            assertEquals( "zip", ai.packaging );
+            assertEquals( "zip", ai.fextension );
+        }
+    }
+    
+    @Override
+    public void testRootGroups()
+        throws Exception
+    {
+        Set<String> rootGroups = context.getRootGroups();
+        assertEquals( rootGroups.toString(), 8, rootGroups.size() );
+      
+        assertGroup( 2, "qdox", context );
+      
+        assertGroup( 1, "proptest", context );
+        
+        assertGroup( 1, "junit", context );
+      
+        assertGroup( 6, "commons-logging", context );
+      
+        assertGroup( 1, "regexp", context );
+      
+        assertGroup( 1, "commons-cli", context );
+      
+        assertGroup( 15, "org", context );
+      
+        assertGroup( 6, "org.slf4j", context );
+      
+        assertGroup( 3, "org.testng", context );
+      
+        assertGroup( 3, "org.apache", context );
+      
+        assertGroup( 1, "org.apache.directory", context );
+        assertGroup( 1, "org.apache.directory.server", context );
+      
+        assertGroup( 1, "org.apache.maven", context );
+        assertGroup( 1, "org.apache.maven.plugins", context );
+        assertGroup( 0, "org.apache.maven.plugins.maven-core-it-plugin", context );
+    }
+
+    @Override
+    public void testSearchFlatPaged()
+        throws Exception
+    {
+        FlatSearchRequest request = new FlatSearchRequest( nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org" ) );
+    
+        request.setStart( 0 );
+    
+        request.setCount( 50 );
+    
+        FlatSearchResponse response = nexusIndexer.searchFlat( request );
+    
+        assertEquals( response.getResults().toString(), 15, response.getTotalHits() );
+    }
+    
+    @Override
+    public void testSearchGroupedProblematicNames()
+        throws Exception
+    {
+    
+        // ----------------------------------------------------------------------------
+        // Artifacts with "problematic" names
+        // ----------------------------------------------------------------------------
+        {
+            // "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "commons-logg*" );
+    
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            
+            Map<String, ArtifactInfoGroup> r = response.getResults(); 
+    
+            assertEquals( 1, r.size() );
+    
+            ArtifactInfoGroup ig = r.values().iterator().next();
+    
+            assertEquals( "commons-logging : commons-logging", ig.getGroupKey() );
+    
+            assertEquals( ig.getArtifactInfos().toString(), 6, ig.getArtifactInfos().size() );
+        }
+    
+        {
+            // numbers and "-" in the name
+            Query q = nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "jcl104-over-slf4*" );
+    
+            GroupedSearchRequest request = new GroupedSearchRequest( q, new GAGrouping() );
+            
+            GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
+            Map<String, ArtifactInfoGroup> r = response.getResults();
+    
+            assertEquals( 1, r.size() );
+    
+            ArtifactInfoGroup ig = r.values().iterator().next();
+    
+            assertEquals( ig.getArtifactInfos().toString(), 1, ig.getArtifactInfos().size() );
+    
+            assertEquals( "org.slf4j : jcl104-over-slf4j", ig.getGroupKey() );
+        }
+    }
+
+    @Override
+    public void donttestPaging()
+        throws Exception
+    {
+        // we have 15 artifact for this search
+        int total = 15;
+        
+        int pageSize = 4;
+        
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org" );
+    
+        FlatSearchRequest req = new FlatSearchRequest( q );
+    
+        // have page size of 4, that will make us 4 pages
+        req.setCount( pageSize );
+        
+        List<ArtifactInfo> constructedPageList = new ArrayList<ArtifactInfo>();
+        
+        int offset = 0;
+        
+        while( true ) 
+        {
+            req.setStart( offset );
+            
+            FlatSearchResponse resp = nexusIndexer.searchFlat( req );
+      
+            Collection<ArtifactInfo> p = resp.getResults();
+            
+            assertEquals( p.toString(), total, resp.getTotalHits() );
+      
+            assertEquals( Math.min( pageSize, total - offset ), p.size() );
+    
+            constructedPageList.addAll( p );
+            
+            offset += pageSize;
+            
+            if( offset > total )
+            {
+                break;
+            }
+        }
+        
+        // 
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+        Collection<ArtifactInfo> onePage = response.getResults(); 
+    
+        List<ArtifactInfo> onePageList = new ArrayList<ArtifactInfo>( onePage );
+    
+        // onePage and constructedPage should hold equal elems in the same order
+        assertTrue( resultsAreEqual( onePageList, constructedPageList ) );
+    }
+    
+    @Override
+    public void testPurge()
+        throws Exception
+    {
+        // we have 14 artifact for this search
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org" );
+        FlatSearchRequest request = new FlatSearchRequest( q );
+        
+        FlatSearchResponse response1 = nexusIndexer.searchFlat( request );
+        Collection<ArtifactInfo> p1 = response1.getResults();
+    
+        assertEquals( 15, p1.size() );
+    
+        context.purge();
+    
+        FlatSearchResponse response2 = nexusIndexer.searchFlat( request );
+        Collection<ArtifactInfo> p2 = response2.getResults();
+    
+        assertEquals( 0, p2.size() );
+    }
+
+    @Override
+    public void testIdentify()
+    {
+        // skip test (sha1 field wasn't stored in the old index format)
+    }
+    
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Index20081108RegressionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.util.Set;
+
+import org.apache.lucene.search.Query;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.NexusIndexer;
+
+/**
+ * @author Jason van Zyl
+ * @author Eugene Kuleshov
+ */
+public class MinimalIndexNexusIndexerTest
+    extends AbstractRepoNexusIndexerTest
+{
+    @Override
+    protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception
+    {
+        context = nexusIndexer.addIndexingContext( "test-minimal", "test", repo, indexDir, null, null, MIN_CREATORS );
+
+        nexusIndexer.scan( context );
+    }
+
+    public void testNEXUS2712()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "com.adobe.flexunit" );
+
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+
+        Set<ArtifactInfo> r = response.getResults();
+
+        assertEquals( 1, r.size() );
+
+        ArtifactInfo ai = r.iterator().next();
+
+        assertEquals( "com.adobe.flexunit", ai.groupId );
+        assertEquals( "flexunit", ai.artifactId );
+        assertEquals( "0.90", ai.version );
+        assertEquals( null, ai.classifier );
+        assertEquals( "swc", ai.packaging );
+
+        assertEquals( "swc", ai.fextension );
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java?rev=1030748&view=auto
==============================================================================
--- maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java (added)
+++ maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java Wed Nov  3 22:51:12 2010
@@ -0,0 +1,109 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.index;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.lucene.search.Query;
+import org.apache.maven.index.ArtifactInfo;
+import org.apache.maven.index.FlatSearchRequest;
+import org.apache.maven.index.FlatSearchResponse;
+import org.apache.maven.index.NexusIndexer;
+
+public class Nexus1179NexusIndexerTest
+extends AbstractNexusIndexerTest
+{
+    protected File repo = new File( getBasedir(), "src/test/nexus-1179" );
+
+    @Override
+    protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
+        throws Exception
+    {
+        context = nexusIndexer.addIndexingContext(
+            "nexus-1179",
+            "nexus-1179",
+            repo,
+            indexDir,
+            null,
+            null,
+            DEFAULT_CREATORS );
+        nexusIndexer.scan( context );
+    }
+    
+    public void testSearchFlat()
+        throws Exception
+    {
+        Query q = nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "*" );
+        FlatSearchResponse response = nexusIndexer.searchFlat( new FlatSearchRequest( q ) );
+        Collection<ArtifactInfo> r = response.getResults(); 
+    
+        assertEquals( 4, r.size() );
+    
+        List<ArtifactInfo> list = new ArrayList<ArtifactInfo>( r );
+    
+        ArtifactInfo ai = null;
+    
+        // g a v p c #1
+        ai = list.get( 0 );
+    
+        assertEquals( "ant", ai.groupId );
+        assertEquals( "ant", ai.artifactId );
+        assertEquals( "1.6.5", ai.version );
+        assertEquals( "jar", ai.packaging );
+        assertEquals( null, ai.classifier );
+        assertEquals( "nexus-1179", ai.repository );
+        assertEquals( "jar", ai.fextension );
+    
+        // g a v p c #2
+        ai = list.get( 1 );
+        
+        assertEquals( "ant", ai.groupId );
+        assertEquals( "ant", ai.artifactId );
+        assertEquals( "1.5.1", ai.version );
+        assertEquals( null, ai.packaging );
+        assertEquals( null, ai.classifier );
+        assertEquals( "nexus-1179", ai.repository );
+        assertEquals( "pom", ai.fextension );
+    
+        // g a v p c #3
+        ai = list.get( 2 );
+    
+        assertEquals( "asm", ai.groupId );
+        assertEquals( "asm-commons", ai.artifactId );
+        assertEquals( "3.1", ai.version );
+        assertEquals( "jar", ai.packaging );
+        assertEquals( null, ai.classifier );
+        assertEquals( "nexus-1179", ai.repository );
+        assertEquals( "pom", ai.fextension );
+        
+        // g a v p c #4
+        ai = list.get( 3 );
+    
+        assertEquals( "org", ai.groupId );
+        assertEquals( "test", ai.artifactId );
+        assertEquals( "1.0", ai.version );
+        assertEquals( null, ai.packaging );
+        assertEquals( null, ai.classifier );
+        assertEquals( "nexus-1179", ai.repository );
+        assertEquals( "pom", ai.fextension );
+    }
+}

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/indexer/trunk/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message