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 static final String TEST_REPO = "test-repo";
42 private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
44 private ArtifactDAOStub artifactDAOStub;
46 private RssFeedGenerator rssFeedGenerator;
54 newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
55 artifactDAOStub = new ArtifactDAOStub();
57 rssFeedGenerator = new RssFeedGenerator();
59 newVersionsProcessor.setGenerator( rssFeedGenerator );
60 newVersionsProcessor.setArtifactDAO( artifactDAOStub );
63 @SuppressWarnings("unchecked")
64 public void testProcess()
67 List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
69 Date whenGathered = Calendar.getInstance().getTime();
70 whenGathered.setTime( 123456789 );
72 ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
73 artifact.getModel().setWhenGathered( whenGathered );
74 artifacts.add( artifact );
76 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
77 artifact.getModel().setWhenGathered( whenGathered );
78 artifacts.add( artifact );
80 Date whenGatheredNext = Calendar.getInstance().getTime();
81 whenGatheredNext.setTime( 345678912 );
83 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
84 artifact.getModel().setWhenGathered( whenGatheredNext );
85 artifacts.add( artifact );
87 artifactDAOStub.setArtifacts( artifacts );
89 Map<String, String> reqParams = new HashMap<String, String>();
90 reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
91 reqParams.put( RssFeedProcessor.KEY_GROUP_ID, "org.apache.archiva" );
92 reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, "artifact-two" );
94 SyndFeed feed = newVersionsProcessor.process( reqParams );
96 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
98 "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
99 feed.getDescription() );
100 assertEquals( "en-us", feed.getLanguage() );
101 assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() );
103 List<SyndEntry> entries = feed.getEntries();
105 assertEquals( 2, entries.size() );
107 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
108 entries.get( 0 ).getTitle() );
109 assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
111 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
112 entries.get( 1 ).getTitle() );
113 assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );