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.doxia.siterenderer;
20  
21  import java.io.File;
22  
23  import org.codehaus.plexus.testing.PlexusTest;
24  import org.junit.jupiter.api.Test;
25  
26  import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
27  import static org.junit.jupiter.api.Assertions.assertEquals;
28  
29  /**
30   * @author <a href="mailto:olamy@apache.org">olamy</a>
31   * @since 20 oct. 07
32   */
33  @PlexusTest
34  public class RenderingContextTest {
35  
36      /**
37       * Test getRelativePath() with various file names.
38       *
39       * @throws java.lang.Exception if any.
40       */
41      @Test
42      public void testFileNameWithDot() throws Exception {
43          File baseDir = new File(getBasedir() + File.separatorChar + "test" + File.separatorChar + "resources");
44  
45          String docName = "file.with.dot.in.name.xml";
46          DocumentRenderingContext docRenderingContext =
47                  new DocumentRenderingContext(baseDir, "test", docName, "", "xml", false);
48          assertEquals("file.with.dot.in.name.html", docRenderingContext.getOutputName());
49          assertEquals(".", docRenderingContext.getRelativePath());
50  
51          docName = "file.with.dot.in.name";
52          docRenderingContext = new DocumentRenderingContext(baseDir, docName, "generator"); // not Doxia source
53          assertEquals("file.with.dot.in.name.html", docRenderingContext.getOutputName());
54          assertEquals(".", docRenderingContext.getRelativePath());
55  
56          docName = "index.xml.vm";
57          docRenderingContext = new DocumentRenderingContext(baseDir, "test", docName, "", "xml", false);
58          assertEquals("index.html", docRenderingContext.getOutputName());
59          assertEquals(".", docRenderingContext.getRelativePath());
60  
61          docName = "download.apt.vm";
62          docRenderingContext = new DocumentRenderingContext(baseDir, "test", docName, "", "apt", false);
63          assertEquals("download.html", docRenderingContext.getOutputName());
64          assertEquals(".", docRenderingContext.getRelativePath());
65  
66          docName = "path/file.apt";
67          docRenderingContext = new DocumentRenderingContext(baseDir, "test", docName, "", "apt", false);
68          assertEquals("path/file.html", docRenderingContext.getOutputName());
69          assertEquals("..", docRenderingContext.getRelativePath());
70  
71          docName = "path/file";
72          docRenderingContext = new DocumentRenderingContext(baseDir, docName, "generator"); // not Doxia source
73          assertEquals("path/file.html", docRenderingContext.getOutputName());
74          assertEquals("..", docRenderingContext.getRelativePath());
75      }
76  }