use of org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement in project plexus-containers by codehaus-plexus.
the class ComponentsXmlMergerTest method testInvalidMergeableElements.
public void testInvalidMergeableElements() throws Exception {
// dominant Component Element
AbstractMergeableElement dCE = new ComponentElement(new Element("component"));
Element roleElt = new Element("role");
roleElt.setText("org.codehaus.plexus.ISampleRole");
dCE.addContent(roleElt);
AbstractMergeableElementList reqElt = new RequirementsElement(new Element("requirement"));
// attempt and invalid merge
try {
dCE.merge(reqElt);
fail("Expected MergeException!");
} catch (MergeException e) {
// do nothing.
}
}
use of org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement 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());
}
use of org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement in project plexus-containers by codehaus-plexus.
the class ComponentsXmlMergerTest method testDeepComponentsMerge.
/**
* <em>This is deprecated as we dont' want to drill to merging
* nested elements within a component.</em><p>
* <em>Keeping this around for testing MergeStrategy implmentation.</em>
*
* @throws Exception in case of an error.
*/
public void testDeepComponentsMerge() throws Exception {
// FIXME: Review this after MergeStrategies are in place.
if (true) {
return;
}
// dominant Component Element
AbstractMergeableElement dCE = new ComponentElement(new Element("component"));
Element roleElt = new Element("role");
roleElt.setText("org.codehaus.plexus.ISampleRole");
dCE.addContent(roleElt);
Element roleHintElt;
// roleHintElt = new Element ("role-hint");
// roleHintElt.setText ("sample-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 rCE = new ComponentElement(new Element("component"));
roleElt = new Element("role");
roleElt.setText("org.codehaus.plexus.ISampleRole");
rCE.addContent(roleElt);
roleHintElt = new Element("role-hint");
roleHintElt.setText("recessive-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
dCE.merge(rCE);
// verify the merge
assertTrue(null != dCE.getChild("role"));
assertEquals("org.codehaus.plexus.ISampleRole", dCE.getChildText("role"));
assertTrue(null != dCE.getChild("role-hint"));
assertEquals("recessive-hint", dCE.getChildText("role-hint"));
assertTrue(null != dCE.getChild("lifecycle-handler"));
assertEquals("plexus-configurable", dCE.getChildText("lifecycle-handler"));
assertTrue(null != dCE.getChild("requirements"));
assertEquals(1, dCE.getChild("requirements").getChildren("requirement").size());
assertEquals("recessive-required-role-hint", ((Element) dCE.getChild("requirements").getChildren("requirement").get(0)).getChildText("role-hint"));
}
Aggregations