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
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.apache.commons.io.FileUtils;
27 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
28 import org.custommonkey.xmlunit.XMLAssert;
31 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34 public class RssFeedGeneratorTest
35 extends PlexusInSpringTestCase
37 private RssFeedGenerator generator;
44 generator = (RssFeedGenerator) lookup( RssFeedGenerator.class );
46 File outputDir = new File( getBasedir(), "/target/test-classes/rss-feeds" );
50 public void testNewFeed()
53 generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
55 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
56 RssFeedEntry entry = new RssFeedEntry( "Item 1", "http://rss-2.0-test-feed.com" );
58 entry.setDescription( "RSS 2.0 feed item 1." );
59 entry.setGuid( "http://rss-2.0-test-feed.com/item1" );
62 entry = new RssFeedEntry( "Item 2", "http://rss-2.0-test-feed.com" );
63 entry.setDescription( "RSS 2.0 feed item 2." );
64 entry.setGuid( "http://rss-2.0-test-feed.com/item2" );
67 entry = new RssFeedEntry( "Item 3", "http://rss-2.0-test-feed.com" );
68 entry.setDescription( "RSS 2.0 feed item 3." );
69 entry.setGuid( "http://rss-2.0-test-feed.com/item3" );
72 generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
73 "generated-rss2.0-feed.xml" );
75 File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-rss2.0-feed.xml" );
76 String generatedContent = FileUtils.readFileToString( outputFile );
78 XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
79 XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva", "//channel/link", generatedContent );
80 XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
81 XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
83 String expectedItem1 =
84 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item>"
85 + "<item><title>Item 3</title></item></channel>";
86 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
88 outputFile.deleteOnExit();
91 public void testUpdateFeed()
94 generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
96 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
97 RssFeedEntry entry = new RssFeedEntry( "Item 1", "http://rss-2.0-test-feed.com" );
99 entry.setDescription( "RSS 2.0 feed item 1." );
100 entry.setGuid( "http://rss-2.0-test-feed.com/item1" );
101 entries.add( entry );
103 entry = new RssFeedEntry( "Item 2", "http://rss-2.0-test-feed.com" );
104 entry.setDescription( "RSS 2.0 feed item 2." );
105 entry.setGuid( "http://rss-2.0-test-feed.com/item2" );
106 entries.add( entry );
108 generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
109 "generated-test-update-rss2.0-feed.xml" );
111 File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
112 String generatedContent = FileUtils.readFileToString( outputFile );
114 XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
115 XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva", "//channel/link", generatedContent );
116 XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
117 XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
119 String expectedItem1 =
120 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
122 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
124 //update existing rss feed
125 entries = new ArrayList<RssFeedEntry>();
126 entry = new RssFeedEntry( "Item 3", "http://rss-2.0-test-feed.com" );
128 entry.setDescription( "RSS 2.0 feed item 3." );
129 entry.setGuid( "http://rss-2.0-test-feed.com/item4" );
130 entries.add( entry );
132 entry = new RssFeedEntry( "Item 4", "http://rss-2.0-test-feed.com" );
133 entry.setDescription( "RSS 2.0 feed item 4." );
134 entry.setGuid( "http://rss-2.0-test-feed.com/item5" );
135 entries.add( entry );
137 generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
138 "generated-test-update-rss2.0-feed.xml" );
140 outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
141 generatedContent = FileUtils.readFileToString( outputFile );
143 XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
144 XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva", "//channel/link", generatedContent );
145 XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
146 XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
149 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item>"
150 + "<item><title>Item 3</title></item><item><title>Item 4</title></item></channel>";
151 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
153 outputFile.deleteOnExit();