1 package org.codehaus.modello.generator.xml.xpp3;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.List;
26 import java.util.Map;
27
28 import org.codehaus.modello.AbstractModelloJavaGeneratorTest;
29 import org.codehaus.modello.core.ModelloCore;
30 import org.codehaus.modello.model.Model;
31 import org.codehaus.modello.model.ModelClass;
32 import org.codehaus.modello.model.ModelField;
33 import org.codehaus.modello.model.Version;
34 import org.codehaus.modello.plugins.xml.metadata.XmlFieldMetadata;
35
36
37
38
39
40 public class Xpp3GeneratorTest extends AbstractModelloJavaGeneratorTest {
41 public Xpp3GeneratorTest() {
42 super("xpp3");
43 }
44
45 public void testXpp3Generator() throws Throwable {
46 ModelloCore modello = (ModelloCore) lookup(ModelloCore.ROLE);
47
48 Model model = modello.loadModel(getXmlResourceReader("/maven.mdo"));
49
50
51 List<ModelClass> classesList = model.getClasses(new Version("4.0.0"));
52
53 assertEquals(28, classesList.size());
54
55 ModelClass clazz = (ModelClass) classesList.get(0);
56
57 assertEquals("Model", clazz.getName());
58
59 ModelField extend = clazz.getField("extend", new Version("4.0.0"));
60
61 assertTrue(extend.hasMetadata(XmlFieldMetadata.ID));
62
63 XmlFieldMetadata xml = (XmlFieldMetadata) extend.getMetadata(XmlFieldMetadata.ID);
64
65 assertNotNull(xml);
66
67 assertTrue(xml.isAttribute());
68
69 assertEquals("extender", xml.getTagName());
70
71 ModelField build = clazz.getField("build", new Version("4.0.0"));
72
73 assertTrue(build.hasMetadata(XmlFieldMetadata.ID));
74
75 xml = (XmlFieldMetadata) build.getMetadata(XmlFieldMetadata.ID);
76
77 assertNotNull(xml);
78
79 assertEquals("builder", xml.getTagName());
80
81
82 Map<String, Object> parameters = getModelloParameters("4.0.0", 8);
83
84 modello.generate(model, "java", parameters);
85 modello.generate(model, "xpp3-writer", parameters);
86 modello.generate(model, "xpp3-reader", parameters);
87
88 addDependency("org.xmlunit", "xmlunit-core");
89 compileGeneratedSources(8);
90
91
92 System.setProperty("version", getModelloVersion());
93
94 verifyCompiledGeneratedSources("org.codehaus.modello.generator.xml.xpp3.Xpp3Verifier");
95 }
96 }