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;
32 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
35 public class RssFeedGeneratorTest
36 extends PlexusInSpringTestCase
38 private RssFeedGenerator generator;
45 generator = (RssFeedGenerator) lookup( RssFeedGenerator.class );
48 public void testNewFeed()
51 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
52 RssFeedEntry entry = new RssFeedEntry( "Item 1" );
54 Date whenGathered = new Date( System.currentTimeMillis() );
56 entry.setDescription( "RSS 2.0 feed item 1." );
57 entry.setPublishedDate( whenGathered );
60 entry = new RssFeedEntry( "Item 2" );
61 entry.setDescription( "RSS 2.0 feed item 2." );
62 entry.setPublishedDate( whenGathered );
65 entry = new RssFeedEntry( "Item 3" );
66 entry.setDescription( "RSS 2.0 feed item 3." );
67 entry.setPublishedDate( whenGathered );
71 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries );
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() );
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() );
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.
89 public void testUpdateFeed()
92 generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
94 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
95 RssFeedEntry entry = new RssFeedEntry( "Item 1" );
97 entry.setDescription( "RSS 2.0 feed item 1." );
100 entry = new RssFeedEntry( "Item 2" );
101 entry.setDescription( "RSS 2.0 feed item 2." );
102 entries.add( entry );
104 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
105 "generated-test-update-rss2.0-feed.xml" );
107 File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
108 String generatedContent = FileUtils.readFileToString( outputFile );
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 );
115 String expectedItem1 =
116 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
118 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
120 //update existing rss feed
121 entries = new ArrayList<RssFeedEntry>();
122 entry = new RssFeedEntry( "Item 3" );
124 entry.setDescription( "RSS 2.0 feed item 3." );
125 entries.add( entry );
127 entry = new RssFeedEntry( "Item 4" );
128 entry.setDescription( "RSS 2.0 feed item 4." );
129 entries.add( entry );
131 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
132 "generated-test-update-rss2.0-feed.xml" );
134 outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
135 generatedContent = FileUtils.readFileToString( outputFile );
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 );
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 );
147 outputFile.deleteOnExit();