KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > plugin > jspwiki > test > Java2HtmlPluginTest


1 package de.java2html.plugin.jspwiki.test;
2
3 import java.util.HashMap JavaDoc;
4
5 import junit.framework.TestCase;
6
7 import com.ecyrd.jspwiki.plugin.PluginException;
8
9 import de.java2html.JavaSourceConversionSettings;
10 import de.java2html.options.JavaSourceStyleTable;
11 import de.java2html.plugin.AbstractJava2HtmlPlugin;
12 import de.java2html.plugin.jspwiki.Java2HtmlPlugin;
13
14 /**
15  * @author Markus Gebhard
16  */

17 public class Java2HtmlPluginTest extends TestCase {
18   private final static String JavaDoc SOURCE_CODE = "public class HelloWorld {\n"
19       + " public static void main(String args[]) {\n"
20       + " System.out.println(\"Hello World!\");\n"
21       + " }\n"
22       + "}";
23
24   private final static String JavaDoc CONVERTED_HTML_DEFAULT_STYLE = AbstractJava2HtmlPlugin.convert(
25       SOURCE_CODE,
26       AbstractJava2HtmlPlugin.getDefaultSettings());
27
28   private Java2HtmlPlugin plugin;
29
30   private static String JavaDoc CONVERTED_HTML_MONOCHROME_STYLE;
31
32   static {
33     JavaSourceConversionSettings monochromeOptions = AbstractJava2HtmlPlugin.getDefaultSettings();
34     monochromeOptions.getConversionOptions().setStyleTable(JavaSourceStyleTable.getDefaultMonochromeStyleTable());
35     CONVERTED_HTML_MONOCHROME_STYLE = AbstractJava2HtmlPlugin.convert(SOURCE_CODE, monochromeOptions);
36   }
37
38   protected void setUp() throws Exception JavaDoc {
39     plugin = new Java2HtmlPlugin();
40
41   }
42
43   public void testThrowsUsageExceptionWhenNoSourceCodeGiven() {
44     try {
45       plugin.execute(null, new HashMap JavaDoc());
46       fail();
47     }
48     catch (PluginException expected) {
49       assertEquals(Java2HtmlPlugin.DEFAULT_USAGE_MESSAGE, expected.getMessage());
50     }
51   }
52
53   public void testConversionAsSourceParameter() throws PluginException {
54     HashMap JavaDoc map = new HashMap JavaDoc();
55     map.put("source", SOURCE_CODE);
56     assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map));
57   }
58
59   public void testConversionAsBodyParameter() throws PluginException {
60     HashMap JavaDoc map = new HashMap JavaDoc();
61     map.put("_body", SOURCE_CODE);
62     assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map));
63   }
64
65   public void testConversionAsBodyParameterWithLeadingNewLine() throws PluginException {
66     /*
67      * Reason: JSPWiki does not automatically remove the extra newline in the
68      * multiline parameter _body
69      */

70     HashMap JavaDoc map = new HashMap JavaDoc();
71     map.put("_body", "\n" + SOURCE_CODE);
72     assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map));
73   }
74
75   //TODO Dec 2, 2003 (Markus Gebhard): This test needs a WikiContext
76
// public void testConversionFromNonExistingFile() {
77
// HashMap map = new HashMap();
78
// map.put("url", "file:/i/am/not/existing/at/all.java");
79
// try {
80
// plugin.execute(null, map);
81
// }
82
// catch (PluginException expected) {
83
// //expected
84
// }
85
// }
86

87   public void testUsingDefaultStyleNameIsSameAsUsingDefaultStyle() throws PluginException {
88     HashMap JavaDoc map = new HashMap JavaDoc();
89     map.put("source", SOURCE_CODE);
90     map.put("style", AbstractJava2HtmlPlugin
91         .getDefaultSettings().getConversionOptions().getStyleTable().getName());
92     assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null, map));
93   }
94
95   public void testUsingMonochromeStyle() throws PluginException {
96     HashMap JavaDoc map = new HashMap JavaDoc();
97     map.put("source", SOURCE_CODE);
98     map.put("style", JavaSourceStyleTable.getDefaultMonochromeStyleTable().getName());
99     assertEquals(CONVERTED_HTML_MONOCHROME_STYLE, plugin.execute(null, map));
100   }
101
102   public void testUnsupportedConversionStyle() {
103     HashMap JavaDoc map = new HashMap JavaDoc();
104     map.put("style", "a_definitely_not_existing_style");
105     try {
106       plugin.execute(null, map);
107     }
108     catch (PluginException expected) {
109       //expected
110
}
111   }
112 }
Popular Tags