View Javadoc

1   package org.apache.maven.model.converter.plugins;
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 junit.framework.Assert;
23  import org.apache.maven.model.converter.ProjectConverterException;
24  import org.codehaus.plexus.util.xml.Xpp3Dom;
25  
26  import java.io.IOException;
27  
28  /**
29   * @author Dennis Lundberg
30   * @version $Id: PCCChangelogTest.java 661727 2008-05-30 14:21:49Z bentmann $
31   */
32  public class PCCChangelogTest
33      extends AbstractPCCTest
34  {
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39  
40          pluginConfigurationConverter = new PCCChangelog();
41      }
42  
43      public void testBuildConfiguration1()
44      {
45          try
46          {
47              projectProperties.load( getClassLoader().getResourceAsStream( "PCCChangelogTest1.properties" ) );
48  
49              pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
50  
51              String value = configuration.getChild( "commentFormat" ).getValue();
52              Assert.assertEquals( "check commentFormat value", "%Sn - %c - Activity: %[activity]p", value );
53  
54              value = configuration.getChild( "dateFormat" ).getValue();
55              Assert.assertEquals( "check dateFormat value", "yyyy-MM-dd", value );
56  
57              value = configuration.getChild( "outputEncoding" ).getValue();
58              Assert.assertEquals( "check outputEncoding value", "ISO-8859-1", value );
59  
60              value = configuration.getChild( "tagBase" ).getValue();
61              Assert.assertEquals( "check tagBase value", "http://svn.apache.org/repos/asf/maven/plugins/", value );
62  
63              value = configuration.getChild( "type" ).getValue();
64              Assert.assertEquals( "check type value", "date", value );
65  
66              Xpp3Dom dates = configuration.getChild( "dates" );
67              if ( dates.getChildCount() == 1 )
68              {
69                  Xpp3Dom date = dates.getChild( 0 );
70                  Assert.assertEquals( "check dates/date value", "2005-01-01", date.getValue() );
71              }
72              else
73              {
74                  Assert.fail( "Wrong number of date elements" );
75              }
76          }
77          catch ( ProjectConverterException e )
78          {
79              Assert.fail( e.getMessage() );
80          }
81          catch ( IOException e )
82          {
83              Assert.fail( "Unable to find the requested resource." );
84          }
85      }
86  
87      public void testBuildConfiguration2()
88      {
89          try
90          {
91              projectProperties.load( getClassLoader().getResourceAsStream( "PCCChangelogTest2.properties" ) );
92  
93              pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
94  
95              String value = configuration.getChild( "type" ).getValue();
96              Assert.assertEquals( "check type value", "range", value );
97  
98              value = configuration.getChild( "range" ).getValue();
99              Assert.assertEquals( "check range value", "120", value );
100         }
101         catch ( ProjectConverterException e )
102         {
103             Assert.fail( e.getMessage() );
104         }
105         catch ( IOException e )
106         {
107             Assert.fail( "Unable to find the requested resource." );
108         }
109     }
110 
111     public void testBuildConfiguration3()
112     {
113         try
114         {
115             projectProperties.load( getClassLoader().getResourceAsStream( "PCCChangelogTest3.properties" ) );
116 
117             pluginConfigurationConverter.buildConfiguration( configuration, v3Model, projectProperties );
118 
119             String value = configuration.getChild( "type" ).getValue();
120             Assert.assertEquals( "check type value", "tag", value );
121 
122             Xpp3Dom tags = configuration.getChild( "tags" );
123             if ( tags.getChildCount() == 1 )
124             {
125                 Xpp3Dom tag = tags.getChild( 0 );
126                 Assert.assertEquals( "check tags/tag value", "RELEASE-1_0", tag.getValue() );
127             }
128             else
129             {
130                 Assert.fail( "Wrong number of tag elements" );
131             }
132         }
133         catch ( ProjectConverterException e )
134         {
135             Assert.fail( e.getMessage() );
136         }
137         catch ( IOException e )
138         {
139             Assert.fail( "Unable to find the requested resource." );
140         }
141     }
142 }