]> source.dussan.org Git - archiva.git/blob
1b8b876b7b335617d18a85b98645989bc1890ec9
[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( "http://localhost:8080/archiva/rss/generated-rss2.0-feed.xml", feed.getLink() );
75         assertEquals( "The test feed from Archiva.", feed.getDescription() );
76         assertEquals( "en-us", feed.getLanguage() );
77         assertEquals( entries.get( 2 ).getPublishedDate(), feed.getPublishedDate() );
78
79         List<SyndEntry> syndEntries = feed.getEntries();
80         assertEquals( 3, syndEntries.size() );
81         assertEquals( "Item 1", syndEntries.get( 0 ).getTitle() );
82         assertEquals( "Item 2", syndEntries.get( 1 ).getTitle() );
83         assertEquals( "Item 3", syndEntries.get( 2 ).getTitle() );
84     }
85
86     /*
87      * this test might need to be removed since
88      * no updates are happening in the feeds anymore since everything's processed from the db.
89      * 
90     public void testUpdateFeed()
91         throws Exception
92     {
93         generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
94
95         List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
96         RssFeedEntry entry = new RssFeedEntry( "Item 1" );
97
98         entry.setDescription( "RSS 2.0 feed item 1." );
99         entries.add( entry );
100
101         entry = new RssFeedEntry( "Item 2" );
102         entry.setDescription( "RSS 2.0 feed item 2." );
103         entries.add( entry );
104
105         generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
106                                 "generated-test-update-rss2.0-feed.xml" );
107
108         File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
109         String generatedContent = FileUtils.readFileToString( outputFile );
110
111         XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
112         XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva/rss/generated-test-update-rss2.0-feed.xml", "//channel/link", generatedContent );
113         XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
114         XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
115
116         String expectedItem1 =
117             "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
118         
119         XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
120
121         //update existing rss feed
122         entries = new ArrayList<RssFeedEntry>();
123         entry = new RssFeedEntry( "Item 3" );
124
125         entry.setDescription( "RSS 2.0 feed item 3." );
126         entries.add( entry );
127
128         entry = new RssFeedEntry( "Item 4" );
129         entry.setDescription( "RSS 2.0 feed item 4." );
130         entries.add( entry );
131
132         generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
133                                 "generated-test-update-rss2.0-feed.xml" );
134         
135         outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );        
136         generatedContent = FileUtils.readFileToString( outputFile );       
137         
138         XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
139         XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva/rss/generated-test-update-rss2.0-feed.xml", "//channel/link", generatedContent );
140         XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
141         XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
142
143         expectedItem1 =
144             "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item>"
145             + "<item><title>Item 3</title></item><item><title>Item 4</title></item></channel>";
146         XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
147         
148         outputFile.deleteOnExit();
149     }
150      */
151
152 }