1 package org.apache.maven.plugin.testing;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.configuration.PlexusConfiguration;
23 import org.codehaus.plexus.util.xml.Xpp3Dom;
24 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
25
26 import java.io.StringReader;
27 import java.util.Map;
28
29
30
31
32
33 public class MojoTestCaseTest
34 extends AbstractMojoTestCase
35 {
36 private String pom;
37
38 private Xpp3Dom pomDom;
39
40 private PlexusConfiguration pluginConfiguration;
41
42
43 protected void setUp()
44 throws Exception
45 {
46 super.setUp();
47
48 pom =
49 "<project>" +
50 "<build>" +
51 "<plugins>" +
52 "<plugin>" +
53 "<artifactId>maven-simple-plugin</artifactId>" +
54 "<configuration>" +
55 "<keyOne>valueOne</keyOne>" +
56 "<keyTwo>valueTwo</keyTwo>" +
57 "</configuration>" +
58 "</plugin>" +
59 "</plugins>" +
60 "</build>" +
61 "</project>";
62
63 pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
64
65 pluginConfiguration = extractPluginConfiguration( "maven-simple-plugin", pomDom );
66 }
67
68
69
70
71 public void testPluginConfigurationExtraction()
72 throws Exception
73 {
74 assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() );
75
76 assertEquals( "valueTwo", pluginConfiguration.getChild( "keyTwo" ).getValue() );
77 }
78
79
80
81
82 public void testMojoConfiguration()
83 throws Exception
84 {
85 SimpleMojo mojo = new SimpleMojo();
86
87 mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
88
89 assertEquals( "valueOne", mojo.getKeyOne() );
90
91 assertEquals( "valueTwo", mojo.getKeyTwo() );
92 }
93
94
95
96
97 public void testVariableAccessWithoutGetter()
98 throws Exception
99 {
100 SimpleMojo mojo = new SimpleMojo();
101
102 mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
103
104 assertEquals( "valueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) );
105
106 assertEquals( "valueTwo", (String)getVariableValueFromObject( mojo, "keyTwo" ) );
107 }
108
109
110
111
112 public void testVariableAccessWithoutGetter2()
113 throws Exception
114 {
115 SimpleMojo mojo = new SimpleMojo();
116
117 mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
118
119 Map map = getVariablesAndValuesFromObject( mojo );
120
121 assertEquals( "valueOne", (String)map.get( "keyOne" ) );
122
123 assertEquals( "valueTwo", (String)map.get( "keyTwo" ) );
124 }
125
126
127
128
129 public void testSettingMojoVariables()
130 throws Exception
131 {
132 SimpleMojo mojo = new SimpleMojo();
133
134 mojo = (SimpleMojo) configureMojo( mojo, pluginConfiguration );
135
136 setVariableValueToObject( mojo, "keyOne", "myValueOne" );
137
138 assertEquals( "myValueOne", (String)getVariableValueFromObject( mojo, "keyOne" ) );
139
140 }
141
142 }