View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.testing;
20  
21  import java.io.StringReader;
22  
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.codehaus.plexus.configuration.PlexusConfiguration;
25  import org.codehaus.plexus.util.xml.Xpp3Dom;
26  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
27  
28  /**
29   * @author Edwin Punzalan
30   */
31  public class ExpressionEvaluatorTest extends AbstractMojoTestCase {
32      private Xpp3Dom pomDom;
33  
34      private PlexusConfiguration pluginConfiguration;
35  
36      /** {@inheritDoc} */
37      @Override
38      protected void setUp() throws Exception {
39          super.setUp();
40  
41          StringBuffer pom = new StringBuffer();
42  
43          pom.append("<project>").append("\n");
44          pom.append("  <build>").append("\n");
45          pom.append("    <plugins>").append("\n");
46          pom.append("      <plugin>").append("\n");
47          pom.append("        <artifactId>maven-test-mojo</artifactId>").append("\n");
48          pom.append("        <configuration>").append("\n");
49          pom.append("          <basedir>${basedir}</basedir>").append("\n");
50          pom.append("          <workdir>${basedir}/workDirectory</workdir>").append("\n");
51          pom.append("          <localRepository>${localRepository}</localRepository>")
52                  .append("\n");
53          pom.append("        </configuration>").append("\n");
54          pom.append("      </plugin>").append("\n");
55          pom.append("    </plugins>").append("\n");
56          pom.append("  </build>").append("\n");
57          pom.append("</project>").append("\n");
58  
59          pomDom = Xpp3DomBuilder.build(new StringReader(pom.toString()));
60  
61          pluginConfiguration = extractPluginConfiguration("maven-test-mojo", pomDom);
62      }
63  
64      /**
65       * @throws Exception if any
66       */
67      public void testInjection() throws Exception {
68          ExpressionEvaluatorMojo mojo = new ExpressionEvaluatorMojo();
69  
70          mojo = (ExpressionEvaluatorMojo) configureMojo(mojo, pluginConfiguration);
71  
72          try {
73              mojo.execute();
74          } catch (MojoExecutionException e) {
75              fail(e.getMessage());
76          }
77      }
78  }