use of org.codehaus.plexus.metadata.merge.support.ComponentsElement in project plexus-containers by codehaus-plexus.
the class ComponentsXmlMergerTest method testComponentsMerge.
/**
* Tests if <component> elements from two sets are being merged properly.
*
* @throws Exception if there was an unexpected error.
*/
public void testComponentsMerge() throws Exception {
// dominant Components Element
AbstractMergeableElement dParent = new ComponentsElement(new Element("components"));
Element dCE = new Element("component");
dParent.addContent(dCE);
Element roleElt = new Element("role");
roleElt.setText("org.codehaus.plexus.ISampleRole");
dCE.addContent(roleElt);
Element roleHintElt = new Element("role-hint");
roleHintElt.setText("sample-role-hint");
dCE.addContent(roleHintElt);
Element implElt = new Element("implementation");
implElt.setText("org.codehaus.plexus.DominantImplementation");
dCE.addContent(implElt);
Element requirementsElt = new Element("requirements");
Element reqElt = new Element("requirement");
Element reqRoleElt = new Element("role");
reqRoleElt.setText("org.codehaus.plexus.IRequiredRole");
reqElt.addContent(reqRoleElt);
requirementsElt.addContent(reqElt);
dCE.addContent(requirementsElt);
// recessive Component Element
AbstractMergeableElement rParent = new ComponentsElement(new Element("components"));
Element rCE = new Element("component");
rParent.addContent(rCE);
roleElt = new Element("role");
roleElt.setText("org.codehaus.plexus.ISampleRole");
rCE.addContent(roleElt);
roleHintElt = new Element("role-hint");
roleHintElt.setText("sample-role-hint");
rCE.addContent(roleHintElt);
implElt = new Element("implementation");
implElt.setText("org.codehaus.plexus.RecessiveImplementation");
rCE.addContent(implElt);
Element lifecycleHandlerElt = new Element("lifecycle-handler");
rCE.addContent(lifecycleHandlerElt);
lifecycleHandlerElt.setText("plexus-configurable");
requirementsElt = new Element("requirements");
reqElt = new Element("requirement");
reqRoleElt = new Element("role");
reqRoleElt.setText("org.codehaus.plexus.IRequiredRole");
reqElt.addContent(reqRoleElt);
requirementsElt.addContent(reqElt);
Element reqRoleHintElt = new Element("role-hint");
reqRoleHintElt.setText("recessive-required-role-hint");
reqElt.addContent(reqRoleHintElt);
rCE.addContent(requirementsElt);
// attempt to merge
dParent.merge(rParent);
assertEquals(1, dParent.getChildren("component").size());
assertEquals("org.codehaus.plexus.DominantImplementation", dParent.getChild("component").getChildText("implementation"));
assertEquals(1, dParent.getChild("component").getChild("requirements").getChildren("requirement").size());
}
Aggregations