1 package com.sourcesense.maven.plugins.test;
2
3
4 import java.io.File;
5
6 import org.apache.maven.plugin.MojoExecutionException;
7 import org.apache.maven.project.MavenProject;
8
9 import com.sourcesense.maven.StripMojo;
10
11 public class StripTest extends org.apache.maven.plugin.testing.AbstractMojoTestCase {
12
13 File testPom;
14 MavenProject project = new MavenProject();
15
16 protected void setUp() throws Exception {
17
18 super.setUp();
19
20 }
21
22 /***
23 * tests the proper discovery and configuration of the mojo
24 *
25 * @throws Exception
26 */
27 public void testMojoDefaultEnvironment() throws Exception {
28 testPom = new File( getBasedir(), "target/test-classes/snapshot-pom.xml" );
29 StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
30 assertNotNull( mojo );
31
32 }
33
34 public void testSnapshotVersion() throws Exception {
35 testPom = new File( getBasedir(), "target/test-classes/snapshot-pom.xml" );
36 StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
37 setVariableValueToObject(mojo, "version", "3.0.0-SNAPSHOT");
38 setVariableValueToObject(mojo, "project", project);
39 try {
40 mojo.execute();
41 } catch (MojoExecutionException e) {
42 fail("Mojo execution exception" + e);
43 }
44 assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
45 mojo.getPropertyName()));
46 }
47
48 public void testReleaseCandidateVersion() throws Exception {
49 testPom = new File( getBasedir(), "target/test-classes/relcandidate-pom.xml" );
50 StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
51 setVariableValueToObject(mojo, "version", "3.0.0-RC1");
52 setVariableValueToObject(mojo, "project", project);
53 try {
54 mojo.execute();
55 } catch (MojoExecutionException e) {
56 fail("Mojo execution exception" + e);
57 }
58 assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
59 mojo.getPropertyName()));
60 }
61
62 public void testIdempotent() throws Exception {
63 testPom = new File( getBasedir(), "target/test-classes/snapshot-pom.xml" );
64 StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
65 setVariableValueToObject(mojo, "version", "3.0.0");
66 setVariableValueToObject(mojo, "project", project);
67 try {
68 mojo.execute();
69 } catch (MojoExecutionException e) {
70 fail("Mojo execution exception" + e);
71 }
72 assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
73 mojo.getPropertyName()));
74 }
75
76 public void testUnderscore() throws Exception {
77 testPom = new File( getBasedir(), "target/test-classes/underscore-pom.xml" );
78 StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
79 setVariableValueToObject(mojo, "version", "3.0.0_RC1");
80 setVariableValueToObject(mojo, "project", project);
81 try {
82 mojo.execute();
83 } catch (MojoExecutionException e) {
84 fail("Mojo execution exception" + e);
85 }
86 assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
87 mojo.getPropertyName()));
88 }
89
90 public void testCustomPropName() throws Exception {
91 testPom = new File( getBasedir(), "target/test-classes/customprop-pom.xml" );
92 StripMojo mojo = (StripMojo) lookupMojo ("strip", testPom );
93 setVariableValueToObject(mojo, "version", "3.0.0-RC1");
94 setVariableValueToObject(mojo, "project", project);
95 try {
96 mojo.execute();
97 } catch (MojoExecutionException e) {
98 fail("Mojo execution exception" + e);
99 }
100 assertEquals("3.0.0", mojo.getProject().getProperties().getProperty(
101 "foobar"));
102 }
103
104 }