01: package net.sourceforge.jaxor.parser.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.parser.*;
05: import org.apache.velocity.runtime.RuntimeServices;
06: import org.apache.velocity.runtime.log.LogSystem;
07:
08: import java.io.ByteArrayOutputStream;
09: import java.io.File;
10: import java.io.PrintStream;
11: import java.util.Properties;
12:
13: /*
14: * User: Mike
15: * Date: Nov 10, 2002
16: * Time: 10:35:05 PM
17: */
18:
19: public class SourceGeneratorTest extends TestCase implements LogSystem {
20: public void testGeneration() throws Exception {
21: Entity ent = new Entity("name");
22: ent.addAggregate(new Aggregate("type", "Alias", "Mapper"));
23: ent.addQuery(new Query("Name", "select * from table"));
24: PrimaryKey key = new PrimaryKey();
25: key.addAttribute(new Attribute("name", "java.lang.Long", true));
26: ent.addPrimaryKey(key);
27: ent.addAttribute(new Attribute("name", "type", true, true));
28: Generator config = createGenerator();
29: Properties registry = new Properties();
30: registry.put("type", "type");
31: registry.put("java.lang.Long", "LongMapper");
32: Jaxor j = new Jaxor();
33: j.addEntity(ent);
34: j.setPackage("com.temp");
35: j.setMapperProps(registry);
36: j.setConfig(config);
37: SourceGenerator gen = new SourceGenerator(j, new File("none"),
38: 0, this );
39: gen.print(new PrintStream(new ByteArrayOutputStream()),
40: "Finder.vm");
41: }
42:
43: public void init(RuntimeServices runtimeServices) throws Exception {
44:
45: }
46:
47: public void logVelocityMessage(int i, String s) {
48: if (i > 1)
49: System.out.println("Level: " + i + " Message: " + s);
50: }
51:
52: public static Generator createGenerator() {
53: Generator config = new Generator();
54: Extends ext = new Extends();
55: ext.setName("java.lang.Object");
56: config.addExtends(ext);
57: Implements i = new Implements();
58: i.setName("java.io.Serial");
59: config.addImplements(i);
60: return config;
61: }
62:
63: }
|