]> source.dussan.org Git - archiva.git/blob
0c8287be0dc40d0c5c6aa45cb73c0ac7a80c0ab4
[archiva.git] /
1 package org.apache.archiva.rss;
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.Date;
24 import java.util.List;
25
26 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
27
28 import com.sun.syndication.feed.synd.SyndEntry;
29 import com.sun.syndication.feed.synd.SyndFeed;
30
31 /**
32  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
33  * @version
34  */
35 public class RssFeedGeneratorTest
36     extends PlexusInSpringTestCase
37 {
38     private RssFeedGenerator generator;
39
40     public void setUp()
41         throws Exception
42     {
43         super.setUp();
44
45         generator = (RssFeedGenerator) lookup( RssFeedGenerator.class );
46     }
47
48     public void testNewFeed()
49         throws Exception
50     {
51         List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
52         RssFeedEntry entry = new RssFeedEntry( "Item 1" );
53         
54         Date whenGathered = new Date( System.currentTimeMillis() );
55
56         entry.setDescription( "RSS 2.0 feed item 1." );
57         entry.setPublishedDate( whenGathered );
58         entries.add( entry );
59
60         entry = new RssFeedEntry( "Item 2" );
61         entry.setDescription( "RSS 2.0 feed item 2." );
62         entry.setPublishedDate( whenGathered );
63         entries.add( entry );
64
65         entry = new RssFeedEntry( "Item 3" );
66         entry.setDescription( "RSS 2.0 feed item 3." );
67         entry.setPublishedDate( whenGathered );
68         entries.add( entry );
69
70         SyndFeed feed =
71             generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries );
72
73         assertEquals( "Test Feed", feed.getTitle() );        
74         assertEquals( "The test feed from Archiva.", feed.getDescription() );
75         assertEquals( "en-us", feed.getLanguage() );
76         assertEquals( entries.get( 2 ).getPublishedDate(), feed.getPublishedDate() );
77
78         List<SyndEntry> syndEntries = feed.getEntries();
79         assertEquals( 3, syndEntries.size() );
80         assertEquals( "Item 1", syndEntries.get( 0 ).getTitle() );
81         assertEquals( "Item 2", syndEntries.get( 1 ).getTitle() );
82         assertEquals( "Item 3", syndEntries.get( 2 ).getTitle() );
83     }
84
85     /*
86      * this test might need to be removed since
87      * no updates are happening in the feeds anymore since everything's processed from the db.
88      * 
89     public void testUpdateFeed()
90         throws Exception
91     {
92         generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
93
94         List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
95         RssFeedEntry entry = new RssFeedEntry( "Item 1" );
96
97         entry.setDescription( "RSS 2.0 feed item 1." );
98         entries.add( entry );
99
100         entry = new RssFeedEntry( "Item 2" );
101         entry.setDescription( "RSS 2.0 feed item 2." );
102         entries.add( entry );
103
104         generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
105                                 "generated-test-update-rss2.0-feed.xml" );
106
107         File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
108         String generatedContent = FileUtils.readFileToString( outputFile );
109
110         XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
111         XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva/rss/generated-test-update-rss2.0-feed.xml", "//channel/link", generatedContent );
112         XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
113         XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
114
115         String expectedItem1 =
116             "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
117         
118         XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
119
120         //update existing rss feed
121         entries = new ArrayList<RssFeedEntry>();
122         entry = new RssFeedEntry( "Item 3" );
123
124         entry.setDescription( "RSS 2.0 feed item 3." );
125         entries.add( entry );
126
127         entry = new RssFeedEntry( "Item 4" );
128         entry.setDescription( "RSS 2.0 feed item 4." );
129         entries.add( entry );
130
131         generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
132                                 "generated-test-update-rss2.0-feed.xml" );
133         
134         outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );        
135         generatedContent = FileUtils.readFileToString( outputFile );       
136         
137         XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
138         XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva/rss/generated-test-update-rss2.0-feed.xml", "//channel/link", generatedContent );
139         XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
140         XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
141
142         expectedItem1 =
143             "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item>"
144             + "<item><title>Item 3</title></item><item><title>Item 4</title></item></channel>";
145         XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
146         
147         outputFile.deleteOnExit();
148     }
149      */
150
151 }