1 package org.apache.maven.plugin.pmd;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.plugin.MojoFailureException;
23 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
24
25 import java.io.File;
26
27
28
29
30
31 public class PmdViolationCheckMojoTest
32 extends AbstractMojoTestCase
33 {
34
35 protected void setUp()
36 throws Exception
37 {
38 super.setUp();
39 }
40
41 public void testDefaultConfiguration()
42 throws Exception
43 {
44 try
45 {
46 File testPom = new File( getBasedir(),
47 "src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml" );
48 PmdViolationCheckMojo mojo = (PmdViolationCheckMojo) lookupMojo( "check", testPom );
49 mojo.execute();
50
51 fail( "MojoFailureException should be thrown." );
52 }
53 catch ( Exception e )
54 {
55 assertTrue( true );
56 }
57 }
58
59 public void testNotFailOnViolation()
60 throws Exception
61 {
62 File testPom = new File( getBasedir(),
63 "src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" );
64 PmdReport mojo = (PmdReport) lookupMojo( "pmd", testPom );
65 mojo.execute();
66
67 testPom = new File( getBasedir(),
68 "src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml" );
69 PmdViolationCheckMojo pmdViolationMojo = (PmdViolationCheckMojo) lookupMojo( "check", testPom );
70 pmdViolationMojo.execute();
71
72 assertTrue( true );
73 }
74
75 public void testFailurePriority()
76 throws Exception
77 {
78 File testPom = new File( getBasedir(),
79 "src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml" );
80 PmdViolationCheckMojo pmdViolationMojo = (PmdViolationCheckMojo) lookupMojo( "check", testPom );
81 pmdViolationMojo.execute();
82
83 testPom = new File( getBasedir(),
84 "src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml" );
85 pmdViolationMojo = (PmdViolationCheckMojo) lookupMojo( "check", testPom );
86 try
87 {
88 pmdViolationMojo.execute();
89 fail( "Exception Expected" );
90 }
91 catch ( MojoFailureException e )
92 {
93 System.out.println( "Caught Expected Message: " + e.getMessage() );
94 }
95
96 }
97
98 public void testException()
99 throws Exception
100 {
101 try
102 {
103 File testPom = new File( getBasedir(),
104 "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml" );
105 PmdViolationCheckMojo mojo = (PmdViolationCheckMojo) lookupMojo( "check", testPom );
106 mojo.execute();
107
108 fail( "MojoFailureException should be thrown." );
109 }
110 catch ( Exception e )
111 {
112 assertTrue( true );
113 }
114
115 }
116 }