1 package org.apache.archiva.rss;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
26 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
28 import com.sun.syndication.feed.synd.SyndEntry;
29 import com.sun.syndication.feed.synd.SyndFeed;
34 public class RssFeedGeneratorTest
35 extends PlexusInSpringTestCase
37 private RssFeedGenerator generator;
44 generator = (RssFeedGenerator) lookup( RssFeedGenerator.class );
47 public void testNewFeed()
50 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
51 RssFeedEntry entry = new RssFeedEntry( "Item 1" );
53 Date whenGathered = new Date( System.currentTimeMillis() );
55 entry.setDescription( "RSS 2.0 feed item 1." );
56 entry.setPublishedDate( whenGathered );
59 entry = new RssFeedEntry( "Item 2" );
60 entry.setDescription( "RSS 2.0 feed item 2." );
61 entry.setPublishedDate( whenGathered );
64 entry = new RssFeedEntry( "Item 3" );
65 entry.setDescription( "RSS 2.0 feed item 3." );
66 entry.setPublishedDate( whenGathered );
70 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries );
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() );
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() );
84 public void testNoDataEntries()
87 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
89 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries );
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.
98 public void testUpdateFeed()
101 generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
103 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
104 RssFeedEntry entry = new RssFeedEntry( "Item 1" );
106 entry.setDescription( "RSS 2.0 feed item 1." );
107 entries.add( entry );
109 entry = new RssFeedEntry( "Item 2" );
110 entry.setDescription( "RSS 2.0 feed item 2." );
111 entries.add( entry );
113 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
114 "generated-test-update-rss2.0-feed.xml" );
116 File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
117 String generatedContent = FileUtils.readFileToString( outputFile );
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 );
124 String expectedItem1 =
125 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
127 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
129 //update existing rss feed
130 entries = new ArrayList<RssFeedEntry>();
131 entry = new RssFeedEntry( "Item 3" );
133 entry.setDescription( "RSS 2.0 feed item 3." );
134 entries.add( entry );
136 entry = new RssFeedEntry( "Item 4" );
137 entry.setDescription( "RSS 2.0 feed item 4." );
138 entries.add( entry );
140 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
141 "generated-test-update-rss2.0-feed.xml" );
143 outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
144 generatedContent = FileUtils.readFileToString( outputFile );
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 );
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 );
156 outputFile.deleteOnExit();