View Javadoc
1   package org.apache.maven.plugins.javadoc;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.apache.maven.model.Plugin;
25  import org.apache.maven.plugin.MojoExecution;
26  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
27  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
28  import org.apache.maven.project.MavenProject;
29  import org.codehaus.plexus.util.FileUtils;
30  
31  /**
32   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
33   */
34  public class TestJavadocReportTest
35      extends AbstractMojoTestCase
36  {
37      /**
38       * Test the test-javadoc configuration for the plugin
39       *
40       * @throws Exception if any
41       */
42      public void testTestJavadoc()
43          throws Exception
44      {
45          File testPom =
46              new File( getBasedir(),
47                        "src/test/resources/unit/test-javadoc-test/test-javadoc-test-plugin-config.xml" );
48          TestJavadocReport mojo = (TestJavadocReport) lookupMojo( "test-javadoc", testPom );
49          
50          MojoExecution mojoExec = new MojoExecution( new Plugin(), "test-javadoc", null );
51  
52          setVariableValueToObject( mojo, "mojo", mojoExec );
53  
54          MavenProject currentProject = new MavenProjectStub();
55          currentProject.setGroupId( "GROUPID" );
56          currentProject.setArtifactId( "ARTIFACTID" );
57          
58          setVariableValueToObject( mojo, "session", newMavenSession( currentProject ) );
59  
60          mojo.execute();
61  
62          File generatedFile =
63              new File( getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/maven/AppTest.html" );
64          assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
65          
66          File options = new File( getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/options");
67          FileUtils.fileRead( options ).contains( "junit-3.8.1.jar" );
68      }
69  }