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;
38 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
41 public class NewArtifactsRssFeedProcessorTest
42 extends PlexusInSpringTestCase
44 private NewArtifactsRssFeedProcessor newArtifactsProcessor;
46 private ArtifactDAOStub artifactDAOStub;
48 private RssFeedGenerator rssFeedGenerator;
55 newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
56 artifactDAOStub = new ArtifactDAOStub();
58 rssFeedGenerator = new RssFeedGenerator();
60 newArtifactsProcessor.setGenerator( rssFeedGenerator );
61 newArtifactsProcessor.setArtifactDAO( artifactDAOStub );
64 public void testProcess()
67 List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
68 Date whenGathered = Calendar.getInstance().getTime();
70 ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar" );
71 artifact.getModel().setRepositoryId( "test-repo" );
72 artifact.getModel().setWhenGathered( whenGathered );
73 newArtifacts.add( artifact );
75 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar" );
76 artifact.getModel().setRepositoryId( "test-repo" );
77 artifact.getModel().setWhenGathered( whenGathered );
78 newArtifacts.add( artifact );
80 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar" );
81 artifact.getModel().setRepositoryId( "test-repo" );
82 artifact.getModel().setWhenGathered( whenGathered );
83 newArtifacts.add( artifact );
85 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar" );
86 artifact.getModel().setRepositoryId( "test-repo" );
87 artifact.getModel().setWhenGathered( whenGathered );
88 newArtifacts.add( artifact );
90 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar" );
91 artifact.getModel().setRepositoryId( "test-repo" );
92 artifact.getModel().setWhenGathered( whenGathered );
93 newArtifacts.add( artifact );
95 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar" );
96 artifact.getModel().setRepositoryId( "test-repo" );
97 artifact.getModel().setWhenGathered( whenGathered );
98 newArtifacts.add( artifact );
100 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar" );
101 artifact.getModel().setRepositoryId( "test-repo" );
102 artifact.getModel().setWhenGathered( whenGathered );
103 newArtifacts.add( artifact );
105 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar" );
106 artifact.getModel().setRepositoryId( "test-repo" );
107 artifact.getModel().setWhenGathered( whenGathered );
108 newArtifacts.add( artifact );
110 artifactDAOStub.setArtifacts( newArtifacts );
112 Map<String, String> reqParams = new HashMap<String, String>();
113 reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
115 SyndFeed feed = newArtifactsProcessor.process( reqParams );
117 assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
118 assertTrue( feed.getLink().equals( "http://localhost:8080/archiva/rss/rss_feeds?repoId=test-repo" ) );
119 assertTrue( feed.getDescription().equals(
120 "New artifacts found in repository 'test-repo' during repository scan." ) );
121 assertTrue( feed.getLanguage().equals( "en-us" ) );
122 assertTrue( feed.getPublishedDate().equals( whenGathered ) );
124 List<SyndEntry> entries = feed.getEntries();
125 assertEquals( entries.size(), 1 );
126 assertTrue( entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
127 assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );