001package org.apache.turbine.util.template; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 023import static org.junit.jupiter.api.Assertions.*; 024 025import org.apache.turbine.TurbineConstants; 026import org.apache.turbine.annotation.AnnotationProcessor; 027import org.apache.turbine.annotation.TurbineConfiguration; 028import org.apache.turbine.test.BaseTestCase; 029import org.apache.turbine.util.TurbineConfig; 030import org.apache.turbine.util.TurbineException; 031import org.junit.jupiter.api.AfterAll; 032import org.junit.jupiter.api.BeforeAll; 033import org.junit.jupiter.api.BeforeEach; 034import org.junit.jupiter.api.Test; 035 036/** 037 * Testing of the HtmlPageAttributes class 038 * 039 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> 040 */ 041public class HtmlPageAttributesTest extends BaseTestCase 042{ 043 044 @TurbineConfiguration( TurbineConstants.DEFAULT_HTML_DOCTYPE_ROOT_ELEMENT_KEY ) 045 private String defaultHtmlDoctypeRootElement = TurbineConstants.DEFAULT_HTML_DOCTYPE_ROOT_ELEMENT_DEFAULT; 046 047 @TurbineConfiguration( TurbineConstants.DEFAULT_HTML_DOCTYPE_IDENTIFIER_KEY ) 048 private String defaultHtmlDoctypeIdentifier; 049 050 @TurbineConfiguration( TurbineConstants.DEFAULT_HTML_DOCTYPE_URI_KEY ) 051 private String defaultHtmlDoctypeUri; 052 053 private static TurbineConfig tc = null; 054 055 @BeforeAll 056 public static void init() throws Exception 057 { 058 tc = new TurbineConfig(".", "/conf/test/CompleteTurbineResources.properties"); 059 tc.initialize(); 060 } 061 062 @AfterAll 063 public static void destroy() 064 throws Exception 065 { 066 tc.dispose(); 067 } 068 069 @BeforeEach 070 public void setUpBefore() throws Exception 071 { 072 // do nothing 073 } 074 075 @Test public void testBuildDoctype() throws TurbineException 076 { 077 HtmlPageAttributes page = new HtmlPageAttributes(); 078 assertEquals("<!DOCTYPE html>", page.getDoctype("html", null, null)); 079 assertEquals("<!DOCTYPE html>", page.getDoctype("html", "", "")); 080 assertEquals("<!DOCTYPE html SYSTEM \"bla\">", page.getDoctype("html", "", "bla")); 081 082 // by default empty in HTML 5 083 assertEquals("<!DOCTYPE HTML>", 084 page.getDoctype(TurbineConstants.DEFAULT_HTML_DOCTYPE_ROOT_ELEMENT_DEFAULT, 085 TurbineConstants.DEFAULT_HTML_DOCTYPE_IDENTIFIER_DEFAULT, 086 TurbineConstants.DEFAULT_HTML_DOCTYPE_URI_DEFAULT)); 087 // test old style locally 088 AnnotationProcessor.process(this); 089 assertEquals("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " 090 + "\"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">", 091 page.getDoctype(defaultHtmlDoctypeRootElement, 092 defaultHtmlDoctypeIdentifier, 093 defaultHtmlDoctypeUri)); 094 095 // HTML 5 is the default 096 assertEquals("<!DOCTYPE HTML>", page.getDefaultDoctype()); 097 } 098}