summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rss
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-12-09 08:08:21 +0000
committerBrett Porter <brett@apache.org>2009-12-09 08:08:21 +0000
commit99765460e017147e9663e3f653a3f243a6b705ea (patch)
treed29640960376b4688556f3935cd4f983dbf83a3c /archiva-modules/archiva-web/archiva-rss
parent94e702281c96889f2736ba937cdde517646921ed (diff)
downloadarchiva-99765460e017147e9663e3f653a3f243a6b705ea.tar.gz
archiva-99765460e017147e9663e3f653a3f243a6b705ea.zip
[MRM-1299] migrate RSS from the database to the metadata repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888723 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rss')
-rw-r--r--archiva-modules/archiva-web/archiva-rss/pom.xml12
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java78
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java76
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java108
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java8
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java102
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java102
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java79
8 files changed, 241 insertions, 324 deletions
diff --git a/archiva-modules/archiva-web/archiva-rss/pom.xml b/archiva-modules/archiva-web/archiva-rss/pom.xml
index 95633e203..b94aa75c7 100644
--- a/archiva-modules/archiva-web/archiva-rss/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rss/pom.xml
@@ -35,12 +35,7 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
- <artifactId>archiva-model</artifactId>
- </dependency>
- <!-- TODO: replace with metadata processor -->
- <dependency>
- <groupId>org.apache.archiva</groupId>
- <artifactId>archiva-database</artifactId>
+ <artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -65,5 +60,10 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
index 92aa5e245..0dca954c7 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
@@ -19,82 +19,22 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.rss.RssFeedEntry;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import com.sun.syndication.feed.synd.SyndFeed;
-
-/**
- * @version
- */
public abstract class AbstractArtifactsRssFeedProcessor
implements RssFeedProcessor
{
- public abstract SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
-
- protected List<RssFeedEntry> processData( List<ArchivaArtifact> artifacts, boolean isRepoLevel )
- {
- long tmp = 0;
- RssFeedEntry entry = null;
- List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
- String description = "";
- int idx = 0;
- for ( ArchivaArtifact artifact : artifacts )
- {
- long whenGathered = artifact.getModel().getWhenGathered().getTime();
-
- if ( tmp != whenGathered )
- {
- if ( entry != null )
- {
- entry.setDescription( description );
- entries.add( entry );
- entry = null;
- }
-
- if ( !isRepoLevel )
- {
- entry =
- new RssFeedEntry( getTitle() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() +
- "\'" + " as of " + new Date( whenGathered ) );
- entry.setPublishedDate( artifact.getModel().getWhenGathered() );
- description = getDescription() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() +
- "\'" + ": \n" + artifact.toString() + " | ";
- }
- else
- {
- String repoId = artifact.getModel().getRepositoryId();
- entry = new RssFeedEntry( getTitle() + "\'" + repoId + "\'" + " as of " + new Date( whenGathered ) );
- entry.setPublishedDate( artifact.getModel().getWhenGathered() );
- description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | ";
- }
- }
- else
- {
- description = description + artifact.toString() + " | ";
- }
-
- if ( idx == ( artifacts.size() - 1 ) )
- {
- entry.setDescription( description );
- entries.add( entry );
- }
-
- tmp = whenGathered;
- idx++;
- }
-
- return entries;
- }
+ /**
+ * @plexus.requirement
+ */
+ protected MetadataRepository metadataRepository;
protected abstract String getTitle();
protected abstract String getDescription();
+ public void setMetadataRepository( MetadataRepository metadataRepository )
+ {
+ this.metadataRepository = metadataRepository;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
index addf50dec..c7d81921c 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
@@ -19,19 +19,17 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.rss.RssFeedEntry;
import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
-import org.apache.maven.archiva.model.ArchivaArtifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +38,6 @@ import org.slf4j.LoggerFactory;
* The artifacts will be grouped by the date when the artifacts were gathered.
* Each group will appear as one entry in the feed.
*
- * @version
* @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-artifacts"
*/
public class NewArtifactsRssFeedProcessor
@@ -59,18 +56,13 @@ public class NewArtifactsRssFeedProcessor
private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class );
- /**
- * @plexus.requirement role-hint="jdo"
- */
- private ArtifactDAO artifactDAO;
-
private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
/**
* Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
* new versions of artifact.
*/
- public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
+ public SyndFeed process( Map<String, String> reqParams )
{
log.debug( "Process new artifacts into rss feeds." );
@@ -83,16 +75,53 @@ public class NewArtifactsRssFeedProcessor
return null;
}
- private SyndFeed processNewArtifactsInRepo( String repoId ) throws ArchivaDatabaseException
+ private SyndFeed processNewArtifactsInRepo( String repoId )
{
-
Calendar greaterThanThisDate = Calendar.getInstance( GMT_TIME_ZONE );
greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) );
-
- Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, greaterThanThisDate.getTime(), "whenGathered", false );
- List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo );
+ greaterThanThisDate.clear( Calendar.MILLISECOND );
- List<RssFeedEntry> entries = processData( artifacts, true );
+ List<ArtifactMetadata> artifacts =
+ metadataRepository.getArtifactsByDateRange( repoId, greaterThanThisDate.getTime(), null );
+
+ long tmp = 0;
+ RssFeedEntry entry = null;
+ List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
+ String description = "";
+ int idx = 0;
+ for ( ArtifactMetadata artifact : artifacts )
+ {
+ long whenGathered = artifact.getWhenGathered().getTime();
+
+ String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
+ if ( tmp != whenGathered )
+ {
+ if ( entry != null )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ entry = null;
+ }
+
+ String repoId1 = artifact.getRepositoryId();
+ entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( whenGathered ) );
+ entry.setPublishedDate( artifact.getWhenGathered() );
+ description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
+ }
+ else
+ {
+ description = description + id + " | ";
+ }
+
+ if ( idx == ( artifacts.size() - 1 ) )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ }
+
+ tmp = whenGathered;
+ idx++;
+ }
return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " +
"\'" + repoId + "\'" + " during repository scan.", entries );
@@ -118,16 +147,6 @@ public class NewArtifactsRssFeedProcessor
this.generator = generator;
}
- public ArtifactDAO getArtifactDAO()
- {
- return artifactDAO;
- }
-
- public void setArtifactDAO( ArtifactDAO artifactDAO )
- {
- this.artifactDAO = artifactDAO;
- }
-
public int getNumberOfDaysBeforeNow()
{
return numberOfDaysBeforeNow;
@@ -137,5 +156,4 @@ public class NewArtifactsRssFeedProcessor
{
this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;
}
-
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
index c4c50e84f..a1a80ed54 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
@@ -19,25 +19,23 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Map;
+import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
import org.apache.archiva.rss.RssFeedEntry;
import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import com.sun.syndication.feed.synd.SyndFeed;
/**
* Retrieve and process new versions of an artifact from the database and
- * generate a rss feed. The versions will be grouped by the date when the artifact
+ * generate a rss feed. The versions will be grouped by the date when the artifact
* was gathered. Each group will appear as one entry in the feed.
- *
- * @version
+ *
* @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-versions"
*/
public class NewVersionsOfArtifactRssFeedProcessor
@@ -53,39 +51,80 @@ public class NewVersionsOfArtifactRssFeedProcessor
private RssFeedGenerator generator;
/**
- * @plexus.requirement role-hint="jdo"
- */
- private ArtifactDAO artifactDAO;
-
- /**
* Process all versions of the artifact which had a rss feed request.
*/
- public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
+ public SyndFeed process( Map<String, String> reqParams )
+ throws MetadataResolverException
{
- String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
-
+
if ( groupId != null && artifactId != null )
{
- return processNewVersionsOfArtifact( repoId, groupId, artifactId );
+ return processNewVersionsOfArtifact( groupId, artifactId );
}
return null;
}
- private SyndFeed processNewVersionsOfArtifact( String repoId, String groupId, String artifactId )
- throws ArchivaDatabaseException
+ private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId )
+ throws MetadataResolverException
{
-
- Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" );
- List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions );
-
- List<RssFeedEntry> entries = processData( artifacts, false );
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
+ for ( String repoId : metadataRepository.getRepositories() )
+ {
+ Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
+ for ( String version : versions )
+ {
+ artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
+ }
+ }
+
+ long tmp = 0;
+ RssFeedEntry entry = null;
+ List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
+ String description = "";
+ int idx = 0;
+ for ( ArtifactMetadata artifact : artifacts )
+ {
+ long whenGathered = artifact.getWhenGathered().getTime();
+
+ if ( tmp != whenGathered )
+ {
+ if ( entry != null )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ entry = null;
+ }
+
+ entry = new RssFeedEntry(
+ this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
+ entry.setPublishedDate( artifact.getWhenGathered() );
+ description =
+ this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
+ " | ";
+ }
+ else
+ {
+ description = description + artifact.getId() + " | ";
+ }
+
+ if ( idx == ( artifacts.size() - 1 ) )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ }
+
+ tmp = whenGathered;
+ idx++;
+ }
+
String key = groupId + ":" + artifactId;
-
- return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key +
- "\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries );
+
+ return generator.generateFeed( getTitle() + "\'" + key + "\'",
+ "New versions of artifact " + "\'" + key + "\' found during repository scan.",
+ entries );
}
public String getTitle()
@@ -107,15 +146,4 @@ public class NewVersionsOfArtifactRssFeedProcessor
{
this.generator = generator;
}
-
- public ArtifactDAO getArtifactDAO()
- {
- return artifactDAO;
- }
-
- public void setArtifactDAO( ArtifactDAO artifactDAO )
- {
- this.artifactDAO = artifactDAO;
- }
-
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
index 68590b50f..7d4723e31 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
@@ -21,14 +21,11 @@ package org.apache.archiva.rss.processor;
import java.util.Map;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
/**
* Retrieve and process the data that will be fed into the RssFeedGenerator.
- *
- * @version
*/
public interface RssFeedProcessor
{
@@ -38,5 +35,6 @@ public interface RssFeedProcessor
public static final String KEY_ARTIFACT_ID = "artifactId";
- SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
+ SyndFeed process( Map<String, String> reqParams )
+ throws MetadataResolverException;
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
index c4587e386..5c9670f6a 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
@@ -25,18 +25,16 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.archiva.rss.stubs.ArtifactDAOStub;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import java.util.TimeZone;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.rss.RssFeedGenerator;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
-/**
- * @version
- */
public class NewArtifactsRssFeedProcessorTest
extends PlexusInSpringTestCase
{
@@ -44,9 +42,9 @@ public class NewArtifactsRssFeedProcessorTest
private NewArtifactsRssFeedProcessor newArtifactsProcessor;
- private ArtifactDAOStub artifactDAOStub;
+ private MetadataRepository metadataRepository;
- private RssFeedGenerator rssFeedGenerator;
+ private MockControl metadataRepositoryControl;
@Override
public void setUp()
@@ -55,69 +53,65 @@ public class NewArtifactsRssFeedProcessorTest
super.setUp();
newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
- artifactDAOStub = new ArtifactDAOStub();
-
- rssFeedGenerator = new RssFeedGenerator();
+ newArtifactsProcessor.setGenerator( new RssFeedGenerator() );
- newArtifactsProcessor.setGenerator( rssFeedGenerator );
- newArtifactsProcessor.setArtifactDAO( artifactDAOStub );
+ metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
+ metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
+ newArtifactsProcessor.setMetadataRepository( metadataRepository );
}
@SuppressWarnings("unchecked")
public void testProcess()
throws Exception
{
- List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
+ List<ArtifactMetadata> newArtifacts = new ArrayList<ArtifactMetadata>();
Date whenGathered = Calendar.getInstance().getTime();
- ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifactDAOStub.setArtifacts( newArtifacts );
+ newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-one", "2.0", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-two", "1.0.1", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-two", "1.0.2", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-four", "1.1-beta-2", whenGathered ) );
+
+ Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
+ cal.add( Calendar.DATE, -30 );
+ cal.clear( Calendar.MILLISECOND );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifactsByDateRange( TEST_REPO, cal.getTime(), null ), newArtifacts );
+ metadataRepositoryControl.replay();
Map<String, String> reqParams = new HashMap<String, String>();
- reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
+ reqParams.put( RssFeedProcessor.KEY_REPO_ID, TEST_REPO );
SyndFeed feed = newArtifactsProcessor.process( reqParams );
- assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
- assertTrue( feed.getDescription().equals(
- "New artifacts found in repository 'test-repo' during repository scan." ) );
+ assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
+ assertTrue(
+ feed.getDescription().equals( "New artifacts found in repository 'test-repo' during repository scan." ) );
assertTrue( feed.getLanguage().equals( "en-us" ) );
assertTrue( feed.getPublishedDate().equals( whenGathered ) );
List<SyndEntry> entries = feed.getEntries();
assertEquals( entries.size(), 1 );
- assertTrue( entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
+ assertTrue(
+ entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );
+
+ metadataRepositoryControl.verify();
+ }
+
+ private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setNamespace( "org.apache.archiva" );
+ artifact.setId( artifactId + "-" + version + ".jar" );
+ artifact.setRepositoryId( TEST_REPO );
+ artifact.setWhenGathered( whenGathered );
+ artifact.setProject( artifactId );
+ artifact.setVersion( version );
+ return artifact;
}
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
index e1256954b..b1cdf7cf8 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
@@ -19,31 +19,35 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.Calendar;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.archiva.rss.stubs.ArtifactDAOStub;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.rss.RssFeedGenerator;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
public class NewVersionsOfArtifactRssFeedProcessorTest
extends PlexusInSpringTestCase
{
+ private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
+
private static final String TEST_REPO = "test-repo";
- private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
+ private static final String GROUP_ID = "org.apache.archiva";
+
+ private static final String ARTIFACT_ID = "artifact-two";
- private ArtifactDAOStub artifactDAOStub;
+ private MockControl metadataRepositoryControl;
- private RssFeedGenerator rssFeedGenerator;
+ private MetadataRepository metadataRepository;
@Override
public void setUp()
@@ -52,64 +56,78 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
super.setUp();
newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
- artifactDAOStub = new ArtifactDAOStub();
+ newVersionsProcessor.setGenerator( new RssFeedGenerator() );
- rssFeedGenerator = new RssFeedGenerator();
-
- newVersionsProcessor.setGenerator( rssFeedGenerator );
- newVersionsProcessor.setArtifactDAO( artifactDAOStub );
+ metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
+ metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
+ newVersionsProcessor.setMetadataRepository( metadataRepository );
}
@SuppressWarnings("unchecked")
public void testProcess()
throws Exception
{
- List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
-
- Date whenGathered = Calendar.getInstance().getTime();
- whenGathered.setTime( 123456789 );
-
- ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
+ Date whenGathered = new Date( 123456789 );
- Date whenGatheredNext = Calendar.getInstance().getTime();
- whenGatheredNext.setTime( 345678912 );
+ ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" );
+ ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" );
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGatheredNext );
- artifacts.add( artifact );
+ Date whenGatheredNext = new Date( 345678912 );
- artifactDAOStub.setArtifacts( artifacts );
+ ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" );
Map<String, String> reqParams = new HashMap<String, String>();
- reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
- reqParams.put( RssFeedProcessor.KEY_GROUP_ID, "org.apache.archiva" );
- reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, "artifact-two" );
+ reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
+ reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
+
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(),
+ Collections.singletonList( TEST_REPO ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, ARTIFACT_ID ),
+ Arrays.asList( "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1" ),
+ Collections.singletonList( artifact1 ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2" ),
+ Collections.singletonList( artifact2 ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT" ),
+ Collections.singletonList( artifact3 ) );
+ metadataRepositoryControl.replay();
SyndFeed feed = newVersionsProcessor.process( reqParams );
- assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
- assertEquals(
- "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
+ assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
+ assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.",
feed.getDescription() );
assertEquals( "en-us", feed.getLanguage() );
- assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() );
+ assertEquals( whenGatheredNext, feed.getPublishedDate() );
List<SyndEntry> entries = feed.getEntries();
assertEquals( 2, entries.size() );
-
+
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
entries.get( 0 ).getTitle() );
assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
-
+
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
entries.get( 1 ).getTitle() );
assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );
+
+ metadataRepositoryControl.verify();
+ }
+
+ private ArtifactMetadata createArtifact( Date whenGathered, String version )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setNamespace( GROUP_ID );
+ artifact.setProject( ARTIFACT_ID );
+ artifact.setVersion( version );
+ artifact.setRepositoryId( TEST_REPO );
+ artifact.setId( ARTIFACT_ID + "-" + version + ".jar" );
+ artifact.setWhenGathered( whenGathered );
+ return artifact;
}
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java
deleted file mode 100644
index 9eade4d65..000000000
--- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.archiva.rss.stubs;
-
-/*
- * 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.List;
-
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-/**
- * ArtifactDAO stub.
- *
- * @version *
- */
-public class ArtifactDAOStub
- implements ArtifactDAO
-{
- private List<ArchivaArtifact> artifacts;
-
- public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
- String type, String repositoryId )
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void deleteArtifact( ArchivaArtifact artifact )
- throws ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
-
- }
-
- public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
- String type, String repositoryId )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List<ArchivaArtifact> queryArtifacts( Constraint constraint )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- return artifacts;
- }
-
- public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
- throws ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void setArtifacts( List<ArchivaArtifact> artifacts )
- {
- this.artifacts = artifacts;
- }
-}