001: package de.java2html.plugin.jspwiki.test;
002:
003: import java.util.HashMap;
004:
005: import junit.framework.TestCase;
006:
007: import com.ecyrd.jspwiki.plugin.PluginException;
008:
009: import de.java2html.JavaSourceConversionSettings;
010: import de.java2html.options.JavaSourceStyleTable;
011: import de.java2html.plugin.AbstractJava2HtmlPlugin;
012: import de.java2html.plugin.jspwiki.Java2HtmlPlugin;
013:
014: /**
015: * @author Markus Gebhard
016: */
017: public class Java2HtmlPluginTest extends TestCase {
018: private final static String SOURCE_CODE = "public class HelloWorld {\n"
019: + " public static void main(String args[]) {\n"
020: + " System.out.println(\"Hello World!\");\n"
021: + " }\n"
022: + "}";
023:
024: private final static String CONVERTED_HTML_DEFAULT_STYLE = AbstractJava2HtmlPlugin
025: .convert(SOURCE_CODE, AbstractJava2HtmlPlugin
026: .getDefaultSettings());
027:
028: private Java2HtmlPlugin plugin;
029:
030: private static String CONVERTED_HTML_MONOCHROME_STYLE;
031:
032: static {
033: JavaSourceConversionSettings monochromeOptions = AbstractJava2HtmlPlugin
034: .getDefaultSettings();
035: monochromeOptions.getConversionOptions().setStyleTable(
036: JavaSourceStyleTable.getDefaultMonochromeStyleTable());
037: CONVERTED_HTML_MONOCHROME_STYLE = AbstractJava2HtmlPlugin
038: .convert(SOURCE_CODE, monochromeOptions);
039: }
040:
041: protected void setUp() throws Exception {
042: plugin = new Java2HtmlPlugin();
043:
044: }
045:
046: public void testThrowsUsageExceptionWhenNoSourceCodeGiven() {
047: try {
048: plugin.execute(null, new HashMap());
049: fail();
050: } catch (PluginException expected) {
051: assertEquals(Java2HtmlPlugin.DEFAULT_USAGE_MESSAGE,
052: expected.getMessage());
053: }
054: }
055:
056: public void testConversionAsSourceParameter()
057: throws PluginException {
058: HashMap map = new HashMap();
059: map.put("source", SOURCE_CODE);
060: assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null,
061: map));
062: }
063:
064: public void testConversionAsBodyParameter() throws PluginException {
065: HashMap map = new HashMap();
066: map.put("_body", SOURCE_CODE);
067: assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null,
068: map));
069: }
070:
071: public void testConversionAsBodyParameterWithLeadingNewLine()
072: throws PluginException {
073: /*
074: * Reason: JSPWiki does not automatically remove the extra newline in the
075: * multiline parameter _body
076: */
077: HashMap map = new HashMap();
078: map.put("_body", "\n" + SOURCE_CODE);
079: assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null,
080: map));
081: }
082:
083: //TODO Dec 2, 2003 (Markus Gebhard): This test needs a WikiContext
084: // public void testConversionFromNonExistingFile() {
085: // HashMap map = new HashMap();
086: // map.put("url", "file:/i/am/not/existing/at/all.java");
087: // try {
088: // plugin.execute(null, map);
089: // }
090: // catch (PluginException expected) {
091: // //expected
092: // }
093: // }
094:
095: public void testUsingDefaultStyleNameIsSameAsUsingDefaultStyle()
096: throws PluginException {
097: HashMap map = new HashMap();
098: map.put("source", SOURCE_CODE);
099: map.put("style", AbstractJava2HtmlPlugin.getDefaultSettings()
100: .getConversionOptions().getStyleTable().getName());
101: assertEquals(CONVERTED_HTML_DEFAULT_STYLE, plugin.execute(null,
102: map));
103: }
104:
105: public void testUsingMonochromeStyle() throws PluginException {
106: HashMap map = new HashMap();
107: map.put("source", SOURCE_CODE);
108: map.put("style", JavaSourceStyleTable
109: .getDefaultMonochromeStyleTable().getName());
110: assertEquals(CONVERTED_HTML_MONOCHROME_STYLE, plugin.execute(
111: null, map));
112: }
113:
114: public void testUnsupportedConversionStyle() {
115: HashMap map = new HashMap();
116: map.put("style", "a_definitely_not_existing_style");
117: try {
118: plugin.execute(null, map);
119: } catch (PluginException expected) {
120: //expected
121: }
122: }
123: }
|