diff options
author | Carlos Sanchez Gonzalez <carlos@apache.org> | 2010-08-09 18:05:55 +0000 |
---|---|---|
committer | Carlos Sanchez Gonzalez <carlos@apache.org> | 2010-08-09 18:05:55 +0000 |
commit | 887786e0596389d3ae929c0b96a444be5c93019e (patch) | |
tree | 210507cd40fbaf09d7940c56c8041626e9849f6d /archiva-modules/archiva-web/archiva-rss | |
parent | a96167a55df36d1a866622bdad83b0c6103a728a (diff) | |
download | archiva-887786e0596389d3ae929c0b96a444be5c93019e.tar.gz archiva-887786e0596389d3ae929c0b96a444be5c93019e.zip |
Seconds difference could make test fail, compare date differences
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@983755 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rss')
-rw-r--r-- | archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java | 225 |
1 files changed, 199 insertions, 26 deletions
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 924715ef0..a862ca393 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 @@ -19,22 +19,28 @@ package org.apache.archiva.rss.processor; * 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 { @@ -42,9 +48,7 @@ public class NewArtifactsRssFeedProcessorTest private NewArtifactsRssFeedProcessor newArtifactsProcessor; - private MetadataRepository metadataRepository; - - private MockControl metadataRepositoryControl; + private MetadataRepositoryMock metadataRepository; @Override public void setUp() @@ -55,12 +59,11 @@ public class NewArtifactsRssFeedProcessorTest 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 { @@ -76,31 +79,30 @@ public class NewArtifactsRssFeedProcessorTest 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 ) @@ -115,4 +117,175 @@ public class NewArtifactsRssFeedProcessorTest 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; + } + } } |