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  public class NewVersionsOfArtifactRssFeedProcessorTest
38      extends PlexusInSpringTestCase
39  {
40      private static final String TEST_REPO = "test-repo";
41  
42      private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
43  
44      private ArtifactDAOStub artifactDAOStub;
45  
46      private RssFeedGenerator rssFeedGenerator;
47  
48      @Override
49      public void setUp()
50          throws Exception
51      {
52          super.setUp();
53  
54          newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
55          artifactDAOStub = new ArtifactDAOStub();
56  
57          rssFeedGenerator = new RssFeedGenerator();
58  
59          newVersionsProcessor.setGenerator( rssFeedGenerator );
60          newVersionsProcessor.setArtifactDAO( artifactDAOStub );
61      }
62  
63      @SuppressWarnings("unchecked")
64      public void testProcess()
65          throws Exception
66      {
67          List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
68  
69          Date whenGathered = Calendar.getInstance().getTime();
70          whenGathered.setTime( 123456789 );
71   
72          ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
73          artifact.getModel().setWhenGathered( whenGathered );
74          artifacts.add( artifact );
75  
76          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
77          artifact.getModel().setWhenGathered( whenGathered );
78          artifacts.add( artifact );
79  
80          Date whenGatheredNext = Calendar.getInstance().getTime();
81          whenGatheredNext.setTime( 345678912 );      
82  
83          artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
84          artifact.getModel().setWhenGathered( whenGatheredNext );
85          artifacts.add( artifact );
86  
87          artifactDAOStub.setArtifacts( artifacts );
88  
89          Map<String, String> reqParams = new HashMap<String, String>();
90          reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
91          reqParams.put( RssFeedProcessor.KEY_GROUP_ID, "org.apache.archiva" );
92          reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, "artifact-two" );
93  
94          SyndFeed feed = newVersionsProcessor.process( reqParams );
95  
96          assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );        
97          assertEquals(
98                        "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
99                        feed.getDescription() );
100         assertEquals( "en-us", feed.getLanguage() );
101         assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() );
102 
103         List<SyndEntry> entries = feed.getEntries();
104 
105         assertEquals( 2, entries.size() );
106         
107         assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered,
108                       entries.get( 0 ).getTitle() );
109         assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() );
110         
111         assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext,
112                       entries.get( 1 ).getTitle() );
113         assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() );
114     }
115 }