View Javadoc
1   package org.apache.maven.plugin.pmd;
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 org.apache.maven.plugin.testing.AbstractMojoTestCase;
23  
24  import java.io.File;
25  
26  
27  /**
28   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
29   * @version $Id$
30   */
31  public class CpdViolationCheckMojoTest
32      extends AbstractMojoTestCase
33  {
34      /** {@inheritDoc} */
35      @Override
36      protected void setUp()
37          throws Exception
38      {
39          super.setUp();
40      }
41  
42      public void testDefaultConfiguration()
43          throws Exception
44      {
45          try
46          {
47              final File testPom = new File( getBasedir(),
48                                       "src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml" );
49              final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
50              mojo.execute();
51  
52              fail( "MojoFailureException should be thrown." );
53          }
54          catch ( final Exception e )
55          {
56              assertTrue( true );
57          }
58      }
59  
60      public void testNotFailOnViolation()
61          throws Exception
62      {
63  
64          File testPom = new File( getBasedir(),
65                                   "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
66          final CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
67          mojo.execute();
68  
69          testPom = new File( getBasedir(),
70                              "src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml" );
71          final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
72          cpdViolationMojo.execute();
73  
74          assertTrue( true );
75      }
76  
77      public void testException()
78          throws Exception
79      {
80          try
81          {
82              final File testPom = new File( getBasedir(),
83                                             "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml" );
84              final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
85              mojo.execute();
86  
87              fail( "MojoFailureException should be thrown." );
88          }
89          catch ( final Exception e )
90          {
91              assertTrue( true );
92          }
93      }
94  
95      public void testExclusionsConfiguration()
96          throws Exception
97      {
98          File testPom = new File( getBasedir(),
99                                   "src/test/resources/unit/default-configuration/cpd-default-configuration-plugin-config.xml" );
100         final CpdReport mojo = (CpdReport) lookupMojo( "cpd", testPom );
101         mojo.execute();
102 
103         testPom = new File( getBasedir(),
104                             "src/test/resources/unit/default-configuration/pmd-check-cpd-exclusions-configuration-plugin-config.xml" );
105         final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo( "cpd-check", testPom );
106         cpdViolationMojo.execute();
107 
108         assertTrue( true );
109     }       
110 }