]> source.dussan.org Git - archiva.git/blob
c8eb0c192f03df82a98a4bed621a6695a00acb19
[archiva.git] /
1 package org.apache.archiva.rss;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.commons.io.FileUtils;
27 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
28 import org.custommonkey.xmlunit.XMLAssert;
29
30 /**
31  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
32  * @version
33  */
34 public class RssFeedGeneratorTest
35     extends PlexusInSpringTestCase
36 {
37     private RssFeedGenerator generator;
38    
39     public void setUp()
40         throws Exception
41     {
42         super.setUp();
43
44         generator = (RssFeedGenerator) lookup( RssFeedGenerator.class );
45
46         File outputDir = new File( getBasedir(), "/target/test-classes/rss-feeds" );
47         outputDir.mkdir();
48     }
49     
50     public void testNewFeed()
51         throws Exception
52     {
53         generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
54
55         List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
56         RssFeedEntry entry = new RssFeedEntry( "Item 1", "http://rss-2.0-test-feed.com" );
57
58         entry.setDescription( "RSS 2.0 feed item 1." );
59         entry.setGuid( "http://rss-2.0-test-feed.com/item1" );
60         entries.add( entry );
61
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" );
65         entries.add( entry );
66
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" );
70         entries.add( entry );
71
72         generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
73                                 "generated-rss2.0-feed.xml" );
74
75         File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-rss2.0-feed.xml" );
76         String generatedContent = FileUtils.readFileToString( outputFile );
77
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 );
82
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 );
87
88         outputFile.deleteOnExit();
89     }
90     
91     public void testUpdateFeed()
92         throws Exception
93     {
94         generator.setRssDirectory( getBasedir() + "/target/test-classes/rss-feeds/" );
95
96         List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
97         RssFeedEntry entry = new RssFeedEntry( "Item 1", "http://rss-2.0-test-feed.com" );
98
99         entry.setDescription( "RSS 2.0 feed item 1." );
100         entry.setGuid( "http://rss-2.0-test-feed.com/item1" );
101         entries.add( entry );
102
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 );
107
108         generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
109                                 "generated-test-update-rss2.0-feed.xml" );
110
111         File outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );
112         String generatedContent = FileUtils.readFileToString( outputFile );
113
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 );
118
119         String expectedItem1 =
120             "<channel><item><title>Item 1</title></item><item><title>Item 2</title></item></channel>";
121         
122         XMLAssert.assertXpathsEqual( "//channel/item/title", expectedItem1, "//channel/item/title", generatedContent );
123
124         //update existing rss feed
125         entries = new ArrayList<RssFeedEntry>();
126         entry = new RssFeedEntry( "Item 3", "http://rss-2.0-test-feed.com" );
127
128         entry.setDescription( "RSS 2.0 feed item 3." );
129         entry.setGuid( "http://rss-2.0-test-feed.com/item4" );
130         entries.add( entry );
131
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 );
136
137         generator.generateFeed( "Test Feed", "http://localhost:8080/archiva", "The test feed from Archiva.", entries,
138                                 "generated-test-update-rss2.0-feed.xml" );
139         
140         outputFile = new File( getBasedir(), "/target/test-classes/rss-feeds/generated-test-update-rss2.0-feed.xml" );        
141         generatedContent = FileUtils.readFileToString( outputFile );       
142         
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 );
147
148         expectedItem1 =
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 );
152         
153         outputFile.deleteOnExit();
154     }
155
156 }