View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.changes;
20  
21  import java.io.IOException;
22  import java.io.StringWriter;
23  import java.io.Writer;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Locale;
27  
28  import junit.framework.TestCase;
29  import org.apache.maven.plugins.changes.model.Release;
30  
31  /**
32   * @author ltheussl
33   */
34  public class FeedGeneratorTest extends TestCase {
35      /**
36       * Test of isSupportedFeedType method, of class FeedGenerator.
37       */
38      public void testIsSupportedFeedType() {
39          final FeedGenerator generator = new FeedGenerator(Locale.ENGLISH);
40  
41          assertTrue("rss_0.9 not supported?", generator.isSupportedFeedType("rss_0.9"));
42          assertTrue("rss_0.91N not supported?", generator.isSupportedFeedType("rss_0.91N"));
43          assertTrue("rss_0.91U not supported?", generator.isSupportedFeedType("rss_0.91U"));
44          assertTrue("rss_0.92 not supported?", generator.isSupportedFeedType("rss_0.92"));
45          assertTrue("rss_0.93 not supported?", generator.isSupportedFeedType("rss_0.93"));
46          assertTrue("rss_0.94 not supported?", generator.isSupportedFeedType("rss_0.94"));
47          assertTrue("rss_1.0 not supported?", generator.isSupportedFeedType("rss_1.0"));
48          assertTrue("rss_2.0 not supported?", generator.isSupportedFeedType("rss_2.0"));
49          assertTrue("atom_0.3 not supported?", generator.isSupportedFeedType("atom_0.3"));
50          assertTrue("atom_1.0 not supported?", generator.isSupportedFeedType("atom_1.0"));
51  
52          assertFalse(generator.isSupportedFeedType(""));
53          assertFalse(generator.isSupportedFeedType(null));
54          assertFalse(generator.isSupportedFeedType("rss"));
55      }
56  
57      /**
58       * Test of export method, of class FeedGenerator.
59       *
60       * @throws Exception if any.
61       */
62      public void testExport() throws Exception {
63          final FeedGenerator generator = new FeedGenerator(Locale.ENGLISH);
64          generator.setAuthor("author");
65          generator.setTitle("title");
66          generator.setLink("url");
67          generator.setDateFormat(null);
68  
69          Release release = new Release();
70          release.setVersion("1.0");
71          List<Release> releases = new ArrayList<>(1);
72  
73          try {
74              // test with no release: should fail
75              generator.export(releases, "rss_0.9", new StringWriter(512));
76              fail("0 releases not allowed!");
77          } catch (IOException ex) {
78              assertNotNull(ex.getMessage());
79          }
80  
81          releases.add(release);
82  
83          for (String type : generator.getSupportedFeedTypes()) {
84              try (Writer writer = new StringWriter(512)) {
85                  generator.export(releases, type, writer);
86                  String result = writer.toString(); // TODO: save for inspection?
87                  assertNotNull(result);
88                  assertTrue(result.length() > 0);
89              }
90          }
91      }
92  }