Map<String, Definition> defs = new HashMap<String, Definition>();
Definition def = new Definition();
def.setName("parent.def1");
def.setTemplate("/test1.jsp");
Attribute attr = new Attribute();
attr.setValue("value1");
def.putAttribute("attr1", attr);
attr = new Attribute();
attr.setValue("tiles.def1");
// No type set
def.putAttribute("attr2", attr);
defs.put(def.getName(), def);
attr = new Attribute();
attr.setValue("tiles.def1");
attr.setType(AttributeType.STRING);
def.putAttribute("attr3", attr);
defs.put(def.getName(), def);
def = new Definition();
def.setName("tiles.def1");
def.setTemplate("/test2.jsp");
defs.put(def.getName(), def);
def = new Definition();
def.setName("child.def1");
def.setExtends("parent.def1");
attr = new Attribute();
attr.setValue("New value");
def.putAttribute("attr1", attr);
defs.put(def.getName(), def);
Definitions definitions = new DefinitionsImpl();
try {
definitions.addDefinitions(defs);
} catch (NoSuchDefinitionException e) {
fail("Test failure: " + e);
}
def = definitions.getDefinition("parent.def1");
assertNotNull("Couldn't get parent.", def);
assertEquals("Incorrect template value.", "/test1.jsp", def
.getTemplate());
assertEquals("Incorrect attr1 value", "value1", def
.getAttribute("attr1").getValue());
attr = def.getAttributes().get("attr1");
assertNotNull("Dependent attribute not found.", attr);
attr = def.getAttributes().get("attr2");
assertNotNull("Dependent attribute not found.", attr);
attr = def.getAttributes().get("attr3");
assertNotNull("Dependent attribute not found.", attr);
assertTrue("The attribute 'attr3' should be of type STRING", attr
.getType() == AttributeType.STRING);
def = definitions.getDefinition("child.def1");
assertNotNull("Couldn't get child.",
definitions.getDefinition("child.def1"));
assertEquals("Incorrect template value." , "/test1.jsp",
definitions.getDefinition("child.def1").getTemplate());
assertEquals("Incorrect attr1 value", "New value", definitions
.getDefinition("child.def1").getAttribute("attr1").getValue());
attr = def.getAttributes().get("attr1");
assertNotNull("Dependent attribute not found.", attr);
attr = def.getAttributes().get("attr2");
assertNotNull("Dependent attribute not found.", attr);
attr = def.getAttributes().get("attr3");
assertNotNull("Dependent attribute not found.", attr);
assertTrue("The attribute 'attr3' should be of type STRING", attr
.getType() == AttributeType.STRING);
}