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