View Javadoc

1   package org.apache.archiva.rss.processor;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
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;
27  import java.util.Map;
28  
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;
33  
34  import com.sun.syndication.feed.synd.SyndEntry;
35  import com.sun.syndication.feed.synd.SyndFeed;
36  
37  /**
38   * @version
39   */
40  public class NewArtifactsRssFeedProcessorTest
41      extends PlexusInSpringTestCase
42  {
43      private static final String TEST_REPO = "test-repo";
44  
45      private NewArtifactsRssFeedProcessor newArtifactsProcessor;
46  
47      private ArtifactDAOStub artifactDAOStub;
48  
49      private RssFeedGenerator rssFeedGenerator;
50  
51      @Override
52      public void setUp()
53          throws Exception
54      {
55          super.setUp();
56  
57          newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
58          artifactDAOStub = new ArtifactDAOStub();
59  
60          rssFeedGenerator = new RssFeedGenerator();
61  
62          newArtifactsProcessor.setGenerator( rssFeedGenerator );
63          newArtifactsProcessor.setArtifactDAO( artifactDAOStub );
64      }
65  
66      @SuppressWarnings("unchecked")
67      public void testProcess()
68          throws Exception
69      {
70          List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
71          Date whenGathered = Calendar.getInstance().getTime();
72  
73          ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar", TEST_REPO );
74          artifact.getModel().setWhenGathered( whenGathered );
75          newArtifacts.add( artifact );
76  
77          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar", TEST_REPO );
78          artifact.getModel().setWhenGathered( whenGathered );
79          newArtifacts.add( artifact );
80  
81          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar", TEST_REPO );
82          artifact.getModel().setWhenGathered( whenGathered );
83          newArtifacts.add( artifact );
84  
85          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
86          artifact.getModel().setWhenGathered( whenGathered );
87          newArtifacts.add( artifact );
88  
89          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
90          artifact.getModel().setWhenGathered( whenGathered );
91          newArtifacts.add( artifact );
92  
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 );
96  
97          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar", TEST_REPO );
98          artifact.getModel().setWhenGathered( whenGathered );
99          newArtifacts.add( artifact );
100 
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 );
104 
105         artifactDAOStub.setArtifacts( newArtifacts );
106 
107         Map<String, String> reqParams = new HashMap<String, String>();
108         reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
109 
110         SyndFeed feed = newArtifactsProcessor.process( reqParams );
111 
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 ) );
117 
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 ) );
122     }
123 }