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;
40 public class NewArtifactsRssFeedProcessorTest
41 extends PlexusInSpringTestCase
43 private static final String TEST_REPO = "test-repo";
45 private NewArtifactsRssFeedProcessor newArtifactsProcessor;
47 private ArtifactDAOStub artifactDAOStub;
49 private RssFeedGenerator rssFeedGenerator;
57 newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
58 artifactDAOStub = new ArtifactDAOStub();
60 rssFeedGenerator = new RssFeedGenerator();
62 newArtifactsProcessor.setGenerator( rssFeedGenerator );
63 newArtifactsProcessor.setArtifactDAO( artifactDAOStub );
66 @SuppressWarnings("unchecked")
67 public void testProcess()
70 List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
71 Date whenGathered = Calendar.getInstance().getTime();
73 ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar", TEST_REPO );
74 artifact.getModel().setWhenGathered( whenGathered );
75 newArtifacts.add( artifact );
77 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar", TEST_REPO );
78 artifact.getModel().setWhenGathered( whenGathered );
79 newArtifacts.add( artifact );
81 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar", TEST_REPO );
82 artifact.getModel().setWhenGathered( whenGathered );
83 newArtifacts.add( artifact );
85 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
86 artifact.getModel().setWhenGathered( whenGathered );
87 newArtifacts.add( artifact );
89 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
90 artifact.getModel().setWhenGathered( whenGathered );
91 newArtifacts.add( artifact );
93 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
94 artifact.getModel().setWhenGathered( whenGathered );
95 newArtifacts.add( artifact );
97 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar", TEST_REPO );
98 artifact.getModel().setWhenGathered( whenGathered );
99 newArtifacts.add( artifact );
101 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar", TEST_REPO );
102 artifact.getModel().setWhenGathered( whenGathered );
103 newArtifacts.add( artifact );
105 artifactDAOStub.setArtifacts( newArtifacts );
107 Map<String, String> reqParams = new HashMap<String, String>();
108 reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
110 SyndFeed feed = newArtifactsProcessor.process( reqParams );
112 assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
113 assertTrue( feed.getDescription().equals(
114 "New artifacts found in repository 'test-repo' during repository scan." ) );
115 assertTrue( feed.getLanguage().equals( "en-us" ) );
116 assertTrue( feed.getPublishedDate().equals( whenGathered ) );
118 List<SyndEntry> entries = feed.getEntries();
119 assertEquals( entries.size(), 1 );
120 assertTrue( entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
121 assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );