Search in sources :

Example 1 with AbstractMergeableElement

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.
    }
}
Also used : RequirementsElement(org.codehaus.plexus.metadata.merge.support.RequirementsElement) AbstractMergeableElementList(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElementList) ComponentsElement(org.codehaus.plexus.metadata.merge.support.ComponentsElement) RequirementsElement(org.codehaus.plexus.metadata.merge.support.RequirementsElement) ComponentElement(org.codehaus.plexus.metadata.merge.support.ComponentElement) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) Element(org.jdom2.Element) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) ComponentElement(org.codehaus.plexus.metadata.merge.support.ComponentElement)

Example 2 with AbstractMergeableElement

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());
}
Also used : ComponentsElement(org.codehaus.plexus.metadata.merge.support.ComponentsElement) RequirementsElement(org.codehaus.plexus.metadata.merge.support.RequirementsElement) ComponentElement(org.codehaus.plexus.metadata.merge.support.ComponentElement) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) Element(org.jdom2.Element) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) ComponentsElement(org.codehaus.plexus.metadata.merge.support.ComponentsElement)

Example 3 with AbstractMergeableElement

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"));
}
Also used : ComponentsElement(org.codehaus.plexus.metadata.merge.support.ComponentsElement) RequirementsElement(org.codehaus.plexus.metadata.merge.support.RequirementsElement) ComponentElement(org.codehaus.plexus.metadata.merge.support.ComponentElement) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) Element(org.jdom2.Element) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) ComponentElement(org.codehaus.plexus.metadata.merge.support.ComponentElement)

Aggregations

AbstractMergeableElement (org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement)3 ComponentElement (org.codehaus.plexus.metadata.merge.support.ComponentElement)3 ComponentsElement (org.codehaus.plexus.metadata.merge.support.ComponentsElement)3 RequirementsElement (org.codehaus.plexus.metadata.merge.support.RequirementsElement)3 Element (org.jdom2.Element)3 AbstractMergeableElementList (org.codehaus.plexus.metadata.merge.support.AbstractMergeableElementList)1