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