package org.carlspring.strongbox.storage.indexing;

import org.apache.maven.index.ArtifactInfo;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.Set;

public class LocalRepositoryIndexerTest
{
    final File indexDir = new File("target/test-idx");

    @Before
    public void init()
    {
        indexDir.mkdirs();
    }

    @Test
    public void testIndex() throws Exception
    {
        final LocalRepositoryIndexer i = new LocalRepositoryIndexer(
                "test", new File(System.getProperty("user.home"), ".m2/repository"), indexDir);
        try
        {
            final int x = i.index(new File("antlr"));
            Assert.assertEquals("two artifacts expected", x,
                    2); // one is jar another pom, both would be added into the same Lucene document

            Set<ArtifactInfo> search = i.search("antlr", "antlr", null);
            for (final ArtifactInfo ai : search)
            {
                System.out.println(ai.groupId + " / " + ai.artifactId + " / " + ai.version + " / " + ai.description);
            }
            Assert.assertEquals("only one antlr artifact", search.size(), 1);

            i.delete(search);
            search = i.search("antlr", "antlr", null);
            Assert.assertEquals("antlr should be deleted", search.size(), 0);
        }
        finally
        {
            i.close(false);
        }
    }
}
@@ -60,39 +60,274 @@
 org.
-apache.maven.index.ArtifactInfo
+carlspring.maven.commons.util.ArtifactUtils;%0Aimport org.carlspring.strongbox.artifact.generator.ArtifactGenerator;%0A%0Aimport org.apache.maven.artifact.Artifact;%0Aimport org.apache.maven.index.ArtifactInfo;%0Aimport org.codehaus.plexus.util.xml.pull.XmlPullParserException
 ;%0Aim
@@ -419,16 +419,91 @@
 o.File;%0A
+import java.io.IOException;%0Aimport java.security.NoSuchAlgorithmException;%0A
 import j
@@ -563,128 +563,712 @@
 t%0A%7B%0A
+%0A
     
-final File indexDir = new File(%22target/test-idx%22);%0A%0A    @Before%0A    public void init()%0A    %7B%0A        indexDir.mkdirs
+private static final File REPOSITORY_BASEDIR = new File(%22target/strongbox/storages/storage0/releases%22);%0A%0A    private static final File INDEX_DIR = new File(REPOSITORY_BASEDIR, %22.index%22);%0A%0A    private static final Artifact artifact = ArtifactUtils.getArtifactFromGAVTC(%22org.carlspring.strongbox:strongbox-commons:1.0:jar%22);%0A%0A%0A    @Before%0A    public void init()%0A            throws NoSuchAlgorithmException,%0A                   XmlPullParserException,%0A                   IOException%0A    %7B%0A        //noinspection ResultOfMethodCallIgnored%0A        INDEX_DIR.mkdirs();%0A%0A%0A        ArtifactGenerator generator = new ArtifactGenerator(REPOSITORY_BASEDIR.getAbsolutePath(), artifact);%0A        generator.generate
 ();%0A
@@ -1403,16 +1403,59 @@
 Indexer(
+%22releases%22, REPOSITORY_BASEDIR, INDEX_DIR);
 %0A       
@@ -1455,24 +1455,28 @@
         
+try%0A
         
 %22test%22, 
@@ -1471,109 +1471,141 @@
     
-%22test%22, new File(System.getProperty(%22user.home%22), %22.m2/repository%22), indexDir);%0A        try%0A        %7B
+%7B%0A            System.out.println(REPOSITORY_BASEDIR.getAbsolutePath());%0A            System.out.println(INDEX_DIR.getAbsolutePath());%0A
 %0A   
@@ -1639,25 +1639,26 @@
 dex(
-new File(%22antlr%22)
+REPOSITORY_BASEDIR
 );%0A 
@@ -1689,17 +1689,17 @@
 Equals(%22
-t
+T
 wo artif
@@ -1707,16 +1707,21 @@
 cts 
+were 
 expected
 %22, x
@@ -1720,14 +1720,55 @@
 cted
+!
 %22,
- x,%0A
+%0A                                x,%0A        
     
@@ -1787,38 +1787,52 @@
     
+    
 2); // 
-o
+O
 ne is 
+a 
 jar
- an
+, the 
 other 
+-- a 
 pom
-,
+;
  bot
@@ -1927,32 +1927,63 @@
 .search(
-%22antlr%22, %22antlr%22
+artifact.getGroupId(), artifact.getArtifactId()
 , null);
@@ -2170,32 +2170,33 @@
 ;%0A            %7D%0A
+%0A
             Asse
@@ -2216,17 +2216,17 @@
 ls(%22
-o
+O
 nly one 
 antl
@@ -2225,22 +2225,63 @@
 one 
-antlr artifact
+%22 + artifact.getArtifactId() + %22 artifact was expected!
 %22, s
@@ -2363,89 +2363,166 @@
 rch(
-%22antlr%22, %22antlr%22, null);%0A            Assert.assertEquals(%22antlr should be
+artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());%0A            Assert.assertEquals(artifact.getArtifactId() + %22 should have been
  deleted
 %22, s
@@ -2517,16 +2517,17 @@
  deleted
+!
 %22, searc
@@ -2620,9 +2620,10 @@
 %7D%0A    %7D%0A
+%0A
 %7D

Implement indexing for hosted repositories