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 public void testProcess()
69 List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
70 Date whenGathered = Calendar.getInstance().getTime();
72 ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar", TEST_REPO );
73 artifact.getModel().setWhenGathered( whenGathered );
74 newArtifacts.add( artifact );
76 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar", TEST_REPO );
77 artifact.getModel().setWhenGathered( whenGathered );
78 newArtifacts.add( artifact );
80 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar", TEST_REPO );
81 artifact.getModel().setWhenGathered( whenGathered );
82 newArtifacts.add( artifact );
84 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
85 artifact.getModel().setWhenGathered( whenGathered );
86 newArtifacts.add( artifact );
88 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
89 artifact.getModel().setWhenGathered( whenGathered );
90 newArtifacts.add( artifact );
92 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
93 artifact.getModel().setWhenGathered( whenGathered );
94 newArtifacts.add( artifact );
96 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar", TEST_REPO );
97 artifact.getModel().setWhenGathered( whenGathered );
98 newArtifacts.add( artifact );
100 artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar", TEST_REPO );
101 artifact.getModel().setWhenGathered( whenGathered );
102 newArtifacts.add( artifact );
104 artifactDAOStub.setArtifacts( newArtifacts );
106 Map<String, String> reqParams = new HashMap<String, String>();
107 reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
109 SyndFeed feed = newArtifactsProcessor.process( reqParams );
111 assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
112 assertTrue( feed.getDescription().equals(
113 "New artifacts found in repository 'test-repo' during repository scan." ) );
114 assertTrue( feed.getLanguage().equals( "en-us" ) );
115 assertTrue( feed.getPublishedDate().equals( whenGathered ) );
117 List<SyndEntry> entries = feed.getEntries();
118 assertEquals( entries.size(), 1 );
119 assertTrue( entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
120 assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );