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.PlexusTestCase;
28 import org.custommonkey.xmlunit.XMLAssert;
31 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34 public class RssFeedGeneratorTest
35 extends PlexusTestCase
37 private RssFeedGenerator generator;
44 generator = (RssFeedGenerator) lookup( RssFeedGenerator.class );
46 File outputDir = new File( getBasedir(), "/target/test-classes/rss-feeds" );
50 public void testGenerateFeed()
53 File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-rss2.0-feed.xml" );
55 List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
56 RssFeedEntry entry = new RssFeedEntry();
58 entry.setTitle( "Item 1" );
59 entry.setLink( "http://rss-2.0-test-feed.com" );
60 entry.setDescription( "RSS 2.0 feed item 1." );
61 entry.setGuid( "http://rss-2.0-test-feed.com/item1" );
64 entry = new RssFeedEntry();
65 entry.setTitle( "Item 2" );
66 entry.setLink( "http://rss-2.0-test-feed.com" );
67 entry.setDescription( "RSS 2.0 feed item 2." );
68 entry.setGuid( "http://rss-2.0-test-feed.com/item2" );
71 entry = new RssFeedEntry();
72 entry.setTitle( "Item 3" );
73 entry.setLink( "http://rss-2.0-test-feed.com" );
74 entry.setDescription( "RSS 2.0 feed item 3." );
75 entry.setGuid( "http://rss-2.0-test-feed.com/item3" );
78 generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
81 String generatedContent = FileUtils.readFileToString( outputFile );
83 XMLAssert.assertXpathEvaluatesTo( "Test Feed", "//channel/title", generatedContent );
84 XMLAssert.assertXpathEvaluatesTo( "http://localhost:8080/archiva", "//channel/link", generatedContent );
85 XMLAssert.assertXpathEvaluatesTo( "The test feed from Archiva.", "//channel/description", generatedContent );
86 XMLAssert.assertXpathEvaluatesTo( "en-us", "//channel/language", generatedContent );
88 String expectedItem1 =
89 "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item>"
90 + "<item><title>Item 3</title></item></channel>";
91 XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );