View Javadoc

1   package org.apache.maven.plugin.jxr;
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 org.apache.maven.plugin.testing.AbstractMojoTestCase;
23  import org.codehaus.plexus.util.FileUtils;
24  
25  import java.io.BufferedReader;
26  import java.io.File;
27  import java.io.FileReader;
28  import java.io.IOException;
29  
30  /**
31   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
32   */
33  public class JxrTestReportTest
34      extends AbstractMojoTestCase
35  {
36      protected void setUp()
37          throws Exception
38      {
39          super.setUp();
40      }
41  
42      /**
43       * Method to test when the source dir is the test source dir
44       *
45       * @throws Exception
46       */
47      public void testSourceDir()
48          throws Exception
49      {
50          File testPom =
51              new File( getBasedir(), "src/test/resources/unit/testsourcedir-test/testsourcedir-test-plugin-config.xml" );
52          JxrTestReport mojo = (JxrTestReport) lookupMojo( "test-jxr", testPom );
53          mojo.execute();
54  
55      	File xrefTestDir = new File( getBasedir(), "target/test/unit/testsourcedir-test/target/site/xref-test" );
56  
57          //check if the jxr docs were generated
58          assertTrue( new File( xrefTestDir, "testsourcedir/test/AppSampleTest.html" ).exists() );
59          assertTrue( new File( xrefTestDir, "testsourcedir/test/AppTest.html" ).exists() );
60          assertTrue( new File( xrefTestDir, "testsourcedir/test/package-frame.html" ).exists() );
61          assertTrue( new File( xrefTestDir, "testsourcedir/test/package-summary.html" ).exists() );
62          assertTrue( new File( xrefTestDir, "allclasses-frame.html" ).exists() );
63          assertTrue( new File( xrefTestDir, "index.html" ).exists() );
64          assertTrue( new File( xrefTestDir, "overview-frame.html" ).exists() );
65          assertTrue( new File( xrefTestDir, "overview-summary.html" ).exists() );
66          assertTrue( new File( xrefTestDir, "stylesheet.css" ).exists() );
67  
68          //check if there's a link to the javadoc files
69          String str = readFile( new File( xrefTestDir, "testsourcedir/test/AppSampleTest.html" ) );
70          assertTrue( str.toLowerCase().indexOf( "/apidocs/testsourcedir/test/AppSample.html\"".toLowerCase() ) == -1 );
71  
72          str = readFile( new File( xrefTestDir, "testsourcedir/test/AppTest.html" ) );
73          assertTrue( str.toLowerCase().indexOf( "/apidocs/testsourcedir/test/App.html\"".toLowerCase() ) == -1 );
74  
75      }
76  
77      protected void tearDown()
78          throws Exception
79      {
80  
81      }
82  
83      /**
84       * Read the contents of the specified file object into a string
85       *
86       * @param file the file to be read
87       * @return a String object that contains the contents of the file
88       * @throws java.io.IOException
89       */
90      private String readFile( File file )
91          throws IOException
92      {
93          String str = "", strTmp = "";
94          BufferedReader in = new BufferedReader( new FileReader( file ) );
95  
96          while ( ( strTmp = in.readLine() ) != null )
97          {
98              str = str + " " + strTmp;
99          }
100         in.close();
101 
102         return str;
103     }
104 
105 }