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.File;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.apache.maven.plugin.logging.Log;
27  import org.apache.maven.plugins.changes.model.Action;
28  import org.apache.maven.plugins.changes.model.FixedIssue;
29  import org.apache.maven.plugins.changes.model.Release;
30  import org.codehaus.plexus.PlexusTestCase;
31  import org.codehaus.plexus.logging.Logger;
32  import org.codehaus.plexus.logging.console.ConsoleLogger;
33  
34  /**
35   * @author <a href="mailto:olamy@apache.org">olamy</a>
36   * @since 27 juil. 2008
37   * @version $Id: ChangesXMLTest.html 816603 2012-05-08 12:53:30Z hboutemy $
38   */
39  public class ChangesXMLTest
40      extends PlexusTestCase
41  {
42  
43      private static class MockLog
44          implements Log
45      {
46          Logger consoleLogger;
47  
48          private MockLog()
49          {
50              consoleLogger = new ConsoleLogger( 1, "test" );
51          }
52  
53          public void debug( CharSequence content )
54          {
55              consoleLogger.debug( content.toString() );
56          }
57  
58          public void debug( Throwable error )
59          {
60              consoleLogger.debug( error.getMessage() );
61  
62          }
63  
64          public void debug( CharSequence content, Throwable error )
65          {
66              consoleLogger.debug( error.getMessage(), error );
67  
68          }
69  
70          public void error( CharSequence content )
71          {
72              consoleLogger.error( content.toString() );
73          }
74  
75          public void error( Throwable error )
76          {
77              consoleLogger.error( error.getMessage() );
78          }
79  
80          public void error( CharSequence content, Throwable error )
81          {
82              consoleLogger.error( error.getMessage(), error );
83  
84          }
85  
86          public void info( CharSequence content )
87          {
88              consoleLogger.info( content.toString() );
89          }
90  
91          public void info( Throwable error )
92          {
93              consoleLogger.info( error.getMessage() );
94          }
95  
96          public void info( CharSequence content, Throwable error )
97          {
98              consoleLogger.info( error.getMessage(), error );
99          }
100 
101         public boolean isDebugEnabled()
102         {
103             return consoleLogger.isDebugEnabled();
104         }
105 
106         public boolean isErrorEnabled()
107         {
108             return consoleLogger.isErrorEnabled();
109         }
110 
111         public boolean isInfoEnabled()
112         {
113             return consoleLogger.isInfoEnabled();
114         }
115 
116         public boolean isWarnEnabled()
117         {
118             return consoleLogger.isWarnEnabled();
119         }
120 
121         public void warn( CharSequence content )
122         {
123             consoleLogger.warn( content.toString() );
124         }
125 
126         public void warn( Throwable error )
127         {
128             consoleLogger.warn( error.getMessage() );
129 
130         }
131 
132         public void warn( CharSequence content, Throwable error )
133         {
134             consoleLogger.warn( content.toString(), error );
135 
136         }
137 
138     }
139 
140     public void testParseChangesFile()
141         throws Exception
142     {
143         File changesFile = new File( getBasedir() + "/src/test/unit/changes.xml" );
144         ChangesXML changesXML = new ChangesXML( changesFile, new MockLog() );
145         assertNotNull( changesXML.getChangesDocument() );
146         assertEquals( "Changes report Project", changesXML.getTitle() );
147 
148         List releases = changesXML.getReleaseList();
149         assertEquals( 2, releases.size() );
150         for ( Iterator iterator = releases.iterator(); iterator.hasNext(); )
151         {
152             Release release = (Release) iterator.next();
153             if ( "1.0".equals( release.getVersion() ) )
154             {
155                 Action action = (Action) release.getActions().get( 0 );
156                 assertEquals( 2, action.getFixedIssues().size() );
157                 assertEquals( "JIRA-XXX", ( (FixedIssue) action.getFixedIssues().get( 0 ) ).getIssue() );
158                 assertEquals( "JIRA-YYY", ( (FixedIssue) action.getFixedIssues().get( 1 ) ).getIssue() );
159                 assertEquals( 2, action.getDueTos().size() );
160             }
161         }
162     }
163     
164 }