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( "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() );
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() );
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.
90 public void testUpdateFeed()
93 generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
95 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
96 RssFeedEntry entry = new RssFeedEntry( "Item 1" );
98 entry.setDescription( "RSS 2.0 feed item 1." );
101 entry = new RssFeedEntry( "Item 2" );
102 entry.setDescription( "RSS 2.0 feed item 2." );
103 entries.add( entry );
105 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
106 "generated-test-update-rss2.0-feed.xml" );
108 File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
109 String generatedContent = FileUtils.readFileToString( outputFile );
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 );
116 String expectedItem1 =
117 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
119 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
121 //update existing rss feed
122 entries = new ArrayList<RssFeedEntry>();
123 entry = new RssFeedEntry( "Item 3" );
125 entry.setDescription( "RSS 2.0 feed item 3." );
126 entries.add( entry );
128 entry = new RssFeedEntry( "Item 4" );
129 entry.setDescription( "RSS 2.0 feed item 4." );
130 entries.add( entry );
132 generator.generateFeed( "Test Feed", "The test feed from Archiva.", entries,
133 "generated-test-update-rss2.0-feed.xml" );
135 outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
136 generatedContent = FileUtils.readFileToString( outputFile );
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 );
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 );
148 outputFile.deleteOnExit();