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