aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-10-16 12:35:38 +0000
committerBrett Porter <brett@apache.org>2009-10-16 12:35:38 +0000
commite89326d687c1964ded21519c65bc59bcdf9f0526 (patch)
tree93548dcff1bea21d2b5e036720d71fb87c11591f /archiva-modules/archiva-base/archiva-repository-scanner/src/test/java
parent4e4362191f12adbffc2af970b6e1e4affea94954 (diff)
downloadarchiva-e89326d687c1964ded21519c65bc59bcdf9f0526.tar.gz
archiva-e89326d687c1964ded21519c65bc59bcdf9f0526.zip
[MRM-1025] merge -r721944:723577 from former MRM-1025 branch, now aligned to trunk
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@825867 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-scanner/src/test/java')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java97
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java114
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersStub.java42
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java503
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java419
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java88
6 files changed, 1263 insertions, 0 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java
new file mode 100644
index 000000000..6e39db51a
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/InvalidScanConsumer.java
@@ -0,0 +1,97 @@
+package org.apache.archiva.repository.scanner;
+
+/*
+ * 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.util.Date;
+import java.util.List;
+
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
+
+/**
+ * InvalidScanConsumer
+ *
+ * @version $Id$
+ */
+public class InvalidScanConsumer
+ extends AbstractMonitoredConsumer
+ implements InvalidRepositoryContentConsumer
+{
+ /**
+ * @plexus.configuration default-value="unset-id"
+ */
+ private String id = "unset-id";
+
+ private int processCount = 0;
+
+ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
+ throws ConsumerException
+ {
+ /* do nothing */
+ }
+
+ public void completeScan()
+ {
+ /* do nothing */
+ }
+
+ public List<String> getExcludes()
+ {
+ return null;
+ }
+
+ public List<String> getIncludes()
+ {
+ return null;
+ }
+
+ public void processFile( String path )
+ throws ConsumerException
+ {
+ processCount++;
+ }
+
+ public String getDescription()
+ {
+ return "Bad Content Scan Consumer (for testing)";
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+
+ public int getProcessCount()
+ {
+ return processCount;
+ }
+
+ public void setProcessCount( int processCount )
+ {
+ this.processCount = processCount;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java
new file mode 100644
index 000000000..8498b4dd8
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/KnownScanConsumer.java
@@ -0,0 +1,114 @@
+package org.apache.archiva.repository.scanner;
+
+/*
+ * 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+
+/**
+ * ScanConsumer
+ *
+ * @version $Id$
+ */
+public class KnownScanConsumer
+ extends AbstractMonitoredConsumer
+ implements KnownRepositoryContentConsumer
+{
+ private int processCount = 0;
+
+ private List<String> includes = new ArrayList<String>();
+
+ private boolean processUnmodified = false;
+
+ public List<String> getExcludes()
+ {
+ return null;
+ }
+
+ public void setIncludes( String includesArray[] )
+ {
+ this.includes.clear();
+ this.includes.addAll( Arrays.asList( includesArray ) );
+ }
+
+ public List<String> getIncludes()
+ {
+ return includes;
+ }
+
+ public String getId()
+ {
+ return "test-scan-consumer";
+ }
+
+ public String getDescription()
+ {
+ return "Scan Consumer (for testing)";
+ }
+
+ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
+ throws ConsumerException
+ {
+ /* do nothing */
+ }
+
+ public void processFile( String path )
+ throws ConsumerException
+ {
+ this.processCount++;
+ }
+
+ public void completeScan()
+ {
+ /* do nothing */
+ }
+
+ public int getProcessCount()
+ {
+ return processCount;
+ }
+
+ public void setProcessCount( int processCount )
+ {
+ this.processCount = processCount;
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+
+ public boolean isProcessUnmodified()
+ {
+ return processUnmodified;
+ }
+
+ public void setProcessUnmodified( boolean processUnmodified )
+ {
+ this.processUnmodified = processUnmodified;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersStub.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersStub.java
new file mode 100644
index 000000000..bd47bce23
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersStub.java
@@ -0,0 +1,42 @@
+package org.apache.archiva.repository.scanner;
+
+/*
+ * 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.util.Date;
+
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+
+public class RepositoryContentConsumersStub
+ extends RepositoryContentConsumers
+{
+ public RepositoryContentConsumersStub(ArchivaConfiguration archivaConfiguration)
+ {
+ super(archivaConfiguration);
+ }
+
+ @Override
+ public Date getStartTime()
+ {
+ Date startTimeForTest = new Date( System.currentTimeMillis() );
+ startTimeForTest.setTime( 12345678 );
+
+ return startTimeForTest;
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java
new file mode 100644
index 000000000..e6a5cc391
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java
@@ -0,0 +1,503 @@
+package org.apache.archiva.repository.scanner;
+
+/*
+ * 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.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.commons.lang.SystemUtils;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.MessageSourceResolvable;
+import org.springframework.context.NoSuchMessageException;
+import org.springframework.core.io.Resource;
+
+/**
+ * RepositoryContentConsumersTest
+ *
+ * @version $Id$
+ */
+public class RepositoryContentConsumersTest
+ extends PlexusInSpringTestCase
+{
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
+ */
+ @Override
+ protected String getSpringConfigLocation()
+ {
+ return "org/apache/maven/archiva/repository/spring-context.xml";
+ }
+
+ protected ManagedRepositoryConfiguration createRepository( String id, String name, File location )
+ {
+ ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setLocation( location.getAbsolutePath() );
+ return repo;
+ }
+
+ protected RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
+ {
+ RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setUrl( url );
+ return repo;
+ }
+
+ private RepositoryContentConsumers lookupRepositoryConsumers()
+ throws Exception
+ {
+ ArchivaConfiguration configuration = (ArchivaConfiguration)lookup(ArchivaConfiguration.class);
+
+ RepositoryContentConsumers consumerUtilStub = new RepositoryContentConsumersStub(configuration);
+
+ RepositoryContentConsumers consumerUtil = (RepositoryContentConsumers) lookup( RepositoryContentConsumers.class
+ .getName() );
+ ApplicationContext context = new MockApplicationContext(consumerUtil.getAvailableKnownConsumers(), consumerUtil.getAvailableInvalidConsumers());
+
+ consumerUtilStub.setApplicationContext(context);
+ consumerUtilStub.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers() );
+ consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers() );
+ consumerUtilStub.setArchivaConfiguration( configuration );
+
+ assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtilStub );
+
+ return consumerUtilStub;
+ }
+
+ public void testGetSelectedKnownIds()
+ throws Exception
+ {
+ RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
+
+ String expectedKnownIds[] = new String[] {
+ "update-db-artifact",
+ "create-missing-checksums",
+ "update-db-repository-metadata",
+ "validate-checksum",
+ "validate-signature",
+ "index-content",
+ "auto-remove",
+ "auto-rename" };
+
+ List<String> knownConsumers = consumerutil.getSelectedKnownConsumerIds();
+ assertNotNull( "Known Consumer IDs should not be null", knownConsumers );
+ assertEquals( "Known Consumer IDs.size", expectedKnownIds.length, knownConsumers.size() );
+
+ for ( String expectedId : expectedKnownIds )
+ {
+ assertTrue( "Known id [" + expectedId + "] exists.", knownConsumers.contains( expectedId ) );
+ }
+ }
+
+ public void testGetSelectedInvalidIds()
+ throws Exception
+ {
+ RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
+
+ String expectedInvalidIds[] = new String[] { "update-db-bad-content" };
+
+ List<String> invalidConsumers = consumerutil.getSelectedInvalidConsumerIds();
+ assertNotNull( "Invalid Consumer IDs should not be null", invalidConsumers );
+ assertEquals( "Invalid Consumer IDs.size", expectedInvalidIds.length, invalidConsumers.size() );
+
+ for ( String expectedId : expectedInvalidIds )
+ {
+ assertTrue( "Invalid id [" + expectedId + "] exists.", invalidConsumers.contains( expectedId ) );
+ }
+ }
+
+ public void testGetSelectedKnownConsumerMap()
+ throws Exception
+ {
+ RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
+
+ String expectedSelectedKnownIds[] = new String[] {
+ "update-db-artifact",
+ "create-missing-checksums",
+ "update-db-repository-metadata",
+ "validate-checksum",
+ "index-content",
+ "auto-remove",
+ "auto-rename" };
+
+ Map<String, KnownRepositoryContentConsumer> knownConsumerMap = consumerutil.getSelectedKnownConsumersMap();
+ assertNotNull( "Known Consumer Map should not be null", knownConsumerMap );
+ assertEquals( "Known Consumer Map.size", expectedSelectedKnownIds.length, knownConsumerMap.size() );
+
+ for ( String expectedId : expectedSelectedKnownIds )
+ {
+ KnownRepositoryContentConsumer consumer = knownConsumerMap.get( expectedId );
+ assertNotNull( "Known[" + expectedId + "] should not be null.", consumer );
+ assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId() );
+ }
+ }
+
+ public void testGetSelectedInvalidConsumerMap()
+ throws Exception
+ {
+ RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
+
+ String expectedSelectedInvalidIds[] = new String[] { "update-db-bad-content" };
+
+ Map<String, InvalidRepositoryContentConsumer> invalidConsumerMap = consumerutil
+ .getSelectedInvalidConsumersMap();
+ assertNotNull( "Invalid Consumer Map should not be null", invalidConsumerMap );
+ assertEquals( "Invalid Consumer Map.size", expectedSelectedInvalidIds.length, invalidConsumerMap.size() );
+
+ for ( String expectedId : expectedSelectedInvalidIds )
+ {
+ InvalidRepositoryContentConsumer consumer = invalidConsumerMap.get( expectedId );
+ assertNotNull( "Known[" + expectedId + "] should not be null.", consumer );
+ assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId() );
+ }
+ }
+
+ public void testGetAvailableKnownList()
+ throws Exception
+ {
+ RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
+
+ String expectedKnownIds[] = new String[] {
+ "update-db-artifact",
+ "create-missing-checksums",
+ "update-db-repository-metadata",
+ "validate-checksum",
+ "index-content",
+ "auto-remove",
+ "auto-rename",
+ "available-but-unselected" };
+
+ List<KnownRepositoryContentConsumer> knownConsumers = consumerutil.getAvailableKnownConsumers();
+ assertNotNull( "known consumers should not be null.", knownConsumers );
+ assertEquals( "known consumers", expectedKnownIds.length, knownConsumers.size() );
+
+ List<String> expectedIds = Arrays.asList( expectedKnownIds );
+ for ( KnownRepositoryContentConsumer consumer : knownConsumers )
+ {
+ assertTrue( "Consumer [" + consumer.getId() + "] returned by .getAvailableKnownConsumers() is unexpected.",
+ expectedIds.contains( consumer.getId() ) );
+ }
+ }
+
+ public void testGetAvailableInvalidList()
+ throws Exception
+ {
+ RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();
+
+ String expectedInvalidIds[] = new String[] { "update-db-bad-content", "move-to-trash-then-notify" };
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = consumerutil.getAvailableInvalidConsumers();
+ assertNotNull( "invalid consumers should not be null.", invalidConsumers );
+ assertEquals( "invalid consumers", expectedInvalidIds.length, invalidConsumers.size() );
+
+ List<String> expectedIds = Arrays.asList( expectedInvalidIds );
+ for ( InvalidRepositoryContentConsumer consumer : invalidConsumers )
+ {
+ assertTrue( "Consumer [" + consumer.getId()
+ + "] returned by .getAvailableInvalidConsumers() is unexpected.", expectedIds.contains( consumer
+ .getId() ) );
+ }
+ }
+
+ public void testExecution()
+ throws Exception
+ {
+ MockControl knownControl = MockControl.createNiceControl( KnownRepositoryContentConsumer.class );
+ RepositoryContentConsumers consumers = lookupRepositoryConsumers();
+ KnownRepositoryContentConsumer selectedKnownConsumer = (KnownRepositoryContentConsumer) knownControl.getMock();
+ KnownRepositoryContentConsumer unselectedKnownConsumer =
+ (KnownRepositoryContentConsumer) MockControl.createNiceControl(
+ KnownRepositoryContentConsumer.class ).getMock();
+
+ consumers.setApplicationContext(new MockApplicationContext(Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null));
+
+ consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) );
+
+ MockControl invalidControl = MockControl.createControl( InvalidRepositoryContentConsumer.class );
+ InvalidRepositoryContentConsumer selectedInvalidConsumer =
+ (InvalidRepositoryContentConsumer) invalidControl.getMock();
+ InvalidRepositoryContentConsumer unselectedInvalidConsumer =
+ (InvalidRepositoryContentConsumer) MockControl.createControl(
+ InvalidRepositoryContentConsumer.class ).getMock();
+
+ consumers.setApplicationContext( new MockApplicationContext(null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer )));
+
+ consumers.setSelectedInvalidConsumers( Collections.singletonList( selectedInvalidConsumer ) );
+
+ ManagedRepositoryConfiguration repo = createRepository( "id", "name", getTestFile( "target/test-repo" ) );
+ File testFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
+
+ Date startTime = new Date( System.currentTimeMillis() );
+ startTime.setTime( 12345678 );
+
+ selectedKnownConsumer.beginScan( repo, startTime );
+ selectedKnownConsumer.getExcludes();
+ knownControl.setReturnValue( Collections.EMPTY_LIST );
+ selectedKnownConsumer.getIncludes();
+ knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
+ selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ) );
+ // knownConsumer.completeScan();
+ knownControl.replay();
+
+ selectedInvalidConsumer.beginScan( repo, startTime );
+ // invalidConsumer.completeScan();
+ invalidControl.replay();
+
+ consumers.executeConsumers( repo, testFile, true );
+
+ knownControl.verify();
+ invalidControl.verify();
+
+ knownControl.reset();
+ invalidControl.reset();
+
+ File notIncludedTestFile = getTestFile( "target/test-repo/path/to/test-file.xml" );
+
+ selectedKnownConsumer.beginScan( repo, startTime );
+ selectedKnownConsumer.getExcludes();
+ knownControl.setReturnValue( Collections.EMPTY_LIST );
+ selectedKnownConsumer.getIncludes();
+ knownControl.setReturnValue( Collections.singletonList( "**/*.txt" ) );
+ // knownConsumer.completeScan();
+ knownControl.replay();
+
+ selectedInvalidConsumer.beginScan( repo, startTime );
+ selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ) );
+ selectedInvalidConsumer.getId();
+ invalidControl.setReturnValue( "invalid" );
+ // invalidConsumer.completeScan();
+ invalidControl.replay();
+
+ consumers.executeConsumers( repo, notIncludedTestFile, true );
+
+ knownControl.verify();
+ invalidControl.verify();
+
+ knownControl.reset();
+ invalidControl.reset();
+
+ File excludedTestFile = getTestFile( "target/test-repo/path/to/test-file.txt" );
+
+ selectedKnownConsumer.beginScan( repo, startTime );
+ selectedKnownConsumer.getExcludes();
+ knownControl.setReturnValue( Collections.singletonList( "**/test-file.txt" ) );
+ // knownConsumer.completeScan();
+ knownControl.replay();
+
+ selectedInvalidConsumer.beginScan( repo, startTime );
+ selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ) );
+ selectedInvalidConsumer.getId();
+ invalidControl.setReturnValue( "invalid" );
+ // invalidConsumer.completeScan();
+ invalidControl.replay();
+
+ consumers.executeConsumers( repo, excludedTestFile, true );
+
+ knownControl.verify();
+ invalidControl.verify();
+ }
+
+ /**
+ * Create an OS specific version of the filepath.
+ * Provide path in unix "/" format.
+ */
+ private String _OS( String path )
+ {
+ if ( SystemUtils.IS_OS_WINDOWS )
+ {
+ return path.replace( '/', '\\' );
+ }
+ return path;
+ }
+
+ private static Map convertToMap(List objects)
+ {
+ HashMap map = new HashMap();
+ for (Object o : objects)
+ {
+ map.put(o, o);
+ }
+ return map;
+ }
+
+ public class MockApplicationContext implements ApplicationContext
+ {
+ private List<KnownRepositoryContentConsumer> knownRepositoryContentConsumer;
+
+ private List<InvalidRepositoryContentConsumer> invalidRepositoryContentConsumers;
+
+ public MockApplicationContext(List<KnownRepositoryContentConsumer> knownRepositoryContentConsumer, List<InvalidRepositoryContentConsumer> invalidRepositoryContentConsumers)
+ {
+ this.knownRepositoryContentConsumer = knownRepositoryContentConsumer;
+ this.invalidRepositoryContentConsumers = invalidRepositoryContentConsumers;
+ }
+
+ public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getDisplayName() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getId() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public ApplicationContext getParent() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public long getStartupDate() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean containsBeanDefinition(String beanName) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public int getBeanDefinitionCount() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getBeanDefinitionNames() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getBeanNamesForType(Class type) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getBeanNamesForType(Class type, boolean includeNonSingletons, boolean allowEagerInit) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Map getBeansOfType(Class type) throws BeansException {
+ if (type == KnownRepositoryContentConsumer.class)
+ {
+ return convertToMap(knownRepositoryContentConsumer);
+ }
+ if (type == InvalidRepositoryContentConsumer.class)
+ {
+ return convertToMap(invalidRepositoryContentConsumers);
+ }
+ throw new UnsupportedOperationException("Should not have been called");
+ }
+
+ public Map getBeansOfType(Class type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean containsBean(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String[] getAliases(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getBean(String name) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getBean(String name, Class requiredType) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Object getBean(String name, Object[] args) throws BeansException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Class getType(String name) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isPrototype(String name) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean containsLocalBean(String name) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public BeanFactory getParentBeanFactory() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void publishEvent(ApplicationEvent event) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Resource[] getResources(String locationPattern) throws IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public ClassLoader getClassLoader() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Resource getResource(String location) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java
new file mode 100644
index 000000000..2f8c6408e
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryScannerTest.java
@@ -0,0 +1,419 @@
+package org.apache.archiva.repository.scanner;
+
+/*
+ * 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.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+/**
+ * RepositoryScannerTest
+ *
+ * @version $Id$
+ */
+public class RepositoryScannerTest
+ extends PlexusInSpringTestCase
+{
+ /**
+ * {@inheritDoc}
+ * @see org.codehaus.plexus.spring.PlexusInSpringTestCase#getSpringConfigLocation()
+ */
+ @Override
+ protected String getSpringConfigLocation()
+ {
+ return "org/apache/maven/archiva/repository/spring-context.xml";
+ }
+
+ protected ManagedRepositoryConfiguration createRepository( String id, String name, File location )
+ {
+ ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setLocation( location.getAbsolutePath() );
+ return repo;
+ }
+
+ protected RemoteRepositoryConfiguration createRemoteRepository( String id, String name, String url )
+ {
+ RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration();
+ repo.setId( id );
+ repo.setName( name );
+ repo.setUrl( url );
+ return repo;
+ }
+
+ private static final String[] ARTIFACT_PATTERNS =
+ new String[]{"**/*.jar", "**/*.pom", "**/*.rar", "**/*.zip", "**/*.war", "**/*.tar.gz"};
+
+ private ManagedRepositoryConfiguration createDefaultRepository()
+ {
+ File repoDir = new File( getBasedir(), "src/test/repositories/default-repository" );
+
+ assertTrue( "Default Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
+
+ return createRepository( "testDefaultRepo", "Test Default Repository", repoDir );
+ }
+
+ private ManagedRepositoryConfiguration createSimpleRepository()
+ throws IOException, ParseException
+ {
+ File srcDir = new File( getBasedir(), "src/test/repositories/simple-repository" );
+
+ File repoDir = getTestFile( "target/test-repos/simple-repository" );
+
+ FileUtils.deleteDirectory( repoDir );
+
+ FileUtils.copyDirectory( srcDir, repoDir );
+
+ File repoFile = new File( repoDir,
+ "groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom" );
+ repoFile.setLastModified( getTimestampAsMillis( "20050611.202024" ) );
+
+ assertTrue( "Simple Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
+
+ return createRepository( "testSimpleRepo", "Test Simple Repository", repoDir );
+ }
+
+ private static long getTimestampAsMillis( String timestamp )
+ throws ParseException
+ {
+ SimpleDateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss", Locale.US );
+ fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
+ return fmt.parse( timestamp ).getTime();
+ }
+
+ private ManagedRepositoryConfiguration createLegacyRepository()
+ {
+ File repoDir = new File( getBasedir(), "src/test/repositories/legacy-repository" );
+
+ assertTrue( "Legacy Test Repository should exist.", repoDir.exists() && repoDir.isDirectory() );
+
+ ManagedRepositoryConfiguration repo = createRepository( "testLegacyRepo", "Test Legacy Repository", repoDir );
+ repo.setLayout( "legacy" );
+
+ return repo;
+ }
+
+ private void assertMinimumHits( String msg, int minimumHitCount, long actualCount )
+ {
+ if ( actualCount < minimumHitCount )
+ {
+ fail( "Minimum hit count on " + msg + " not satisfied. Expected more than <" + minimumHitCount +
+ ">, but actually got <" + actualCount + ">." );
+ }
+ }
+
+ private RepositoryScanner lookupRepositoryScanner()
+ throws Exception
+ {
+ return (RepositoryScanner) lookup( RepositoryScanner.class );
+ }
+
+ private List<String> getIgnoreList()
+ {
+ List<String> ignores = new ArrayList<String>();
+ ignores.addAll( Arrays.asList( RepositoryScanner.IGNORABLE_CONTENT ) );
+ return ignores;
+ }
+
+ public void testTimestampRepositoryScanner()
+ throws Exception
+ {
+ ManagedRepositoryConfiguration repository = createSimpleRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setIncludes( ARTIFACT_PATTERNS );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+
+ RepositoryScanStatistics stats = scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(),
+ getTimestampAsMillis( "20061101.000000" ) );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertEquals( "Stats.totalFileCount", 4, stats.getTotalFileCount() );
+ assertEquals( "Stats.newFileCount", 3, stats.getNewFileCount() );
+ assertEquals( "Processed Count", 2, consumer.getProcessCount() );
+ assertEquals( "Processed Count (of invalid items)", 1, badconsumer.getProcessCount() );
+ }
+
+ public void testTimestampRepositoryScannerFreshScan()
+ throws Exception
+ {
+ ManagedRepositoryConfiguration repository = createSimpleRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setIncludes( ARTIFACT_PATTERNS );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats =
+ scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertEquals( "Stats.totalFileCount", 4, stats.getTotalFileCount() );
+ assertEquals( "Stats.newFileCount", 4, stats.getNewFileCount() );
+ assertEquals( "Processed Count", 3, consumer.getProcessCount() );
+ assertEquals( "Processed Count (of invalid items)", 1, badconsumer.getProcessCount() );
+ }
+
+ public void testTimestampRepositoryScannerProcessUnmodified()
+ throws Exception
+ {
+ ManagedRepositoryConfiguration repository = createSimpleRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setProcessUnmodified( true );
+ consumer.setIncludes( ARTIFACT_PATTERNS );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats = scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(),
+ getTimestampAsMillis( "20061101.000000" ) );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertEquals( "Stats.totalFileCount", 4, stats.getTotalFileCount() );
+ assertEquals( "Stats.newFileCount", 3, stats.getNewFileCount() );
+ assertEquals( "Processed Count", 3, consumer.getProcessCount() );
+ assertEquals( "Processed Count (of invalid items)", 1, badconsumer.getProcessCount() );
+ }
+
+ public void testDefaultRepositoryScanner()
+ throws Exception
+ {
+ ManagedRepositoryConfiguration repository = createDefaultRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setIncludes( new String[]{"**/*.jar", "**/*.war", "**/*.pom", "**/maven-metadata.xml", "**/*-site.xml",
+ "**/*.zip", "**/*.tar.gz", "**/*.sha1", "**/*.md5"} );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats =
+ scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertMinimumHits( "Stats.totalFileCount", 17, stats.getTotalFileCount() );
+ assertMinimumHits( "Processed Count", 17, consumer.getProcessCount() );
+ assertEquals( "Processed Count (of invalid items)", 6, badconsumer.getProcessCount() );
+ }
+
+ public void testDefaultRepositoryArtifactScanner()
+ throws Exception
+ {
+ List<String> actualArtifactPaths = new ArrayList<String>();
+
+ actualArtifactPaths.add( "invalid/invalid/1.0-20050611.123456-1/invalid-1.0-20050611.123456-1.jar" );
+ actualArtifactPaths.add( "invalid/invalid/1.0-SNAPSHOT/invalid-1.0.jar" );
+ actualArtifactPaths.add( "invalid/invalid/1.0/invalid-1.0b.jar" );
+ actualArtifactPaths.add( "invalid/invalid/1.0/invalid-2.0.jar" );
+ actualArtifactPaths.add( "invalid/invalid-1.0.jar" );
+ actualArtifactPaths.add( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar" );
+ actualArtifactPaths.add( "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1-javadoc.jar" );
+ actualArtifactPaths.add( "org/apache/maven/test/1.0-SNAPSHOT/test-1.0-20050611.112233-1.jar" );
+ actualArtifactPaths.add( "org/apache/maven/A/1.0/A-1.0.war" );
+ actualArtifactPaths.add( "org/apache/maven/A/1.0/A-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/B/2.0/B-2.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/B/1.0/B-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/some-ejb/1.0/some-ejb-1.0-client.jar" );
+ actualArtifactPaths.add( "org/apache/maven/C/1.0/C-1.0.war" );
+ actualArtifactPaths.add( "org/apache/maven/C/1.0/C-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.jar" );
+ actualArtifactPaths.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.jar" );
+ actualArtifactPaths.add( "org/apache/maven/discovery/1.0/discovery-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/testing/1.0/testing-1.0-test-sources.jar" );
+ actualArtifactPaths.add( "org/apache/maven/testing/1.0/testing-1.0.jar" );
+ actualArtifactPaths.add( "org/apache/maven/testing/1.0/testing-1.0-sources.jar" );
+ actualArtifactPaths.add( "org/apache/maven/testing/1.0/testing-1.0.zip" );
+ actualArtifactPaths.add( "org/apache/maven/testing/1.0/testing-1.0.tar.gz" );
+ actualArtifactPaths.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.jar" );
+ actualArtifactPaths.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" );
+ actualArtifactPaths.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" );
+ actualArtifactPaths.add( "org/apache/testgroup/discovery/1.0/discovery-1.0.pom" );
+ actualArtifactPaths.add( "javax/sql/jdbc/2.0/jdbc-2.0.jar" );
+
+ ManagedRepositoryConfiguration repository = createDefaultRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setIncludes( ARTIFACT_PATTERNS );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats =
+ scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertMinimumHits( "Stats.totalFileCount", actualArtifactPaths.size(), stats.getTotalFileCount() );
+ assertMinimumHits( "Processed Count", actualArtifactPaths.size(), consumer.getProcessCount() );
+ }
+
+ public void testDefaultRepositoryMetadataScanner()
+ throws Exception
+ {
+ List<String> actualMetadataPaths = new ArrayList<String>();
+
+ actualMetadataPaths.add( "org/apache/maven/some-ejb/1.0/maven-metadata.xml" );
+ actualMetadataPaths.add( "org/apache/maven/update/test-not-updated/maven-metadata.xml" );
+ actualMetadataPaths.add( "org/apache/maven/update/test-updated/maven-metadata.xml" );
+ actualMetadataPaths.add( "org/apache/maven/maven-metadata.xml" );
+ actualMetadataPaths.add( "org/apache/testgroup/discovery/1.0/maven-metadata.xml" );
+ actualMetadataPaths.add( "org/apache/testgroup/discovery/maven-metadata.xml" );
+ actualMetadataPaths.add( "javax/sql/jdbc/2.0/maven-metadata-repository.xml" );
+ actualMetadataPaths.add( "javax/sql/jdbc/maven-metadata-repository.xml" );
+ actualMetadataPaths.add( "javax/sql/maven-metadata-repository.xml" );
+ actualMetadataPaths.add( "javax/maven-metadata.xml" );
+
+ ManagedRepositoryConfiguration repository = createDefaultRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer knownConsumer = new KnownScanConsumer();
+ knownConsumer.setIncludes( new String[]{"**/maven-metadata*.xml"} );
+ knownConsumers.add( knownConsumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats =
+ scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertMinimumHits( "Stats.totalFileCount", actualMetadataPaths.size(), stats.getTotalFileCount() );
+ assertMinimumHits( "Processed Count", actualMetadataPaths.size(), knownConsumer.getProcessCount() );
+ }
+
+ public void testDefaultRepositoryProjectScanner()
+ throws Exception
+ {
+ List<String> actualProjectPaths = new ArrayList<String>();
+
+ actualProjectPaths.add( "org/apache/maven/A/1.0/A-1.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/B/2.0/B-2.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/B/1.0/B-1.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/C/1.0/C-1.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/update/test-not-updated/1.0/test-not-updated-1.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/update/test-updated/1.0/test-updated-1.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/discovery/1.0/discovery-1.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/samplejar/2.0/samplejar-2.0.pom" );
+ actualProjectPaths.add( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" );
+ actualProjectPaths.add( "org/apache/testgroup/discovery/1.0/discovery-1.0.pom" );
+
+ ManagedRepositoryConfiguration repository = createDefaultRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setIncludes( new String[]{"**/*.pom"} );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats =
+ scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertMinimumHits( "Stats.totalFileCount", actualProjectPaths.size(), stats.getTotalFileCount() );
+ assertMinimumHits( "Processed Count", actualProjectPaths.size(), consumer.getProcessCount() );
+ }
+
+ public void testLegacyRepositoryArtifactScanner()
+ throws Exception
+ {
+ List<String> actualArtifactPaths = new ArrayList<String>();
+
+ actualArtifactPaths.add( "invalid/jars/1.0/invalid-1.0.jar" );
+ actualArtifactPaths.add( "invalid/jars/invalid-1.0.rar" );
+ actualArtifactPaths.add( "invalid/jars/invalid.jar" );
+ actualArtifactPaths.add( "invalid/invalid-1.0.jar" );
+ actualArtifactPaths.add( "javax.sql/jars/jdbc-2.0.jar" );
+ actualArtifactPaths.add( "org.apache.maven/jars/some-ejb-1.0-client.jar" );
+ actualArtifactPaths.add( "org.apache.maven/jars/testing-1.0.jar" );
+ actualArtifactPaths.add( "org.apache.maven/jars/testing-1.0-sources.jar" );
+ actualArtifactPaths.add( "org.apache.maven/jars/testing-UNKNOWN.jar" );
+ actualArtifactPaths.add( "org.apache.maven/jars/testing-1.0.zip" );
+ actualArtifactPaths.add( "org.apache.maven/jars/testing-1.0-20050611.112233-1.jar" );
+ actualArtifactPaths.add( "org.apache.maven/jars/testing-1.0.tar.gz" );
+ actualArtifactPaths.add( "org.apache.maven.update/jars/test-not-updated-1.0.jar" );
+ actualArtifactPaths.add( "org.apache.maven.update/jars/test-updated-1.0.jar" );
+
+ ManagedRepositoryConfiguration repository = createLegacyRepository();
+
+ List<KnownRepositoryContentConsumer> knownConsumers = new ArrayList<KnownRepositoryContentConsumer>();
+ KnownScanConsumer consumer = new KnownScanConsumer();
+ consumer.setIncludes( ARTIFACT_PATTERNS );
+ knownConsumers.add( consumer );
+
+ List<InvalidRepositoryContentConsumer> invalidConsumers = new ArrayList<InvalidRepositoryContentConsumer>();
+ InvalidScanConsumer badconsumer = new InvalidScanConsumer();
+ invalidConsumers.add( badconsumer );
+
+ RepositoryScanner scanner = lookupRepositoryScanner();
+ RepositoryScanStatistics stats =
+ scanner.scan( repository, knownConsumers, invalidConsumers, getIgnoreList(), RepositoryScanner.FRESH_SCAN );
+
+ assertNotNull( "Stats should not be null.", stats );
+ assertMinimumHits( "Stats.totalFileCount", actualArtifactPaths.size(), stats.getTotalFileCount() );
+ assertMinimumHits( "Processed Count", actualArtifactPaths.size(), consumer.getProcessCount() );
+ }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java
new file mode 100644
index 000000000..340be8b2b
--- /dev/null
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/SampleKnownConsumer.java
@@ -0,0 +1,88 @@
+package org.apache.archiva.repository.scanner;
+
+/*
+ * 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.util.Date;
+import java.util.List;
+
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+
+/**
+ * SampleKnownConsumer
+ *
+ * @version $Id$
+ *
+ * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
+ * role-hint="sample-known"
+ */
+public class SampleKnownConsumer
+ extends AbstractMonitoredConsumer
+ implements KnownRepositoryContentConsumer
+{
+ /**
+ * @plexus.configuration default-value="unset-id"
+ */
+ private String id = "unset-id";
+
+ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
+ throws ConsumerException
+ {
+ /* nothing to do */
+ }
+
+ public void completeScan()
+ {
+ /* nothing to do */
+ }
+
+ public List<String> getExcludes()
+ {
+ return null;
+ }
+
+ public List<String> getIncludes()
+ {
+ return null;
+ }
+
+ public void processFile( String path )
+ throws ConsumerException
+ {
+ /* nothing to do */
+ }
+
+ public String getDescription()
+ {
+ return "Sample Known Consumer";
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+}