1 package org.apache.archiva.rss.processor;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.sun.syndication.feed.synd.SyndEntry;
23 import com.sun.syndication.feed.synd.SyndFeed;
24 import org.apache.archiva.metadata.model.ArtifactMetadata;
25 import org.apache.archiva.metadata.repository.MetadataRepository;
26 import org.apache.archiva.rss.RssFeedGenerator;
27 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
28 import org.easymock.MockControl;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import java.util.Date;
33 import java.util.HashMap;
34 import java.util.List;
37 public class NewVersionsOfArtifactRssFeedProcessorTest
38 extends PlexusInSpringTestCase
40 private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
42 private static final String TEST_REPO = "test-repo";
44 private static final String GROUP_ID = "org.apache.archiva";
46 private static final String ARTIFACT_ID = "artifact-two";
48 private MockControl metadataRepositoryControl;
50 private MetadataRepository metadataRepository;
58 newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
59 newVersionsProcessor.setGenerator( new RssFeedGenerator() );
61 metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
62 metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
63 newVersionsProcessor.setMetadataRepository( metadataRepository );
66 @SuppressWarnings("unchecked")
67 public void testProcess()
70 Date whenGathered = new Date( 123456789 );
72 ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" );
73 ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" );
75 Date whenGatheredNext = new Date( 345678912 );
77 ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" );
79 Map<String, String> reqParams = new HashMap<String, String>();
80 reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
81 reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
83 metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(),
84 Collections.singletonList( TEST_REPO ) );
85 metadataRepositoryControl.expectAndReturn(
86 metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, ARTIFACT_ID ),
87 Arrays.asList( "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) );
88 metadataRepositoryControl.expectAndReturn(
89 metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1" ),
90 Collections.singletonList( artifact1 ) );
91 metadataRepositoryControl.expectAndReturn(
92 metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2" ),
93 Collections.singletonList( artifact2 ) );
94 metadataRepositoryControl.expectAndReturn(
95 metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT" ),
96 Collections.singletonList( artifact3 ) );
97 metadataRepositoryControl.replay();
99 SyndFeed feed = newVersionsProcessor.process( reqParams );
101 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
102 assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.",
103 feed.getDescription() );
104 assertEquals( "en-us", feed.getLanguage() );
105 assertEquals( whenGatheredNext, feed.getPublishedDate() );
107 List<SyndEntry> entries = feed.getEntries();
109 assertEquals( 2, entries.size() );
111 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
112 entries.get( 0 ).getTitle() );
113 assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
115 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
116 entries.get( 1 ).getTitle() );
117 assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );
119 metadataRepositoryControl.verify();
122 private ArtifactMetadata createArtifact( Date whenGathered, String version )
124 ArtifactMetadata artifact = new ArtifactMetadata();
125 artifact.setNamespace( GROUP_ID );
126 artifact.setProject( ARTIFACT_ID );
127 artifact.setProjectVersion( version );
128 artifact.setVersion( version );
129 artifact.setRepositoryId( TEST_REPO );
130 artifact.setId( ARTIFACT_ID + "-" + version + ".jar" );
131 artifact.setWhenGathered( whenGathered );