You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2022/10/14 12:42:11 UTC
[maven-indexer] branch master updated: [MINDEXER-141][MINDEXER-169][MINDEXER-170] Movel tests on Junit4, drop legacy (#252)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-indexer.git
The following commit(s) were added to refs/heads/master by this push:
new d34b545 [MINDEXER-141][MINDEXER-169][MINDEXER-170] Movel tests on Junit4, drop legacy (#252)
d34b545 is described below
commit d34b545f32fce63a8241c98de599691108011431
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Oct 14 14:42:06 2022 +0200
[MINDEXER-141][MINDEXER-169][MINDEXER-170] Movel tests on Junit4, drop legacy (#252)
As this is simplest, sisu offers InjectedTest that is Junit4 and we will see later where from here (or how to Junit5 from here). There is a LOT of old plexus/junit3 remnants that needs cleanup.
This PR also drops use of Plexus as it is not more needed.
High level changes:
* dropped Plexus container
* dropped Plexus CLI
* dropped logback (was used by Spring example, unsure why when slf4j-simple was there as well)
* dropped Wagon and Wagon Provider API (using plain Java11 HttpClient in tests instead)
* due plexus drop. PlexusTestCase (Junit3) is gone as well, all tests moved to Junit4 (sisu InjectedTest)
* dropped some disabled/ignored tests (as they tested client timeout, not indexer)
----
https://issues.apache.org/jira/browse/MINDEXER-141
https://issues.apache.org/jira/browse/MINDEXER-169
https://issues.apache.org/jira/browse/MINDEXER-170
---
indexer-cli/pom.xml | 33 +-
.../org/apache/maven/index/cli/Components.java | 30 +-
.../apache/maven/index/cli/NexusIndexerCli.java | 502 +++++++++++++--------
.../index/cli/AbstractNexusIndexerCliTest.java | 125 +----
.../apache/maven/index/cli/NexusIndexerCliIT.java | 2 +-
.../maven/index/cli/NexusIndexerCliTest.java | 7 +-
indexer-core/pom.xml | 29 +-
.../apache/maven/index/updater/WagonHelper.java | 247 ----------
.../maven/index/AbstractIndexCreatorHelper.java | 9 +-
.../maven/index/AbstractNexusIndexerTest.java | 6 +-
.../maven/index/AbstractRepoNexusIndexerTest.java | 15 +
.../apache/maven/index/AbstractTestSupport.java | 16 +-
.../org/apache/maven/index/ConcurrentUseTest.java | 13 +-
...ncurrentUseWithMergedContextPublishingTest.java | 4 +-
.../index/ConcurrentUseWithMergedContextTest.java | 2 +
.../maven/index/DefaultIndexNexusIndexerTest.java | 16 +-
.../maven/index/DefaultSearchEngineTest.java | 8 +-
.../apache/maven/index/DuplicateSearchTest.java | 19 +-
.../apache/maven/index/FSDirectoryDeleteTest.java | 6 +-
.../maven/index/FullIndexNexusIndexerTest.java | 20 +-
.../org/apache/maven/index/Java11HttpClient.java | 78 ++++
.../apache/maven/index/Mindexer14HitLimitTest.java | 15 +-
.../maven/index/Mindexer35NexusIndexerTest.java | 4 +
.../maven/index/MinimalIndexNexusIndexerTest.java | 7 +-
.../maven/index/Nexus1179NexusIndexerTest.java | 15 +-
.../maven/index/Nexus13NexusIndexerTest.java | 13 +
.../index/Nexus1911IncrementalMergedCtxTest.java | 4 +-
.../maven/index/Nexus1911IncrementalTest.java | 139 +++---
.../maven/index/Nexus2046NexusIndexerTest.java | 7 +-
.../maven/index/Nexus3177HitLimitChecks.java | 7 +
.../maven/index/Nexus3233NexusIndexerTest.java | 6 +
.../index/Nexus3293TimestampSnapshotTest.java | 5 +
.../maven/index/Nexus3881NexusIndexerTest.java | 9 +-
.../maven/index/Nexus4674GavPathReindexTest.java | 7 +
.../maven/index/Nexus645NexusIndexerTest.java | 4 +
.../maven/index/Nexus658NexusIndexerTest.java | 4 +
.../maven/index/Nexus687NexusIndexerTest.java | 4 +
.../maven/index/Nexus737NexusIndexerTest.java | 4 +
.../org/apache/maven/index/NexusIndexerTest.java | 19 +-
.../maven/index/SearchWithAnEmptyIndexTest.java | 20 +-
.../org/apache/maven/index/SubPathReindexTest.java | 7 +
.../maven/index/UniqueArtifactFilterTest.java | 6 +
.../maven/index/artifact/M1GavCalculatorTest.java | 19 +-
.../maven/index/artifact/M2GavCalculatorTest.java | 28 +-
.../artifact/MavenArtifactRecognizerTest.java | 9 +-
.../maven/index/context/NexusAnalyzerTest.java | 17 +-
.../index/context/TrackingLockFactoryTest.java | 3 -
.../creator/JarFileContentsIndexCreatorTest.java | 11 +
.../MavenPluginArtifactInfoIndexCreatorTest.java | 4 +
.../creator/OsgiArtifactIndexCreatorTest.java | 13 +
.../incremental/DefaultIncrementalHandlerTest.java | 11 +-
.../maven/index/locator/ArtifactLocatorTest.java | 5 +
.../index/packer/NEXUS4149TransferFormatTest.java | 24 +-
.../maven/index/treeview/IndexTreeViewTest.java | 13 +-
.../index/updater/AbstractIndexUpdaterTest.java | 6 +-
.../updater/DefaultIndexUpdaterEmbeddingIT.java | 287 ++----------
.../index/updater/DefaultIndexUpdaterTest.java | 42 +-
.../updater/DownloadRemoteIndexerManagerTest.java | 19 +-
.../index/updater/FullBootProofOfConcept.java | 181 --------
.../apache/maven/index/updater/IndexDataTest.java | 8 +
.../maven/index/updater/LocalIndexCacheTest.java | 16 +-
.../updater/fixtures/TransferListenerFixture.java | 84 ----
.../maven/index/util/IndexCreatorSorterTest.java | 69 +--
indexer-examples/indexer-examples-basic/pom.xml | 22 +-
.../maven/index/examples/BasicUsageExample.java | 139 +++---
.../index/examples/BasicUsageExampleTest.java | 14 +-
indexer-examples/indexer-examples-spring/pom.xml | 39 +-
.../index/examples/SpringUsageExampleTest.java | 3 +-
.../META-INF/spring/indexer-examples-context.xml | 43 --
.../src/test/resources/logback.xml | 35 --
indexer-reader/pom.xml | 10 +
.../apache/maven/index/reader/ChunkReaderTest.java | 2 +-
.../apache/maven/index/reader/IndexReaderTest.java | 3 +-
.../apache/maven/index/reader/IndexWriterTest.java | 3 +-
.../org/apache/maven/index/reader/TestSupport.java | 5 +-
.../apache/maven/index/reader/TransformTest.java | 3 +-
pom.xml | 64 +--
search-api/pom.xml | 10 +
search-backend-indexer/pom.xml | 21 +-
.../internal/IndexerCoreSearchBackendImplTest.java | 161 ++++---
search-backend-smo/pom.xml | 5 +
.../smo/internal/SmoSearchBackendImplTest.java | 2 +-
82 files changed, 1279 insertions(+), 1667 deletions(-)
diff --git a/indexer-cli/pom.xml b/indexer-cli/pom.xml
index a433d69..022cc9d 100644
--- a/indexer-cli/pom.xml
+++ b/indexer-cli/pom.xml
@@ -58,11 +58,6 @@ under the License.
<artifactId>guice</artifactId>
</dependency>
- <dependency>
- <groupId>org.eclipse.sisu</groupId>
- <artifactId>org.eclipse.sisu.plexus</artifactId>
- </dependency>
-
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
@@ -70,17 +65,6 @@ under the License.
</dependency>
<!-- Needed for CLI assembly only, to make it work in "standalone" CLI mode -->
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-cli</artifactId>
- <version>1.6</version>
- <exclusions>
- <exclusion>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-container-default</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
@@ -88,6 +72,16 @@ under the License.
</dependency>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -103,11 +97,6 @@ under the License.
<artifactId>jetty-webapp</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-http</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
@@ -144,8 +133,8 @@ under the License.
</filter>
</filters>
<transformers>
- <transformer implementation="org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
+ <transformer implementation="org.apache.maven.plugins.shade.resource.SisuIndexResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>org.apache.maven.index.cli.NexusIndexerCli</Main-Class>
diff --git a/indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java b/indexer-cli/src/main/java/org/apache/maven/index/cli/Components.java
similarity index 63%
copy from indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java
copy to indexer-cli/src/main/java/org/apache/maven/index/cli/Components.java
index 13d5dff..5398101 100644
--- a/indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java
+++ b/indexer-cli/src/main/java/org/apache/maven/index/cli/Components.java
@@ -1,4 +1,4 @@
-package org.apache.maven.index.examples;
+package org.apache.maven.index.cli;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,14 +19,26 @@ package org.apache.maven.index.examples;
* under the License.
*/
-import junit.framework.TestCase;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
-public class BasicUsageExampleTest
- extends TestCase
+import java.util.Map;
+
+import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexCreator;
+import org.apache.maven.index.packer.IndexPacker;
+
+@Named
+@Singleton
+public class Components
{
- public void testApp()
- throws Exception
- {
- BasicUsageExample.main( null );
- }
+ @Inject
+ Map<String, IndexCreator> allIndexCreators;
+
+ @Inject
+ NexusIndexer indexer;
+
+ @Inject
+ IndexPacker packer;
}
diff --git a/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java b/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
index 6b76830..7d5e2bb 100644
--- a/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
+++ b/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
@@ -9,7 +9,7 @@ package org.apache.maven.index.cli;
* "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
+ * 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
@@ -19,9 +19,23 @@ package org.apache.maven.index.cli;
* under the License.
*/
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import com.google.inject.Guice;
+import com.google.inject.Module;
import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.lucene.search.IndexSearcher;
@@ -29,7 +43,6 @@ import org.apache.lucene.store.FSDirectory;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.ArtifactScanningListener;
-import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.ScanningResult;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
@@ -38,25 +51,10 @@ import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
import org.apache.maven.index.packer.IndexPackingRequest.IndexFormat;
import org.apache.maven.index.updater.DefaultIndexUpdater;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.classworlds.ClassWorld;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.LoggerManager;
-import org.codehaus.plexus.tools.cli.AbstractCli;
+import org.eclipse.sisu.launch.Main;
+import org.eclipse.sisu.space.BeanScanning;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
+import static java.util.Objects.requireNonNull;
/**
* A command line tool that can be used to index local Maven repository.
@@ -80,213 +78,327 @@ import java.util.concurrent.TimeUnit;
* {@link org.apache.maven.index.creator.JarFileContentsIndexCreator}.
*/
public class NexusIndexerCli
- extends AbstractCli
{
+
+ // Generic command line options
+
+ public static final String QUIET = "q";
+
+ public static final String DEBUG = "X";
+
+ public static final String HELP = "h";
+
+ public static final String VERSION = "v";
+
// Command line options
- public static final char REPO = 'r';
+ public static final String REPO = "r";
- public static final char INDEX = 'i';
+ public static final String INDEX = "i";
- public static final char NAME = 'n';
+ public static final String NAME = "n";
- public static final char TYPE = 't';
+ public static final String TYPE = "t";
- public static final char TARGET_DIR = 'd';
+ public static final String TARGET_DIR = "d";
- public static final char CREATE_INCREMENTAL_CHUNKS = 'c';
+ public static final String CREATE_INCREMENTAL_CHUNKS = "c";
- public static final char CREATE_FILE_CHECKSUMS = 's';
+ public static final String CREATE_FILE_CHECKSUMS = "s";
- public static final char INCREMENTAL_CHUNK_KEEP_COUNT = 'k';
+ public static final String INCREMENTAL_CHUNK_KEEP_COUNT = "k";
- public static final char UNPACK = 'u';
+ public static final String UNPACK = "u";
private static final long MB = 1024 * 1024;
private Options options;
- private int status = 0;
-
public static void main( String[] args )
- throws Exception
{
- NexusIndexerCli cli = new NexusIndexerCli();
-
- cli.execute( args );
-
- System.exit( cli.status );
+ System.exit( new NexusIndexerCli().execute( args ) );
}
- @Override
- public int execute( String[] arg0, ClassWorld arg1 )
+ /**
+ * Visible for testing.
+ */
+ int execute( String[] args )
{
- int value = super.execute( arg0, arg1 );
+ CommandLine cli;
- if ( status == 0 )
+ try
{
- status = value;
+ cli = new DefaultParser().parse( buildCliOptions(), cleanArgs( args ) );
}
+ catch ( ParseException e )
+ {
+ System.err.println( "Unable to parse command line options: " + e.getMessage() );
- return status;
- }
+ displayHelp();
- @Override
- public int execute( String[] args )
- {
- int value = super.execute( args );
+ return 1;
+ }
- if ( status == 0 )
+ boolean debug = cli.hasOption( DEBUG );
+
+ if ( cli.hasOption( HELP ) )
{
- status = value;
+ displayHelp();
+
+ return 0;
}
- return status;
- }
+ if ( cli.hasOption( VERSION ) )
+ {
+ showVersion();
- @Override
- protected void showError( String message, Exception e, boolean show )
- {
- status = 1;
- super.showError( message, e, show );
- }
+ return 0;
+ }
+ else if ( debug )
+ {
+ showVersion();
+ }
- @Override
- protected int showFatalError( String message, Exception e, boolean show )
- {
- status = 1;
- return super.showFatalError( message, e, show );
- }
+ final Module app = Main.wire(
+ BeanScanning.INDEX
+ );
- @Override
- public CommandLine parse( String[] args )
- throws ParseException
- {
- try
+ Components components =
+ Guice.createInjector( app ).getInstance( Components.class );
+
+ if ( cli.hasOption( UNPACK ) )
{
- return super.parse( args );
+ try
+ {
+ return unpack( cli, components );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace( System.err );
+ return 1;
+ }
}
- catch ( ParseException e )
+ else if ( cli.hasOption( INDEX ) && cli.hasOption( REPO ) )
{
- status = 1;
- throw e;
+ try
+ {
+ return index( cli, components );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace( System.err );
+ return 1;
+ }
+ }
+ else
+ {
+ System.out.println();
+ System.out.println( "Use either unpack (\"" + UNPACK + "\") or index (\"" + INDEX + "\" and \"" + REPO
+ + "\") options, but none has been found!" );
+ System.out.println();
+ displayHelp();
+ return 1;
}
}
- @Override
- public String getPomPropertiesPath()
+ /**
+ * Visible for testing.
+ */
+ Options buildCliOptions()
{
- return "META-INF/maven/org.apache.maven.indexer/indexer-core/pom.properties";
- }
+ this.options = new Options();
- @Override
- @SuppressWarnings( "static-access" )
- public Options buildCliOptions( Options options )
- {
- this.options = options;
+ options.addOption( Option.builder( QUIET ).longOpt( "quiet" )
+ .desc( "Quiet output - only show errors" ).build() );
+
+ options.addOption( Option.builder( DEBUG ).longOpt( "debug" )
+ .desc( "Produce execution debug output" ).build() );
+
+ options.addOption( Option.builder( VERSION ).longOpt( "version" )
+ .desc( "Display version information" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "index" ).hasArg() //
- .withDescription( "Path to the index folder." ).create( INDEX ) );
+ options.addOption( Option.builder( HELP ).longOpt( "help" )
+ .desc( "Display help information" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "destination" ).hasArg() //
- .withDescription( "Target folder." ).create( TARGET_DIR ) );
- options.addOption( OptionBuilder.withLongOpt( "repository" ).hasArg() //
- .withDescription( "Path to the Maven repository." ).create( REPO ) );
+ options.addOption( Option.builder( INDEX ).longOpt( "index" ).argName( "path" ).hasArg()
+ .desc( "Path to the index folder" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "name" ).hasArg() //
- .withDescription( "Repository name." ).create( NAME ) );
+ options.addOption( Option.builder( TARGET_DIR ).longOpt( "destination" ).argName( "path" ).hasArg()
+ .desc( "Target folder" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "chunks" ) //
- .withDescription( "Create incremental chunks." ).create( CREATE_INCREMENTAL_CHUNKS ) );
+ options.addOption( Option.builder( REPO ).longOpt( "repository" ).argName( "path" ).hasArg()
+ .desc( "Path to the Maven repository" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "keep" ).hasArg().withDescription(
- "Number of incremental chunks to keep." ).create( INCREMENTAL_CHUNK_KEEP_COUNT ) );
+ options.addOption( Option.builder( NAME ).longOpt( "name" ).argName( "string" ).hasArg()
+ .desc( "Repository name" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "checksums" ) //
- .withDescription( "Create checksums for all files (sha1, md5)." ).create( CREATE_FILE_CHECKSUMS ) );
+ options.addOption( Option.builder( CREATE_INCREMENTAL_CHUNKS ).longOpt( "chunks" )
+ .desc( "Create incremental chunks" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "type" ).hasArg() //
- .withDescription( "Indexer type (default, min, full or comma separated list of custom types)." )
- .create( TYPE ) );
+ options.addOption( Option.builder( INCREMENTAL_CHUNK_KEEP_COUNT ).longOpt( "keep" ).argName( "num" ).hasArg()
+ .desc( "Number of incremental chunks to keep" ).build() );
- options.addOption( OptionBuilder.withLongOpt( "unpack" ) //
- .withDescription( "Unpack an index file" ).create( UNPACK ) );
+ options.addOption( Option.builder( CREATE_FILE_CHECKSUMS ).longOpt( "checksums" )
+ .desc( "Create checksums for all files (sha1, md5)" ).build() );
+
+ options.addOption( Option.builder( TYPE ).longOpt( "type" ).argName( "type" ).hasArg()
+ .desc( "Indexer type (default, min, full or comma separated list of custom types)" ).build() );
+
+ options.addOption( Option.builder( UNPACK ).longOpt( "unpack" )
+ .desc( "Unpack an index file" ).build() );
return options;
}
- @Override
- public void displayHelp()
+ private String[] cleanArgs( String[] args )
{
- System.out.println();
+ List<String> cleaned = new ArrayList<>();
- HelpFormatter formatter = new HelpFormatter();
+ StringBuilder currentArg = null;
- formatter.printHelp( "nexus-indexer [options]", "\nOptions:", options, "\n" );
- }
+ for ( String arg : args )
+ {
+ boolean addedToBuffer = false;
- public void displayHelp( String message )
- {
- System.out.println();
+ if ( arg.startsWith( "\"" ) )
+ {
+ // if we're in the process of building up another arg, push it and start over.
+ // this is for the case: "-Dfoo=bar "-Dfoo2=bar two" (note the first unterminated quote)
+ if ( currentArg != null )
+ {
+ cleaned.add( currentArg.toString() );
+ }
- System.out.println( message );
+ // start building an argument here.
+ currentArg = new StringBuilder( arg.substring( 1 ) );
- System.out.println();
+ addedToBuffer = true;
+ }
- displayHelp();
- }
+ // this has to be a separate "if" statement, to capture the case of: "-Dfoo=bar"
+ if ( arg.endsWith( "\"" ) )
+ {
+ String cleanArgPart = arg.substring( 0, arg.length() - 1 );
- @Override
- public void invokePlexusComponent( final CommandLine cli, PlexusContainer plexus )
- throws Exception
- {
- final DefaultContainerConfiguration configuration = new DefaultContainerConfiguration();
- configuration.setClassWorld( ( (DefaultPlexusContainer) plexus ).getClassWorld() );
- configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
+ // if we're building an argument, keep doing so.
+ if ( currentArg != null )
+ {
+ // if this is the case of "-Dfoo=bar", then we need to adjust the buffer.
+ if ( addedToBuffer )
+ {
+ currentArg.setLength( currentArg.length() - 1 );
+ }
+ // otherwise, we trim the trailing " and append to the buffer.
+ else
+ {
+ // TODO: introducing a space here...not sure what else to do but collapse whitespace
+ currentArg.append( ' ' ).append( cleanArgPart );
+ }
- // replace plexus, as PlexusCli is blunt, does not allow to modify configuration
- // TODO: get rid of PlexusCli use!
- plexus = new DefaultPlexusContainer( configuration );
+ // we're done with this argument, so add it.
+ cleaned.add( currentArg.toString() );
+ }
+ else
+ {
+ // this is a simple argument...just add it.
+ cleaned.add( cleanArgPart );
+ }
- if ( cli.hasOption( QUIET ) )
- {
- setLogLevel( plexus, Logger.LEVEL_DISABLED );
- }
- else if ( cli.hasOption( DEBUG ) )
- {
- setLogLevel( plexus, Logger.LEVEL_DEBUG );
- }
- else if ( cli.hasOption( ERRORS ) )
- {
- setLogLevel( plexus, Logger.LEVEL_ERROR );
+ // the currentArg MUST be finished when this completes.
+ currentArg = null;
+
+ continue;
+ }
+
+ // if we haven't added this arg to the buffer, and we ARE building an argument
+ // buffer, then append it with a preceding space...again, not sure what else to
+ // do other than collapse whitespace.
+ // NOTE: The case of a trailing quote is handled by nullifying the arg buffer.
+ if ( !addedToBuffer )
+ {
+ // append to the argument we're building, collapsing whitespace to a single space.
+ if ( currentArg != null )
+ {
+ currentArg.append( ' ' ).append( arg );
+ }
+ // this is a loner, just add it directly.
+ else
+ {
+ cleaned.add( arg );
+ }
+ }
}
- if ( cli.hasOption( UNPACK ) )
+ // clean up.
+ if ( currentArg != null )
{
- unpack( cli, plexus );
+ cleaned.add( currentArg.toString() );
}
- else if ( cli.hasOption( INDEX ) && cli.hasOption( REPO ) )
+
+ int cleanedSz = cleaned.size();
+ String[] cleanArgs;
+
+ if ( cleanedSz == 0 )
{
- index( cli, plexus );
+ // if we didn't have any arguments to clean, simply pass the original array through
+ cleanArgs = args;
}
else
{
- status = 1;
-
- displayHelp( "Use either unpack (\"" + UNPACK + "\") or index (\"" + INDEX + "\" and \"" + REPO
- + "\") options, but none has been found!" );
+ cleanArgs = cleaned.toArray( new String[cleanedSz] );
}
+
+ return cleanArgs;
}
- private void setLogLevel( PlexusContainer plexus, int logLevel )
- throws ComponentLookupException
+ private void displayHelp()
{
- plexus.lookup( LoggerManager.class ).setThresholds( logLevel );
+ System.out.println();
+
+ HelpFormatter formatter = new HelpFormatter();
+
+ formatter.printHelp( "nexus-indexer [options]", "\nOptions:", options, "\n" );
}
- private void index( final CommandLine cli, PlexusContainer plexus )
- throws ComponentLookupException, IOException, UnsupportedExistingLuceneIndexException
+ private void showVersion()
+ {
+ InputStream is;
+
+ try
+ {
+ Properties properties = new Properties();
+
+ is = getClass().getClassLoader().getResourceAsStream(
+ "META-INF/maven/org.apache.maven.indexer/indexer-core/pom.properties" );
+
+ if ( is == null )
+ {
+ System.err.println( "Unable determine version from JAR file." );
+
+ return;
+ }
+
+ properties.load( is );
+
+ if ( properties.getProperty( "builtOn" ) != null )
+ {
+ System.out.println( "Version: " + properties.getProperty( "version", "unknown" )
+ + " built on " + properties.getProperty( "builtOn" ) );
+ }
+ else
+ {
+ System.out.println( "Version: " + properties.getProperty( "version", "unknown" ) );
+ }
+ }
+ catch ( IOException e )
+ {
+ System.err.println( "Unable determine version from JAR file: " + e.getMessage() );
+ }
+ }
+
+ private int index( final CommandLine cli, Components components )
+ throws IOException, UnsupportedExistingLuceneIndexException
{
String indexDirectoryName = cli.getOptionValue( INDEX );
@@ -300,7 +412,7 @@ public class NexusIndexerCli
String repositoryName = cli.getOptionValue( NAME, indexFolder.getName() );
- List<IndexCreator> indexers = getIndexers( cli, plexus );
+ List<IndexCreator> indexers = getIndexers( cli, components );
boolean createChecksums = cli.hasOption( CREATE_FILE_CHECKSUMS );
@@ -320,47 +432,43 @@ public class NexusIndexerCli
System.err.printf( "Index Folder: %s\n", indexFolder.getAbsolutePath() );
System.err.printf( "Output Folder: %s\n", outputFolder.getAbsolutePath() );
System.err.printf( "Repository name: %s\n", repositoryName );
- System.err.printf( "Indexers: %s\n", indexers.toString() );
+ System.err.printf( "Indexers: %s\n", indexers );
if ( createChecksums )
{
- System.err.printf( "Will create checksum files for all published files (sha1, md5).\n" );
+ System.err.print( "Will create checksum files for all published files (sha1, md5).\n" );
}
else
{
- System.err.printf( "Will not create checksum files.\n" );
+ System.err.print( "Will not create checksum files.\n" );
}
if ( createIncrementalChunks )
{
- System.err.printf( "Will create incremental chunks for changes, along with baseline file.\n" );
+ System.err.print( "Will create incremental chunks for changes, along with baseline file.\n" );
}
else
{
- System.err.printf( "Will create baseline file.\n" );
+ System.err.print( "Will create baseline file.\n" );
}
}
- NexusIndexer indexer = plexus.lookup( NexusIndexer.class );
-
long tstart = System.currentTimeMillis();
- IndexingContext context = indexer.addIndexingContext( //
- repositoryName, // context id
- repositoryName, // repository id
- repositoryFolder, // repository folder
- indexFolder, // index folder
- null, // repositoryUrl
- null, // index update url
- indexers );
+ IndexingContext context = components.indexer.addIndexingContext( //
+ repositoryName, // context id
+ repositoryName, // repository id
+ repositoryFolder, // repository folder
+ indexFolder, // index folder
+ null, // repositoryUrl
+ null, // index update url
+ indexers );
try
{
- IndexPacker packer = plexus.lookup( IndexPacker.class );
-
ArtifactScanningListener listener = new IndexerListener( context, debug, quiet );
- indexer.scan( context, listener, true );
+ components.indexer.scan( context, listener, true );
IndexSearcher indexSearcher = context.acquireIndexSearcher();
@@ -373,14 +481,14 @@ public class NexusIndexerCli
request.setCreateIncrementalChunks( createIncrementalChunks );
- request.setFormats( Arrays.asList( IndexFormat.FORMAT_V1 ) );
+ request.setFormats( List.of( IndexFormat.FORMAT_V1 ) );
if ( chunkCount != null )
{
request.setMaxIndexChunks( chunkCount );
}
- packIndex( packer, request, debug, quiet );
+ packIndex( components.packer, request, debug, quiet );
}
finally
{
@@ -394,12 +502,13 @@ public class NexusIndexerCli
}
finally
{
- indexer.removeIndexingContext( context, false );
+ components.indexer.removeIndexingContext( context, false );
}
+ return 0;
}
- private void unpack( CommandLine cli, PlexusContainer plexus )
- throws ComponentLookupException, IOException
+ private int unpack( CommandLine cli, Components components )
+ throws IOException
{
final String indexDirectoryName = cli.getOptionValue( INDEX, "." );
final File indexFolder = new File( indexDirectoryName ).getCanonicalFile();
@@ -417,19 +526,19 @@ public class NexusIndexerCli
long tstart = System.currentTimeMillis();
- final List<IndexCreator> indexers = getIndexers( cli, plexus );
+ final List<IndexCreator> indexers = getIndexers( cli, components );
try ( BufferedInputStream is = new BufferedInputStream( new FileInputStream( indexArchive ) ); //
- FSDirectory directory = FSDirectory.open( outputFolder.toPath() ) )
+ FSDirectory directory = FSDirectory.open( outputFolder.toPath() ) )
{
DefaultIndexUpdater.unpackIndexData( is, directory, (IndexingContext) Proxy.newProxyInstance(
- getClass().getClassLoader(), new Class[] { IndexingContext.class }, new PartialImplementation()
- {
- public List<IndexCreator> getIndexCreators()
+ getClass().getClassLoader(), new Class[] {IndexingContext.class}, new PartialImplementation()
{
- return indexers;
- }
- } )
+ public List<IndexCreator> getIndexCreators()
+ {
+ return indexers;
+ }
+ } )
);
}
@@ -438,10 +547,10 @@ public class NexusIndexerCli
{
printStats( tstart );
}
+ return 0;
}
- private List<IndexCreator> getIndexers( final CommandLine cli, PlexusContainer plexus )
- throws ComponentLookupException
+ private List<IndexCreator> getIndexers( final CommandLine cli, Components components )
{
String type = "default";
@@ -454,21 +563,18 @@ public class NexusIndexerCli
if ( "default".equals( type ) )
{
- indexers.add( plexus.lookup( IndexCreator.class, "min" ) );
- indexers.add( plexus.lookup( IndexCreator.class, "jarContent" ) );
+ indexers.add( requireNonNull( components.allIndexCreators.get( "min" ) ) );
+ indexers.add( requireNonNull( components.allIndexCreators.get( "jarContent" ) ) );
}
else if ( "full".equals( type ) )
{
- for ( Object component : plexus.lookupList( IndexCreator.class ) )
- {
- indexers.add( (IndexCreator) component );
- }
+ indexers.addAll( components.allIndexCreators.values() );
}
else
{
- for ( String hint : type.split( "," ) )
+ for ( String name : type.split( "," ) )
{
- indexers.add( plexus.lookup( IndexCreator.class, hint ) );
+ indexers.add( requireNonNull( components.allIndexCreators.get( name ) ) );
}
}
return indexers;
@@ -513,20 +619,20 @@ public class NexusIndexerCli
Runtime r = Runtime.getRuntime();
System.err.printf( "Final memory: %dM/%dM\n", //
- ( r.totalMemory() - r.freeMemory() ) / MB, r.totalMemory() / MB );
+ ( r.totalMemory() - r.freeMemory() ) / MB, r.totalMemory() / MB );
}
/**
* Scanner listener
*/
private static final class IndexerListener
- implements ArtifactScanningListener
+ implements ArtifactScanningListener
{
private final IndexingContext context;
private final boolean debug;
- private boolean quiet;
+ private final boolean quiet;
private long ts = System.currentTimeMillis();
@@ -539,6 +645,7 @@ public class NexusIndexerCli
this.quiet = quiet;
}
+ @Override
public void scanningStarted( IndexingContext context )
{
if ( !quiet )
@@ -547,6 +654,7 @@ public class NexusIndexerCli
}
}
+ @Override
public void artifactDiscovered( ArtifactContext ac )
{
count++;
@@ -558,7 +666,7 @@ public class NexusIndexerCli
if ( !quiet && debug && "maven-plugin".equals( ai.getPackaging() ) )
{
System.err.printf( "Plugin: %s:%s:%s - %s %s\n", //
- ai.getGroupId(), ai.getArtifactId(), ai.getVersion(), ai.getPrefix(), "" + ai.getGoals() );
+ ai.getGroupId(), ai.getArtifactId(), ai.getVersion(), ai.getPrefix(), "" + ai.getGoals() );
}
if ( !quiet && ( debug || ( t - ts ) > 2000L ) )
@@ -568,6 +676,7 @@ public class NexusIndexerCli
}
}
+ @Override
public void artifactError( ArtifactContext ac, Exception e )
{
if ( !quiet )
@@ -590,6 +699,7 @@ public class NexusIndexerCli
return file.getAbsolutePath().substring( context.getRepository().getAbsolutePath().length() + 1 );
}
+ @Override
public void scanningFinished( IndexingContext context, ScanningResult result )
{
if ( !quiet )
diff --git a/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java b/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
index e7d6b14..f6d37c6 100644
--- a/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
+++ b/indexer-cli/src/test/java/org/apache/maven/index/cli/AbstractNexusIndexerCliTest.java
@@ -22,24 +22,17 @@ package org.apache.maven.index.cli;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
-import java.util.List;
import java.util.Random;
-import org.apache.lucene.search.Query;
-import org.apache.maven.index.FlatSearchRequest;
-import org.apache.maven.index.FlatSearchResponse;
-import org.apache.maven.index.MAVEN;
-import org.apache.maven.index.NexusIndexer;
-import org.apache.maven.index.SearchType;
-import org.apache.maven.index.context.IndexCreator;
-import org.apache.maven.index.context.IndexingContext;
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
-import org.junit.Ignore;
+import org.eclipse.sisu.launch.InjectedTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
public abstract class AbstractNexusIndexerCliTest
- extends PlexusTestCase
+ extends InjectedTest
{
private static final long rand = new Random().nextLong();
@@ -51,28 +44,21 @@ public abstract class AbstractNexusIndexerCliTest
* getBasedir(), "target/tests/clitest/unpack-"+rand ).getAbsolutePath(); private static final String TEST_REPO =
* new File( getBasedir(), "src/test/repo" ).getAbsolutePath();
*/
- private static final String DEST_DIR =
+ private final String DEST_DIR =
new File( getBasedir(), "target/tests/clitest-" + rand + "/output" ).getAbsolutePath();
- private static final String INDEX_DIR =
+ private final String INDEX_DIR =
new File( getBasedir(), "target/tests/clitest-" + rand + "/index" ).getAbsolutePath();
- private static final String UNPACK_DIR =
+ private final String UNPACK_DIR =
new File( getBasedir(), "target/tests/clitest-" + rand + "/unpack" ).getAbsolutePath();
- private static final String TEST_REPO = new File( getBasedir(), "src/test/repo" ).getAbsolutePath();
+ private final String TEST_REPO = new File( getBasedir(), "src/test/repo" ).getAbsolutePath();
protected OutputStream out;
@Override
- protected void customizeContainerConfiguration( final ContainerConfiguration containerConfiguration )
- {
- super.customizeContainerConfiguration( containerConfiguration );
- containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
- }
-
- @Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -84,7 +70,6 @@ public abstract class AbstractNexusIndexerCliTest
@Override
public void write( int b )
- throws IOException
{
byte[] bytes = new byte[1];
bytes[0] = (byte) b;
@@ -107,13 +92,19 @@ public abstract class AbstractNexusIndexerCliTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
super.tearDown();
}
+ protected File getTestFile( String path )
+ {
+ return new File( new File( getBasedir() ), path );
+ }
+
+ @Test
public void testNoArgs()
{
int code = execute();
@@ -122,15 +113,16 @@ public abstract class AbstractNexusIndexerCliTest
assertTrue( "Should print usage", output.contains( "usage: nexus-indexer [options]" ) );
}
+ @Test
public void testRequiredArgs()
throws Exception
{
int code = execute( "--repository", TEST_REPO, "--index", INDEX_DIR, "-d", DEST_DIR );
String output = out.toString();
assertEquals( output, 0, code );
- assertIndexFiles();
}
+ @Test
public void testUnpack()
throws Exception
{
@@ -145,6 +137,7 @@ public abstract class AbstractNexusIndexerCliTest
//assertIndexFiles( UNPACK_DIR );
}
+ @Test
public void testMissingArgs()
throws IOException
{
@@ -173,48 +166,16 @@ public abstract class AbstractNexusIndexerCliTest
assertFalse( "Index file was generated", new File( INDEX_DIR ).exists() );
}
+ @Test
public void testAbrvsRequiredArgs()
throws Exception
{
int code = execute( "-r", TEST_REPO, "-i", INDEX_DIR, "-d", DEST_DIR );
String output = out.toString();
assertEquals( output, 0, code );
- assertIndexFiles();
- }
-
- public void testLoggingLevel()
- throws Exception
- {
- int code = execute( "-r", TEST_REPO, "-i", INDEX_DIR, "-d", DEST_DIR );
- String normal = out.toString();
- assertEquals( normal, 0, code );
- assertIndexFiles();
-
- setUp();
-
- code = execute( "-q", "-r", TEST_REPO, "-i", INDEX_DIR, "-d", DEST_DIR );
- String quiet = out.toString();
- assertEquals( quiet, 0, code );
- assertFalse( "Expected an different output on quiet mode:\n" + normal, normal.equals( quiet ) );
- assertIndexFiles();
-
- setUp();
-
- code = execute( "-X", "-r", TEST_REPO, "-i", INDEX_DIR, "-d", DEST_DIR );
- String debug = out.toString();
- assertEquals( debug, 0, code );
- assertFalse( "Expected an different output on debug mode:\n" + normal, normal.equals( debug ) );
- assertIndexFiles();
-
- setUp();
-
- code = execute( "-e", "-r", TEST_REPO, "-i", INDEX_DIR, "-d", DEST_DIR );
- String error = out.toString();
- assertEquals( error, 0, code );
- assertFalse( "Expected an different output on error mode:\n" + normal, normal.equals( error ) );
- assertIndexFiles();
}
+ @Test
public void testInvalidRepo()
throws Exception
{
@@ -225,44 +186,6 @@ public abstract class AbstractNexusIndexerCliTest
assertEquals( output, 1, code );
}
- private void assertIndexFiles()
- throws Exception
- {
- //FIXME: Looks strange that a newly generated index can not be reopened.
- //assertIndexFiles( INDEX_DIR );
- }
-
- @Ignore("Old lucene format not supported")
- private void ignoreAssertIndexFiles( final String indexDir )
- throws Exception
- {
- IndexingContext context = null;
- NexusIndexer indexer = lookup( NexusIndexer.class );
- try
- {
- List<IndexCreator> indexCreators = getContainer().lookupList( IndexCreator.class );
-
- context =
- indexer.addIndexingContext( "index", "index", new File( TEST_REPO ), new File( indexDir ), null, null,
- indexCreators );
-
- assertFalse( "No index file was generated", new File( indexDir ).list().length == 0 );
-
- Query query = indexer.constructQuery( MAVEN.GROUP_ID, "ch.marcus-schulte.maven", SearchType.SCORED );
-
- FlatSearchRequest request = new FlatSearchRequest( query );
- FlatSearchResponse response = indexer.searchFlat( request );
- assertEquals( response.getResults().toString(), 1, response.getTotalHits() );
- }
- finally
- {
- if ( context != null )
- {
- indexer.removeIndexingContext( context, true );
- }
- }
- }
-
protected abstract int execute( String... args );
}
\ No newline at end of file
diff --git a/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliIT.java b/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliIT.java
index ea883ba..2fcfb8b 100644
--- a/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliIT.java
+++ b/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliIT.java
@@ -33,7 +33,7 @@ public class NexusIndexerCliIT
private StreamConsumer sout;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
diff --git a/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliTest.java b/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliTest.java
index 12fe715..c9c0310 100644
--- a/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliTest.java
+++ b/indexer-cli/src/test/java/org/apache/maven/index/cli/NexusIndexerCliTest.java
@@ -29,6 +29,7 @@ import java.util.List;
import org.apache.commons.cli.Option;
import org.apache.maven.index.cli.NexusIndexerCli;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
public class NexusIndexerCliTest
extends AbstractNexusIndexerCliTest
@@ -37,7 +38,7 @@ public class NexusIndexerCliTest
protected NexusIndexerCli cli;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -67,8 +68,7 @@ public class NexusIndexerCliTest
public String getOptionsAsHtml()
{
- @SuppressWarnings( "unchecked" )
- List<Option> optList = new ArrayList<Option>( new NexusIndexerCli().buildDefaultCliOptions().getOptions() );
+ List<Option> optList = new ArrayList<>( new NexusIndexerCli().buildCliOptions().getOptions() );
optList.sort( new OptionComparator() );
StringBuilder sb = new StringBuilder();
@@ -106,6 +106,7 @@ public class NexusIndexerCliTest
return sb.toString();
}
+ @Test
public void testOptionsAsHtml()
throws IOException
{
diff --git a/indexer-core/pom.xml b/indexer-core/pom.xml
index af89dd3..3ee3354 100644
--- a/indexer-core/pom.xml
+++ b/indexer-core/pom.xml
@@ -101,13 +101,6 @@ under the License.
<artifactId>maven-model</artifactId>
</dependency>
- <!-- Wagon, as optional for those want to use ResourceFetcher backed by Wagons -->
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-provider-api</artifactId>
- <optional>true</optional>
- </dependency>
-
<!-- Using org.apache.maven.archetype.source.ArchetypeDataSource from it only -->
<dependency>
<groupId>org.apache.maven.archetype</groupId>
@@ -116,6 +109,16 @@ under the License.
</dependency>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -134,23 +137,11 @@ under the License.
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.eclipse.sisu</groupId>
- <artifactId>org.eclipse.sisu.plexus</artifactId>
- <scope>test</scope>
- </dependency>
-
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-http</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
diff --git a/indexer-core/src/main/java/org/apache/maven/index/updater/WagonHelper.java b/indexer-core/src/main/java/org/apache/maven/index/updater/WagonHelper.java
deleted file mode 100644
index 6796241..0000000
--- a/indexer-core/src/main/java/org/apache/maven/index/updater/WagonHelper.java
+++ /dev/null
@@ -1,247 +0,0 @@
-package org.apache.maven.index.updater;
-
-/*
- * 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.
- */
-
-import com.google.inject.Injector;
-import com.google.inject.Key;
-import com.google.inject.name.Names;
-import org.apache.maven.wagon.ConnectionException;
-import org.apache.maven.wagon.ResourceDoesNotExistException;
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.WagonException;
-import org.apache.maven.wagon.authentication.AuthenticationException;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
-import org.apache.maven.wagon.authorization.AuthorizationException;
-import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.wagon.proxy.ProxyInfo;
-import org.apache.maven.wagon.repository.Repository;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-
-/**
- * This is a helper for obtaining Wagon based ResourceFetchers. Some Indexer integrations does have access to Wagon
- * already, so this is here just to help them. Since Wagon (et al) is just optional dependency, looking up this
- * component in integrations where Wagon is not present, should be avoided. This helper is rather limited, as it offers
- * only "HTTP" wagons! This is not made a Plexus component since SISU would crack in CLI, while trying to load up this
- * class, because of lacking Wagon classes from classpath!
- *
- * @author cstamas
- */
-public class WagonHelper
-{
- private final Injector injector;
-
- public WagonHelper( final Injector injector )
- {
- this.injector = injector;
- }
-
- public WagonFetcher getWagonResourceFetcher( final TransferListener listener )
- {
- return getWagonResourceFetcher( listener, null, null );
- }
-
- /**
- * @param listener
- * @param authenticationInfo
- * @param proxyInfo
- * @return
- * @deprecated use getWagonResourceFetcher with protocol argument
- */
- public WagonFetcher getWagonResourceFetcher( final TransferListener listener,
- final AuthenticationInfo authenticationInfo,
- final ProxyInfo proxyInfo )
- {
- // we limit ourselves to HTTP only
- return new WagonFetcher( injector.getInstance( Key.get( Wagon.class, Names.named( "http" ) ) ),
- listener, authenticationInfo, proxyInfo );
- }
-
- /**
- * @param listener
- * @param authenticationInfo
- * @param proxyInfo
- * @param protocol protocol supported by wagon http/https
- * @return
- * @since 4.1.3
- */
- public WagonFetcher getWagonResourceFetcher( final TransferListener listener,
- final AuthenticationInfo authenticationInfo,
- final ProxyInfo proxyInfo,
- final String protocol )
- {
- return new WagonFetcher( injector.getInstance( Key.get( Wagon.class, Names.named( protocol ) ) ),
- listener, authenticationInfo, proxyInfo );
- }
-
- public static class WagonFetcher
- implements ResourceFetcher
- {
- private final TransferListener listener;
-
- private final AuthenticationInfo authenticationInfo;
-
- private final ProxyInfo proxyInfo;
-
- private final Wagon wagon;
-
- public WagonFetcher( final Wagon wagon, final TransferListener listener,
- final AuthenticationInfo authenticationInfo, final ProxyInfo proxyInfo )
- {
- this.wagon = wagon;
- this.listener = listener;
- this.authenticationInfo = authenticationInfo;
- this.proxyInfo = proxyInfo;
- }
-
- public void connect( final String id, final String url )
- throws IOException
- {
- Repository repository = new Repository( id, url );
-
- try
- {
- // wagon = wagonManager.getWagon( repository );
-
- if ( listener != null )
- {
- wagon.addTransferListener( listener );
- }
-
- // when working in the context of Maven, the WagonManager is already
- // populated with proxy information from the Maven environment
-
- if ( authenticationInfo != null )
- {
- if ( proxyInfo != null )
- {
- wagon.connect( repository, authenticationInfo, proxyInfo );
- }
- else
- {
- wagon.connect( repository, authenticationInfo );
- }
- }
- else
- {
- if ( proxyInfo != null )
- {
- wagon.connect( repository, proxyInfo );
- }
- else
- {
- wagon.connect( repository );
- }
- }
- }
- catch ( AuthenticationException ex )
- {
- String msg = "Authentication exception connecting to " + repository;
- logError( msg, ex );
- throw new IOException( msg, ex );
- }
- catch ( WagonException ex )
- {
- String msg = "Wagon exception connecting to " + repository;
- logError( msg, ex );
- throw new IOException( msg, ex );
- }
- }
-
- public void disconnect()
- throws IOException
- {
- if ( wagon != null )
- {
- try
- {
- wagon.disconnect();
- }
- catch ( ConnectionException ex )
- {
- throw new IOException( ex.toString(), ex );
- }
- }
- }
-
- public InputStream retrieve( String name )
- throws IOException, FileNotFoundException
- {
- final File target = Files.createTempFile( name, "tmp" ).toFile();
- target.deleteOnExit();
- retrieve( name, target );
- return new FileInputStream( target )
- {
- @Override
- public void close()
- throws IOException
- {
- super.close();
- target.delete();
- }
- };
- }
-
- public void retrieve( final String name, final File targetFile )
- throws IOException, FileNotFoundException
- {
- try
- {
- wagon.get( name, targetFile );
- }
- catch ( AuthorizationException e )
- {
- targetFile.delete();
- String msg = "Authorization exception retrieving " + name;
- logError( msg, e );
- throw new IOException( msg, e );
- }
- catch ( ResourceDoesNotExistException e )
- {
- targetFile.delete();
- String msg = "Resource " + name + " does not exist";
- logError( msg, e );
- FileNotFoundException fileNotFoundException = new FileNotFoundException( msg );
- fileNotFoundException.initCause( e );
- throw fileNotFoundException;
- }
- catch ( WagonException e )
- {
- targetFile.delete();
- String msg = "Transfer for " + name + " failed";
- logError( msg, e );
- throw new IOException( msg + "; " + e.getMessage(), e );
- }
- }
-
- private void logError( final String msg, final Exception ex )
- {
- if ( listener != null )
- {
- listener.debug( msg + "; " + ex.getMessage() );
- }
- }
- }
-}
\ No newline at end of file
diff --git a/indexer-core/src/test/java/org/apache/maven/index/AbstractIndexCreatorHelper.java b/indexer-core/src/test/java/org/apache/maven/index/AbstractIndexCreatorHelper.java
index 11f661b..fd5a706 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/AbstractIndexCreatorHelper.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/AbstractIndexCreatorHelper.java
@@ -31,6 +31,10 @@ import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator;
import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator;
import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
public class AbstractIndexCreatorHelper
extends AbstractTestSupport
@@ -44,7 +48,7 @@ public class AbstractIndexCreatorHelper
Random rand = new Random();
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -86,6 +90,7 @@ public class AbstractIndexCreatorHelper
return outputFolder;
}
+ @Test
public void testDirectory()
throws IOException
{
@@ -95,6 +100,6 @@ public class AbstractIndexCreatorHelper
assertFalse( dir.exists() );
File dir2 = this.getDirectory( "foo" );
- assertFalse( "Directories aren't unique", dir.getCanonicalPath().equals( dir2.getCanonicalPath() ) );
+ assertNotEquals( "Directories aren't unique", dir.getCanonicalPath(), dir2.getCanonicalPath() );
}
}
diff --git a/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java
index 8df4d1a..8a1920f 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/AbstractNexusIndexerTest.java
@@ -27,6 +27,8 @@ import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.maven.index.context.IndexingContext;
+import static org.junit.Assert.assertEquals;
+
public abstract class AbstractNexusIndexerTest
extends AbstractIndexCreatorHelper
{
@@ -37,7 +39,7 @@ public abstract class AbstractNexusIndexerTest
protected IndexingContext context;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
// indexDir = new SimpleFSDirectory(new File("/tmp/nexus-test"));
@@ -48,7 +50,7 @@ public abstract class AbstractNexusIndexerTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
unprepareNexusIndexer( nexusIndexer );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
index 49919c5..0442414 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/AbstractRepoNexusIndexerTest.java
@@ -33,6 +33,12 @@ import org.apache.lucene.index.MultiBits;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Bits;
import org.apache.maven.index.search.grouping.GAGrouping;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
public abstract class AbstractRepoNexusIndexerTest
extends AbstractNexusIndexerTest
@@ -40,6 +46,7 @@ public abstract class AbstractRepoNexusIndexerTest
protected File repo = new File( getBasedir(), "src/test/repo" );
+ @Test
public void testRootGroups()
throws Exception
{
@@ -77,6 +84,7 @@ public abstract class AbstractRepoNexusIndexerTest
assertGroup( 0, "org.apache.maven.plugins.maven-core-it-plugin", context );
}
+ @Test
public void testSearchFlatPaged()
throws Exception
{
@@ -94,6 +102,7 @@ public abstract class AbstractRepoNexusIndexerTest
assertEquals( response.getResults().toString(), 22, response.getTotalHits() );
}
+ @Test
public void testSearchFlat()
throws Exception
{
@@ -120,6 +129,7 @@ public abstract class AbstractRepoNexusIndexerTest
}
}
+ @Test
public void testSearchGrouped()
throws Exception
{
@@ -155,6 +165,7 @@ public abstract class AbstractRepoNexusIndexerTest
assertEquals( "test", ai.getRepository() );
}
+ @Test
public void testSearchGroupedProblematicNames()
throws Exception
{
@@ -383,6 +394,7 @@ public abstract class AbstractRepoNexusIndexerTest
//
// }
+ @Test
public void testIdentify()
throws Exception
{
@@ -473,6 +485,7 @@ public abstract class AbstractRepoNexusIndexerTest
// assertTrue( resultsAreEqual( onePageList, constructedPageList ) );
// }
+ @Test
public void testPurge()
throws Exception
{
@@ -509,6 +522,7 @@ public abstract class AbstractRepoNexusIndexerTest
return true;
}
+ @Test
public void testPackaging()
throws Exception
{
@@ -556,6 +570,7 @@ public abstract class AbstractRepoNexusIndexerTest
}
}
+ @Test
public void testPrefixWildcard()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/AbstractTestSupport.java b/indexer-core/src/test/java/org/apache/maven/index/AbstractTestSupport.java
index 8ea204d..fead2b6 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/AbstractTestSupport.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/AbstractTestSupport.java
@@ -9,7 +9,7 @@ package org.apache.maven.index;
* "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
+ * 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
@@ -19,20 +19,18 @@ package org.apache.maven.index;
* under the License.
*/
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusTestCase;
+import java.io.File;
+
+import org.eclipse.sisu.launch.InjectedTest;
/**
* @author cstamas
*/
public class AbstractTestSupport
- extends PlexusTestCase
+ extends InjectedTest
{
- @Override
- protected void customizeContainerConfiguration( final ContainerConfiguration containerConfiguration )
+ protected File getTestFile( String path )
{
- super.customizeContainerConfiguration( containerConfiguration );
- containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
+ return new File( new File( getBasedir() ), path );
}
}
\ No newline at end of file
diff --git a/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseTest.java b/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseTest.java
index 7c428fc..d96a207 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseTest.java
@@ -23,11 +23,15 @@ import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
-import junit.framework.Assert;
-
import org.apache.lucene.search.Query;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.expr.UserInputSearchExpression;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
public class ConcurrentUseTest
extends AbstractNexusIndexerTest
@@ -56,6 +60,7 @@ public class ConcurrentUseTest
return new IndexUserThread( this, nexusIndexer, context, context, ai );
}
+ @Test
public void testConcurrency()
throws Exception
{
@@ -88,7 +93,7 @@ public class ConcurrentUseTest
totalAdded += threads[i].getAdded();
}
- Assert.assertFalse( "Not all thread did clean job!", thereWereProblems );
+ assertFalse( "Not all thread did clean job!", thereWereProblems );
context.commit();
@@ -102,7 +107,7 @@ public class ConcurrentUseTest
FlatSearchResponse result = nexusIndexer.searchFlat( new FlatSearchRequest( q, context ) );
- Assert.assertEquals( "All added should be found after final commit!", totalAdded, result.getTotalHitsCount() );
+ assertEquals( "All added should be found after final commit!", totalAdded, result.getTotalHitsCount() );
}
// ==
diff --git a/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextPublishingTest.java b/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextPublishingTest.java
index e4c9908..1b59842 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextPublishingTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextPublishingTest.java
@@ -44,7 +44,7 @@ public class ConcurrentUseWithMergedContextPublishingTest
protected final AtomicInteger counter = new AtomicInteger();
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -53,7 +53,7 @@ public class ConcurrentUseWithMergedContextPublishingTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
File props = new File( IndexingContext.INDEX_PACKER_PROPERTIES_FILE );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextTest.java b/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextTest.java
index 859ea3a..11f6a7d 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/ConcurrentUseWithMergedContextTest.java
@@ -25,6 +25,8 @@ import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.maven.index.context.IndexingContext;
+import static org.junit.Assert.assertNotNull;
+
/**
* The point in this test is: we use Merged context, and we modify some of the "members" in the merged context, while we
* try to search over merged one simultaneously.
diff --git a/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
index 3348752..494a647 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/DefaultIndexNexusIndexerTest.java
@@ -43,6 +43,12 @@ import org.apache.maven.index.packer.IndexPackingRequest;
import org.apache.maven.index.updater.DefaultIndexUpdater;
import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.IndexUpdater;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
public class DefaultIndexNexusIndexerTest
extends MinimalIndexNexusIndexerTest
@@ -61,6 +67,7 @@ public class DefaultIndexNexusIndexerTest
assertNotNull( context.getTimestamp() );
}
+ @Test
public void testPlugin()
throws Exception
{
@@ -99,6 +106,7 @@ public class DefaultIndexNexusIndexerTest
assertEquals( "tricky-params", goals.get( 13 ) );
}
+ @Test
public void testPluginPackaging()
throws Exception
{
@@ -108,6 +116,7 @@ public class DefaultIndexNexusIndexerTest
assertEquals( response.getResults().toString(), 2, response.getTotalHits() );
}
+ @Test
public void testSearchArchetypes()
throws Exception
{
@@ -144,6 +153,7 @@ public class DefaultIndexNexusIndexerTest
}
}
+ @Test
public void testIndexTimestamp()
throws Exception
{
@@ -223,6 +233,7 @@ public class DefaultIndexNexusIndexerTest
assertFalse( new File( newIndex, "timestamp" ).exists() );
}
+ @Test
public void testArchetype()
throws Exception
{
@@ -238,6 +249,7 @@ public class DefaultIndexNexusIndexerTest
assertEquals( r.toString(), 1, r.size() );
}
+ @Test
public void testArchetypePackaging()
throws Exception
{
@@ -246,6 +258,7 @@ public class DefaultIndexNexusIndexerTest
assertEquals( response.getResults().toString(), 4, response.getTotalHits() );
}
+ @Test
public void testBrokenJar()
throws Exception
{
@@ -264,9 +277,10 @@ public class DefaultIndexNexusIndexerTest
assertEquals( "brokenjar", ai.getGroupId() );
assertEquals( "brokenjar", ai.getArtifactId() );
assertEquals( "1.0", ai.getVersion() );
- assertEquals( null, ai.getClassNames() );
+ assertNull( ai.getClassNames() );
}
+ @Test
public void testMissingPom()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java b/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java
index 81e4851..6b194c5 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/DefaultSearchEngineTest.java
@@ -32,6 +32,9 @@ import org.apache.maven.index.context.ExistingLuceneIndexMismatchException;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.util.IndexCreatorSorter;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
public class DefaultSearchEngineTest
extends AbstractNexusIndexerTest
@@ -94,7 +97,7 @@ public class DefaultSearchEngineTest
private SearchEngine searchEngine;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -103,13 +106,14 @@ public class DefaultSearchEngineTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
searchEngine = null;
super.tearDown();
}
+ @Test
public void testExceptionInArtifactFilter()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/DuplicateSearchTest.java b/indexer-core/src/test/java/org/apache/maven/index/DuplicateSearchTest.java
index 4cab9d7..301e1f3 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/DuplicateSearchTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/DuplicateSearchTest.java
@@ -24,13 +24,15 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
-import junit.framework.Assert;
-
import org.apache.lucene.search.Query;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.expr.SourcedSearchExpression;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class DuplicateSearchTest
extends AbstractNexusIndexerTest
@@ -123,6 +125,7 @@ public class DuplicateSearchTest
//
// ArtifactInfo, along with GAV carries contextId and repositoryId too!
+ @Test
public void testProveSvnRev1158917IsWrong()
throws IOException
{
@@ -138,13 +141,14 @@ public class DuplicateSearchTest
FlatSearchResponse fsResp = nexusIndexer.searchFlat( fsReq );
- Assert.assertEquals( "We have 10 GAVs coming from three contextes", 10, fsResp.getResults().size() );
+ assertEquals( "We have 10 GAVs coming from three contextes", 10, fsResp.getResults().size() );
// Why? Look at the FlatSearchRequest default comparator it uses, it is ArtifactInfo.VERSION_COMPARATOR
// that neglects contextId and repositoryId and compares GAVs only, and the Collection fixed in SVN Rev1158917
// is actually a Set<ArtifactInfo with proper comparator set.
}
+ @Test
public void testHowUniqueSearchShouldBeDone()
throws IOException
{
@@ -161,12 +165,13 @@ public class DuplicateSearchTest
FlatSearchResponse fsResp = nexusIndexer.searchFlat( fsReq );
- Assert.assertEquals( "We have 10 GAVs coming from three contextes, it is 30", 30, fsResp.getResults().size() );
+ assertEquals( "We have 10 GAVs coming from three contextes, it is 30", 30, fsResp.getResults().size() );
// Why? We set explicitly the comparator to CONTEXT_VERSION_COMPARATOR, that compares GAV+contextId, hence,
// will return all hits from all participating contexts.
}
+ @Test
public void testHowtoPerformAggregatedSearch()
throws IOException
{
@@ -213,12 +218,12 @@ public class DuplicateSearchTest
}
}
- Assert.assertEquals( "Iterator delivered to us 3 results, since we have 3 GA combinations", 3,
+ assertEquals( "Iterator delivered to us 3 results, since we have 3 GA combinations", 3,
actualResultCount );
- Assert.assertEquals(
+ assertEquals(
"IteratorSearch is strange beast, due to it's nature, it cannot say how many elements it (will) return in advance, due to filtering, postprocessing, etc",
-1, isResp.getReturnedHitsCount() );
- Assert.assertEquals(
+ assertEquals(
"The processing/search tackled 10 GAVs coming from three contextes, it is 30. This is the record count that were hit by processing of this search, but IS NOT the count results (it depends on filtering, comparators, etc)!",
30, isResp.getTotalHitsCount() );
}
diff --git a/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java b/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
index 5a541ca..41297fb 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/FSDirectoryDeleteTest.java
@@ -25,6 +25,7 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.maven.index.context.IndexingContext;
+import org.junit.Test;
public class FSDirectoryDeleteTest
extends AbstractIndexCreatorHelper
@@ -46,7 +47,7 @@ public class FSDirectoryDeleteTest
protected Directory otherIndexDir;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -68,7 +69,7 @@ public class FSDirectoryDeleteTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
super.tearDown();
@@ -82,6 +83,7 @@ public class FSDirectoryDeleteTest
super.deleteDirectory( otherIndexDirFile );
}
+ @Test
public void testIndexAndDelete()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
index db69e47..2febfea 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/FullIndexNexusIndexerTest.java
@@ -46,10 +46,17 @@ import org.apache.maven.index.search.grouping.GGrouping;
import org.apache.maven.index.updater.DefaultIndexUpdater;
import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.IndexUpdater;
+import org.junit.Assert;
+import org.junit.Test;
import static org.apache.lucene.search.BooleanClause.*;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class FullIndexNexusIndexerTest
extends DefaultIndexNexusIndexerTest
@@ -67,6 +74,7 @@ public class FullIndexNexusIndexerTest
assertNotNull( context.getTimestamp() );
}
+ @Test
public void testSearchGroupedClasses()
throws Exception
{
@@ -116,7 +124,7 @@ public class FullIndexNexusIndexerTest
GroupedSearchResponse response = nexusIndexer.searchGrouped( request );
Map<String, ArtifactInfoGroup> r = response.getResults();
- assertThat(r.toString(), r.size(), is(2));
+ Assert.assertThat(r.toString(), r.size(), is(2));
Iterator<ArtifactInfoGroup> it = r.values().iterator();
@@ -288,6 +296,7 @@ public class FullIndexNexusIndexerTest
}
}
+ @Test
public void testSearchArchetypes()
throws Exception
{
@@ -324,6 +333,7 @@ public class FullIndexNexusIndexerTest
}
}
+ @Test
public void testIndexTimestamp()
throws Exception
{
@@ -402,6 +412,7 @@ public class FullIndexNexusIndexerTest
assertFalse( new File( newIndex, "timestamp" ).exists() );
}
+ @Test
public void testArchetype()
throws Exception
{
@@ -421,6 +432,7 @@ public class FullIndexNexusIndexerTest
assertEquals( r.toString(), 1, r.size() );
}
+ @Test
public void testArchetypePackaging()
throws Exception
{
@@ -429,6 +441,7 @@ public class FullIndexNexusIndexerTest
assertEquals( response.getResults().toString(), 4, response.getTotalHits() );
}
+ @Test
public void testBrokenJar()
throws Exception
{
@@ -450,6 +463,7 @@ public class FullIndexNexusIndexerTest
assertEquals( null, ai.getClassNames() );
}
+ @Test
public void testMissingPom()
throws Exception
{
@@ -486,6 +500,7 @@ public class FullIndexNexusIndexerTest
return request;
}
+ @Test
public void testClassnameSearchNgWithHighlighting()
throws Exception
{
@@ -514,6 +529,7 @@ public class FullIndexNexusIndexerTest
assertEquals( "found in jcl104-over-slf4j and commons-logging", 5, response.getTotalHits() );
}
+ @Test
public void testGAVSearchNgWithHighlighting()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Java11HttpClient.java b/indexer-core/src/test/java/org/apache/maven/index/Java11HttpClient.java
new file mode 100644
index 0000000..f1f2a80
--- /dev/null
+++ b/indexer-core/src/test/java/org/apache/maven/index/Java11HttpClient.java
@@ -0,0 +1,78 @@
+package org.apache.maven.index;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+
+import org.apache.maven.index.updater.ResourceFetcher;
+
+/**
+ * {@link ResourceFetcher} backed by Java11 HttpClient to be used in tests.
+ */
+public class Java11HttpClient implements ResourceFetcher
+{
+ private final HttpClient client = HttpClient.newBuilder().followRedirects( HttpClient.Redirect.NEVER ).build();
+
+ private URI uri;
+
+ @Override
+ public void connect( String id, String url )
+ {
+ this.uri = URI.create( url + "/" );
+ }
+
+ @Override
+ public void disconnect()
+ {
+
+ }
+
+ @Override
+ public InputStream retrieve( String name ) throws IOException
+ {
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri( uri.resolve( name ) )
+ .GET()
+ .build();
+ try
+ {
+ HttpResponse<InputStream> response = client.send( request, HttpResponse.BodyHandlers.ofInputStream() );
+ if ( response.statusCode() == HttpURLConnection.HTTP_OK )
+ {
+ return response.body();
+ }
+ else
+ {
+ throw new IOException( "Unexpected response: " + response );
+ }
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ throw new IOException( e );
+ }
+ }
+}
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java b/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java
index 5f62d1b..7ec34ca 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Mindexer14HitLimitTest.java
@@ -25,8 +25,9 @@ import java.io.IOException;
import org.apache.lucene.search.Query;
import org.apache.maven.index.expr.SourcedSearchExpression;
import org.apache.maven.index.search.grouping.GAGrouping;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.logging.LoggerManager;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
public class Mindexer14HitLimitTest
extends AbstractNexusIndexerTest
@@ -37,13 +38,10 @@ public class Mindexer14HitLimitTest
protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
throws Exception
{
- // Put Plexus into DEBUG mode
- lookup( LoggerManager.class ).setThresholds( Logger.LEVEL_DEBUG );
-
repo.mkdirs();
context =
- nexusIndexer.addIndexingContext( "mindexer14", "mindexer14", repo, indexDir, null, null, MIN_CREATORS );
+ nexusIndexer.addIndexingContext( "mindexer14", "mindexer14", repo, indexDir, null, null, MIN_CREATORS );
nexusIndexer.scan( context, false );
}
@@ -64,6 +62,7 @@ public class Mindexer14HitLimitTest
}
+ @Test
public void testFlatSearchTotalHitsLie1k()
throws Exception
{
@@ -80,6 +79,7 @@ public class Mindexer14HitLimitTest
response.close();
}
+ @Test
public void testFlatSearchUnlimited()
throws Exception
{
@@ -98,6 +98,7 @@ public class Mindexer14HitLimitTest
response.close();
}
+ @Test
public void testFlatSearchLimited()
throws Exception
{
@@ -117,6 +118,7 @@ public class Mindexer14HitLimitTest
response.close();
}
+ @Test
public void testGroupedSearchTotalHitsLie1k()
throws Exception
{
@@ -137,6 +139,7 @@ public class Mindexer14HitLimitTest
response.close();
}
+ @Test
public void testIteratorSearchTotalHitsLie1k()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java
index 841cf3f..ac16c97 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Mindexer35NexusIndexerTest.java
@@ -25,7 +25,10 @@ import java.util.Collection;
import java.util.List;
import org.apache.lucene.search.Query;
import org.apache.maven.index.expr.UserInputSearchExpression;
+import org.junit.Test;
+
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class Mindexer35NexusIndexerTest
@@ -42,6 +45,7 @@ public class Mindexer35NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchWar()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java
index b19fc5e..ed7f738 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/MinimalIndexNexusIndexerTest.java
@@ -26,6 +26,10 @@ 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.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
/**
* @author Jason van Zyl
@@ -43,6 +47,7 @@ public class MinimalIndexNexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testNEXUS2712()
throws Exception
{
@@ -59,7 +64,7 @@ public class MinimalIndexNexusIndexerTest
assertEquals( "com.adobe.flexunit", ai.getGroupId() );
assertEquals( "flexunit", ai.getArtifactId() );
assertEquals( "0.90", ai.getVersion() );
- assertEquals( null, ai.getClassifier() );
+ assertNull( ai.getClassifier() );
assertEquals( "swc", ai.getPackaging() );
assertEquals( "swc", ai.getFileExtension() );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java
index 89cca56..c92c3c3 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus1179NexusIndexerTest.java
@@ -29,6 +29,10 @@ 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.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
public class Nexus1179NexusIndexerTest
extends AbstractNexusIndexerTest
@@ -44,6 +48,7 @@ public class Nexus1179NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchFlat()
throws Exception
{
@@ -68,8 +73,8 @@ public class Nexus1179NexusIndexerTest
assertEquals( "ant", ai.getGroupId() );
assertEquals( "ant", ai.getArtifactId() );
assertEquals( "1.6.5", ai.getVersion() );
- assertEquals( null, ai.getPackaging() ); // coz no POM present
- assertEquals( null, ai.getClassifier() );
+ assertNull( ai.getPackaging() ); // coz no POM present
+ assertNull( ai.getClassifier() );
assertEquals( "nexus-1179", ai.getRepository() );
assertEquals( "jar", ai.getFileExtension() );
@@ -80,7 +85,7 @@ public class Nexus1179NexusIndexerTest
assertEquals( "ant", ai.getArtifactId() );
assertEquals( "1.5.1", ai.getVersion() );
assertEquals( "jar", ai.getPackaging() ); // coz POM is present and says so
- assertEquals( null, ai.getClassifier() );
+ assertNull( ai.getClassifier() );
assertEquals( "nexus-1179", ai.getRepository() );
assertEquals( "pom", ai.getFileExtension() );
@@ -91,7 +96,7 @@ public class Nexus1179NexusIndexerTest
assertEquals( "asm-commons", ai.getArtifactId() );
assertEquals( "3.1", ai.getVersion() );
assertEquals( "jar", ai.getPackaging() );
- assertEquals( null, ai.getClassifier() );
+ assertNull( ai.getClassifier() );
assertEquals( "nexus-1179", ai.getRepository() );
assertEquals( "pom", ai.getFileExtension() );
@@ -102,7 +107,7 @@ public class Nexus1179NexusIndexerTest
assertEquals( "test", ai.getArtifactId() );
assertEquals( "1.0", ai.getVersion() );
assertEquals( "jar", ai.getPackaging() ); // coz POM is present and says so
- assertEquals( null, ai.getClassifier() );
+ assertNull( ai.getClassifier() );
assertEquals( "nexus-1179", ai.getRepository() );
assertEquals( "pom", ai.getFileExtension() );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
index be128e1..f4848a9 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus13NexusIndexerTest.java
@@ -40,6 +40,11 @@ import org.apache.maven.index.search.grouping.GAGrouping;
import org.apache.maven.index.updater.DefaultIndexUpdater;
import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.IndexUpdater;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/** http://issues.sonatype.org/browse/NEXUS-13 */
public class Nexus13NexusIndexerTest
@@ -55,6 +60,7 @@ public class Nexus13NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchGroupedClasses()
throws Exception
{
@@ -85,6 +91,7 @@ public class Nexus13NexusIndexerTest
}
}
+ @Test
public void testSearchArchetypes()
throws Exception
{
@@ -100,6 +107,7 @@ public class Nexus13NexusIndexerTest
assertEquals( "1.0-SNAPSHOT", ai.getVersion() );
}
+ @Test
public void testIndexTimestamp()
throws Exception
{
@@ -160,6 +168,7 @@ public class Nexus13NexusIndexerTest
newContext.close( true );
}
+ @Test
public void testRootGroups()
throws Exception
{
@@ -169,6 +178,7 @@ public class Nexus13NexusIndexerTest
assertGroup( 10, "cisco", context );
}
+ @Test
public void testSearchFlat()
throws Exception
{
@@ -192,6 +202,7 @@ public class Nexus13NexusIndexerTest
}
+ @Test
public void testSearchGrouped()
throws Exception
{
@@ -220,6 +231,7 @@ public class Nexus13NexusIndexerTest
assertEquals( "1.0-SNAPSHOT", ai.getVersion() );
}
+ @Test
public void testSearchGroupedProblematicNames()
throws Exception
{
@@ -243,6 +255,7 @@ public class Nexus13NexusIndexerTest
assertEquals( 1, ig.getArtifactInfos().size() );
}
+ @Test
public void testIdentify()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalMergedCtxTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalMergedCtxTest.java
index d52fc87..cfbf49e 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalMergedCtxTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalMergedCtxTest.java
@@ -32,7 +32,7 @@ public class Nexus1911IncrementalMergedCtxTest
File indexMergedDir;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -48,7 +48,7 @@ public class Nexus1911IncrementalMergedCtxTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
indexer.removeIndexingContext( context, true );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalTest.java
index 9d19d42..ad4c393 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus1911IncrementalTest.java
@@ -24,13 +24,19 @@ import java.io.FileInputStream;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
-import junit.framework.Assert;
import org.apache.lucene.search.IndexSearcher;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
//FIXME - hardcoded assumptions in test that break with lucene 4, or bugs?
//@Ignore("Segment merge may work differently in Lucene 4")
@@ -52,7 +58,7 @@ public class Nexus1911IncrementalTest
File reposTargetDir;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -76,7 +82,7 @@ public class Nexus1911IncrementalTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
indexer.removeIndexingContext( context, true );
@@ -86,6 +92,7 @@ public class Nexus1911IncrementalTest
super.tearDown();
}
+ @Test
public void testNoIncremental()
throws Exception
{
@@ -105,22 +112,23 @@ public class Nexus1911IncrementalTest
Set<String> filenames = getFilenamesFromFiles( indexPackDir.listFiles() );
Properties props = getPropertiesFromFiles( indexPackDir.listFiles() );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
- Assert.assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
- Assert.assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
+ assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
+ assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
- Assert.assertNotNull( props );
+ assertNotNull( props );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "0" );
- Assert.assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "0" );
+ assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
}
+ @Test
public void test1Incremental()
throws Exception
{
@@ -142,22 +150,23 @@ public class Nexus1911IncrementalTest
Set<String> filenames = getFilenamesFromFiles( indexPackDir.listFiles() );
Properties props = getPropertiesFromFiles( indexPackDir.listFiles() );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
- Assert.assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
+ assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
- Assert.assertNotNull( props );
+ assertNotNull( props );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "1" );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "1" );
- Assert.assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "1" );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "1" );
+ assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
}
+ @Test
public void test2Incremental()
throws Exception
{
@@ -180,24 +189,25 @@ public class Nexus1911IncrementalTest
Set<String> filenames = getFilenamesFromFiles( indexPackDir.listFiles() );
Properties props = getPropertiesFromFiles( indexPackDir.listFiles() );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
//1 is missing with updated Lucene 4 implementation
// Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
- Assert.assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
-
- Assert.assertNotNull( props );
-
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "2" );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ), "1" );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "2" );
- Assert.assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
+ assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
+
+ assertNotNull( props );
+
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "2" );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ), "1" );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "2" );
+ assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
}
+ @Test
public void test3Incremental()
throws Exception
{
@@ -221,24 +231,25 @@ public class Nexus1911IncrementalTest
Set<String> filenames = getFilenamesFromFiles( indexPackDir.listFiles() );
Properties props = getPropertiesFromFiles( indexPackDir.listFiles() );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
//1,2 are missing with updated Lucene 4 implementation
// Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
// Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
- Assert.assertNotNull( props );
+ assertNotNull( props );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "3" );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ), "2" );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ), "1" );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "3" );
- Assert.assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "3" );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ), "2" );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ), "1" );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "3" );
+ assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
}
+ @Test
public void testMaxChunks()
throws Exception
{
@@ -266,24 +277,24 @@ public class Nexus1911IncrementalTest
System.out.println( filenames );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
- Assert.assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".properties" ) );
+ assertFalse( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".1.gz" ) );
//2,3 are missing with updated Lucene 4 implementation
// Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
// Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
- Assert.assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".4.gz" ) );
+ assertTrue( filenames.contains( IndexingContext.INDEX_FILE_PREFIX + ".4.gz" ) );
- Assert.assertNotNull( props );
+ assertNotNull( props );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "4" );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ), "3" );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ), "2" );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
- Assert.assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
- Assert.assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "4" );
- Assert.assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "0" ), "4" );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "1" ), "3" );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "2" ), "2" );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "3" ) );
+ assertNull( props.getProperty( IndexingContext.INDEX_CHUNK_PREFIX + "4" ) );
+ assertEquals( props.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ), "4" );
+ assertNotNull( props.getProperty( IndexingContext.INDEX_CHAIN_ID ) );
}
private void copyRepoContentsAndReindex( File src, int maxIndexChunks )
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus2046NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus2046NexusIndexerTest.java
index 1044e08..ffb77d6 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus2046NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus2046NexusIndexerTest.java
@@ -25,6 +25,10 @@ import java.util.Collection;
import java.util.List;
import org.apache.lucene.search.Query;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
public class Nexus2046NexusIndexerTest
extends AbstractNexusIndexerTest
@@ -40,6 +44,7 @@ public class Nexus2046NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchFlat()
throws Exception
{
@@ -62,7 +67,7 @@ public class Nexus2046NexusIndexerTest
assertEquals( "org.maven.ide.eclipse.feature", ai.getArtifactId() );
assertEquals( "0.9.7", ai.getVersion() );
assertEquals( "eclipse-feature", ai.getPackaging() );
- assertEquals( null, ai.getClassifier() );
+ assertNull( ai.getClassifier() );
assertEquals( "nexus-2046", ai.getRepository() );
assertEquals( "jar", ai.getFileExtension() );
}
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java
index ab30553..c6d0131 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus3177HitLimitChecks.java
@@ -27,6 +27,9 @@ import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.maven.index.context.IndexingContext;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
public class Nexus3177HitLimitChecks
extends AbstractNexusIndexerTest
@@ -69,6 +72,7 @@ public class Nexus3177HitLimitChecks
// Hence, some of the tests, that can keep still original semantics were updated and left in place
// but the two test explicitly testing LIMIT_EXCEEDED were just removed/commented out.
+ @Test
public void testHitLimitNotReachedSingleContext()
throws Exception
{
@@ -85,6 +89,7 @@ public class Nexus3177HitLimitChecks
assertEquals( r.toString(), 4, response.getTotalHitsCount() );
}
+ @Test
public void testHitLimitEqualSingleContext()
throws Exception
{
@@ -117,6 +122,7 @@ public class Nexus3177HitLimitChecks
// assertEquals( r.toString(), AbstractSearchResponse.LIMIT_EXCEEDED, response.getTotalHits() );
// }
+ @Test
public void testHitLimitNotReachedMultipleContexts()
throws Exception
{
@@ -135,6 +141,7 @@ public class Nexus3177HitLimitChecks
assertEquals( r.toString(), 8, response.getTotalHitsCount() );
}
+ @Test
public void testHitLimitEqualMultipleContexts()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus3233NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus3233NexusIndexerTest.java
index 4b3a047..2a174a4 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus3233NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus3233NexusIndexerTest.java
@@ -22,6 +22,11 @@ package org.apache.maven.index;
import java.io.File;
import java.util.Collection;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
/** http://issues.sonatype.org/browse/NEXUS-3233 */
public class Nexus3233NexusIndexerTest
extends AbstractNexusIndexerTest
@@ -37,6 +42,7 @@ public class Nexus3233NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testIdentifyPomPackagingArtifacts()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus3293TimestampSnapshotTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus3293TimestampSnapshotTest.java
index 48cacaf..a71429b 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus3293TimestampSnapshotTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus3293TimestampSnapshotTest.java
@@ -30,6 +30,9 @@ import org.apache.maven.index.artifact.M2GavCalculator;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
public class Nexus3293TimestampSnapshotTest
extends AbstractIndexCreatorHelper
@@ -60,6 +63,7 @@ public class Nexus3293TimestampSnapshotTest
return indexer;
}
+ @Test
public void test_nexus_3293_releaseJar()
throws Exception
{
@@ -89,6 +93,7 @@ public class Nexus3293TimestampSnapshotTest
validateIndexContents( indexer );
}
+ @Test
public void test_nexus_3293_indexTimestampedSnapshotJar()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus3881NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus3881NexusIndexerTest.java
index dbc3750..6275d22 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus3881NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus3881NexusIndexerTest.java
@@ -21,10 +21,12 @@ package org.apache.maven.index;
import java.io.File;
-import junit.framework.Assert;
-
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class Nexus3881NexusIndexerTest
extends AbstractNexusIndexerTest
@@ -40,6 +42,7 @@ public class Nexus3881NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testRelevances()
throws Exception
{
@@ -52,7 +55,7 @@ public class Nexus3881NexusIndexerTest
IteratorSearchResponse response = nexusIndexer.searchIterator( request );
- Assert.assertEquals( "All artifacts has 'solution' in their GA!", 4, response.getTotalHits() );
+ assertEquals( "All artifacts has 'solution' in their GA!", 4, response.getTotalHits() );
// for (ArtifactInfo ai : response) {
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus4674GavPathReindexTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus4674GavPathReindexTest.java
index 9e33c87..3887754 100755
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus4674GavPathReindexTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus4674GavPathReindexTest.java
@@ -23,6 +23,11 @@ import java.io.File;
import java.util.Collection;
import java.util.Set;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class Nexus4674GavPathReindexTest
extends AbstractNexusIndexerTest
{
@@ -38,6 +43,7 @@ public class Nexus4674GavPathReindexTest
nexusIndexer.scan( context, "/org/slf4j/slf4j-api/1.4.1", null, true );
}
+ @Test
public void testRootGroups()
throws Exception
{
@@ -49,6 +55,7 @@ public class Nexus4674GavPathReindexTest
assertGroup( 4, "org.slf4j", context );
}
+ @Test
public void testIdentify()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus645NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus645NexusIndexerTest.java
index 8d10a79..7348d67 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus645NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus645NexusIndexerTest.java
@@ -25,6 +25,9 @@ import java.util.Collection;
import java.util.List;
import org.apache.lucene.search.Query;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/** http://issues.sonatype.org/browse/NEXUS-13 */
public class Nexus645NexusIndexerTest
@@ -41,6 +44,7 @@ public class Nexus645NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchFlat()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus658NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus658NexusIndexerTest.java
index a7872c4..0b03a59 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus658NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus658NexusIndexerTest.java
@@ -25,6 +25,9 @@ import java.util.Collection;
import java.util.List;
import org.apache.lucene.search.Query;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/** http://issues.sonatype.org/browse/NEXUS-13 */
public class Nexus658NexusIndexerTest
@@ -41,6 +44,7 @@ public class Nexus658NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchFlat()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus687NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus687NexusIndexerTest.java
index 51e5949..9bad3c1 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus687NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus687NexusIndexerTest.java
@@ -25,6 +25,9 @@ import java.util.Collection;
import java.util.List;
import org.apache.lucene.search.Query;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* @author Juven Xu http://issues.sonatype.org/browse/NEXUS-687
@@ -43,6 +46,7 @@ public class Nexus687NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testSearchFlat()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/Nexus737NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/Nexus737NexusIndexerTest.java
index 8d073ec..0f3a146 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/Nexus737NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/Nexus737NexusIndexerTest.java
@@ -25,6 +25,9 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiBits;
import org.apache.lucene.util.Bits;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/** http://issues.sonatype.org/browse/NEXUS-737 */
public class Nexus737NexusIndexerTest
@@ -41,6 +44,7 @@ public class Nexus737NexusIndexerTest
nexusIndexer.scan( context );
}
+ @Test
public void testValidateUINFOs()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java b/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
index b4aa599..907eab8 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/NexusIndexerTest.java
@@ -56,9 +56,14 @@ import org.apache.maven.index.updater.DefaultIndexUpdater;
import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.IndexUpdater;
import org.codehaus.plexus.util.StringUtils;
+import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
/** @author Jason van Zyl */
public class NexusIndexerTest
@@ -66,6 +71,7 @@ public class NexusIndexerTest
{
private IndexingContext context;
+ @Test
public void testSingleQuery() throws Exception
{
NexusIndexer indexer = lookup(NexusIndexer.class);
@@ -84,7 +90,8 @@ public class NexusIndexerTest
q = indexer.constructQuery( MAVEN.NAME, "Some artifact name from Pom", SearchType.SCORED );
assertThat(q.toString(), is("(+n:some +n:artifact +n:name +n:from +n:Pom*) n:\"some artifact name from pom\""));
}
-
+
+ @Test
public void testQueryCreatorNG()
throws Exception
{
@@ -256,6 +263,7 @@ public class NexusIndexerTest
assertEquals( "commons-logging:commons-logging:1.0.4:null:jar", ai.getGroupId() + ":" + ai.getArtifactId() + ":" + ai.getVersion() + ":" + ai.getClassifier() + ":" + ai.getPackaging() );
}
+ @Test
public void testQueryCreatorNGSearch()
throws Exception
{
@@ -264,6 +272,7 @@ public class NexusIndexerTest
performQueryCreatorNGSearch( indexer, context );
}
+ @Test
public void testQueryCreatorNGSearchOnMergedContext()
throws Exception
{
@@ -350,6 +359,7 @@ public class NexusIndexerTest
assertEquals( "Search results inconsistent!", shouldBe, whatWeHave );
}
+ @Test
public void testSearchIterator()
throws Exception
{
@@ -369,6 +379,7 @@ public class NexusIndexerTest
}
}
+ @Test
public void testSearchIteratorWithFilter()
throws Exception
{
@@ -393,6 +404,7 @@ public class NexusIndexerTest
assertEquals( "1.5 is filtered out, so 1.6.1 must appear here!", "1.6.1", ai.getVersion() );
}
+ @Test
public void testSearchGrouped()
throws Exception
{
@@ -427,6 +439,7 @@ public class NexusIndexerTest
}
}
+ @Test
public void testSearchFlat()
throws Exception
{
@@ -453,6 +466,7 @@ public class NexusIndexerTest
}
}
+ @Test
public void testSearchPackaging()
throws Exception
{
@@ -464,6 +478,7 @@ public class NexusIndexerTest
assertEquals( r.toString(), 2, r.size() );
}
+ @Test
public void testIdentity()
throws Exception
{
@@ -508,6 +523,7 @@ public class NexusIndexerTest
assertEquals( "test", ai.getRepository() );
}
+ @Test
public void testUpdateArtifact()
throws Exception
{
@@ -554,6 +570,7 @@ public class NexusIndexerTest
assertEquals( "bla bla bla", ai2.getName() );
}
+ @Test
public void testUnpack()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/SearchWithAnEmptyIndexTest.java b/indexer-core/src/test/java/org/apache/maven/index/SearchWithAnEmptyIndexTest.java
index 4874c28..e395b09 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/SearchWithAnEmptyIndexTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/SearchWithAnEmptyIndexTest.java
@@ -19,6 +19,8 @@ package org.apache.maven.index;
* under the License.
*/
+import javax.inject.Inject;
+
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.maven.index.context.IndexCreator;
@@ -27,6 +29,7 @@ import org.apache.maven.index.expr.StringSearchExpression;
import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
@@ -34,6 +37,7 @@ import java.util.Arrays;
import java.util.List;
import static org.apache.lucene.search.BooleanClause.*;
+import static org.junit.Assert.assertEquals;
/**
* @author Olivier Lamy
@@ -43,22 +47,22 @@ public class SearchWithAnEmptyIndexTest
{
static final String INDEX_ID1 = "osgi-test1";
static final String INDEX_ID2 = "empty-repo";
- protected List<IndexCreator> indexCreators;
+
+ @Inject
private NexusIndexer nexusIndexer;
+
+ @Inject
private IndexPacker indexPacker;
+ @Inject
+ protected List<IndexCreator> indexCreators;
+
@Override
public void setUp()
throws Exception
{
super.setUp();
- indexCreators = this.getContainer().lookupList( IndexCreator.class );
-
- nexusIndexer = this.lookup( NexusIndexer.class );
-
- indexPacker = this.lookup( IndexPacker.class );
-
if ( !nexusIndexer.getIndexingContexts().isEmpty() )
{
for ( IndexingContext context : nexusIndexer.getIndexingContexts().values() )
@@ -68,6 +72,7 @@ public class SearchWithAnEmptyIndexTest
}
}
+ @Test
public void testWithTwoContextWithOneEmptyFirstInContextsListSearchFlat()
throws Exception
{
@@ -143,6 +148,7 @@ public class SearchWithAnEmptyIndexTest
/**
* both repos contains commons-cli so ensure we don't return duplicates
*/
+ @Test
public void testSearchNoDuplicateArtifactInfo()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/SubPathReindexTest.java b/indexer-core/src/test/java/org/apache/maven/index/SubPathReindexTest.java
index cb429c0..aae78dd 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/SubPathReindexTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/SubPathReindexTest.java
@@ -23,6 +23,11 @@ import java.io.File;
import java.util.Collection;
import java.util.Set;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class SubPathReindexTest
extends AbstractNexusIndexerTest
{
@@ -37,6 +42,7 @@ public class SubPathReindexTest
nexusIndexer.scan( context, "/org/slf4j/slf4j-api", null, false );
}
+ @Test
public void testRootGroups()
throws Exception
{
@@ -74,6 +80,7 @@ public class SubPathReindexTest
assertGroup( 0, "org.apache.maven.plugins.maven-core-it-plugin", context );
}
+ @Test
public void testIdentify()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/UniqueArtifactFilterTest.java b/indexer-core/src/test/java/org/apache/maven/index/UniqueArtifactFilterTest.java
index 7f2ca57..f515f67 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/UniqueArtifactFilterTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/UniqueArtifactFilterTest.java
@@ -26,12 +26,17 @@ import org.apache.lucene.search.Query;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
public class UniqueArtifactFilterTest
extends AbstractIndexCreatorHelper
{
private IndexingContext context;
+ @Test
public void testSearchIterator()
throws Exception
{
@@ -51,6 +56,7 @@ public class UniqueArtifactFilterTest
}
}
+ @Test
public void testSearchIteratorWithFilter()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/artifact/M1GavCalculatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/artifact/M1GavCalculatorTest.java
index 0f334d8..fe926b4 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/artifact/M1GavCalculatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/artifact/M1GavCalculatorTest.java
@@ -22,26 +22,16 @@ package org.apache.maven.index.artifact;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import org.apache.maven.index.artifact.Gav;
-import org.apache.maven.index.artifact.M1GavCalculator;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
public class M1GavCalculatorTest
- extends TestCase
{
- private M1GavCalculator gavCalculator;
+ private M1GavCalculator gavCalculator = new M1GavCalculator();
private SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
- @Override
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- gavCalculator = new M1GavCalculator();
- }
protected Long parseTimestamp( String timeStamp )
throws ParseException
@@ -56,6 +46,7 @@ public class M1GavCalculatorTest
}
}
+ @Test
public void testGav()
throws Exception
{
@@ -260,6 +251,7 @@ public class M1GavCalculatorTest
assertEquals( "/xpp3/poms/xpp3_min-1.1.3.4.O.pom", path );
}
+ @Test
public void testNEXUS1336()
throws Exception
{
@@ -336,6 +328,7 @@ public class M1GavCalculatorTest
assertEquals( "/castor/ejbs/castor-ejb-1.0.7-client.jar", path );
}
+ @Test
public void testGavExtreme()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java
index 3e54d5f..b12f49f 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/artifact/M2GavCalculatorTest.java
@@ -22,27 +22,20 @@ package org.apache.maven.index.artifact;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import junit.framework.TestCase;
+import org.junit.Test;
-import org.apache.maven.index.artifact.Gav;
-import org.apache.maven.index.artifact.M2GavCalculator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class M2GavCalculatorTest
- extends TestCase
{
- private M2GavCalculator gavCalculator;
+ private M2GavCalculator gavCalculator = new M2GavCalculator();
private SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
- @Override
- public void setUp()
- throws Exception
- {
- super.setUp();
-
- gavCalculator = new M2GavCalculator();
- }
-
protected Long parseTimestamp( String timeStamp )
throws ParseException
{
@@ -56,6 +49,7 @@ public class M2GavCalculatorTest
}
}
+ @Test
public void testGav()
throws Exception
{
@@ -591,6 +585,7 @@ public class M2GavCalculatorTest
assertNull( gav );
}
+ @Test
public void testNegGav()
throws Exception
{
@@ -603,6 +598,7 @@ public class M2GavCalculatorTest
// NEXUS-4132 END
}
+ @Test
public void testGavExtreme()
throws Exception
{
@@ -645,6 +641,7 @@ public class M2GavCalculatorTest
assertEquals( null, gav );
}
+ @Test
public void testIssueNexus57()
throws Exception
{
@@ -655,6 +652,7 @@ public class M2GavCalculatorTest
assertNull( "We expect null since baseVersion and version mismatch in path!", gav );
}
+ @Test
public void testGavExtensionAndClassifier()
throws Exception
{
@@ -717,6 +715,7 @@ public class M2GavCalculatorTest
assertEquals( "1.0.0-beta-6-20080809.181715-2", gav.getVersion() );
}
+ @Test
public void testGavSnapshotVersion()
throws Exception
{
@@ -755,6 +754,7 @@ public class M2GavCalculatorTest
assertFalse( gav.isSnapshot() );
}
+ @Test
public void testGavLooseStrictedSnapshot()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java b/indexer-core/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java
index 8fd1691..95a7fae 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/artifact/MavenArtifactRecognizerTest.java
@@ -19,14 +19,14 @@ package org.apache.maven.index.artifact;
* under the License.
*/
-import org.apache.maven.index.artifact.M2ArtifactRecognizer;
+import org.junit.Test;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
public class MavenArtifactRecognizerTest
- extends TestCase
{
+ @Test
public void testIsPom()
{
assertEquals( true, M2ArtifactRecognizer.isPom( "aaa.pom" ) );
@@ -35,6 +35,7 @@ public class MavenArtifactRecognizerTest
assertEquals( false, M2ArtifactRecognizer.isPom( "aaa.pom-a" ) );
}
+ @Test
public void testIsSnapshot1()
{
// NEXUS-3148
@@ -49,6 +50,7 @@ public class MavenArtifactRecognizerTest
assertEquals( false, M2ArtifactRecognizer.isSnapshot( "/javax/mail/mail/1.4/mail-1.4.jar" ) );
}
+ @Test
public void testIsSnapshot2()
{
assertEquals(
@@ -59,6 +61,7 @@ public class MavenArtifactRecognizerTest
M2ArtifactRecognizer.isSnapshot( "/org/somewhere/appassembler-maven-plugin/1.0/appassembler-maven-plugin-1.0-20060714.142547-1.pom" ) );
}
+ @Test
public void testIsMetadata()
{
assertEquals( true, M2ArtifactRecognizer.isMetadata( "maven-metadata.xml" ) );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/context/NexusAnalyzerTest.java b/indexer-core/src/test/java/org/apache/maven/index/context/NexusAnalyzerTest.java
index a4929ab..91a0aa4 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/context/NexusAnalyzerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/context/NexusAnalyzerTest.java
@@ -24,26 +24,19 @@ import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
-import junit.framework.TestCase;
-
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.maven.index.IndexerField;
import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
public class NexusAnalyzerTest
- extends TestCase
{
- protected NexusAnalyzer nexusAnalyzer;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- nexusAnalyzer = new NexusAnalyzer();
- }
+ protected NexusAnalyzer nexusAnalyzer = new NexusAnalyzer();
+ @Test
public void testGroupIdTokenization()
throws IOException
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/context/TrackingLockFactoryTest.java b/indexer-core/src/test/java/org/apache/maven/index/context/TrackingLockFactoryTest.java
index d35741e..b3790d4 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/context/TrackingLockFactoryTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/context/TrackingLockFactoryTest.java
@@ -34,9 +34,6 @@ import static org.junit.Assert.*;
*/
public class TrackingLockFactoryTest {
- public TrackingLockFactoryTest() {
- }
-
@Test
public void testLockUnlock() throws IOException {
final TrackingLockFactory lf = new TrackingLockFactory(new SingleInstanceLockFactory());
diff --git a/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
index 8032706..5358bac 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/creator/JarFileContentsIndexCreatorTest.java
@@ -25,6 +25,12 @@ import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.AbstractTestSupport;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* @author Alin Dreghiciu
@@ -43,6 +49,7 @@ public class JarFileContentsIndexCreatorTest
indexCreator = this.lookup( IndexCreator.class, "jarContent" );
}
+ @Test
public void test_nexus_2318_indexJarWithClasses()
throws Exception
{
@@ -59,6 +66,7 @@ public class JarFileContentsIndexCreatorTest
assertNotNull( "Classes should not be null", artifactContext.getArtifactInfo().getClassNames() );
}
+ @Test
public void test_nexus_2318_indexZipWithClasses()
throws Exception
{
@@ -97,6 +105,7 @@ public class JarFileContentsIndexCreatorTest
assertEquals("MethodInvocation class was expected", "/org/aopalliance/intercept/MethodInvocation", classNames[8] );
}
+ @Test
public void test_nexus_2318_indexJarWithSources()
throws Exception
{
@@ -114,6 +123,7 @@ public class JarFileContentsIndexCreatorTest
assertNull( "Classes should be null", artifactContext.getArtifactInfo().getClassNames() );
}
+ @Test
public void test_nexus_2318_indexZipWithSources()
throws Exception
{
@@ -131,6 +141,7 @@ public class JarFileContentsIndexCreatorTest
assertNull( "Classes should be null", artifactContext.getArtifactInfo().getClassNames() );
}
+ @Test
public void testMindexer35ScanWar()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreatorTest.java
index 34959bb..62f6204 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/creator/MavenPluginArtifactInfoIndexCreatorTest.java
@@ -27,6 +27,9 @@ import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.AbstractTestSupport;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* @author juven
@@ -45,6 +48,7 @@ public class MavenPluginArtifactInfoIndexCreatorTest
indexCreator = this.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID );
}
+ @Test
public void testMavenPluginInfo()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/creator/OsgiArtifactIndexCreatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/creator/OsgiArtifactIndexCreatorTest.java
index 5dcec94..3079b72 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/creator/OsgiArtifactIndexCreatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/creator/OsgiArtifactIndexCreatorTest.java
@@ -35,7 +35,11 @@ import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.expr.StringSearchExpression;
import org.apache.maven.index.AbstractTestSupport;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
+
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
@@ -63,12 +67,14 @@ public class OsgiArtifactIndexCreatorTest
nexusIndexer = this.lookup( NexusIndexer.class );
}
+ @Test
public void testAssertIndexCreatorComponentExists()
throws Exception
{
assertNotNull( indexCreator );
}
+ @Test
public void testPopulateArtifactInfo()
throws Exception
{
@@ -111,6 +117,7 @@ public class OsgiArtifactIndexCreatorTest
ai.getBundleImportPackage() );
}
+ @Test
public void testPopulateFragmentHost() throws Exception {
File artifact = new File(getBasedir(),
"src/test/repo-with-osgi/org/slf4j/slf4j-simple/1.7.7/slf4j-simple-1.7.7.jar");
@@ -126,6 +133,7 @@ public class OsgiArtifactIndexCreatorTest
}
+ @Test
public void testPopulateCapabilityAndSha256() throws Exception {
File artifact = new File(getBasedir(),
"src/test/repo-with-osgi/org/apache/karaf/features/org.apache.karaf.features.core/4.1.0/org.apache.karaf.features.core-4.1.0.jar");
@@ -185,6 +193,7 @@ public class OsgiArtifactIndexCreatorTest
}
+ @Test
public void testIndexOSGIRepoThenSearch()
throws Exception
{
@@ -219,6 +228,7 @@ public class OsgiArtifactIndexCreatorTest
}
}
+ @Test
public void testIndexOSGIRepoThenSearchWithVersion()
throws Exception
{
@@ -246,6 +256,7 @@ public class OsgiArtifactIndexCreatorTest
}
+ @Test
public void testIndexOSGIRepoThenSearchWithSha256()
throws Exception {
@@ -272,6 +283,7 @@ public class OsgiArtifactIndexCreatorTest
}
+ @Test
public void testIndexOSGIRepoThenSearchWithExportPackage()
throws Exception
{
@@ -316,6 +328,7 @@ public class OsgiArtifactIndexCreatorTest
}
+ @Test
public void testIndexOSGIRepoThenSearchWithExportService()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/incremental/DefaultIncrementalHandlerTest.java b/indexer-core/src/test/java/org/apache/maven/index/incremental/DefaultIncrementalHandlerTest.java
index 1e8518b..346027f 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/incremental/DefaultIncrementalHandlerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/incremental/DefaultIncrementalHandlerTest.java
@@ -27,6 +27,7 @@ import org.apache.maven.index.packer.IndexPackingRequest;
import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.ResourceFetcher;
import org.codehaus.plexus.util.FileUtils;
+import org.junit.Test;
import java.io.File;
import java.io.FileNotFoundException;
@@ -35,6 +36,9 @@ import java.io.InputStream;
import java.util.List;
import java.util.Properties;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
public class DefaultIncrementalHandlerTest
extends AbstractIndexCreatorHelper
{
@@ -49,7 +53,7 @@ public class DefaultIncrementalHandlerTest
File repoDir = null;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -66,7 +70,7 @@ public class DefaultIncrementalHandlerTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
super.tearDown();
@@ -74,6 +78,7 @@ public class DefaultIncrementalHandlerTest
indexer.removeIndexingContext( context, true );
}
+ @Test
public void testUpdateInvalidProperties()
throws Exception
{
@@ -104,6 +109,7 @@ public class DefaultIncrementalHandlerTest
}
}
+ @Test
public void testUpdateValid()
throws Exception
{
@@ -129,6 +135,7 @@ public class DefaultIncrementalHandlerTest
}
}
+ @Test
public void testRemoteUpdatesInvalidProperties()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java b/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java
index 8ec2009..fdcba34 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/locator/ArtifactLocatorTest.java
@@ -28,6 +28,9 @@ import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.artifact.ArtifactPackagingMapper;
import org.apache.maven.index.artifact.Gav;
import org.apache.maven.index.artifact.M2GavCalculator;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
public class ArtifactLocatorTest
extends AbstractNexusIndexerTest
@@ -51,6 +54,7 @@ public class ArtifactLocatorTest
artifactPackagingMapper = lookup( ArtifactPackagingMapper.class );
}
+ @Test
public void testContextProducer()
{
final File pomFile =
@@ -62,6 +66,7 @@ public class ArtifactLocatorTest
assertTrue( "Artifact file was not found!", ac.getArtifact().exists() );
}
+ @Test
public void testArtifactLocator()
{
ArtifactLocator al = new ArtifactLocator( artifactPackagingMapper );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/packer/NEXUS4149TransferFormatTest.java b/indexer-core/src/test/java/org/apache/maven/index/packer/NEXUS4149TransferFormatTest.java
index df4d921..4b76c48 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/packer/NEXUS4149TransferFormatTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/packer/NEXUS4149TransferFormatTest.java
@@ -27,8 +27,6 @@ import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
-import junit.framework.Assert;
-
import org.apache.lucene.document.Document;
import org.apache.lucene.search.IndexSearcher;
import org.apache.maven.index.AbstractNexusIndexerTest;
@@ -39,6 +37,10 @@ import org.apache.maven.index.context.MergedIndexingContext;
import org.apache.maven.index.packer.IndexPackingRequest.IndexFormat;
import org.apache.maven.index.updater.IndexDataReader;
import org.codehaus.plexus.util.StringUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
public class NEXUS4149TransferFormatTest
extends AbstractNexusIndexerTest
@@ -48,7 +50,7 @@ public class NEXUS4149TransferFormatTest
protected File idxsBase = new File( getBasedir(), "target/index/nexus-4149" );
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -108,6 +110,7 @@ public class NEXUS4149TransferFormatTest
// we use no directory
}
+ @Test
public void testMembersAndMergedRootGroups()
throws Exception
{
@@ -117,14 +120,15 @@ public class NEXUS4149TransferFormatTest
{
if ( !"repo4".equals( member.getId() ) ) // repo4 is empty
{
- Assert.assertEquals( "Members should have one root group!", 1, member.getRootGroups().size() );
+ assertEquals( "Members should have one root group!", 1, member.getRootGroups().size() );
}
}
- Assert.assertEquals( "Merged should have one root multiply members count (sans repo4)!", 3,
+ assertEquals( "Merged should have one root multiply members count (sans repo4)!", 3,
mctx.getRootGroups().size() );
}
+ @Test
public void testTransportFile()
throws Exception
{
@@ -182,16 +186,16 @@ public class NEXUS4149TransferFormatTest
}
}
- Assert.assertNotNull( "Group transport file should contain allGroups!", allGroups );
- Assert.assertNotNull( "Group transport file should contain rootGroups!", rootGroups );
+ assertNotNull( "Group transport file should contain allGroups!", allGroups );
+ assertNotNull( "Group transport file should contain rootGroups!", rootGroups );
checkListOfStringDoesNotContainEmptyString( ArtifactInfo.str2lst( allGroups ) );
checkListOfStringDoesNotContainEmptyString( ArtifactInfo.str2lst( rootGroups ) );
- Assert.assertEquals( 15, totalDocs );
+ assertEquals( 15, totalDocs );
// 1 descriptor + 1 allGroups + 1 rootGroups
- Assert.assertEquals( 3, specialDocs );
+ assertEquals( 3, specialDocs );
// repo1 has 1 artifact, repo2 has 1 artifact and repo3 has 10 artifact
- Assert.assertEquals( 12, artifactDocs );
+ assertEquals( 12, artifactDocs );
}
finally
diff --git a/indexer-core/src/test/java/org/apache/maven/index/treeview/IndexTreeViewTest.java b/indexer-core/src/test/java/org/apache/maven/index/treeview/IndexTreeViewTest.java
index 37c3558..7143a52 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/treeview/IndexTreeViewTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/treeview/IndexTreeViewTest.java
@@ -23,9 +23,9 @@ import java.io.File;
import org.apache.maven.index.AbstractNexusIndexerTest;
import org.apache.maven.index.NexusIndexer;
-import org.apache.maven.index.treeview.DefaultTreeNodeFactory;
-import org.apache.maven.index.treeview.IndexTreeView;
-import org.apache.maven.index.treeview.TreeNode;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
public class IndexTreeViewTest
extends AbstractNexusIndexerTest
@@ -37,7 +37,7 @@ public class IndexTreeViewTest
protected boolean debug = false;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -81,6 +81,7 @@ public class IndexTreeViewTest
return files;
}
+ @Test
public void testRoot()
throws Exception
{
@@ -95,6 +96,7 @@ public class IndexTreeViewTest
assertEquals( 49, leafsFound );
}
+ @Test
public void testPathIsAboveRealGroup()
throws Exception
{
@@ -109,6 +111,7 @@ public class IndexTreeViewTest
assertEquals( 22, leafsFound );
}
+ @Test
public void testPathIsRealGroup()
throws Exception
{
@@ -123,6 +126,7 @@ public class IndexTreeViewTest
assertEquals( 10, leafsFound );
}
+ @Test
public void testPathIsRealGroupArtifact()
throws Exception
{
@@ -138,6 +142,7 @@ public class IndexTreeViewTest
assertEquals( 4, leafsFound );
}
+ @Test
public void testPathIsRealGroupArtifactVersion()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/AbstractIndexUpdaterTest.java b/indexer-core/src/test/java/org/apache/maven/index/updater/AbstractIndexUpdaterTest.java
index 11f671a..8074524 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/AbstractIndexUpdaterTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/AbstractIndexUpdaterTest.java
@@ -39,6 +39,8 @@ import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
import org.codehaus.plexus.util.FileUtils;
+import static org.junit.Assert.assertEquals;
+
public abstract class AbstractIndexUpdaterTest
extends AbstractIndexCreatorHelper
{
@@ -61,7 +63,7 @@ public abstract class AbstractIndexUpdaterTest
IndexingContext context;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -87,7 +89,7 @@ public abstract class AbstractIndexUpdaterTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
super.tearDown();
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
index 513cebc..2627fd8 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterEmbeddingIT.java
@@ -26,41 +26,38 @@ import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
-import com.google.inject.Injector;
-import junit.framework.TestCase;
+import com.google.inject.Inject;
+import org.apache.maven.index.Java11HttpClient;
import org.apache.maven.index.context.DefaultIndexingContext;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.apache.maven.index.updater.fixtures.ServerTestFixture;
-import org.apache.maven.index.updater.fixtures.TransferListenerFixture;
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
-import org.apache.maven.wagon.events.TransferEvent;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.FileUtils;
+import org.eclipse.sisu.launch.InjectedTest;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class DefaultIndexUpdaterEmbeddingIT
- extends TestCase
+ extends InjectedTest
{
private String baseUrl;
- private PlexusContainer container;
private ServerTestFixture server;
+ @Inject
private IndexUpdater updater;
- private WagonHelper wagonHelper;
-
@Override
public void setUp()
throws Exception
{
+
int port;
try ( final ServerSocket ss = new ServerSocket( 0 ) )
{
@@ -69,28 +66,21 @@ public class DefaultIndexUpdaterEmbeddingIT
}
baseUrl = "http://127.0.0.1:" + port + "/";
-
server = new ServerTestFixture( port );
- final DefaultContainerConfiguration configuration = new DefaultContainerConfiguration();
- configuration.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
- container = new DefaultPlexusContainer(configuration);
- updater = container.lookup( IndexUpdater.class, "default" );
-
- wagonHelper = new WagonHelper( container.lookup( Injector.class ) );
+ super.setUp();
}
@Override
public void tearDown()
throws Exception
{
- container.release( updater );
- container.dispose();
server.stop();
}
+ @Test
public void testBasicIndexRetrieval()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
+ throws IOException, UnsupportedExistingLuceneIndexException
{
File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
basedir.delete();
@@ -100,9 +90,7 @@ public class DefaultIndexUpdaterEmbeddingIT
{
IndexingContext ctx = newTestContext( basedir, baseUrl );
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture(), null,
- null ) );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, new Java11HttpClient() );
updater.fetchAndUpdateIndex( updateRequest );
@@ -120,8 +108,9 @@ public class DefaultIndexUpdaterEmbeddingIT
}
}
+ @Test
public void testIndexTempDirB()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
+ throws IOException, UnsupportedExistingLuceneIndexException
{
File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
basedir.delete();
@@ -136,9 +125,7 @@ public class DefaultIndexUpdaterEmbeddingIT
{
IndexingContext ctx = newTestContext( basedir, baseUrl );
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture(), null,
- null ) );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, new Java11HttpClient() );
updateRequest.setIndexTempDir( indexTempDir );
updater.fetchAndUpdateIndex( updateRequest );
@@ -160,83 +147,9 @@ public class DefaultIndexUpdaterEmbeddingIT
}
}
- public void testBasicAuthenticatedIndexRetrieval()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
- {
- File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
-
- try
- {
- IndexingContext ctx = newTestContext( basedir, baseUrl + "protected/" );
-
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture(),
- new AuthenticationInfo()
- {
- private static final long serialVersionUID = 1L;
-
- {
- setUserName( "user" );
- setPassword( "password" );
- }
- }, null ) );
-
- updater.fetchAndUpdateIndex( updateRequest );
-
- ctx.close( false );
- }
- finally
- {
- try
- {
- FileUtils.forceDelete( basedir );
- }
- catch ( IOException e )
- {
- }
- }
- }
-
- public void testAuthenticatedIndexRetrieval_LongAuthorizationHeader()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
- {
- File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
-
-
- try
- {
- IndexingContext ctx = newTestContext( basedir, baseUrl + "protected/" );
-
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture(),
- new AuthenticationInfo()
- {
- private static final long serialVersionUID = 1L;
-
- {
- setUserName( "longuser" );
- setPassword( ServerTestFixture.LONG_PASSWORD );
- }
- }, null ) );
-
- updater.fetchAndUpdateIndex( updateRequest );
-
- ctx.close( false );
- }
- finally
- {
- try
- {
- FileUtils.forceDelete( basedir );
- }
- catch ( IOException e )
- {
- }
- }
- }
-
+ @Test
public void testBasicHighLatencyIndexRetrieval()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
+ throws IOException, UnsupportedExistingLuceneIndexException
{
File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
@@ -244,17 +157,7 @@ public class DefaultIndexUpdaterEmbeddingIT
{
IndexingContext ctx = newTestContext( basedir, baseUrl + "slow/" );
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture(),
- new AuthenticationInfo()
- {
- private static final long serialVersionUID = 1L;
-
- {
- setUserName( "user" );
- setPassword( "password" );
- }
- }, null ) );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, new Java11HttpClient() );
updater.fetchAndUpdateIndex( updateRequest );
@@ -272,118 +175,9 @@ public class DefaultIndexUpdaterEmbeddingIT
}
}
- // Disabled, since with Wagon you cannot set timeout as it was possible with Jetty client
- public void OFFtestHighLatencyIndexRetrieval_LowConnectionTimeout()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
- {
- File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
-
- try
- {
- IndexingContext ctx = newTestContext( basedir, baseUrl + "slow/" );
-
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture()
- {
- @Override
- public void transferError( final TransferEvent transferEvent )
- {
- }
- }, new AuthenticationInfo()
- {
- private static final long serialVersionUID = 1L;
-
- {
- setUserName( "user" );
- setPassword( "password" );
- }
- }, null ) );
-
- // ResourceFetcher fetcher =
- // new JettyResourceFetcher().setConnectionTimeoutMillis( 100 ).setAuthenticationInfo(
- // updateRequest.getAuthenticationInfo() ).addTransferListener( updateRequest.getTransferListener() );
-
- try
- {
- updater.fetchAndUpdateIndex( updateRequest );
- fail( "Should timeout and throw IOException." );
- }
- catch ( IOException e )
- {
- System.out.println( "Operation timed out due to short connection timeout, as expected." );
- }
-
- ctx.close( false );
- }
- finally
- {
- try
- {
- FileUtils.forceDelete( basedir );
- }
- catch ( IOException e )
- {
- }
- }
- }
-
- // Disabled, since with Wagon you cannot set timeout as it was possible with Jetty client
- public void OFFtestHighLatencyIndexRetrieval_LowTransactionTimeout()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
- {
- File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
-
- try
- {
- IndexingContext ctx = newTestContext( basedir, baseUrl + "slow/" );
-
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture()
- {
- @Override
- public void transferError( final TransferEvent transferEvent )
- {
- }
- }, new AuthenticationInfo()
- {
- private static final long serialVersionUID = 1L;
-
- {
- setUserName( "user" );
- setPassword( "password" );
- }
- }, null ) );
-
- // ResourceFetcher fetcher =
- // new JettyResourceFetcher().setTransactionTimeoutMillis( 100 ).setAuthenticationInfo(
- // updateRequest.getAuthenticationInfo() ).addTransferListener( updateRequest.getTransferListener() );
-
- try
- {
- updater.fetchAndUpdateIndex( updateRequest );
- fail( "Should timeout and throw IOException." );
- }
- catch ( IOException e )
- {
- System.out.println( "Operation timed out due to short transaction timeout, as expected." );
- }
-
- ctx.close( false );
- }
- finally
- {
- try
- {
- FileUtils.forceDelete( basedir );
- }
- catch ( IOException e )
- {
- }
- }
- }
-
+ @Test
public void testIndexRetrieval_InfiniteRedirection()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
+ throws IOException, UnsupportedExistingLuceneIndexException
{
File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
@@ -391,14 +185,7 @@ public class DefaultIndexUpdaterEmbeddingIT
{
IndexingContext ctx = newTestContext( basedir, baseUrl + "redirect-trap/" );
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture()
- {
- @Override
- public void transferError( final TransferEvent transferEvent )
- {
- }
- }, null, null ) );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, new Java11HttpClient() );
try
{
@@ -424,8 +211,9 @@ public class DefaultIndexUpdaterEmbeddingIT
}
}
+ @Test
public void testIndexRetrieval_BadHostname()
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
+ throws IOException, UnsupportedExistingLuceneIndexException
{
File basedir = Files.createTempDirectory( "nexus-indexer." ).toFile();
@@ -433,22 +221,7 @@ public class DefaultIndexUpdaterEmbeddingIT
{
IndexingContext ctx = newTestContext( basedir, "http://dummy/" );
- IndexUpdateRequest updateRequest =
- new IndexUpdateRequest( ctx, wagonHelper.getWagonResourceFetcher( new TransferListenerFixture()
- {
- @Override
- public void transferError( final TransferEvent transferEvent )
- {
- }
- }, new AuthenticationInfo()
- {
- private static final long serialVersionUID = 1L;
-
- {
- setUserName( "user" );
- setPassword( "password" );
- }
- }, null ) );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, new Java11HttpClient() );
try
{
@@ -475,10 +248,10 @@ public class DefaultIndexUpdaterEmbeddingIT
}
private IndexingContext newTestContext( final File basedir, final String baseUrl )
- throws IOException, UnsupportedExistingLuceneIndexException, ComponentLookupException
+ throws IOException, UnsupportedExistingLuceneIndexException
{
- IndexCreator min = container.lookup( IndexCreator.class, "min" );
- IndexCreator jar = container.lookup( IndexCreator.class, "jarContent" );
+ IndexCreator min = lookup( IndexCreator.class, "min" );
+ IndexCreator jar = lookup( IndexCreator.class, "jarContent" );
List<IndexCreator> creators = new ArrayList<>();
creators.add( min );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
index 527e3f1..ab54d3c 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/DefaultIndexUpdaterTest.java
@@ -22,6 +22,7 @@ package org.apache.maven.index.updater;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -49,6 +50,11 @@ import org.jmock.api.Invocation;
import org.jmock.lib.action.ReturnValueAction;
import org.jmock.lib.action.VoidAction;
import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
/**
* @author Eugene Kuleshov
@@ -59,6 +65,7 @@ public class DefaultIndexUpdaterTest
SimpleDateFormat df = new SimpleDateFormat( "yyyyMMddHHmmss.SSS Z" );
+ @Test
public void testReplaceIndex()
throws Exception
{
@@ -111,6 +118,7 @@ public class DefaultIndexUpdaterTest
assertEquals( content2.toString(), 2, content2.size() );
}
+ @Test
public void testMergeIndex()
throws Exception
{
@@ -165,6 +173,7 @@ public class DefaultIndexUpdaterTest
}
}
+ @Test
public void testMergeIndexDeletes()
throws Exception
{
@@ -215,6 +224,7 @@ public class DefaultIndexUpdaterTest
assertEquals( content2.toString(), 1, content2.size() );
}
+ @Test
public void testMergeSearch()
throws Exception
{
@@ -243,6 +253,7 @@ public class DefaultIndexUpdaterTest
assertEquals( artifactInfo.getArtifactId(), "dma.integration.tests" );
}
+ @Test
public void testMergeGroups()
throws Exception
{
@@ -294,6 +305,7 @@ public class DefaultIndexUpdaterTest
assertEquals( allGroups.toString(), 5, allGroups.size() );
}
+ @Test
public void testNoIndexUpdate()
throws Exception
{
@@ -363,6 +375,7 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateSucceeded(updateResult);
}
+ @Test
public void testFullIndexUpdate()
throws Exception
{
@@ -417,7 +430,7 @@ public class DefaultIndexUpdaterTest
oneOf( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
+ will( returnValue( newInputStream( "index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
oneOf( tempContext ).replace( with( any( Directory.class ) ), with( any( Set.class ) ), with( any( Set.class ) ) );
@@ -435,6 +448,7 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateSucceeded(updateResult);
}
+ @Test
public void testIncrementalIndexUpdate()
throws Exception
{
@@ -494,10 +508,10 @@ public class DefaultIndexUpdaterTest
oneOf( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".2.gz" ) );
- will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
+ will( returnValue( newInputStream( "index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
oneOf( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
- will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
+ will( returnValue( newInputStream( "index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
// could create index archive there and verify that it is merged correctly
oneOf( tempContext ).merge( with( any( Directory.class ) ) );
@@ -519,6 +533,7 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateSucceeded(updateResult);
}
+ @Test
public void testIncrementalIndexUpdateNoCounter()
throws Exception
{
@@ -574,7 +589,7 @@ public class DefaultIndexUpdaterTest
oneOf( mockFetcher ).retrieve( //
with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
+ will( returnValue( newInputStream( "index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
// could create index archive there and verify that it is merged correctly
oneOf( tempContext ).replace( with( any( Directory.class ) ), with( any( Set.class ) ), with( any( Set.class ) ) );
@@ -597,7 +612,8 @@ public class DefaultIndexUpdaterTest
mockery.assertIsSatisfied();
assertIndexUpdateSucceeded(updateResult);
}
-
+
+ @Test
public void testIncrementalOnlyIndexUpdateNoCounter()
throws Exception
{
@@ -662,6 +678,7 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateFailed(updateResult);
}
+ @Test
public void testIncrementalIndexUpdateNoUpdateNecessary()
throws Exception
{
@@ -750,6 +767,7 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateSucceeded(updateResult);
}
+ @Test
public void testUpdateForceFullUpdate()
throws Exception
{
@@ -815,7 +833,7 @@ public class DefaultIndexUpdaterTest
with( IndexingContext.INDEX_FILE_PREFIX + ".3.gz" ) );
oneOf( mockFetcher ).retrieve( with( IndexingContext.INDEX_FILE_PREFIX + ".gz" ) );
- will( returnValue( newInputStream( "/index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
+ will( returnValue( newInputStream( "index-updater/server-root/nexus-maven-repository-index.gz" ) ) );
never( tempContext ).merge( with( any( Directory.class ) ) );
@@ -839,6 +857,7 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateSucceeded(updateResult);
}
+ @Test
@Ignore("Legacy format no longer supported with Lucene 4")
public void ignoreTestUpdateForceFullUpdateNoGZ()
throws Exception
@@ -896,7 +915,7 @@ public class DefaultIndexUpdaterTest
oneOf( mockFetcher ).retrieve( with( IndexingContext.INDEX_FILE_PREFIX + ".zip" ) );
- will( returnValue( newInputStream( "/index-updater/server-root/legacy/nexus-maven-repository-index.zip" ) ) );
+ will( returnValue( newInputStream( "index-updater/server-root/legacy/nexus-maven-repository-index.zip" ) ) );
never( tempContext ).merge( with( any( Directory.class ) ) );
@@ -920,9 +939,14 @@ public class DefaultIndexUpdaterTest
assertIndexUpdateSucceeded(updateResult);
}
- protected InputStream newInputStream( String path )
+ protected InputStream newInputStream( String path ) throws IOException
{
- return getResourceAsStream( path );
+ File file = getTestFile( "src/test/resources/" + path );
+ if ( file.isFile() )
+ {
+ return new FileInputStream( file );
+ }
+ return null;
}
abstract static class PropertiesAction
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/DownloadRemoteIndexerManagerTest.java b/indexer-core/src/test/java/org/apache/maven/index/updater/DownloadRemoteIndexerManagerTest.java
index 09e288b..a1c2808 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/DownloadRemoteIndexerManagerTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/DownloadRemoteIndexerManagerTest.java
@@ -29,7 +29,7 @@ import java.util.Date;
import java.util.Properties;
import java.util.TimeZone;
-import com.google.inject.Injector;
+import org.apache.maven.index.Java11HttpClient;
import org.apache.maven.index.context.IndexingContext;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.jetty.server.Handler;
@@ -37,6 +37,9 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
public class DownloadRemoteIndexerManagerTest
extends AbstractIndexUpdaterTest
@@ -48,7 +51,7 @@ public class DownloadRemoteIndexerManagerTest
private IndexingContext centralContext;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -78,7 +81,7 @@ public class DownloadRemoteIndexerManagerTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
server.stop();
@@ -88,6 +91,7 @@ public class DownloadRemoteIndexerManagerTest
super.tearDown();
}
+ @Test
public void testRepoReindex()
throws Exception
{
@@ -100,8 +104,7 @@ public class DownloadRemoteIndexerManagerTest
// copy index 02
overwriteIndex( index2, centralIndex );
- iur =
- new IndexUpdateRequest( centralContext, new WagonHelper( getContainer().lookup( Injector.class ) ).getWagonResourceFetcher( null ) );
+ iur = new IndexUpdateRequest( centralContext, new Java11HttpClient() );
iur.setForceFullUpdate( true );
updater.fetchAndUpdateIndex( iur );
@@ -111,8 +114,7 @@ public class DownloadRemoteIndexerManagerTest
// copy index 01
overwriteIndex( index1, centralIndex );
- iur =
- new IndexUpdateRequest( centralContext, new WagonHelper( getContainer().lookup( Injector.class ) ).getWagonResourceFetcher( null ) );
+ iur = new IndexUpdateRequest( centralContext, new Java11HttpClient() );
iur.setForceFullUpdate( true );
// just a dummy filter to invoke filtering! -- this is what I broke unnoticing it
iur.setDocumentFilter( doc -> true );
@@ -124,8 +126,7 @@ public class DownloadRemoteIndexerManagerTest
// copy index 02
overwriteIndex( index2, centralIndex );
- iur =
- new IndexUpdateRequest( centralContext, new WagonHelper( getContainer().lookup( Injector.class ) ).getWagonResourceFetcher( null ) );
+ iur = new IndexUpdateRequest( centralContext, new Java11HttpClient() );
iur.setForceFullUpdate( true );
updater.fetchAndUpdateIndex( iur );
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java b/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java
deleted file mode 100644
index 0e2a90e..0000000
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/FullBootProofOfConcept.java
+++ /dev/null
@@ -1,181 +0,0 @@
-package org.apache.maven.index.updater;
-
-/*
- * 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.
- */
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.google.inject.Injector;
-import org.apache.maven.index.context.DefaultIndexingContext;
-import org.apache.maven.index.context.IndexCreator;
-import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
-import org.apache.maven.index.updater.WagonHelper.WagonFetcher;
-import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.PlexusContainerException;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.util.FileUtils;
-
-public class FullBootProofOfConcept
-{
-
- private static final int ONE_MEGABYTE = 1024 * 1024;
-
- public static void main( final String[] args )
- throws IOException
- {
- for ( int i = 0; i < 1; i++ )
- {
- File basedir = Files.createTempDirectory("nexus-indexer..dir" ).toFile();
- basedir.deleteOnExit();
-
- try
- {
- run( basedir );
- }
- catch ( UnsupportedExistingLuceneIndexException | ParseException | PlexusContainerException | ComponentLookupException | IOException e )
- {
- e.printStackTrace();
- }
- finally
- {
- try
- {
- FileUtils.forceDelete( basedir );
- }
- catch ( IOException e )
- {
- }
- }
- }
- }
-
- public static void run( final File basedir )
- throws IOException, ComponentLookupException, PlexusContainerException, ParseException,
- UnsupportedExistingLuceneIndexException
- {
- try
- {
- FileUtils.forceDelete( basedir );
- }
- catch ( IOException e )
- {
- // just do your best to delete this.
- }
-
- basedir.mkdirs();
-
- PlexusContainer container = new DefaultPlexusContainer();
-
- IndexCreator min = container.lookup( IndexCreator.class, "min" );
- IndexCreator jar = container.lookup( IndexCreator.class, "jarContent" );
-
- List<IndexCreator> creators = new ArrayList<>();
- creators.add( min );
- creators.add( jar );
-
- String repositoryId = "test";
- String repositoryUrl = "http://localhost:8081/nexus/content/groups/sonatype-public/";
- // String repositoryUrl = "http://repository.sonatype.org/content/groups/public/";
- // String repositoryUrl = "http://repository.sonatype.org/content/groups/sonatype/";
- String indexUrl = repositoryUrl + ".index";
-
- IndexingContext ctx =
- new DefaultIndexingContext( repositoryId, repositoryId, basedir, basedir, repositoryUrl, indexUrl,
- creators, true );
-
- // craft the Wagon based Resource
-
- TransferListener tl = new TransferListener()
- {
-
- private int col = 0;
-
- private int count = 0;
-
- private int mb = 0;
-
- public void transferStarted( final TransferEvent transferEvent )
- {
- System.out.println( "Started transfer: " + transferEvent.getResource().getName() );
- }
-
- public void transferProgress( final TransferEvent transferEvent, final byte[] buffer, final int length )
- {
- if ( buffer == null )
- {
- return;
- }
-
- count += buffer.length;
-
- if ( ( count / ONE_MEGABYTE ) > mb )
- {
- if ( col > 80 )
- {
- System.out.println();
- col = 0;
- }
-
- System.out.print( '.' );
- col++;
- mb++;
- }
- }
-
- public void transferInitiated( final TransferEvent transferEvent )
- {
- }
-
- public void transferError( final TransferEvent transferEvent )
- {
- System.out.println( "[ERROR]: " + transferEvent.getException().getLocalizedMessage() );
- transferEvent.getException().printStackTrace();
- }
-
- public void transferCompleted( final TransferEvent transferEvent )
- {
- System.out.println( "\nCompleted transfer: " + transferEvent.getResource().getName() + " ("
- + (double) ( count / ONE_MEGABYTE ) + " MB)" );
- }
-
- public void debug( final String message )
- {
- System.out.println( "[DEBUG]: " + message );
- }
- };
-
- WagonHelper wh = new WagonHelper( container.lookup( Injector.class ) );
-
- WagonFetcher wf = wh.getWagonResourceFetcher( tl, null, null );
-
- IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, wf );
-
- container.lookup( IndexUpdater.class ).fetchAndUpdateIndex( updateRequest );
- }
-
-}
\ No newline at end of file
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/IndexDataTest.java b/indexer-core/src/test/java/org/apache/maven/index/updater/IndexDataTest.java
index 434030e..f790181 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/IndexDataTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/IndexDataTest.java
@@ -38,6 +38,12 @@ import org.apache.maven.index.AbstractRepoNexusIndexerTest;
import org.apache.maven.index.ArtifactInfo;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* @author Eugene Kuleshov
@@ -89,6 +95,7 @@ public class IndexDataTest
context.replace( newDir );
}
+ @Test
public void testEmptyContext()
throws Exception
{
@@ -126,6 +133,7 @@ public class IndexDataTest
context.replace( newDir );
}
+ @Test
public void testData()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/LocalIndexCacheTest.java b/indexer-core/src/test/java/org/apache/maven/index/updater/LocalIndexCacheTest.java
index 1b4fb02..6770e43 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/LocalIndexCacheTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/updater/LocalIndexCacheTest.java
@@ -34,6 +34,12 @@ import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.apache.maven.index.fs.Locker;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class LocalIndexCacheTest
extends AbstractIndexUpdaterTest
@@ -47,7 +53,7 @@ public class LocalIndexCacheTest
private IndexingContext tempContext;
@Override
- protected void setUp()
+ public void setUp()
throws Exception
{
super.setUp();
@@ -66,7 +72,7 @@ public class LocalIndexCacheTest
}
@Override
- protected void tearDown()
+ public void tearDown()
throws Exception
{
removeTempContext();
@@ -97,6 +103,7 @@ public class LocalIndexCacheTest
}
}
+ @Test
public void testBasic()
throws Exception
{
@@ -186,6 +193,7 @@ public class LocalIndexCacheTest
assertEquals( expectedCount, response.getTotalHits() );
}
+ @Test
public void testForceIndexDownload()
throws Exception
{
@@ -218,6 +226,7 @@ public class LocalIndexCacheTest
updater.fetchAndUpdateIndex( updateRequest );
}
+ @Test
public void testInitialForcedFullDownload()
throws Exception
{
@@ -239,6 +248,7 @@ public class LocalIndexCacheTest
assertTrue( new File( localCacheDir, "nexus-maven-repository-index.properties" ).exists() );
}
+ @Test
public void testFailedIndexDownload()
throws Exception
{
@@ -285,6 +295,7 @@ public class LocalIndexCacheTest
assertTrue( new File( localCacheDir, "nexus-maven-repository-index.properties" ).exists() );
}
+ @Test
public void testCleanCacheDirectory()
throws Exception
{
@@ -349,6 +360,7 @@ public class LocalIndexCacheTest
assertFalse( unknownDirectory.isDirectory() );
}
+ @Test
public void testOffline()
throws Exception
{
diff --git a/indexer-core/src/test/java/org/apache/maven/index/updater/fixtures/TransferListenerFixture.java b/indexer-core/src/test/java/org/apache/maven/index/updater/fixtures/TransferListenerFixture.java
deleted file mode 100644
index 2e779bd..0000000
--- a/indexer-core/src/test/java/org/apache/maven/index/updater/fixtures/TransferListenerFixture.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package org.apache.maven.index.updater.fixtures;
-
-/*
- * 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.
- */
-
-import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-
-public class TransferListenerFixture
- implements TransferListener
-{
- private static final int ONE_CHUNK = 64;
-
- private int col = 0;
-
- private int count = 0;
-
- private int kb = 0;
-
- public void transferStarted( final TransferEvent transferEvent )
- {
- System.out.println( "Started transfer: " + transferEvent.getResource().getName() );
- }
-
- public void transferProgress( final TransferEvent transferEvent, final byte[] buffer, final int length )
- {
- if ( buffer == null )
- {
- return;
- }
-
- count += buffer.length;
-
- if ( ( count / ONE_CHUNK ) > kb )
- {
- if ( col > 80 )
- {
- System.out.println();
- col = 0;
- }
-
- System.out.print( '.' );
- col++;
- kb++;
- }
- }
-
- public void transferInitiated( final TransferEvent transferEvent )
- {
- }
-
- public void transferError( final TransferEvent transferEvent )
- {
- System.out.println( "[ERROR]: " + transferEvent.getException().getLocalizedMessage() );
- transferEvent.getException().printStackTrace();
- }
-
- public void transferCompleted( final TransferEvent transferEvent )
- {
- System.out.println( "\nCompleted transfer: " + transferEvent.getResource().getName() + " ("
- + (double) ( count / ONE_CHUNK ) + " chunks of size: " + ONE_CHUNK + " bytes)" );
- }
-
- public void debug( final String message )
- {
- System.out.println( "[DEBUG]: " + message );
- }
-}
diff --git a/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java b/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java
index ef6976c..767005a 100644
--- a/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java
+++ b/indexer-core/src/test/java/org/apache/maven/index/util/IndexCreatorSorterTest.java
@@ -19,22 +19,33 @@ package org.apache.maven.index.util;
* under the License.
*/
+import javax.inject.Inject;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.AbstractTestSupport;
-import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class IndexCreatorSorterTest
extends AbstractTestSupport
{
+ @Inject
+ private List<IndexCreator> creators;
+
+ @Inject
+ private Map<String, IndexCreator> creatorMap;
+
+ @Test
public void testLookupList()
throws Exception
{
- final List<IndexCreator> creators = getContainer().lookupList( IndexCreator.class );
-
final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( creators );
// we are interested in IDs only
@@ -45,33 +56,32 @@ public class IndexCreatorSorterTest
}
// ensure we fulfil some basic conditions
- Assert.assertTrue( "min should be present", sortedCreatorIds.contains( "min" ) );
- Assert.assertTrue( "maven-plugin should be present", sortedCreatorIds.contains( "maven-plugin" ) );
- Assert.assertTrue( "maven-archetype should be present", sortedCreatorIds.contains( "maven-archetype" ) );
+ assertTrue( "min should be present", sortedCreatorIds.contains( "min" ) );
+ assertTrue( "maven-plugin should be present", sortedCreatorIds.contains( "maven-plugin" ) );
+ assertTrue( "maven-archetype should be present", sortedCreatorIds.contains( "maven-archetype" ) );
// currently, both "maven-plugin" and "maven-archetype" creator depend on "min" creator
- Assert.assertTrue( "maven-archetype depends on min",
+ assertTrue( "maven-archetype depends on min",
sortedCreatorIds.indexOf( "min" ) < sortedCreatorIds.indexOf( "maven-archetype" ) );
- Assert.assertTrue( "maven-plugin depends on min",
+ assertTrue( "maven-plugin depends on min",
sortedCreatorIds.indexOf( "min" ) < sortedCreatorIds.indexOf( "maven-plugin" ) );
}
+ @Test
public void testLookupListWithSpoofedCreator()
throws Exception
{
- final List<IndexCreator> creators =
- new ArrayList<>( getContainer().lookupList( IndexCreator.class ) );
+ List<IndexCreator> myIndexCreators = new ArrayList<>( creators );
// now we add spoofs to it, this one depends on ALL creators. Note: we add it as 1st intentionally
- creators.add( 0,
- new SpoofIndexCreator( "depend-on-all", new ArrayList<>(
- getContainer().lookupMap( IndexCreator.class ).keySet() ) ) );
+ myIndexCreators.add( 0,
+ new SpoofIndexCreator( "depend-on-all", new ArrayList<>( creatorMap.keySet() ) ) );
// now we add spoofs to it, this one depends on only one, the "depend-on-all" creator Note: we add it as 1st
// intentionally
- creators.add( 0, new SpoofIndexCreator( "last", Arrays.asList( "depend-on-all" ) ) );
+ myIndexCreators.add( 0, new SpoofIndexCreator( "last", Arrays.asList( "depend-on-all" ) ) );
- final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( creators );
+ final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( myIndexCreators );
// we are interested in IDs only
final List<String> sortedCreatorIds = new ArrayList<>();
@@ -81,43 +91,42 @@ public class IndexCreatorSorterTest
}
// ensure we fulfil some basic conditions
- Assert.assertTrue( "min should be present", sortedCreatorIds.contains( "min" ) );
- Assert.assertTrue( "maven-plugin should be present", sortedCreatorIds.contains( "maven-plugin" ) );
- Assert.assertTrue( "maven-archetype should be present", sortedCreatorIds.contains( "maven-archetype" ) );
- Assert.assertTrue( "depend-on-all should be present", sortedCreatorIds.contains( "depend-on-all" ) );
- Assert.assertTrue( "last should be present", sortedCreatorIds.contains( "last" ) );
+ assertTrue( "min should be present", sortedCreatorIds.contains( "min" ) );
+ assertTrue( "maven-plugin should be present", sortedCreatorIds.contains( "maven-plugin" ) );
+ assertTrue( "maven-archetype should be present", sortedCreatorIds.contains( "maven-archetype" ) );
+ assertTrue( "depend-on-all should be present", sortedCreatorIds.contains( "depend-on-all" ) );
+ assertTrue( "last should be present", sortedCreatorIds.contains( "last" ) );
// "last" has to be last
- Assert.assertTrue( "last creator should be last",
+ assertTrue( "last creator should be last",
sortedCreatorIds.indexOf( "last" ) == sortedCreatorIds.size() - 1 );
- Assert.assertTrue( "depend-on-all should be next to last",
+ assertTrue( "depend-on-all should be next to last",
sortedCreatorIds.indexOf( "depend-on-all" ) == sortedCreatorIds.size() - 2 );
}
+ @Test
public void testLookupListWithNonExistentCreatorDependency()
throws Exception
{
- final List<IndexCreator> creators =
- new ArrayList<>( getContainer().lookupList( IndexCreator.class ) );
-
+ List<IndexCreator> myCreators = new ArrayList<>( creators );
// now we add spoofs to it, this one depends on non existent creator. Note: we add it as 1st intentionally
- creators.add( 0,
+ myCreators.add( 0,
new SpoofIndexCreator( "non-satisfyable", Arrays.asList( "this-creator-i-depend-on-does-not-exists" ) ) );
try
{
- final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( creators );
+ final List<IndexCreator> sortedCreators = IndexCreatorSorter.sort( myCreators );
- Assert.fail( "IndexCreator list is not satisfyable!" );
+ fail( "IndexCreator list is not satisfyable!" );
}
catch ( IllegalArgumentException e )
{
// good, check message
final String message = e.getMessage();
- Assert.assertTrue( "Exception message should mention the problematic creator's ID",
+ assertTrue( "Exception message should mention the problematic creator's ID",
message.contains( "non-satisfyable" ) );
- Assert.assertTrue( "Exception message should mention the missing creator's ID",
+ assertTrue( "Exception message should mention the missing creator's ID",
message.contains( "this-creator-i-depend-on-does-not-exists" ) );
}
}
diff --git a/indexer-examples/indexer-examples-basic/pom.xml b/indexer-examples/indexer-examples-basic/pom.xml
index 6d35f96..6deac48 100644
--- a/indexer-examples/indexer-examples-basic/pom.xml
+++ b/indexer-examples/indexer-examples-basic/pom.xml
@@ -67,18 +67,10 @@ under the License.
<scope>compile</scope>
</dependency>
- <!-- For ResourceFetcher implementation, if used -->
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-http-lightweight</artifactId>
- <version>${wagon.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <!-- Runtime: DI, but using Plexus Shim as we use Wagon -->
+ <!-- Runtime: DI -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
- <artifactId>org.eclipse.sisu.plexus</artifactId>
+ <artifactId>org.eclipse.sisu.inject</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
@@ -86,6 +78,16 @@ under the License.
</dependency>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java b/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
index ace53d5..0a8b92f 100644
--- a/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
+++ b/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/index/examples/BasicUsageExample.java
@@ -19,6 +19,10 @@ package org.apache.maven.index.examples;
* under the License.
*/
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiBits;
@@ -50,24 +54,20 @@ import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.IndexUpdateResult;
import org.apache.maven.index.updater.IndexUpdater;
import org.apache.maven.index.updater.ResourceFetcher;
-import org.apache.maven.index.updater.WagonHelper;
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.wagon.observers.AbstractTransferListener;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.PlexusContainerException;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.util.version.GenericVersionScheme;
import org.eclipse.aether.version.InvalidVersionSpecificationException;
import org.eclipse.aether.version.Version;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
@@ -76,51 +76,33 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
+import static java.util.Objects.requireNonNull;
+
/**
* Collection of some use cases.
*/
+@Singleton
+@Named
public class BasicUsageExample
{
- public static void main( String[] args )
- throws Exception
- {
- new BasicUsageExample().perform();
- }
-
- // ==
-
- private final PlexusContainer plexusContainer;
-
private final Indexer indexer;
private final IndexUpdater indexUpdater;
- private final Wagon httpWagon;
+ private final Map<String, IndexCreator> indexCreators;
private IndexingContext centralContext;
- public BasicUsageExample()
- throws PlexusContainerException, ComponentLookupException
+ @Inject
+ public BasicUsageExample( Indexer indexer, IndexUpdater indexUpdater, Map<String, IndexCreator> indexCreators )
{
- // here we create Plexus container, the Maven default IoC container
- // Plexus falls outside of MI scope, just accept the fact that
- // MI is a Plexus component ;)
- // If needed more info, ask on Maven Users list or Plexus Users list
- // google is your friend!
- final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
- config.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
- this.plexusContainer = new DefaultPlexusContainer( config );
-
- // lookup the indexer components from plexus
- this.indexer = plexusContainer.lookup( Indexer.class );
- this.indexUpdater = plexusContainer.lookup( IndexUpdater.class );
- // lookup wagon used to remotely fetch index
- this.httpWagon = plexusContainer.lookup( Wagon.class, "http" );
-
+ this.indexer = requireNonNull( indexer );
+ this.indexUpdater = requireNonNull( indexUpdater );
+ this.indexCreators = requireNonNull( indexCreators );
}
public void perform()
- throws IOException, ComponentLookupException, InvalidVersionSpecificationException
+ throws IOException, InvalidVersionSpecificationException
{
// Files where local cache is (if any) and Lucene Index should be located
File centralLocalCache = new File( "target/central-cache" );
@@ -128,9 +110,9 @@ public class BasicUsageExample
// Creators we want to use (search for fields it defines)
List<IndexCreator> indexers = new ArrayList<>();
- indexers.add( plexusContainer.lookup( IndexCreator.class, "min" ) );
- indexers.add( plexusContainer.lookup( IndexCreator.class, "jarContent" ) );
- indexers.add( plexusContainer.lookup( IndexCreator.class, "maven-plugin" ) );
+ indexers.add( requireNonNull( indexCreators.get( "min" ) ) );
+ indexers.add( requireNonNull( indexCreators.get( "jarContent" ) ) );
+ indexers.add( requireNonNull( indexCreators.get( "maven-plugin" ) ) );
// Create context for central repository index
centralContext =
@@ -147,31 +129,8 @@ public class BasicUsageExample
Instant updateStart = Instant.now();
System.out.println( "Updating Index..." );
System.out.println( "This might take a while on first run, so please be patient!" );
- // Create ResourceFetcher implementation to be used with IndexUpdateRequest
- // Here, we use Wagon based one as shorthand, but all we need is a ResourceFetcher implementation
- TransferListener listener = new AbstractTransferListener()
- {
- Instant start;
- public void transferStarted( TransferEvent transferEvent )
- {
- start = Instant.now();
- System.out.print( " Downloading " + transferEvent.getResource().getName() );
- }
-
- public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
- {
- }
-
- public void transferCompleted( TransferEvent transferEvent )
- {
- System.out.println( " - Done in "
- + Duration.between( start, Instant.now() ).getSeconds() + " sec" );
- }
- };
- ResourceFetcher resourceFetcher = new WagonHelper.WagonFetcher( httpWagon, listener, null, null );
-
Date centralContextCurrentTimestamp = centralContext.getTimestamp();
- IndexUpdateRequest updateRequest = new IndexUpdateRequest( centralContext, resourceFetcher );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( centralContext, new Java11HttpClient() );
IndexUpdateResult updateResult = indexUpdater.fetchAndUpdateIndex( updateRequest );
if ( updateResult.isFullUpdate() )
{
@@ -393,4 +352,50 @@ public class BasicUsageExample
System.out.println( "Total record hits: " + response.getTotalHitsCount() );
System.out.println();
}
+
+ private static class Java11HttpClient implements ResourceFetcher
+ {
+ private final HttpClient client = HttpClient.newBuilder().followRedirects( HttpClient.Redirect.NEVER ).build();
+
+ private URI uri;
+
+ @Override
+ public void connect( String id, String url ) throws IOException
+ {
+ this.uri = URI.create( url + "/" );
+ }
+
+ @Override
+ public void disconnect() throws IOException
+ {
+
+ }
+
+ @Override
+ public InputStream retrieve( String name ) throws IOException, FileNotFoundException
+ {
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri( uri.resolve( name ) )
+ .GET()
+ .build();
+ try
+ {
+ HttpResponse<InputStream> response = client.send( request, HttpResponse.BodyHandlers.ofInputStream() );
+ if ( response.statusCode() == HttpURLConnection.HTTP_OK )
+ {
+ return response.body();
+ }
+ else
+ {
+ throw new IOException( "Unexpected response: " + response );
+ }
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ throw new IOException( e );
+ }
+ }
+ }
+
}
diff --git a/indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java b/indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java
index 13d5dff..291acab 100644
--- a/indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java
+++ b/indexer-examples/indexer-examples-basic/src/test/java/org/apache/maven/index/examples/BasicUsageExampleTest.java
@@ -19,14 +19,20 @@ package org.apache.maven.index.examples;
* under the License.
*/
-import junit.framework.TestCase;
+import com.google.inject.Guice;
+import org.eclipse.sisu.launch.Main;
+import org.eclipse.sisu.space.BeanScanning;
+import org.junit.Test;
public class BasicUsageExampleTest
- extends TestCase
{
+ @Test
public void testApp()
- throws Exception
+ throws Exception
{
- BasicUsageExample.main( null );
+ final com.google.inject.Module app = Main.wire(
+ BeanScanning.INDEX
+ );
+ Guice.createInjector( app ).getInstance( BasicUsageExample.class ).perform();
}
}
diff --git a/indexer-examples/indexer-examples-spring/pom.xml b/indexer-examples/indexer-examples-spring/pom.xml
index 1c7b3af..4c110f1 100644
--- a/indexer-examples/indexer-examples-spring/pom.xml
+++ b/indexer-examples/indexer-examples-spring/pom.xml
@@ -35,7 +35,7 @@ under the License.
</description>
<properties>
- <version.spring>5.3.22</version.spring>
+ <version.spring>5.3.23</version.spring>
</properties>
<build>
@@ -53,26 +53,26 @@ under the License.
<dependencies>
<!-- For search app in general -->
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <scope>compile</scope>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.2</version>
</dependency>
<dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>compile</scope>
</dependency>
<dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <scope>test</scope>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>compile</scope>
</dependency>
<dependency>
<!-- This dependency is required in order to intercept Spring logging and handle it through Logback + SLF4J,
as it would otherwise use commons-logging and do it's own other thing. -->
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
- <scope>test</scope>
+ <scope>compile</scope>
</dependency>
<dependency>
@@ -88,18 +88,10 @@ under the License.
<scope>test</scope>
</dependency>
- <!-- For ResourceFetcher implementation, if used -->
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-http-lightweight</artifactId>
- <version>${wagon.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <!-- Runtime: DI, but using Plexus Shim as we use Wagon -->
+ <!-- Runtime: DI -->
<dependency>
<groupId>org.eclipse.sisu</groupId>
- <artifactId>org.eclipse.sisu.plexus</artifactId>
+ <artifactId>org.eclipse.sisu.inject</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
@@ -136,6 +128,11 @@ under the License.
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
diff --git a/indexer-examples/indexer-examples-spring/src/test/java/org/apache/maven/index/examples/SpringUsageExampleTest.java b/indexer-examples/indexer-examples-spring/src/test/java/org/apache/maven/index/examples/SpringUsageExampleTest.java
index 7ebd34d..d481d81 100644
--- a/indexer-examples/indexer-examples-spring/src/test/java/org/apache/maven/index/examples/SpringUsageExampleTest.java
+++ b/indexer-examples/indexer-examples-spring/src/test/java/org/apache/maven/index/examples/SpringUsageExampleTest.java
@@ -36,7 +36,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import static junit.framework.TestCase.assertFalse;
+
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
diff --git a/indexer-examples/indexer-examples-spring/src/test/resources/META-INF/spring/indexer-examples-context.xml b/indexer-examples/indexer-examples-spring/src/test/resources/META-INF/spring/indexer-examples-context.xml
deleted file mode 100644
index a51511d..0000000
--- a/indexer-examples/indexer-examples-spring/src/test/resources/META-INF/spring/indexer-examples-context.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- 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.
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
-
- <context:component-scan base-package="org.apache.maven.index.examples"/>
-
- <bean id="indexerConfiguration" class="org.apache.maven.index.examples.indexing.IndexerConfiguration">
- <constructor-arg name="indexer" ref="indexer"/>
- <constructor-arg name="indexers" ref="indexers"/>
- <constructor-arg name="scanner" ref="scanner"/>
- </bean>
-
- <bean id="repositoryIndexerFactory" class="org.apache.maven.index.examples.indexing.RepositoryIndexerFactory"/>
-
- <bean id="repositoryIndexManager" class="org.apache.maven.index.examples.indexing.RepositoryIndexManager"/>
-
- <bean id="artifactIndexingService" class="org.apache.maven.index.examples.services.impl.ArtifactIndexingServiceImpl"/>
-
- <bean id="repositoryBooter" class="org.apache.maven.index.examples.boot.RepositoryBooter"/>
-
-</beans>
diff --git a/indexer-examples/indexer-examples-spring/src/test/resources/logback.xml b/indexer-examples/indexer-examples-spring/src/test/resources/logback.xml
deleted file mode 100644
index 0348ce5..0000000
--- a/indexer-examples/indexer-examples-spring/src/test/resources/logback.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<!--
- 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.
--->
-
-<configuration>
-
- <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
- <encoder>
- <pattern>[%p] %c - %m%n</pattern>
- </encoder>
- </appender>
-
- <logger name="org.springframework" level="ERROR" />
- <logger name="org.apache.maven.index.examples.indexing" level="DEBUG" />
- <logger name="org.apache.maven.index.examples.boot" level="ERROR" />
-
- <root level="ERROR">
- <appender-ref ref="stdout" />
- </root>
-
-</configuration>
\ No newline at end of file
diff --git a/indexer-reader/pom.xml b/indexer-reader/pom.xml
index a32426b..fb7875b 100644
--- a/indexer-reader/pom.xml
+++ b/indexer-reader/pom.xml
@@ -38,6 +38,16 @@ under the License.
<dependencies>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/ChunkReaderTest.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/ChunkReaderTest.java
index eb6a393..1d701bf 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/ChunkReaderTest.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/ChunkReaderTest.java
@@ -32,8 +32,8 @@ import java.util.List;
import java.util.Map;
import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
/**
* UT for {@link ChunkReader}
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexReaderTest.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexReaderTest.java
index cc5c2d2..c300613 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexReaderTest.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexReaderTest.java
@@ -33,12 +33,11 @@ import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-import static com.google.common.collect.Iterables.transform;
import static org.apache.maven.index.reader.TestUtils.expandFunction;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
/**
* UT for {@link IndexReader}
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexWriterTest.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexWriterTest.java
index 48aadb2..46acfd4 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexWriterTest.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/IndexWriterTest.java
@@ -26,10 +26,9 @@ import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-import static com.google.common.collect.Iterables.transform;
import static org.apache.maven.index.reader.TestUtils.expandFunction;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
/**
* UT for {@link IndexWriter}
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
index 72f1040..0b6055a 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/TestSupport.java
@@ -28,14 +28,13 @@ import org.junit.rules.TestName;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
/**
* Test support.
diff --git a/indexer-reader/src/test/java/org/apache/maven/index/reader/TransformTest.java b/indexer-reader/src/test/java/org/apache/maven/index/reader/TransformTest.java
index 1ea6155..7cf6bc5 100644
--- a/indexer-reader/src/test/java/org/apache/maven/index/reader/TransformTest.java
+++ b/indexer-reader/src/test/java/org/apache/maven/index/reader/TransformTest.java
@@ -31,12 +31,11 @@ import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-import static com.google.common.collect.Iterables.transform;
import static org.apache.maven.index.reader.TestUtils.compactFunction;
import static org.apache.maven.index.reader.TestUtils.decorate;
import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
/**
* UT for {@link RecordCompactor} and {@linl RecordExpander}.
diff --git a/pom.xml b/pom.xml
index e01c256..6630c55 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,10 +100,8 @@ under the License.
<maven.version>3.8.6</maven.version>
<resolver.version>1.8.2</resolver.version>
<archetype.version>3.2.1</archetype.version>
- <wagon.version>3.5.2</wagon.version>
<surefire.version>3.0.0-M7</surefire.version>
<slf4j.version>1.7.36</slf4j.version>
- <logback.version>1.4.4</logback.version>
<maven.site.path>maven-indexer-archives/maven-indexer-LATEST</maven.site.path>
<project.build.outputTimestamp>2022-06-03T08:51:57Z</project.build.outputTimestamp>
</properties>
@@ -129,18 +127,6 @@ under the License.
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>${logback.version}</version>
- <optional>true</optional>
- </dependency>
<dependency>
<!-- This dependency is required in order to intercept Spring logging and handle it through Logback + SLF4J,
as it would otherwise use commons-logging and do it's own other thing. -->
@@ -175,18 +161,6 @@ under the License.
<version>${eclipse-sisu.version}</version>
</dependency>
- <dependency>
- <groupId>org.eclipse.sisu</groupId>
- <artifactId>org.eclipse.sisu.plexus</artifactId>
- <version>${eclipse-sisu.version}</version>
- <exclusions>
- <exclusion>
- <groupId>javax.annotation</groupId>
- <artifactId>jsr250-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
-
<!-- Lucene -->
<dependency>
<groupId>org.apache.lucene</groupId>
@@ -244,13 +218,6 @@ under the License.
<version>${maven.version}</version>
</dependency>
- <!-- Wagon, as optional for those want to use ResourceFetcher backed by Wagons -->
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-provider-api</artifactId>
- <version>${wagon.version}</version>
- </dependency>
-
<!-- For org.apache.maven.archetype.source.ArchetypeDataSource helper -->
<dependency>
<groupId>org.apache.maven.archetype</groupId>
@@ -259,6 +226,20 @@ under the License.
</dependency>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -286,13 +267,6 @@ under the License.
<version>9.4.49.v20220914</version>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-http</artifactId>
- <version>${wagon.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</dependencyManagement>
@@ -309,6 +283,11 @@ under the License.
<build>
<pluginManagement>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>3.4.0</version>
+ </plugin>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
@@ -367,11 +346,14 @@ under the License.
</plugins>
</pluginManagement>
<plugins>
+ <plugin>
+ <groupId>org.eclipse.sisu</groupId>
+ <artifactId>sisu-maven-plugin</artifactId>
+ </plugin>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
</plugin>
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
diff --git a/search-api/pom.xml b/search-api/pom.xml
index a338834..f4640d8 100644
--- a/search-api/pom.xml
+++ b/search-api/pom.xml
@@ -35,6 +35,16 @@ under the License.
<dependencies>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
diff --git a/search-backend-indexer/pom.xml b/search-backend-indexer/pom.xml
index e5a2cee..64c6870 100644
--- a/search-backend-indexer/pom.xml
+++ b/search-backend-indexer/pom.xml
@@ -45,6 +45,16 @@ under the License.
</dependency>
<!-- Test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -59,22 +69,13 @@ under the License.
<dependency>
<groupId>org.eclipse.sisu</groupId>
- <artifactId>org.eclipse.sisu.plexus</artifactId>
- <scope>test</scope>
+ <artifactId>org.eclipse.sisu.inject</artifactId>
</dependency>
-
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<scope>test</scope>
</dependency>
-
- <dependency>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-http-lightweight</artifactId>
- <version>${wagon.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/search-backend-indexer/src/test/java/org/apache/maven/search/backend/indexer/internal/IndexerCoreSearchBackendImplTest.java b/search-backend-indexer/src/test/java/org/apache/maven/search/backend/indexer/internal/IndexerCoreSearchBackendImplTest.java
index 2250841..d9fac36 100644
--- a/search-backend-indexer/src/test/java/org/apache/maven/search/backend/indexer/internal/IndexerCoreSearchBackendImplTest.java
+++ b/search-backend-indexer/src/test/java/org/apache/maven/search/backend/indexer/internal/IndexerCoreSearchBackendImplTest.java
@@ -19,53 +19,57 @@ package org.apache.maven.search.backend.indexer.internal;
* under the License.
*/
+import javax.inject.Inject;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
import org.apache.maven.index.Indexer;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.search.MAVEN;
-import org.apache.maven.search.Record;
-import org.apache.maven.search.SearchRequest;
-import org.apache.maven.search.SearchResponse;
import org.apache.maven.index.updater.IndexUpdateRequest;
import org.apache.maven.index.updater.IndexUpdateResult;
import org.apache.maven.index.updater.IndexUpdater;
import org.apache.maven.index.updater.ResourceFetcher;
-import org.apache.maven.index.updater.WagonHelper;
+import org.apache.maven.search.MAVEN;
+import org.apache.maven.search.Record;
+import org.apache.maven.search.SearchRequest;
+import org.apache.maven.search.SearchResponse;
import org.apache.maven.search.request.FieldQuery;
-import org.apache.maven.wagon.Wagon;
-import org.apache.maven.wagon.events.TransferEvent;
-import org.apache.maven.wagon.events.TransferListener;
-import org.apache.maven.wagon.observers.AbstractTransferListener;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusContainer;
+import org.eclipse.sisu.launch.InjectedTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import java.io.File;
-import java.io.IOException;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
+import static java.util.Objects.requireNonNull;
import static org.apache.maven.search.request.BooleanQuery.and;
import static org.apache.maven.search.request.Query.query;
-@Ignore("This is more a showcase")
-public class IndexerCoreSearchBackendImplTest
+@Ignore( "This is not a test, is more a showcase" )
+public class IndexerCoreSearchBackendImplTest extends InjectedTest
{
- private PlexusContainer plexusContainer;
-
+ @Inject
private Indexer indexer;
+ @Inject
private IndexUpdater indexUpdater;
- private Wagon httpWagon;
+ @Inject
+ private Map<String, IndexCreator> indexCreators;
private IndexingContext centralContext;
@@ -117,7 +121,7 @@ public class IndexerCoreSearchBackendImplTest
private void dumpPage( SearchResponse searchResponse ) throws IOException
{
AtomicInteger counter = new AtomicInteger( 0 );
- System.out.println("QUERY: " + searchResponse.getSearchRequest().getQuery().toString());
+ System.out.println( "QUERY: " + searchResponse.getSearchRequest().getQuery().toString() );
dumpSingle( counter, searchResponse.getPage() );
while ( searchResponse.getCurrentHits() > 0 )
{
@@ -135,25 +139,15 @@ public class IndexerCoreSearchBackendImplTest
@Before
public void prepareAndUpdateBackend() throws Exception
{
- final DefaultContainerConfiguration config = new DefaultContainerConfiguration();
- config.setClassPathScanning( PlexusConstants.SCANNING_CACHE );
- this.plexusContainer = new DefaultPlexusContainer( config );
-
- // lookup the indexer components from plexus
- this.indexer = plexusContainer.lookup( Indexer.class );
- this.indexUpdater = plexusContainer.lookup( IndexUpdater.class );
- // lookup wagon used to remotely fetch index
- this.httpWagon = plexusContainer.lookup( Wagon.class, "http" );
-
// Files where local cache is (if any) and Lucene Index should be located
File centralLocalCache = new File( "target/central-cache" );
File centralIndexDir = new File( "target/central-index" );
// Creators we want to use (search for fields it defines)
List<IndexCreator> indexers = new ArrayList<>();
- indexers.add( plexusContainer.lookup( IndexCreator.class, "min" ) );
- indexers.add( plexusContainer.lookup( IndexCreator.class, "jarContent" ) );
- indexers.add( plexusContainer.lookup( IndexCreator.class, "maven-plugin" ) );
+ indexers.add( requireNonNull( indexCreators.get( "min" ) ) );
+ indexers.add( requireNonNull( indexCreators.get( "jarContent" ) ) );
+ indexers.add( requireNonNull( indexCreators.get( "maven-plugin" ) ) );
// Create context for central repository index
centralContext = indexer.createIndexingContext( "central-context", "central", centralLocalCache,
@@ -166,28 +160,9 @@ public class IndexerCoreSearchBackendImplTest
// Preferred frequency is once a week.
System.out.println( "Updating Index..." );
System.out.println( "This might take a while on first run, so please be patient!" );
- // Create ResourceFetcher implementation to be used with IndexUpdateRequest
- // Here, we use Wagon based one as shorthand, but all we need is a ResourceFetcher implementation
- TransferListener listener = new AbstractTransferListener()
- {
- public void transferStarted( TransferEvent transferEvent )
- {
- System.out.print( " Downloading " + transferEvent.getResource().getName() );
- }
-
- public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
- {
- }
-
- public void transferCompleted( TransferEvent transferEvent )
- {
- System.out.println( " - Done" );
- }
- };
- ResourceFetcher resourceFetcher = new WagonHelper.WagonFetcher( httpWagon, listener, null, null );
Date centralContextCurrentTimestamp = centralContext.getTimestamp();
- IndexUpdateRequest updateRequest = new IndexUpdateRequest( centralContext, resourceFetcher );
+ IndexUpdateRequest updateRequest = new IndexUpdateRequest( centralContext, new Java11HttpClient() );
IndexUpdateResult updateResult = indexUpdater.fetchAndUpdateIndex( updateRequest );
if ( updateResult.isFullUpdate() )
{
@@ -200,7 +175,8 @@ public class IndexerCoreSearchBackendImplTest
else
{
System.out.println(
- "Incremental update happened, change covered " + centralContextCurrentTimestamp + " - " + updateResult.getTimestamp() + " period." );
+ "Incremental update happened, change covered " + centralContextCurrentTimestamp + " - "
+ + updateResult.getTimestamp() + " period." );
}
System.out.println();
@@ -211,7 +187,6 @@ public class IndexerCoreSearchBackendImplTest
public void cleanup() throws IOException
{
indexer.closeIndexingContext( centralContext, false );
- plexusContainer.dispose();
}
@Test
@@ -226,7 +201,8 @@ public class IndexerCoreSearchBackendImplTest
@Test
public void g() throws IOException
{
- SearchRequest searchRequest = new SearchRequest( FieldQuery.fieldQuery( MAVEN.GROUP_ID, "org.apache.maven.plugins" ) );
+ SearchRequest searchRequest =
+ new SearchRequest( FieldQuery.fieldQuery( MAVEN.GROUP_ID, "org.apache.maven.plugins" ) );
SearchResponse searchResponse = backend.search( searchRequest );
System.out.println( "TOTAL HITS: " + searchResponse.getTotalHits() );
dumpPage( searchResponse );
@@ -235,8 +211,9 @@ public class IndexerCoreSearchBackendImplTest
@Test
public void ga() throws IOException
{
- SearchRequest searchRequest = new SearchRequest( and( FieldQuery.fieldQuery( MAVEN.GROUP_ID, "org.apache.maven.plugins" ),
- FieldQuery.fieldQuery( MAVEN.ARTIFACT_ID, "maven-clean-plugin" ) ) );
+ SearchRequest searchRequest =
+ new SearchRequest( and( FieldQuery.fieldQuery( MAVEN.GROUP_ID, "org.apache.maven.plugins" ),
+ FieldQuery.fieldQuery( MAVEN.ARTIFACT_ID, "maven-clean-plugin" ) ) );
SearchResponse searchResponse = backend.search( searchRequest );
System.out.println( "TOTAL HITS: " + searchResponse.getTotalHits() );
dumpPage( searchResponse );
@@ -245,8 +222,10 @@ public class IndexerCoreSearchBackendImplTest
@Test
public void gav() throws IOException
{
- SearchRequest searchRequest = new SearchRequest( and( FieldQuery.fieldQuery( MAVEN.GROUP_ID, "org.apache.maven.plugins" ),
- FieldQuery.fieldQuery( MAVEN.ARTIFACT_ID, "maven-clean-plugin" ), FieldQuery.fieldQuery( MAVEN.VERSION, "3.1.0" ) ) );
+ SearchRequest searchRequest =
+ new SearchRequest( and( FieldQuery.fieldQuery( MAVEN.GROUP_ID, "org.apache.maven.plugins" ),
+ FieldQuery.fieldQuery( MAVEN.ARTIFACT_ID, "maven-clean-plugin" ),
+ FieldQuery.fieldQuery( MAVEN.VERSION, "3.1.0" ) ) );
SearchResponse searchResponse = backend.search( searchRequest );
System.out.println( "TOTAL HITS: " + searchResponse.getTotalHits() );
dumpPage( searchResponse );
@@ -265,7 +244,8 @@ public class IndexerCoreSearchBackendImplTest
@Test
public void cn() throws IOException
{
- SearchRequest searchRequest = new SearchRequest( FieldQuery.fieldQuery( MAVEN.CLASS_NAME, "MavenRepositorySystem" ) );
+ SearchRequest searchRequest =
+ new SearchRequest( FieldQuery.fieldQuery( MAVEN.CLASS_NAME, "MavenRepositorySystem" ) );
SearchResponse searchResponse = backend.search( searchRequest );
System.out.println( "TOTAL HITS: " + searchResponse.getTotalHits() );
dumpPage( searchResponse );
@@ -280,4 +260,49 @@ public class IndexerCoreSearchBackendImplTest
System.out.println( "TOTAL HITS: " + searchResponse.getTotalHits() );
dumpPage( searchResponse );
}
+
+ private static class Java11HttpClient implements ResourceFetcher
+ {
+ private final HttpClient client = HttpClient.newBuilder().followRedirects( HttpClient.Redirect.NEVER ).build();
+
+ private URI uri;
+
+ @Override
+ public void connect( String id, String url ) throws IOException
+ {
+ this.uri = URI.create( url + "/" );
+ }
+
+ @Override
+ public void disconnect() throws IOException
+ {
+
+ }
+
+ @Override
+ public InputStream retrieve( String name ) throws IOException, FileNotFoundException
+ {
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri( uri.resolve( name ) )
+ .GET()
+ .build();
+ try
+ {
+ HttpResponse<InputStream> response = client.send( request, HttpResponse.BodyHandlers.ofInputStream() );
+ if ( response.statusCode() == HttpURLConnection.HTTP_OK )
+ {
+ return response.body();
+ }
+ else
+ {
+ throw new IOException( "Unexpected response: " + response );
+ }
+ }
+ catch ( InterruptedException e )
+ {
+ Thread.currentThread().interrupt();
+ throw new IOException( e );
+ }
+ }
+ }
}
diff --git a/search-backend-smo/pom.xml b/search-backend-smo/pom.xml
index 6a979f4..6fa8939 100644
--- a/search-backend-smo/pom.xml
+++ b/search-backend-smo/pom.xml
@@ -52,6 +52,11 @@ under the License.
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/search-backend-smo/src/test/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImplTest.java b/search-backend-smo/src/test/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImplTest.java
index 4b29f15..5c55a10 100644
--- a/search-backend-smo/src/test/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImplTest.java
+++ b/search-backend-smo/src/test/java/org/apache/maven/search/backend/smo/internal/SmoSearchBackendImplTest.java
@@ -35,7 +35,7 @@ import org.apache.maven.search.request.Query;
import org.junit.Ignore;
import org.junit.Test;
-@Ignore( "This is more a showcase" )
+@Ignore( "This is not a test, is more a showcase" )
public class SmoSearchBackendImplTest
{
private final SmoSearchBackendImpl backend = new SmoSearchBackendImpl();