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