View Javadoc
1   package org.apache.turbine.util.template;
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  
23  import static org.junit.jupiter.api.Assertions.*;
24  
25  import org.apache.turbine.TurbineConstants;
26  import org.apache.turbine.annotation.AnnotationProcessor;
27  import org.apache.turbine.annotation.TurbineConfiguration;
28  import org.apache.turbine.test.BaseTestCase;
29  import org.apache.turbine.util.TurbineConfig;
30  import org.apache.turbine.util.TurbineException;
31  import org.junit.jupiter.api.AfterAll;
32  import org.junit.jupiter.api.BeforeAll;
33  import org.junit.jupiter.api.BeforeEach;
34  import org.junit.jupiter.api.Test;
35  
36  /**
37   * Testing of the HtmlPageAttributes class
38   *
39   * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
40   */
41  public class HtmlPageAttributesTest extends BaseTestCase
42  {
43  
44      @TurbineConfiguration( TurbineConstants.DEFAULT_HTML_DOCTYPE_ROOT_ELEMENT_KEY )
45      private String defaultHtmlDoctypeRootElement = TurbineConstants.DEFAULT_HTML_DOCTYPE_ROOT_ELEMENT_DEFAULT;
46  
47      @TurbineConfiguration( TurbineConstants.DEFAULT_HTML_DOCTYPE_IDENTIFIER_KEY )
48      private String defaultHtmlDoctypeIdentifier;
49  
50      @TurbineConfiguration( TurbineConstants.DEFAULT_HTML_DOCTYPE_URI_KEY )
51      private String defaultHtmlDoctypeUri;
52  
53      private static TurbineConfig tc = null;
54  
55      @BeforeAll
56      public static void init() throws Exception
57      {
58          tc = new TurbineConfig(".", "/conf/test/CompleteTurbineResources.properties");
59          tc.initialize();
60      }
61  
62      @AfterAll
63      public static void destroy()
64          throws Exception
65      {
66          tc.dispose();
67      }
68  
69      @BeforeEach
70      public void setUpBefore() throws Exception
71      {
72          // do nothing
73      }
74  
75      @Test public void testBuildDoctype() throws TurbineException
76      {
77          HtmlPageAttributes page = new HtmlPageAttributes();
78          assertEquals("<!DOCTYPE html>", page.getDoctype("html", null, null));
79          assertEquals("<!DOCTYPE html>", page.getDoctype("html", "", ""));
80          assertEquals("<!DOCTYPE html SYSTEM \"bla\">", page.getDoctype("html", "", "bla"));
81  
82         // by default empty in HTML 5
83          assertEquals("<!DOCTYPE HTML>",
84                  page.getDoctype(TurbineConstants.DEFAULT_HTML_DOCTYPE_ROOT_ELEMENT_DEFAULT,
85                          TurbineConstants.DEFAULT_HTML_DOCTYPE_IDENTIFIER_DEFAULT,
86                          TurbineConstants.DEFAULT_HTML_DOCTYPE_URI_DEFAULT));
87          // test old style locally
88          AnnotationProcessor.process(this);
89          assertEquals("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
90                  + "\"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">",
91                  page.getDoctype(defaultHtmlDoctypeRootElement,
92                                  defaultHtmlDoctypeIdentifier,
93                                  defaultHtmlDoctypeUri));
94  
95          // HTML 5 is the default
96          assertEquals("<!DOCTYPE HTML>", page.getDefaultDoctype());
97      }
98  }