View Javadoc
1   package org.apache.maven.plugin.changes;
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.IOException;
23  import java.io.StringWriter;
24  import java.io.Writer;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  import java.util.Locale;
29  
30  import junit.framework.TestCase;
31  
32  import org.apache.maven.plugins.changes.model.Release;
33  
34  /**
35   * @author ltheussl
36   */
37  public class FeedGeneratorTest
38      extends TestCase
39  {
40      /**
41       * Test of isSupportedFeedType method, of class FeedGenerator.
42       */
43      public void testIsSupportedFeedType()
44      {
45          final FeedGenerator generator = new FeedGenerator( Locale.ENGLISH );
46  
47          assertTrue( "rss_0.9 not supported?", generator.isSupportedFeedType( "rss_0.9" ) );
48          assertTrue( "rss_0.91N not supported?", generator.isSupportedFeedType( "rss_0.91N" ) );
49          assertTrue( "rss_0.91U not supported?", generator.isSupportedFeedType( "rss_0.91U" ) );
50          assertTrue( "rss_0.92 not supported?", generator.isSupportedFeedType( "rss_0.92" ) );
51          assertTrue( "rss_0.93 not supported?", generator.isSupportedFeedType( "rss_0.93" ) );
52          assertTrue( "rss_0.94 not supported?", generator.isSupportedFeedType( "rss_0.94" ) );
53          assertTrue( "rss_1.0 not supported?", generator.isSupportedFeedType( "rss_1.0" ) );
54          assertTrue( "rss_2.0 not supported?", generator.isSupportedFeedType( "rss_2.0" ) );
55          assertTrue( "atom_0.3 not supported?", generator.isSupportedFeedType( "atom_0.3" ) );
56          assertTrue( "atom_1.0 not supported?", generator.isSupportedFeedType( "atom_1.0" ) );
57  
58          assertFalse( generator.isSupportedFeedType( "" ) );
59          assertFalse( generator.isSupportedFeedType( null ) );
60          assertFalse( generator.isSupportedFeedType( "rss" ) );
61      }
62  
63      /**
64       * Test of export method, of class FeedGenerator.
65       *
66       * @throws Exception if any.
67       */
68      public void testExport()
69          throws Exception
70      {
71          final FeedGenerator generator = new FeedGenerator( Locale.ENGLISH );
72          generator.setAuthor( "author" );
73          generator.setTitle( "title" );
74          generator.setLink( "url" );
75          generator.setDateFormat( null );
76  
77          Release release = new Release();
78          release.setVersion( "1.0" );
79          List<Release> releases = new ArrayList<Release>( 1 );
80  
81          try
82          {
83              // test with no release: should fail
84              generator.export( releases, "rss_0.9", new StringWriter( 512 ) );
85              fail( "0 releases not allowed!" );
86          }
87          catch ( IOException ex )
88          {
89              assertNotNull( ex );
90          }
91  
92          releases.add( release );
93  
94          for ( String type : generator.getSupportedFeedTypes() )
95          {
96              Writer writer = new StringWriter( 512 );
97              generator.export( releases, type, writer );
98              String result = writer.toString(); // TODO: save for inspection?
99              assertNotNull( result );
100             assertTrue( result.length() > 0 );
101             writer.close();
102         }
103     }
104 }