01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestJdk14Loader.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.cmf.loader.xhtml;
09:
10: import java.util.HashSet;
11: import java.util.Set;
12: import junit.framework.TestCase;
13:
14: public class TestJdk14Loader extends TestCase {
15: public TestJdk14Loader(String name) {
16: super (name);
17: }
18:
19: public void testIsBackendPresent() {
20: Jdk14Loader loader = new Jdk14Loader();
21: assertTrue(loader.isBackendPresent());
22: }
23:
24: public void testLoadSuccess() throws Exception {
25: Jdk14Loader loader = new Jdk14Loader();
26: Set<String> errors = new HashSet<String>();
27:
28: String xhtml = loader.load("<p>some <b>html</b> here</p>",
29: true, errors);
30:
31: assertNotNull(xhtml);
32: assertEquals(0, errors.size());
33: }
34:
35: public void testLoadUnsupportedType() throws Exception {
36: Jdk14Loader loader = new Jdk14Loader();
37: Set<String> errors = new HashSet<String>();
38:
39: String xhtml = loader.load(new Object(), true, errors);
40:
41: assertNull(xhtml);
42: assertEquals(0, errors.size());
43: }
44:
45: public void testLoadFromStringSuccessFragment() throws Exception {
46: Jdk14Loader loader = new Jdk14Loader();
47: Set<String> errors = new HashSet<String>();
48:
49: String xhtml = loader.loadFromString(
50: "<p>some <b>html</b> here</p>", true, errors);
51:
52: assertNotNull(xhtml);
53: assertEquals(0, errors.size());
54: }
55:
56: public void testLoadFromStringSuccessComplete() throws Exception {
57: Jdk14Loader loader = new Jdk14Loader();
58: Set<String> errors = new HashSet<String>();
59:
60: String xhtml = loader
61: .loadFromString(
62: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
63: + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
64: + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body>\n"
65: + "<p>body</p>\n" + "</body></html>",
66: false, errors);
67:
68: assertNotNull(xhtml);
69: assertEquals(0, errors.size());
70: }
71:
72: public void testLoadFromStringError() throws Exception {
73: Jdk14Loader loader = new Jdk14Loader();
74: Set<String> errors = new HashSet<String>();
75:
76: String xhtml = loader.loadFromString("<i><b>error</i>", true,
77: errors);
78:
79: assertNull(xhtml);
80: assertEquals(1, errors.size());
81: }
82:
83: public void testLoadFromStringErrorNoList() throws Exception {
84: Jdk14Loader loader = new Jdk14Loader();
85:
86: String xhtml = loader.loadFromString(
87: "<i><test>error</test></i>", true, null);
88:
89: assertNull(xhtml);
90: }
91: }
|