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 java.util.ArrayList;
23 import java.util.Calendar;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.List;
29 import org.apache.archiva.rss.RssFeedGenerator;
30 import org.apache.archiva.rss.stubs.ArtifactDAOStub;
31 import org.apache.maven.archiva.model.ArchivaArtifact;
32 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
34 import com.sun.syndication.feed.synd.SyndEntry;
35 import com.sun.syndication.feed.synd.SyndFeed;
37 public class NewVersionsOfArtifactRssFeedProcessorTest
38 extends PlexusInSpringTestCase
40 private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
42 private ArtifactDAOStub artifactDAOStub;
44 private RssFeedGenerator rssFeedGenerator;
51 newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
52 artifactDAOStub = new ArtifactDAOStub();
54 rssFeedGenerator = new RssFeedGenerator();
56 newVersionsProcessor.setGenerator( rssFeedGenerator );
57 newVersionsProcessor.setArtifactDAO( artifactDAOStub );
60 public void testProcess()
63 List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
65 Date whenGathered = Calendar.getInstance().getTime();
66 whenGathered.setTime( 123456789 );
68 ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar" );
69 artifact.getModel().setRepositoryId( "test-repo" );
70 artifact.getModel().setWhenGathered( whenGathered );
71 artifacts.add( artifact );
73 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar" );
74 artifact.getModel().setRepositoryId( "test-repo" );
75 artifact.getModel().setWhenGathered( whenGathered );
76 artifacts.add( artifact );
78 Date whenGatheredNext = Calendar.getInstance().getTime();
79 whenGatheredNext.setTime( 345678912 );
81 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar" );
82 artifact.getModel().setRepositoryId( "test-repo" );
83 artifact.getModel().setWhenGathered( whenGatheredNext );
84 artifacts.add( artifact );
86 artifactDAOStub.setArtifacts( artifacts );
88 Map<String, String> reqParams = new HashMap<String, String>();
89 reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
90 reqParams.put( RssFeedProcessor.KEY_GROUP_ID, "org.apache.archiva" );
91 reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, "artifact-two" );
93 SyndFeed feed = newVersionsProcessor.process( reqParams );
95 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
96 assertEquals( "http://localhost:8080/archiva/rss/rss_feeds?groupId=org.apache.archiva&artifactId=artifact-two",
99 "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
100 feed.getDescription() );
101 assertEquals( "en-us", feed.getLanguage() );
102 assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() );
104 List<SyndEntry> entries = feed.getEntries();
106 assertEquals( 2, entries.size() );
108 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
109 entries.get( 0 ).getTitle() );
110 assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
112 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
113 entries.get( 1 ).getTitle() );
114 assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );