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 public void testProcess()
66 List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
68 Date whenGathered = Calendar.getInstance().getTime();
69 whenGathered.setTime( 123456789 );
71 ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
72 artifact.getModel().setWhenGathered( whenGathered );
73 artifacts.add( artifact );
75 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
76 artifact.getModel().setWhenGathered( whenGathered );
77 artifacts.add( artifact );
79 Date whenGatheredNext = Calendar.getInstance().getTime();
80 whenGatheredNext.setTime( 345678912 );
82 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", 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() );
97 "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
98 feed.getDescription() );
99 assertEquals( "en-us", feed.getLanguage() );
100 assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() );
102 List<SyndEntry> entries = feed.getEntries();
104 assertEquals( 2, entries.size() );
106 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
107 entries.get( 0 ).getTitle() );
108 assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
110 assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
111 entries.get( 1 ).getTitle() );
112 assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );