import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.bea.canvas.Context;
import com.bea.canvas.Canvas;
import com.bea.canvas.Template;
/**
* This class
*
* @author Cedric Beust, Mar 6, 2004
*
*/
public class TestCanvas {
public void test1(String templatePath) {
Context ctx = new Context();
ctx.put("firstName", "Cedric");
Company p = new Company();
p.setName("BEA Systems");
p.setLocation("San Jose");
ctx.put("company", p);
List l = new ArrayList();
l.add("Cedric");
l.add("Alois");
ctx.put("family", l);
List l2 = new ArrayList();
Company p2 = new Company();
p2.setName("FFT");
p2.setLocation("Paris");
l2.add(p);
l2.add(p2);
ctx.put("companies", l2);
Map m = new HashMap();
m.put("Cedric", "San Francisco");
m.put("Alois", "Paris");
ctx.put("workplaces", m);
String expected = "My name is Cedric Beust.\n" +
"Cedric lives in San Francisco\n" +
"Cameron lives in Boston\n" +
"\n" +
"BEA Systems is in San Jose\n" +
"Family is Cedric Alois \n" +
"Company locations: San Jose Paris \n" +
"Workplaces are San Francisco Paris\n"
;
try {
Template tmpl = Canvas.getTemplate(templatePath);
StringBuffer sb = new StringBuffer();
tmpl.merge(ctx, sb);
String result = sb.toString();
System.out.println("===" + result + "===");
if (expected.equals(result)) {
System.out.println("Passed");
}
else {
System.out.println("EXPECTED===\n" + expected +
"===\nBUT GOT\n===" + result + " +\n===" + " FAILED");
}
}
catch (FileNotFoundException e) {
// XXX Auto-generated catch block
e.printStackTrace();
}
} // main }
static public void main(String[] argv) {
String templatePath = "template1.canvas";
if (argv.length > 0) templatePath = argv[0];
new TestCanvas().test1(templatePath);
}
}