View Javadoc
1   package org.apache.maven.plugin.announcement;
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.io.FileReader;
24  
25  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
26  import org.codehaus.plexus.util.FileUtils;
27  import org.codehaus.plexus.util.IOUtil;
28  
29  /**
30   * @author Olivier Lamy
31   * @version $Id: AnnouncementMojoTest.java 1742353 2016-05-05 03:22:53Z schulte $
32   */
33  public class AnnouncementMojoTest
34      extends AbstractMojoTestCase
35  {
36  
37      public void testAnnounceGeneration()
38          throws Exception
39      {
40          File pom = new File( getBasedir(), "/src/test/unit/plugin-config.xml" );
41          AnnouncementMojo mojo = (AnnouncementMojo) lookupMojo( "announcement-generate", pom );
42  
43          setVariableValueToObject( mojo, "xmlPath", new File( getBasedir(), "/src/test/unit/announce-changes.xml" ) );
44  
45          File announcementDirectory = new File( getBasedir(), "target/test" );
46  
47          if ( announcementDirectory.exists() )
48          {
49              FileUtils.deleteDirectory( announcementDirectory );
50              announcementDirectory.mkdirs();
51          }
52          else
53          {
54              announcementDirectory.mkdirs();
55          }
56          setVariableValueToObject( mojo, "announcementDirectory", announcementDirectory );
57          setVariableValueToObject( mojo, "version", "1.1" );
58          setVariableValueToObject( mojo, "template", "announcement.vm" );
59          setVariableValueToObject( mojo, "templateDirectory",
60                                    "/src/main/resources/org/apache/maven/plugin/announcement/" );
61          setVariableValueToObject( mojo, "basedir", getBasedir() );
62          setVariableValueToObject( mojo, "introduction", "Nice library" );
63          mojo.execute();
64  
65          FileReader fileReader = new FileReader( new File( announcementDirectory, "announcement.vm" ) );
66          String result = IOUtil.toString( fileReader );
67  
68          fileReader.close();
69  
70          assertContains( "Nice library", result );
71  
72          assertContains( "Changes in this version include:", result );
73  
74          assertContains( "New features:", result );
75  
76          assertContains( "o Added additional documentation on how to configure the plugin.", result );
77  
78          assertContains( "Fixed Bugs:", result );
79  
80          assertContains( "o Enable retrieving component-specific issues.  Issue: MCHANGES-88.", result );
81  
82          assertContains( "Changes:", result );
83  
84          assertContains( "o Handle different issue systems.", result );
85  
86          assertContains( "o Updated dependencies.", result );
87  
88          assertContains( "Removed:", result );
89  
90          assertContains( "o The element type \" link \" must be terminated by the matching end-tag.", result );
91  
92          assertContains( "Deleted the erroneous code.", result );
93      }
94  
95      protected void assertContains( String content, String announce )
96      {
97          assertTrue( announce.indexOf( content ) > 0 );
98      }
99  }