* under the License.
*/
-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;
-
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataResolutionException;
+import org.apache.archiva.rss.RssFeedGenerator;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+
public class NewArtifactsRssFeedProcessorTest
extends PlexusInSpringTestCase
{
private NewArtifactsRssFeedProcessor newArtifactsProcessor;
- private MetadataRepository metadataRepository;
-
- private MockControl metadataRepositoryControl;
+ private MetadataRepositoryMock metadataRepository;
@Override
public void setUp()
newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
newArtifactsProcessor.setGenerator( new RssFeedGenerator() );
- metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
- metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
+ metadataRepository = new MetadataRepositoryMock();
newArtifactsProcessor.setMetadataRepository( metadataRepository );
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public void testProcess()
throws Exception
{
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();
+ metadataRepository.setArtifactsByDateRange( newArtifacts );
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put( RssFeedProcessor.KEY_REPO_ID, TEST_REPO );
SyndFeed feed = newArtifactsProcessor.process( reqParams );
+ // check that the date used in the call is close to the one passed (5 seconds difference at most)
+ Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
+ cal.add( Calendar.DATE, -30 );
+ assertTrue( ( metadataRepository.getFrom().getTime() - cal.getTimeInMillis() ) < 1000 * 5 );
+ assertEquals( null, metadataRepository.getTo() );
+ assertEquals( TEST_REPO, metadataRepository.getRepoId() );
+
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.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 )
artifact.setVersion( version );
return artifact;
}
+
+ private class MetadataRepositoryMock
+ implements MetadataRepository
+ {
+ private Date from, to;
+
+ private String repoId;
+
+ private List<ArtifactMetadata> artifactsByDateRange;
+
+ public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date from, Date to )
+ {
+ setRepoId( repoId );
+ setFrom( from );
+ setTo( to );
+ return artifactsByDateRange;
+ }
+
+ public void addMetadataFacet( String arg0, MetadataFacet arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void deleteArtifact( String arg0, String arg1, String arg2, String arg3, String arg4 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void deleteRepository( String arg0 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<ArtifactMetadata> getArtifactsByChecksum( String arg0, String arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public MetadataFacet getMetadataFacet( String arg0, String arg1, String arg2 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<String> getMetadataFacets( String arg0, String arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getRepositories()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeMetadataFacet( String arg0, String arg1, String arg2 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeMetadataFacets( String arg0, String arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateArtifact( String arg0, String arg1, String arg2, String arg3, ArtifactMetadata arg4 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateNamespace( String arg0, String arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateProject( String arg0, ProjectMetadata arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateProjectReference( String arg0, String arg1, String arg2, String arg3,
+ ProjectVersionReference arg4 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateProjectVersion( String arg0, String arg1, String arg2, ProjectVersionMetadata arg3 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getArtifactVersions( String arg0, String arg1, String arg2, String arg3 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<ArtifactMetadata> getArtifacts( String arg0, String arg1, String arg2, String arg3 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getNamespaces( String arg0, String arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ProjectMetadata getProject( String arg0, String arg1, String arg2 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<ProjectVersionReference> getProjectReferences( String arg0, String arg1, String arg2,
+ String arg3 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ProjectVersionMetadata getProjectVersion( String arg0, String arg1, String arg2, String arg3 )
+ throws MetadataResolutionException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getProjectVersions( String arg0, String arg1, String arg2 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getProjects( String arg0, String arg1 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getRootNamespaces( String arg0 )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setFrom( Date from )
+ {
+ this.from = from;
+ }
+
+ public Date getFrom()
+ {
+ return from;
+ }
+
+ public void setTo( Date to )
+ {
+ this.to = to;
+ }
+
+ public Date getTo()
+ {
+ return to;
+ }
+
+ public void setRepoId( String repoId )
+ {
+ this.repoId = repoId;
+ }
+
+ public String getRepoId()
+ {
+ return repoId;
+ }
+
+ public void setArtifactsByDateRange( List<ArtifactMetadata> artifactsByDateRange )
+ {
+ this.artifactsByDateRange = artifactsByDateRange;
+ }
+ }
}