1 package org.apache.turbine.util.template;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
38
39
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
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
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
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
96 assertEquals("<!DOCTYPE HTML>", page.getDefaultDoctype());
97 }
98 }