View Javadoc

1   package org.apache.velocity.tools.plugin.taglib;
2   
3   import static org.easymock.EasyMock.*;
4   
5   import java.io.File;
6   import java.io.IOException;
7   import java.util.ArrayList;
8   import java.util.List;
9   
10  import org.apache.commons.io.FileUtils;
11  import org.apache.maven.plugin.MojoExecutionException;
12  import org.apache.maven.plugin.MojoFailureException;
13  import org.apache.maven.project.MavenProject;
14  import org.junit.Test;
15  
16  /**
17   * Tests {@link Taglib2Directive}.
18   *
19   */
20  public class Taglib2DirectiveTest
21  {
22  
23      /**
24       * Tests {@link Taglib2Directive#execute()}.
25       *
26       * @throws IOException If something goes wrong.
27       * @throws MojoFailureException If something goes wrong.
28       * @throws MojoExecutionException If something goes wrong.
29       */
30      @Test
31      public void testExecute() throws IOException, MojoExecutionException,
32              MojoFailureException
33      {
34          MavenProject mavenProject = createMock(MavenProject.class);
35  
36          Taglib2Directive mojo = new Taglib2Directive();
37          File tempDir = File.createTempFile("velocity2directive", "tmp");
38          tempDir.delete();
39          tempDir.mkdirs();
40          mojo.classesOutputDirectory = tempDir;
41          List<String> classpathElements = new ArrayList<String>();
42          String classesPath = System.getProperty("basedir")
43                  + "/target/test-classes";
44          classpathElements.add(classesPath);
45          mojo.classpathElements = classpathElements;
46          mojo.packageName = "org.apache.velocity.tools.test";
47          mojo.prefix = "sample";
48          mojo.tld = "sample.tld";
49  
50          mavenProject.addCompileSourceRoot(tempDir.getAbsolutePath());
51  
52          replay(mavenProject);
53          mojo.project = mavenProject;
54          mojo.execute();
55  
56          FileUtils.contentEquals(new File(tempDir,
57                  "org/apache/velocity/tools/test/MyClassicTag.java"), new File(
58                  classesPath, "MyClassicTag.javat"));
59          FileUtils.contentEquals(new File(tempDir,
60                  "org/apache/velocity/tools/test/MyBodylessClassicTag.java"),
61                  new File(classesPath, "MyBodylessClassicTag.javat"));
62          FileUtils.contentEquals(new File(tempDir,
63                  "org/apache/velocity/tools/test/MySimpleTag.java"), new File(
64                  classesPath, "MySimpleTag.javat"));
65          verify(mavenProject);
66  
67          FileUtils.deleteDirectory(tempDir);
68      }
69  
70  }