001: package de.java2html.properties.test;
002:
003: import java.util.Properties;
004:
005: import junit.framework.TestCase;
006: import de.java2html.javasource.JavaSourceType;
007: import de.java2html.options.HorizontalAlignment;
008: import de.java2html.options.IConversionOptionsConstants;
009: import de.java2html.options.JavaSourceConversionOptions;
010: import de.java2html.options.JavaSourceStyleTable;
011: import de.java2html.properties.ConversionOptionsPropertiesReader;
012: import de.java2html.properties.IllegalPropertyValueException;
013: import de.java2html.util.RGB;
014:
015: /**
016: * @author Markus Gebhard
017: */
018: public class ConversionOptionsPropertiesReaderTest extends TestCase {
019: private ConversionOptionsPropertiesReader reader;
020:
021: protected void setUp() throws Exception {
022: reader = new ConversionOptionsPropertiesReader();
023: }
024:
025: public void testReadingEmptyProperties()
026: throws IllegalPropertyValueException {
027: Properties properties = new Properties();
028: JavaSourceConversionOptions options = reader.read(properties);
029: assertEquals(JavaSourceConversionOptions.getDefault(), options);
030: }
031:
032: public void testUnknownPropertyIgnored()
033: throws IllegalPropertyValueException {
034: Properties properties = new Properties();
035: properties.setProperty("_unsupportedkey_", "value"); //$NON-NLS-1$ //$NON-NLS-2$
036: JavaSourceConversionOptions options = reader.read(properties);
037: assertEquals(JavaSourceConversionOptions.getDefault(), options);
038: }
039:
040: public void testReadDefaultStyleTableName()
041: throws IllegalPropertyValueException {
042: Properties properties = new Properties();
043: properties.put(IConversionOptionsConstants.DEFAULT_STYLE_NAME,
044: JavaSourceStyleTable.getDefaultKawaStyleTable()
045: .getName());
046: JavaSourceConversionOptions options = reader.read(properties);
047: assertEquals(JavaSourceStyleTable.getDefaultKawaStyleTable(),
048: options.getStyleTable());
049: }
050:
051: public void testReadIllegalDefaultStyleTableName() {
052: Properties properties = new Properties();
053: properties
054: .put(
055: IConversionOptionsConstants.DEFAULT_STYLE_NAME,
056: "not_existing_" + JavaSourceStyleTable.getDefaultKawaStyleTable().getName()); //$NON-NLS-1$
057: assertParsingPropertiesFails(properties);
058: }
059:
060: private void assertParsingPropertiesFails(Properties properties) {
061: try {
062: reader.read(properties);
063: fail();
064: } catch (IllegalPropertyValueException expected) {
065: //expected
066: }
067: }
068:
069: public void testTabSize() throws IllegalPropertyValueException {
070: Properties properties = new Properties();
071: properties.put(IConversionOptionsConstants.TAB_SIZE, "9"); //$NON-NLS-1$
072: JavaSourceConversionOptions options = reader.read(properties);
073: assertEquals(9, options.getTabSize());
074: }
075:
076: public void testIllegalTabSize() {
077: Properties properties = new Properties();
078: properties.put(IConversionOptionsConstants.TAB_SIZE, "illegal"); //$NON-NLS-1$
079: assertParsingPropertiesFails(properties);
080: }
081:
082: public void testShowLineNumbers()
083: throws IllegalPropertyValueException {
084: Properties properties = new Properties();
085: properties.put(IConversionOptionsConstants.SHOW_LINE_NUMBERS,
086: "false"); //$NON-NLS-1$
087: JavaSourceConversionOptions options = reader.read(properties);
088: assertFalse(options.isShowLineNumbers());
089: }
090:
091: public void testIllegalShowLineNumbers() {
092: Properties properties = new Properties();
093: properties.put(IConversionOptionsConstants.SHOW_LINE_NUMBERS,
094: "illegal"); //$NON-NLS-1$
095: assertParsingPropertiesFails(properties);
096: }
097:
098: public void testShowFileName() throws IllegalPropertyValueException {
099: Properties properties = new Properties();
100: properties.put(IConversionOptionsConstants.SHOW_FILE_NAME,
101: "true"); //$NON-NLS-1$
102: JavaSourceConversionOptions options = reader.read(properties);
103: assertTrue(options.isShowFileName());
104: }
105:
106: public void testIllegalShowFileName() {
107: Properties properties = new Properties();
108: properties.put(IConversionOptionsConstants.SHOW_FILE_NAME,
109: "illegal"); //$NON-NLS-1$
110: assertParsingPropertiesFails(properties);
111: }
112:
113: public void testShowTableBorder()
114: throws IllegalPropertyValueException {
115: Properties properties = new Properties();
116: properties.put(IConversionOptionsConstants.SHOW_TABLE_BORDER,
117: "true"); //$NON-NLS-1$
118: JavaSourceConversionOptions options = reader.read(properties);
119: assertTrue(options.isShowTableBorder());
120: }
121:
122: public void testIllegalShowTableBorder() {
123: Properties properties = new Properties();
124: properties.put(IConversionOptionsConstants.SHOW_TABLE_BORDER,
125: "illegal"); //$NON-NLS-1$
126: assertParsingPropertiesFails(properties);
127: }
128:
129: public void testShowJava2HtmlLink()
130: throws IllegalPropertyValueException {
131: Properties properties = new Properties();
132: properties.put(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK,
133: "true"); //$NON-NLS-1$
134: JavaSourceConversionOptions options = reader.read(properties);
135: assertTrue(options.isShowJava2HtmlLink());
136: }
137:
138: public void testIllegalJava2HtmlLink() {
139: Properties properties = new Properties();
140: properties.put(IConversionOptionsConstants.SHOW_JAVA2HTML_LINK,
141: "illegal"); //$NON-NLS-1$
142: assertParsingPropertiesFails(properties);
143: }
144:
145: public void testHorizontalAlignment()
146: throws IllegalPropertyValueException {
147: Properties properties = new Properties();
148: properties.put(
149: IConversionOptionsConstants.HORIZONTAL_ALIGNMENT,
150: HorizontalAlignment.RIGHT.getName());
151: JavaSourceConversionOptions options = reader.read(properties);
152: assertEquals(HorizontalAlignment.RIGHT, options
153: .getHorizontalAlignment());
154: }
155:
156: public void testIllegalHorizontalAlignment() {
157: Properties properties = new Properties();
158: properties.put(
159: IConversionOptionsConstants.HORIZONTAL_ALIGNMENT,
160: "illegal"); //$NON-NLS-1$
161: assertParsingPropertiesFails(properties);
162: }
163:
164: public void testColor() throws IllegalPropertyValueException {
165: Properties properties = new Properties();
166: properties.put(JavaSourceType.CODE.getName()
167: + IConversionOptionsConstants.POSTFIX_COLOR,
168: "255,255,255"); //$NON-NLS-1$
169: JavaSourceConversionOptions options = reader.read(properties);
170: assertEquals(RGB.WHITE, options.getStyleTable().get(
171: JavaSourceType.CODE).getColor());
172: }
173:
174: public void testIllegalColor() {
175: Properties properties = new Properties();
176: properties.put(JavaSourceType.CODE.getName()
177: + IConversionOptionsConstants.POSTFIX_COLOR, "illegal"); //$NON-NLS-1$
178: assertParsingPropertiesFails(properties);
179: }
180:
181: public void testBold() throws IllegalPropertyValueException {
182: Properties properties = new Properties();
183: properties.put(JavaSourceType.CODE.getName()
184: + IConversionOptionsConstants.POSTFIX_BOLD, "true"); //$NON-NLS-1$
185: JavaSourceConversionOptions options = reader.read(properties);
186: assertTrue(options.getStyleTable().get(JavaSourceType.CODE)
187: .isBold());
188: }
189:
190: public void testIllegalBold() {
191: Properties properties = new Properties();
192: properties.put(JavaSourceType.CODE.getName()
193: + IConversionOptionsConstants.POSTFIX_BOLD, "illegal"); //$NON-NLS-1$
194: assertParsingPropertiesFails(properties);
195: }
196:
197: public void testItalic() throws IllegalPropertyValueException {
198: Properties properties = new Properties();
199: properties.put(JavaSourceType.CODE.getName()
200: + IConversionOptionsConstants.POSTFIX_ITALIC, "true"); //$NON-NLS-1$
201: JavaSourceConversionOptions options = reader.read(properties);
202: assertTrue(options.getStyleTable().get(JavaSourceType.CODE)
203: .isItalic());
204: }
205:
206: public void testIllegalItalic() {
207: Properties properties = new Properties();
208: properties
209: .put(JavaSourceType.CODE.getName()
210: + IConversionOptionsConstants.POSTFIX_ITALIC,
211: "illegal"); //$NON-NLS-1$
212: assertParsingPropertiesFails(properties);
213: }
214: }
|