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  
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
26  
27  
28  
29  /**
30   * @author <a href="mailto:olamy@apache.org">olamy</a>
31   * @since 29 juil. 2008
32   * @version $Id: ChangesValidatorMojoTest.html 816601 2012-05-08 12:50:18Z hboutemy $
33   */
34  public class ChangesValidatorMojoTest
35      extends AbstractMojoTestCase
36  {
37  
38      protected ChangesValidatorMojo mojo;
39  
40      public void setUp()
41          throws Exception
42      {
43          super.setUp();
44          File pom = new File( getBasedir(), "/src/test/unit/plugin-config.xml" );
45          mojo = (ChangesValidatorMojo) lookupMojo( "changes-validate", pom );
46      }    
47      
48      public void testValidationSuccess()
49          throws Exception
50      {
51          File changesXml = new File( getBasedir(), "/src/test/unit/changes.xml" );
52          setVariableValueToObject( mojo, "xmlPath", changesXml );
53          setVariableValueToObject( mojo, "changesXsdVersion", "1.0.0" );
54          setVariableValueToObject( mojo, "failOnError", Boolean.TRUE );
55          mojo.execute();
56      }
57  
58      public void testValidationFailedWithMojoFailure()
59          throws Exception
60      {
61          File changesXml = new File( getBasedir(), "/src/test/unit/non-valid-changes.xml" );
62          setVariableValueToObject( mojo, "xmlPath", changesXml );
63          setVariableValueToObject( mojo, "changesXsdVersion", "1.0.0" );
64          setVariableValueToObject( mojo, "failOnError", Boolean.TRUE );
65          try
66          {
67              mojo.execute();
68              fail( " a MojoExecutionException should occur here changes file is not valid and failOnError is true " );
69          }
70          catch ( MojoExecutionException e )
71          {
72              // we except exception here
73          }
74      }
75      
76      public void testValidationFailedWithNoMojoFailure()
77          throws Exception
78      {
79          File changesXml = new File( getBasedir(), "/src/test/unit/non-valid-changes.xml" );
80          setVariableValueToObject( mojo, "xmlPath", changesXml );
81          setVariableValueToObject( mojo, "changesXsdVersion", "1.0.0" );
82          setVariableValueToObject( mojo, "failOnError", Boolean.FALSE );
83          mojo.execute();
84  
85      }
86  }