2011-04-07 16:15:49 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
|
|
|
package freemarker.ext.dump;
|
|
|
|
|
2011-04-08 17:23:16 +00:00
|
|
|
import static junit.framework.Assert.assertEquals;
|
|
|
|
import static junit.framework.Assert.fail;
|
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.StringReader;
|
|
|
|
import java.io.StringWriter;
|
2011-04-08 21:23:32 +00:00
|
|
|
import java.sql.Time;
|
|
|
|
import java.sql.Timestamp;
|
2011-04-08 16:50:33 +00:00
|
|
|
import java.util.ArrayList;
|
2011-04-11 22:05:36 +00:00
|
|
|
import java.util.Calendar;
|
2011-04-18 21:09:17 +00:00
|
|
|
import java.util.Collections;
|
2011-04-08 21:23:32 +00:00
|
|
|
import java.util.Date;
|
2011-04-07 16:15:49 +00:00
|
|
|
import java.util.HashMap;
|
2011-04-11 15:32:12 +00:00
|
|
|
import java.util.HashSet;
|
2011-04-07 16:15:49 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2011-04-11 15:32:12 +00:00
|
|
|
import java.util.Set;
|
2011-04-15 15:52:18 +00:00
|
|
|
import java.util.SortedMap;
|
|
|
|
import java.util.TreeMap;
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-20 15:41:05 +00:00
|
|
|
import org.apache.commons.lang.time.DateUtils;
|
2011-04-08 17:23:16 +00:00
|
|
|
import org.apache.log4j.Level;
|
|
|
|
import org.apache.log4j.Logger;
|
2011-04-07 16:15:49 +00:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import freemarker.core.Environment;
|
2011-04-12 19:58:02 +00:00
|
|
|
import freemarker.ext.beans.BeansWrapper;
|
2011-04-11 22:05:36 +00:00
|
|
|
import freemarker.ext.dump.BaseDumpDirective.DateType;
|
|
|
|
import freemarker.ext.dump.BaseDumpDirective.Key;
|
2011-04-12 19:58:02 +00:00
|
|
|
import freemarker.ext.dump.BaseDumpDirective.Type;
|
2011-04-07 16:15:49 +00:00
|
|
|
import freemarker.template.Configuration;
|
2011-04-11 15:32:12 +00:00
|
|
|
import freemarker.template.SimpleCollection;
|
2011-04-07 16:15:49 +00:00
|
|
|
import freemarker.template.Template;
|
2011-04-11 15:32:12 +00:00
|
|
|
import freemarker.template.TemplateCollectionModel;
|
2011-04-07 16:15:49 +00:00
|
|
|
import freemarker.template.TemplateDirectiveBody;
|
|
|
|
import freemarker.template.TemplateDirectiveModel;
|
|
|
|
import freemarker.template.TemplateException;
|
|
|
|
import freemarker.template.TemplateMethodModel;
|
|
|
|
import freemarker.template.TemplateModel;
|
|
|
|
import freemarker.template.TemplateModelException;
|
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
/**
|
|
|
|
* Unit tests of dump directive. The tests follow the same basic pattern:
|
|
|
|
* 1. Create the data model
|
|
|
|
* 2. Create the expected dump data structure
|
|
|
|
* 3. Create the actual dump data structure by running the data model through a processing environment
|
|
|
|
* 4. Compare expected and actual dump data structures
|
|
|
|
*
|
|
|
|
* @author rjy7
|
|
|
|
*
|
|
|
|
*/
|
2011-04-07 16:15:49 +00:00
|
|
|
public class DumpDirectiveTest {
|
|
|
|
|
|
|
|
private Template template;
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
Configuration config = new Configuration();
|
|
|
|
String templateStr = "";
|
|
|
|
try {
|
|
|
|
template = new Template("template", new StringReader(templateStr), config);
|
|
|
|
} catch (Exception e) {
|
2011-04-08 16:50:33 +00:00
|
|
|
fail(e.getMessage());
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
2011-04-08 17:23:16 +00:00
|
|
|
// Turn off log messages to console
|
|
|
|
Logger.getLogger(BaseDumpDirective.class).setLevel(Level.OFF);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 21:23:38 +00:00
|
|
|
@Test
|
|
|
|
public void dumpUndefinedValue() {
|
|
|
|
|
|
|
|
String varName = "dog";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), BaseDumpDirective.VALUE_UNDEFINED);
|
|
|
|
|
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
|
|
|
test(varName, dataModel, expectedDump);
|
|
|
|
}
|
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
@Test
|
|
|
|
public void dumpString() {
|
|
|
|
|
|
|
|
String varName = "dog";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
String value = "Rover";
|
2011-04-07 16:15:49 +00:00
|
|
|
dataModel.put(varName, value);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), value);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpBoolean() {
|
|
|
|
|
2011-04-11 15:32:12 +00:00
|
|
|
String varName = "isLoggedIn";
|
2011-04-07 16:15:49 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
boolean value = true;
|
2011-04-07 16:15:49 +00:00
|
|
|
dataModel.put(varName, value);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.BOOLEAN);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), value);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpNumber() {
|
|
|
|
|
|
|
|
String varName = "tabCount";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
int value = 7;
|
2011-04-07 16:15:49 +00:00
|
|
|
dataModel.put(varName, value);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), value);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2011-04-08 21:23:32 +00:00
|
|
|
public void dumpSimpleDate() {
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-08 21:23:32 +00:00
|
|
|
String varName = "now";
|
2011-04-07 16:15:49 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
Date now = new Date();
|
2011-04-08 21:23:32 +00:00
|
|
|
dataModel.put(varName, now);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
expectedDumpValue.put(Key.DATE_TYPE.toString(), DateType.UNKNOWN);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), now);
|
2011-04-08 21:23:32 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 21:23:32 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 17:29:25 +00:00
|
|
|
@Test
|
|
|
|
public void dumpCalendarDate() {
|
|
|
|
|
|
|
|
String varName = "myDate";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
Calendar c = Calendar.getInstance();
|
2011-04-20 15:41:05 +00:00
|
|
|
c.set(1991, Calendar.MAY, 5);
|
2011-04-18 17:29:25 +00:00
|
|
|
Date myDate = c.getTime();
|
|
|
|
dataModel.put("myDate", myDate);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
expectedDumpValue.put(Key.DATE_TYPE.toString(), DateType.UNKNOWN);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), myDate);
|
2011-04-18 17:29:25 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-18 17:29:25 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
|
|
|
}
|
2011-04-08 21:23:32 +00:00
|
|
|
@Test
|
|
|
|
public void dumpDateTime() {
|
|
|
|
|
|
|
|
String varName = "timestamp";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
Timestamp ts = new Timestamp(1302297332043L);
|
2011-04-08 21:23:32 +00:00
|
|
|
dataModel.put(varName, ts);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
expectedDumpValue.put(Key.DATE_TYPE.toString(), DateType.DATETIME);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), ts);
|
2011-04-08 21:23:32 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 21:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpSqlDate() {
|
|
|
|
|
|
|
|
String varName = "date";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
java.sql.Date date = new java.sql.Date(1302297332043L);
|
2011-04-08 21:23:32 +00:00
|
|
|
dataModel.put(varName, date);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
expectedDumpValue.put(Key.DATE_TYPE.toString(), DateType.DATE);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), date);
|
2011-04-08 21:23:32 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 21:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpTime() {
|
|
|
|
|
|
|
|
String varName = "time";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
Time time = new Time(1302297332043L);
|
2011-04-08 21:23:32 +00:00
|
|
|
dataModel.put(varName, time);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
expectedDumpValue.put(Key.DATE_TYPE.toString(), DateType.TIME);
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), time);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
2011-04-20 18:56:05 +00:00
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
@Test
|
2011-04-08 16:50:33 +00:00
|
|
|
public void dumpHelplessMethod() {
|
|
|
|
|
|
|
|
String varName = "square";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
TemplateMethodModel methodModel = new HelplessMethod();
|
|
|
|
dataModel.put(varName, methodModel);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
2011-04-22 16:55:36 +00:00
|
|
|
expectedDumpValue.put(Key.HELP.toString(), null);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 16:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpHelpfulMethod() {
|
|
|
|
|
|
|
|
String varName = "square";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
TemplateMethodModel methodModel = new HelpfulMethod();
|
|
|
|
dataModel.put(varName, methodModel);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
2011-04-22 16:55:36 +00:00
|
|
|
expectedDumpValue.put(Key.HELP.toString(), getMethodHelp(varName));
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 16:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpMethodWithBadHelp() {
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-08 16:50:33 +00:00
|
|
|
String varName = "square";
|
2011-04-07 16:15:49 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
TemplateMethodModel methodModel = new MethodWithBadHelp();
|
|
|
|
dataModel.put(varName, methodModel);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.METHOD);
|
2011-04-22 16:55:36 +00:00
|
|
|
expectedDumpValue.put(Key.HELP.toString(), null);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 16:50:33 +00:00
|
|
|
}
|
2011-04-08 17:23:16 +00:00
|
|
|
|
2011-04-08 16:50:33 +00:00
|
|
|
@Test
|
|
|
|
public void dumpHelplessDirective() {
|
|
|
|
|
|
|
|
String varName = "dump";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
TemplateDirectiveModel directiveModel = new HelplessDirective();
|
|
|
|
dataModel.put(varName, directiveModel);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
2011-04-22 16:55:36 +00:00
|
|
|
expectedDumpValue.put(Key.HELP.toString(), null);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2011-04-08 16:50:33 +00:00
|
|
|
public void dumpHelpfulDirective() {
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-11 15:32:12 +00:00
|
|
|
String varName = "dump";
|
2011-04-07 16:15:49 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
TemplateDirectiveModel directiveModel = new HelpfulDirective();
|
|
|
|
dataModel.put(varName, directiveModel);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
2011-04-22 16:55:36 +00:00
|
|
|
expectedDumpValue.put(Key.HELP.toString(), getDirectiveHelp(varName));
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
2011-04-08 16:50:33 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpDirectiveWithBadHelp() {
|
|
|
|
|
|
|
|
String varName = "dump";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
TemplateDirectiveModel directiveModel = new DirectiveWithBadHelp();
|
|
|
|
dataModel.put(varName, directiveModel);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.DIRECTIVE);
|
2011-04-22 16:55:36 +00:00
|
|
|
expectedDumpValue.put(Key.HELP.toString(), null);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 16:50:33 +00:00
|
|
|
}
|
2011-04-08 20:15:13 +00:00
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
@Test
|
2011-04-08 21:23:32 +00:00
|
|
|
public void dumpStringList() {
|
2011-04-08 17:23:16 +00:00
|
|
|
|
2011-04-11 15:32:12 +00:00
|
|
|
String varName = "fruit";
|
2011-04-08 17:23:16 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
List<String> myList = new ArrayList<String>();
|
|
|
|
myList.add("apples");
|
|
|
|
myList.add("bananas");
|
|
|
|
myList.add("oranges");
|
|
|
|
dataModel.put(varName, myList);
|
2011-04-08 17:23:16 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.SEQUENCE);
|
2011-04-20 14:42:32 +00:00
|
|
|
List<Map<String, Object>> myListItemsExpectedDump = new ArrayList<Map<String, Object>>(myList.size());
|
2011-04-15 15:52:18 +00:00
|
|
|
for ( String str : myList) {
|
2011-04-11 22:05:36 +00:00
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
itemDump.put(Key.VALUE.toString(), str);
|
2011-04-20 14:42:32 +00:00
|
|
|
myListItemsExpectedDump.add(itemDump);
|
2011-04-08 17:23:16 +00:00
|
|
|
}
|
2011-04-20 14:42:32 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), myListItemsExpectedDump);
|
2011-04-08 17:23:16 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 17:23:16 +00:00
|
|
|
}
|
2011-04-08 20:15:13 +00:00
|
|
|
|
2011-04-08 17:23:16 +00:00
|
|
|
@Test
|
2011-04-08 21:23:32 +00:00
|
|
|
public void dumpStringArray() {
|
2011-04-11 15:32:12 +00:00
|
|
|
|
|
|
|
String varName = "fruit";
|
2011-04-08 20:15:13 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
String[] myArray = { "apples", "bananas", "oranges" };
|
|
|
|
dataModel.put(varName, myArray);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.SEQUENCE);
|
|
|
|
List<Map<String, Object>> myArrayexpectedDumpValue = new ArrayList<Map<String, Object>>(myArray.length);
|
2011-04-15 15:52:18 +00:00
|
|
|
for ( String str : myArray) {
|
2011-04-11 22:05:36 +00:00
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
itemDump.put(Key.VALUE.toString(), str);
|
2011-04-19 18:46:14 +00:00
|
|
|
myArrayexpectedDumpValue.add(itemDump);
|
2011-04-08 20:15:13 +00:00
|
|
|
}
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), myArrayexpectedDumpValue);
|
2011-04-08 17:23:16 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 20:15:13 +00:00
|
|
|
}
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-08 20:15:13 +00:00
|
|
|
@Test
|
|
|
|
public void dumpMixedList() {
|
|
|
|
|
2011-04-11 15:32:12 +00:00
|
|
|
String varName = "stuff";
|
2011-04-08 21:35:10 +00:00
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
List<Object> mixedList = new ArrayList<Object>();
|
|
|
|
|
|
|
|
String myString = "apples";
|
|
|
|
mixedList.add(myString);
|
2011-04-08 21:35:10 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
int myInt = 4;
|
|
|
|
mixedList.add(myInt);
|
2011-04-08 21:35:10 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
boolean myBool = true;
|
|
|
|
mixedList.add(myBool);
|
2011-04-08 21:35:10 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
List<String> myList = new ArrayList<String>();
|
|
|
|
myList.add("dog");
|
|
|
|
myList.add("cat");
|
|
|
|
myList.add("elephant");
|
|
|
|
mixedList.add(myList);
|
|
|
|
|
|
|
|
dataModel.put(varName, mixedList);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.SEQUENCE);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
List<Map<String, Object>> mixedListexpectedDumpValue = new ArrayList<Map<String, Object>>(mixedList.size());
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> myStringexpectedDumpValue = new HashMap<String, Object>();
|
|
|
|
myStringexpectedDumpValue.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
myStringexpectedDumpValue.put(Key.VALUE.toString(), myString);
|
|
|
|
mixedListexpectedDumpValue.add(myStringexpectedDumpValue);
|
2011-04-08 21:35:10 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> myIntexpectedDumpValue = new HashMap<String, Object>();
|
|
|
|
myIntexpectedDumpValue.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
myIntexpectedDumpValue.put(Key.VALUE.toString(), myInt);
|
|
|
|
mixedListexpectedDumpValue.add(myIntexpectedDumpValue);
|
|
|
|
|
|
|
|
Map<String, Object> myBoolexpectedDumpValue = new HashMap<String, Object>();
|
|
|
|
myBoolexpectedDumpValue.put(Key.TYPE.toString(), Type.BOOLEAN);
|
|
|
|
myBoolexpectedDumpValue.put(Key.VALUE.toString(), myBool);
|
|
|
|
mixedListexpectedDumpValue.add(myBoolexpectedDumpValue);
|
|
|
|
|
|
|
|
Map<String, Object> myListexpectedDumpValue = new HashMap<String, Object>();
|
|
|
|
myListexpectedDumpValue.put(Key.TYPE.toString(), Type.SEQUENCE);
|
|
|
|
List<Map<String, Object>> myListItemsexpectedDumpValue = new ArrayList<Map<String, Object>>(myList.size());
|
2011-04-11 22:05:36 +00:00
|
|
|
for ( String animal : myList ) {
|
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
itemDump.put(Key.VALUE.toString(), animal);
|
2011-04-19 18:46:14 +00:00
|
|
|
myListItemsexpectedDumpValue.add(itemDump);
|
2011-04-08 21:35:10 +00:00
|
|
|
}
|
2011-04-19 18:46:14 +00:00
|
|
|
myListexpectedDumpValue.put(Key.VALUE.toString(), myListItemsexpectedDumpValue);
|
|
|
|
mixedListexpectedDumpValue.add(myListexpectedDumpValue);
|
2011-04-08 21:35:10 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), mixedListexpectedDumpValue);
|
2011-04-08 21:35:10 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-08 20:15:13 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 15:32:12 +00:00
|
|
|
@Test
|
|
|
|
public void dumpNumberSet() {
|
|
|
|
|
|
|
|
String varName = "oddNums";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Set<Integer> myIntSet = new HashSet<Integer>();
|
2011-04-11 15:32:12 +00:00
|
|
|
for (int i=0; i <= 10; i++) {
|
|
|
|
if (i % 2 == 1) {
|
2011-04-15 15:52:18 +00:00
|
|
|
myIntSet.add(i);
|
2011-04-11 15:32:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-15 15:52:18 +00:00
|
|
|
dataModel.put(varName, myIntSet);
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.SEQUENCE);
|
|
|
|
List<Map<String, Object>> myIntSetexpectedDumpValue = new ArrayList<Map<String, Object>>(myIntSet.size());
|
2011-04-15 15:52:18 +00:00
|
|
|
for ( int i : myIntSet ) {
|
2011-04-11 22:05:36 +00:00
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
itemDump.put(Key.VALUE.toString(), i);
|
2011-04-19 18:46:14 +00:00
|
|
|
myIntSetexpectedDumpValue.add(itemDump);
|
2011-04-11 15:32:12 +00:00
|
|
|
}
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), myIntSetexpectedDumpValue);
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-11 15:32:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpNumberCollection() {
|
|
|
|
|
|
|
|
String varName = "oddNums";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
Set<Integer> odds = new HashSet<Integer>();
|
|
|
|
for (int i=0; i <= 10; i++) {
|
|
|
|
if (i % 2 == 1) {
|
|
|
|
odds.add(i);
|
|
|
|
}
|
|
|
|
}
|
2011-04-15 15:52:18 +00:00
|
|
|
TemplateCollectionModel myCollection = new SimpleCollection(odds);
|
|
|
|
dataModel.put(varName, myCollection);
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.COLLECTION);
|
|
|
|
List<Map<String, Object>> myCollectionexpectedDumpValue = new ArrayList<Map<String, Object>>(odds.size());
|
2011-04-11 15:32:12 +00:00
|
|
|
for ( int i : odds ) {
|
2011-04-11 22:05:36 +00:00
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
itemDump.put(Key.VALUE.toString(), i);
|
2011-04-19 18:46:14 +00:00
|
|
|
myCollectionexpectedDumpValue.add(itemDump);
|
2011-04-11 15:32:12 +00:00
|
|
|
}
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), myCollectionexpectedDumpValue);
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
test(varName, dataModel, expectedDump);
|
2011-04-11 15:32:12 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
@Test
|
|
|
|
public void dumpHash() {
|
|
|
|
|
|
|
|
}
|
2011-04-08 20:15:13 +00:00
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
@Test
|
2011-04-11 15:32:12 +00:00
|
|
|
public void dumpStringToStringMap() {
|
|
|
|
|
|
|
|
String varName = "capitals";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
Map<String, String> myMap = new HashMap<String, String>();
|
|
|
|
myMap.put("Albany", "New York");
|
|
|
|
myMap.put("St. Paul", "Minnesota");
|
|
|
|
myMap.put("Austin", "Texas");
|
|
|
|
myMap.put("Sacramento", "California");
|
|
|
|
myMap.put("Richmond", "Virginia");
|
|
|
|
dataModel.put(varName, myMap);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.HASH_EX);
|
2011-04-15 15:52:18 +00:00
|
|
|
SortedMap<String, Object> myMapExpectedDump = new TreeMap<String, Object>();
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
for ( String key : myMap.keySet() ) {
|
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
itemDump.put(Key.VALUE.toString(), myMap.get(key));
|
2011-04-15 15:52:18 +00:00
|
|
|
myMapExpectedDump.put(key, itemDump);
|
2011-04-11 15:32:12 +00:00
|
|
|
}
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), (myMapExpectedDump));
|
2011-04-11 15:32:12 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> dump = getDump(varName, dataModel);
|
|
|
|
assertEquals(expectedDump, dump);
|
|
|
|
|
|
|
|
// Test the sorting of the map
|
|
|
|
List<String> expectedKeys = new ArrayList<String>(myMapExpectedDump.keySet());
|
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> actualDumpValue = (Map<String, Object>) dump.get(varName);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
SortedMap<String, Object> myMapActualDump = (SortedMap<String, Object>) actualDumpValue.get(Key.VALUE.toString());
|
2011-04-15 15:52:18 +00:00
|
|
|
List<String> actualKeys = new ArrayList<String>(myMapActualDump.keySet());
|
|
|
|
assertEquals(expectedKeys, actualKeys);
|
2011-04-11 22:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpStringToObjectMap() {
|
|
|
|
|
|
|
|
String varName = "stuff";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
Map<String, Object> mixedMap = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
String myString = "apples";
|
|
|
|
mixedMap.put("myString", myString);
|
|
|
|
|
|
|
|
boolean myBool = true;
|
|
|
|
mixedMap.put("myBoolean", myBool);
|
|
|
|
|
|
|
|
int myInt = 4;
|
|
|
|
mixedMap.put("myNumber", myInt);
|
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Date myDate = new Date();
|
|
|
|
mixedMap.put("myDate", myDate);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
|
|
|
List<String> myList = new ArrayList<String>();
|
|
|
|
myList.add("apples");
|
|
|
|
myList.add("bananas");
|
|
|
|
myList.add("oranges");
|
|
|
|
mixedMap.put("myList", myList);
|
|
|
|
|
|
|
|
Map<String, String> myMap = new HashMap<String, String>();
|
|
|
|
myMap.put("Great Expectations", "Charles Dickens");
|
|
|
|
myMap.put("Pride and Prejudice", "Jane Austen");
|
|
|
|
myMap.put("Middlemarch", "George Eliot");
|
|
|
|
myMap.put("Jude the Obscure", "Thomas Hardy");
|
|
|
|
mixedMap.put("myMap", myMap);
|
|
|
|
|
|
|
|
dataModel.put(varName, mixedMap);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), Type.HASH_EX);
|
|
|
|
SortedMap<String, Object> mixedMapExpectedDump = new TreeMap<String, Object>();
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> myStringExpectedDump = new HashMap<String, Object>();
|
|
|
|
myStringExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
myStringExpectedDump.put(Key.VALUE.toString(), myString);
|
|
|
|
mixedMapExpectedDump.put("myString", myStringExpectedDump);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> myBooleanExpectedDump = new HashMap<String, Object>();
|
|
|
|
myBooleanExpectedDump.put(Key.TYPE.toString(), Type.BOOLEAN);
|
|
|
|
myBooleanExpectedDump.put(Key.VALUE.toString(), myBool);
|
|
|
|
mixedMapExpectedDump.put("myBoolean", myBooleanExpectedDump);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> myIntExpectedDump = new HashMap<String, Object>();
|
|
|
|
myIntExpectedDump.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
myIntExpectedDump.put(Key.VALUE.toString(), myInt);
|
|
|
|
mixedMapExpectedDump.put("myNumber", myIntExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> myDateExpectedDump = new HashMap<String, Object>();
|
|
|
|
myDateExpectedDump.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
myDateExpectedDump.put(Key.DATE_TYPE.toString(), DateType.UNKNOWN);
|
|
|
|
myDateExpectedDump.put(Key.VALUE.toString(), myDate);
|
|
|
|
mixedMapExpectedDump.put("myDate", myDateExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> myListExpectedDump = new HashMap<String, Object>();
|
|
|
|
myListExpectedDump.put(Key.TYPE.toString(), Type.SEQUENCE);
|
|
|
|
List<Map<String, Object>> myListItemsExpectedDump = new ArrayList<Map<String, Object>>(myList.size());
|
2011-04-11 22:05:36 +00:00
|
|
|
for ( String item : myList ) {
|
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
itemDump.put(Key.VALUE.toString(), item);
|
2011-04-15 15:52:18 +00:00
|
|
|
myListItemsExpectedDump.add(itemDump);
|
2011-04-11 22:05:36 +00:00
|
|
|
}
|
2011-04-15 15:52:18 +00:00
|
|
|
myListExpectedDump.put(Key.VALUE.toString(), myListItemsExpectedDump);
|
|
|
|
mixedMapExpectedDump.put("myList", myListExpectedDump);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> myMapExpectedDump = new HashMap<String, Object>();
|
|
|
|
myMapExpectedDump.put(Key.TYPE.toString(), Type.HASH_EX);
|
|
|
|
SortedMap<String, Object> myMapItemsExpectedDump = new TreeMap<String, Object>();
|
2011-04-11 22:05:36 +00:00
|
|
|
for ( String key : myMap.keySet() ) {
|
|
|
|
Map<String, Object> itemDump = new HashMap<String, Object>();
|
|
|
|
itemDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
itemDump.put(Key.VALUE.toString(), myMap.get(key));
|
2011-04-15 15:52:18 +00:00
|
|
|
myMapItemsExpectedDump.put(key, itemDump);
|
2011-04-11 22:05:36 +00:00
|
|
|
}
|
2011-04-15 15:52:18 +00:00
|
|
|
myMapExpectedDump.put(Key.VALUE.toString(), myMapItemsExpectedDump);
|
|
|
|
mixedMapExpectedDump.put("myMap", myMapExpectedDump);
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), mixedMapExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> dump = getDump(varName, dataModel);
|
|
|
|
assertEquals(expectedDump, dump);
|
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
// Test the sorting of the outer map
|
|
|
|
List<String> expectedDumpValueKeys = new ArrayList<String>(mixedMapExpectedDump.keySet());
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
Map<String, Object> actualDumpValue = (Map<String, Object>) dump.get(varName);
|
2011-04-15 15:52:18 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
SortedMap<String, Object> mixedMapActualDump = (SortedMap<String, Object>) actualDumpValue.get(Key.VALUE.toString());
|
|
|
|
List<String> actualDumpValueKeys = new ArrayList<String>(mixedMapActualDump.keySet());
|
|
|
|
assertEquals(expectedDumpValueKeys, actualDumpValueKeys);
|
|
|
|
|
|
|
|
// Test the sorting of the inner map
|
|
|
|
List<String> myMapItemsExpectedDumpKeys = new ArrayList<String>(myMapItemsExpectedDump.keySet());
|
2011-04-15 15:52:18 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> myMapActualDump = (Map<String, Object>) mixedMapActualDump.get("myMap");
|
2011-04-15 15:52:18 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
SortedMap<String, Object> myMapItemsActualDump = (SortedMap<String, Object>) myMapActualDump.get(Key.VALUE.toString());
|
|
|
|
List<String> myMapItemsActualDumpKeys = new ArrayList<String>(myMapItemsActualDump.keySet());
|
|
|
|
assertEquals(myMapItemsExpectedDumpKeys, myMapItemsActualDumpKeys);
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
}
|
2011-04-12 19:58:02 +00:00
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
@Test
|
2011-04-12 19:58:02 +00:00
|
|
|
public void dumpObjectWithExposeNothingWrapper() {
|
2011-04-18 20:02:08 +00:00
|
|
|
dumpObject(BeansWrapper.EXPOSE_NOTHING);
|
2011-04-12 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpObjectWithExposePropertiesOnlyWrapper() {
|
2011-04-18 20:02:08 +00:00
|
|
|
dumpObject(BeansWrapper.EXPOSE_PROPERTIES_ONLY);
|
2011-04-12 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpObjectWithExposeSafeWrapper() {
|
2011-04-18 21:09:17 +00:00
|
|
|
dumpObject(BeansWrapper.EXPOSE_SAFE);
|
2011-04-12 19:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void dumpObjectWithExposeAllWrapper() {
|
2011-04-18 21:09:17 +00:00
|
|
|
dumpObject(BeansWrapper.EXPOSE_ALL);
|
2011-04-18 20:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 14:42:32 +00:00
|
|
|
/////////////////////////// Private test classes and helper methods ///////////////////////////
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
private void test(String varName, Map<String, Object> dataModel, Map<String, Object> expectedDump) {
|
|
|
|
Map<String, Object> dump = getDump(varName, dataModel);
|
|
|
|
assertEquals(expectedDump, dump);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dumpObject(int exposureLevel) {
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-12 19:58:02 +00:00
|
|
|
String varName = "employee";
|
|
|
|
Map<String, Object> dataModel = new HashMap<String, Object>();
|
|
|
|
BeansWrapper wrapper = new BeansWrapper();
|
2011-04-18 20:02:08 +00:00
|
|
|
wrapper.setExposureLevel(exposureLevel);
|
2011-04-12 19:58:02 +00:00
|
|
|
try {
|
|
|
|
dataModel.put("employee", wrapper.wrap(getEmployee()));
|
|
|
|
} catch (TemplateModelException e) {
|
2011-04-15 22:29:29 +00:00
|
|
|
// logging is suppressed, so what do we do here?
|
2011-04-12 19:58:02 +00:00
|
|
|
}
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedDumpValue = new HashMap<String, Object>();
|
|
|
|
expectedDumpValue.put(Key.TYPE.toString(), "freemarker.ext.dump.DumpDirectiveTest$Employee");
|
|
|
|
expectedDumpValue.put(Key.VALUE.toString(), getJohnDoeExpectedDump(exposureLevel));
|
|
|
|
|
2011-04-11 22:05:36 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
2011-04-19 18:46:14 +00:00
|
|
|
expectedDump.put(varName, expectedDumpValue);
|
2011-04-15 22:29:29 +00:00
|
|
|
|
2011-04-18 20:02:08 +00:00
|
|
|
testObjectDump(varName, dataModel, expectedDump);
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
private void testObjectDump(String varName, Map<String, Object> dataModel, Map<String, Object> expectedDump) {
|
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
Map<String, Object> dump = getDump(varName, dataModel);
|
2011-04-18 20:02:08 +00:00
|
|
|
assertEquals(expectedDump, dump);
|
|
|
|
|
2011-04-18 21:09:17 +00:00
|
|
|
// Test the sorting of the properties
|
2011-04-18 20:02:08 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedVarDump = (Map<String, Object>) expectedDump.get(varName);
|
2011-04-18 20:02:08 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> expectedValueDump = (Map<String, Object>) expectedVarDump.get(Key.VALUE.toString());
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
SortedMap<String, Object> expectedPropertyDump = (SortedMap<String, Object>) expectedValueDump.get(Key.PROPERTIES.toString());
|
|
|
|
List<String> expectedPropertyDumpKeys = new ArrayList<String>(expectedPropertyDump.keySet());
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
Map<String, Object> actualVarDump = (Map<String, Object>) dump.get(varName);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
Map<String, Object> actualValueDump = (Map<String, Object>) actualVarDump.get(Key.VALUE.toString());
|
2011-04-18 20:02:08 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2011-04-19 18:46:14 +00:00
|
|
|
SortedMap<String, Object> actualPropertyDump = (SortedMap<String, Object>) actualValueDump.get(Key.PROPERTIES.toString());
|
|
|
|
List<String> actualPropertyDumpKeys = new ArrayList<String>(actualPropertyDump.keySet());
|
|
|
|
|
|
|
|
assertEquals(expectedPropertyDumpKeys, actualPropertyDumpKeys);
|
2011-04-18 21:09:17 +00:00
|
|
|
|
2011-04-15 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> getDump(String varName, Map<String, Object> dataModel) {
|
|
|
|
try {
|
2011-04-08 17:23:16 +00:00
|
|
|
Environment env = template.createProcessingEnvironment(dataModel, new StringWriter());
|
2011-04-19 13:30:23 +00:00
|
|
|
return new DumpDirective().getTemplateVariableDump(varName, env);
|
2011-04-08 17:23:16 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
fail(e.getMessage());
|
2011-04-15 15:52:18 +00:00
|
|
|
return null;
|
|
|
|
}
|
2011-04-08 17:23:16 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 16:50:33 +00:00
|
|
|
private class HelplessMethod implements TemplateMethodModel {
|
2011-04-07 16:15:49 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object exec(List arg0) throws TemplateModelException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2011-04-08 16:50:33 +00:00
|
|
|
|
|
|
|
private class HelpfulMethod implements TemplateMethodModel {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object exec(List arg0) throws TemplateModelException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Object> help(String name) {
|
|
|
|
return getMethodHelp(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class MethodWithBadHelp implements TemplateMethodModel {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object exec(List arg0) throws TemplateModelException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Object> help() {
|
|
|
|
return new HashMap<String, Object>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class HelplessDirective implements TemplateDirectiveModel {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(Environment arg0, Map arg1, TemplateModel[] arg2,
|
|
|
|
TemplateDirectiveBody arg3) throws TemplateException,
|
|
|
|
IOException {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class HelpfulDirective implements TemplateDirectiveModel {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(Environment arg0, Map arg1, TemplateModel[] arg2,
|
|
|
|
TemplateDirectiveBody arg3) throws TemplateException,
|
|
|
|
IOException {
|
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, Object> help(String name) {
|
|
|
|
return getDirectiveHelp(name);
|
|
|
|
}
|
|
|
|
}
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-08 16:50:33 +00:00
|
|
|
private class DirectiveWithBadHelp implements TemplateDirectiveModel {
|
2011-04-07 16:15:49 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute(Environment arg0, Map arg1, TemplateModel[] arg2,
|
|
|
|
TemplateDirectiveBody arg3) throws TemplateException,
|
2011-04-08 16:50:33 +00:00
|
|
|
IOException {
|
|
|
|
}
|
|
|
|
|
|
|
|
public String help(String name) {
|
|
|
|
return "help";
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
2011-04-08 16:50:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> getDirectiveHelp(String name) {
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
map.put("effect", "Dump the contents of a template variable.");
|
|
|
|
|
|
|
|
map.put("comments", "Sequences (lists and arrays) are enclosed in square brackets. Hashes are enclosed in curly braces.");
|
|
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
|
params.put("var", "name of variable to dump");
|
2011-04-22 16:55:36 +00:00
|
|
|
map.put("parameters", params);
|
2011-04-08 16:50:33 +00:00
|
|
|
|
|
|
|
List<String> examples = new ArrayList<String>();
|
|
|
|
examples.add("<@" + name + " var=\"urls\" />");
|
|
|
|
map.put("examples", examples);
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map<String, Object> getMethodHelp(String name) {
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
map.put("returns", "The square of the argument");
|
|
|
|
|
|
|
|
List<String>params = new ArrayList<String>();
|
|
|
|
params.add("Integer to square");
|
2011-04-22 16:55:36 +00:00
|
|
|
map.put("parameters", params);
|
2011-04-07 16:15:49 +00:00
|
|
|
|
2011-04-08 16:50:33 +00:00
|
|
|
List<String> examples = new ArrayList<String>();
|
|
|
|
examples.add(name + "(4)");
|
|
|
|
map.put("examples", examples);
|
|
|
|
|
|
|
|
return map;
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|
2011-04-08 16:50:33 +00:00
|
|
|
|
2011-04-12 19:11:00 +00:00
|
|
|
public static class Employee {
|
|
|
|
|
|
|
|
private static int count = 0;
|
2011-04-11 22:05:36 +00:00
|
|
|
|
2011-04-12 19:11:00 +00:00
|
|
|
private String firstName;
|
|
|
|
private String lastName;
|
|
|
|
private String nickname;
|
2011-04-20 15:41:05 +00:00
|
|
|
private Date birthdate;
|
2011-04-18 17:29:25 +00:00
|
|
|
private boolean married;
|
2011-04-11 22:05:36 +00:00
|
|
|
private int id;
|
2011-04-18 17:29:25 +00:00
|
|
|
private String middleName;
|
2011-04-18 18:38:50 +00:00
|
|
|
private List<String> favoriteColors;
|
2011-04-11 22:05:36 +00:00
|
|
|
private Employee supervisor;
|
|
|
|
private float salary;
|
|
|
|
|
2011-04-20 15:41:05 +00:00
|
|
|
Employee(String firstName, String lastName, int id, Date birthdate) {
|
2011-04-12 19:11:00 +00:00
|
|
|
this.firstName = firstName;
|
|
|
|
this.lastName = lastName;
|
2011-04-18 17:29:25 +00:00
|
|
|
this.middleName = null; // test a null value
|
2011-04-20 15:41:05 +00:00
|
|
|
this.birthdate = birthdate;
|
2011-04-18 17:29:25 +00:00
|
|
|
this.married = true;
|
2011-04-11 22:05:36 +00:00
|
|
|
this.id = id;
|
2011-04-12 19:11:00 +00:00
|
|
|
this.nickname = "";
|
2011-04-18 18:38:50 +00:00
|
|
|
this.favoriteColors = new ArrayList<String>();
|
2011-04-12 19:11:00 +00:00
|
|
|
count++;
|
2011-04-11 22:05:36 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 21:09:17 +00:00
|
|
|
protected void setSupervisor(Employee supervisor) {
|
2011-04-11 22:05:36 +00:00
|
|
|
this.supervisor = supervisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSalary(float salary) {
|
|
|
|
this.salary = salary;
|
|
|
|
}
|
2011-04-12 19:11:00 +00:00
|
|
|
|
|
|
|
public void setNickname(String nickname) {
|
|
|
|
this.nickname = nickname;
|
|
|
|
}
|
2011-04-20 15:41:05 +00:00
|
|
|
|
2011-04-18 18:38:50 +00:00
|
|
|
public void setFavoriteColors(String...colors) {
|
|
|
|
for (String color : colors) {
|
|
|
|
favoriteColors.add(color);
|
|
|
|
}
|
|
|
|
}
|
2011-04-11 22:05:36 +00:00
|
|
|
|
|
|
|
float getSalary() {
|
|
|
|
return salary;
|
|
|
|
}
|
2011-04-12 19:11:00 +00:00
|
|
|
|
|
|
|
public static int getEmployeeCount() {
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Public accessor methods for templates */
|
|
|
|
|
|
|
|
public String getFullName() {
|
|
|
|
return firstName + " " + lastName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName(String which) {
|
|
|
|
return which == "first" ? firstName : lastName;
|
|
|
|
}
|
2011-04-18 17:29:25 +00:00
|
|
|
|
|
|
|
public String getMiddleName() {
|
|
|
|
return middleName;
|
|
|
|
}
|
2011-04-12 19:11:00 +00:00
|
|
|
|
|
|
|
public String getNickname() {
|
|
|
|
return nickname;
|
|
|
|
}
|
|
|
|
|
2011-04-20 15:41:05 +00:00
|
|
|
public Date getBirthdate() {
|
|
|
|
return birthdate;
|
|
|
|
}
|
2011-04-12 19:11:00 +00:00
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
return id;
|
|
|
|
}
|
2011-04-18 17:29:25 +00:00
|
|
|
|
|
|
|
public boolean isMarried() {
|
|
|
|
return married;
|
|
|
|
}
|
2011-04-12 19:11:00 +00:00
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
public int getFormerId() {
|
|
|
|
return id % 10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Employee getSupervisor() {
|
|
|
|
return supervisor;
|
|
|
|
}
|
|
|
|
|
2011-04-18 18:38:50 +00:00
|
|
|
public List<String> getFavoriteColors() {
|
|
|
|
return favoriteColors;
|
2011-04-12 19:11:00 +00:00
|
|
|
}
|
2011-04-11 22:05:36 +00:00
|
|
|
}
|
2011-04-12 19:58:02 +00:00
|
|
|
|
|
|
|
private Employee getEmployee() {
|
2011-04-18 18:38:50 +00:00
|
|
|
|
2011-04-20 15:41:05 +00:00
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.set(1982, Calendar.MAY, 5);
|
|
|
|
c = DateUtils.truncate(c, Calendar.DATE);
|
|
|
|
Employee jdoe = new Employee("John", "Doe", 34523, c.getTime());
|
2011-04-18 18:38:50 +00:00
|
|
|
jdoe.setFavoriteColors("blue", "green");
|
2011-04-12 19:58:02 +00:00
|
|
|
jdoe.setSalary(65000);
|
2011-04-20 15:41:05 +00:00
|
|
|
|
|
|
|
c.clear();
|
|
|
|
c.set(1975, Calendar.OCTOBER, 25);
|
|
|
|
c = DateUtils.truncate(c, Calendar.DATE);
|
|
|
|
Employee jsmith = new Employee("Jane", "Smith", 78234, c.getTime());
|
2011-04-18 18:38:50 +00:00
|
|
|
jsmith.setFavoriteColors("red", "orange");
|
2011-04-20 15:41:05 +00:00
|
|
|
|
2011-04-18 18:38:50 +00:00
|
|
|
jdoe.setSupervisor(jsmith);
|
|
|
|
|
2011-04-12 19:58:02 +00:00
|
|
|
return jdoe;
|
|
|
|
}
|
2011-04-18 17:29:25 +00:00
|
|
|
|
2011-04-18 20:02:08 +00:00
|
|
|
private Map<String, Object> getJohnDoeExpectedDump(int exposureLevel) {
|
|
|
|
|
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
|
|
|
|
// Properties
|
2011-04-18 17:29:25 +00:00
|
|
|
SortedMap<String, Object> propertiesExpectedDump = new TreeMap<String, Object>();
|
|
|
|
|
2011-04-22 19:45:45 +00:00
|
|
|
if (exposureLevel < BeansWrapper.EXPOSE_NOTHING) {
|
2011-04-18 20:02:08 +00:00
|
|
|
|
2011-04-20 15:41:05 +00:00
|
|
|
Map<String, Object> birthdateExpectedDump = new HashMap<String, Object>();
|
|
|
|
birthdateExpectedDump.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
birthdateExpectedDump.put(Key.DATE_TYPE.toString(), DateType.UNKNOWN);
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.set(1982, Calendar.MAY, 5);
|
|
|
|
c = DateUtils.truncate(c, Calendar.DATE);
|
|
|
|
birthdateExpectedDump.put(Key.VALUE.toString(), c.getTime());
|
|
|
|
propertiesExpectedDump.put("birthdate", birthdateExpectedDump);
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
Map<String, Object> fullNameExpectedDump = new HashMap<String, Object>();
|
|
|
|
fullNameExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
fullNameExpectedDump.put(Key.VALUE.toString(), "John Doe");
|
|
|
|
propertiesExpectedDump.put("fullName", fullNameExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> idExpectedDump = new HashMap<String, Object>();
|
|
|
|
idExpectedDump.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
idExpectedDump.put(Key.VALUE.toString(), 34523);
|
|
|
|
propertiesExpectedDump.put("id", idExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> nicknameExpectedDump = new HashMap<String, Object>();
|
|
|
|
nicknameExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
nicknameExpectedDump.put(Key.VALUE.toString(), "");
|
|
|
|
propertiesExpectedDump.put("nickname", nicknameExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> middleNameExpectedDump = new HashMap<String, Object>();
|
|
|
|
middleNameExpectedDump.put(Key.VALUE.toString(), "null");
|
|
|
|
propertiesExpectedDump.put("middleName", middleNameExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> marriedExpectedDump = new HashMap<String, Object>();
|
|
|
|
marriedExpectedDump.put(Key.TYPE.toString(), Type.BOOLEAN);
|
|
|
|
marriedExpectedDump.put(Key.VALUE.toString(), true);
|
|
|
|
propertiesExpectedDump.put("married", marriedExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> supervisorExpectedDump = new HashMap<String, Object>();
|
|
|
|
supervisorExpectedDump.put(Key.TYPE.toString(), "freemarker.ext.dump.DumpDirectiveTest$Employee");
|
|
|
|
|
|
|
|
supervisorExpectedDump.put(Key.VALUE.toString(), getJaneSmithExpectedDump(exposureLevel));
|
|
|
|
propertiesExpectedDump.put("supervisor", supervisorExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> favoriteColorsExpectedDump = new HashMap<String, Object>();
|
|
|
|
favoriteColorsExpectedDump.put(Key.TYPE.toString(), Type.SEQUENCE);
|
|
|
|
List<Map<String, Object>> favoriteColorListExpectedDump = new ArrayList<Map<String, Object>>();
|
|
|
|
Map<String, Object> color1ExpectedDump = new HashMap<String, Object>();
|
|
|
|
color1ExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
color1ExpectedDump.put(Key.VALUE.toString(), "blue");
|
|
|
|
favoriteColorListExpectedDump.add(color1ExpectedDump);
|
|
|
|
Map<String, Object> color2ExpectedDump = new HashMap<String, Object>();
|
|
|
|
color2ExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
color2ExpectedDump.put(Key.VALUE.toString(), "green");
|
|
|
|
favoriteColorListExpectedDump.add(color2ExpectedDump);
|
|
|
|
favoriteColorsExpectedDump.put(Key.VALUE.toString(), favoriteColorListExpectedDump);
|
|
|
|
propertiesExpectedDump.put("favoriteColors", favoriteColorsExpectedDump);
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedDump.put(Key.PROPERTIES.toString(), propertiesExpectedDump);
|
|
|
|
|
2011-04-18 21:09:17 +00:00
|
|
|
// Methods
|
|
|
|
expectedDump.put(Key.METHODS.toString(), getEmployeeMethodsExpectedDump(exposureLevel));
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
return expectedDump;
|
2011-04-18 18:38:50 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 21:09:17 +00:00
|
|
|
private List<String> getEmployeeMethodsExpectedDump(int exposureLevel) {
|
|
|
|
|
|
|
|
List<String> expectedDump = new ArrayList<String>();
|
2011-04-22 19:45:45 +00:00
|
|
|
if (exposureLevel <= BeansWrapper.EXPOSE_SAFE) {
|
2011-04-18 21:09:17 +00:00
|
|
|
expectedDump.add("getEmployeeCount");
|
|
|
|
expectedDump.add("getName(String)");
|
|
|
|
expectedDump.add("setFavoriteColors(Strings)");
|
|
|
|
expectedDump.add("setNickname(String)");
|
|
|
|
}
|
|
|
|
Collections.sort(expectedDump);
|
|
|
|
return expectedDump;
|
|
|
|
}
|
|
|
|
|
2011-04-18 20:02:08 +00:00
|
|
|
private Map<String, Object> getJaneSmithExpectedDump(int exposureLevel) {
|
2011-04-18 18:38:50 +00:00
|
|
|
|
2011-04-18 20:02:08 +00:00
|
|
|
Map<String, Object> expectedDump = new HashMap<String, Object>();
|
|
|
|
|
2011-04-18 18:38:50 +00:00
|
|
|
SortedMap<String, Object> propertiesExpectedDump = new TreeMap<String, Object>();
|
2011-04-18 17:29:25 +00:00
|
|
|
|
2011-04-18 20:02:08 +00:00
|
|
|
// Properties
|
2011-04-22 19:45:45 +00:00
|
|
|
if (exposureLevel < BeansWrapper.EXPOSE_NOTHING) {
|
2011-04-18 20:02:08 +00:00
|
|
|
|
2011-04-20 15:41:05 +00:00
|
|
|
Map<String, Object> birthdateExpectedDump = new HashMap<String, Object>();
|
|
|
|
birthdateExpectedDump.put(Key.TYPE.toString(), Type.DATE);
|
|
|
|
birthdateExpectedDump.put(Key.DATE_TYPE.toString(), DateType.UNKNOWN);
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.set(1975, Calendar.OCTOBER, 25);
|
|
|
|
c = DateUtils.truncate(c, Calendar.DATE);
|
|
|
|
birthdateExpectedDump.put(Key.VALUE.toString(), c.getTime());
|
|
|
|
propertiesExpectedDump.put("birthdate", birthdateExpectedDump);
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
Map<String, Object> fullNameExpectedDump = new HashMap<String, Object>();
|
|
|
|
fullNameExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
fullNameExpectedDump.put(Key.VALUE.toString(), "Jane Smith");
|
|
|
|
propertiesExpectedDump.put("fullName", fullNameExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> idExpectedDump = new HashMap<String, Object>();
|
|
|
|
idExpectedDump.put(Key.TYPE.toString(), Type.NUMBER);
|
|
|
|
idExpectedDump.put(Key.VALUE.toString(), 78234);
|
|
|
|
propertiesExpectedDump.put("id", idExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> nicknameExpectedDump = new HashMap<String, Object>();
|
|
|
|
nicknameExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
nicknameExpectedDump.put(Key.VALUE.toString(), "");
|
|
|
|
propertiesExpectedDump.put("nickname", nicknameExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> middleNameExpectedDump = new HashMap<String, Object>();
|
|
|
|
middleNameExpectedDump.put(Key.VALUE.toString(), "null");
|
|
|
|
propertiesExpectedDump.put("middleName", middleNameExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> marriedExpectedDump = new HashMap<String, Object>();
|
|
|
|
marriedExpectedDump.put(Key.TYPE.toString(), Type.BOOLEAN);
|
|
|
|
marriedExpectedDump.put(Key.VALUE.toString(), true);
|
|
|
|
propertiesExpectedDump.put("married", marriedExpectedDump);
|
|
|
|
|
|
|
|
Map<String, Object> supervisorExpectedDump = new HashMap<String, Object>();
|
|
|
|
supervisorExpectedDump.put(Key.VALUE.toString(), "null");
|
|
|
|
propertiesExpectedDump.put("supervisor", supervisorExpectedDump);
|
2011-04-18 18:38:50 +00:00
|
|
|
|
2011-04-18 20:02:08 +00:00
|
|
|
Map<String, Object> favoriteColorsExpectedDump = new HashMap<String, Object>();
|
|
|
|
favoriteColorsExpectedDump.put(Key.TYPE.toString(), Type.SEQUENCE);
|
|
|
|
List<Map<String, Object>> favoriteColorListExpectedDump = new ArrayList<Map<String, Object>>();
|
|
|
|
Map<String, Object> color1ExpectedDump = new HashMap<String, Object>();
|
|
|
|
color1ExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
color1ExpectedDump.put(Key.VALUE.toString(), "red");
|
|
|
|
favoriteColorListExpectedDump.add(color1ExpectedDump);
|
|
|
|
Map<String, Object> color2ExpectedDump = new HashMap<String, Object>();
|
|
|
|
color2ExpectedDump.put(Key.TYPE.toString(), Type.STRING);
|
|
|
|
color2ExpectedDump.put(Key.VALUE.toString(), "orange");
|
|
|
|
favoriteColorListExpectedDump.add(color2ExpectedDump);
|
|
|
|
favoriteColorsExpectedDump.put(Key.VALUE.toString(), favoriteColorListExpectedDump);
|
|
|
|
propertiesExpectedDump.put("favoriteColors", favoriteColorsExpectedDump);
|
|
|
|
}
|
|
|
|
expectedDump.put(Key.PROPERTIES.toString(), propertiesExpectedDump);
|
|
|
|
|
|
|
|
// Methods
|
2011-04-18 21:09:17 +00:00
|
|
|
expectedDump.put(Key.METHODS.toString(), getEmployeeMethodsExpectedDump(exposureLevel));
|
2011-04-18 20:02:08 +00:00
|
|
|
|
|
|
|
return expectedDump;
|
2011-04-18 17:29:25 +00:00
|
|
|
}
|
2011-04-18 20:02:08 +00:00
|
|
|
|
2011-04-07 16:15:49 +00:00
|
|
|
}
|