package be.iminds.ilabt.jfed.rspec.rspec_source;

import be.iminds.ilabt.jfed.rspec.model.ModelRspec;
import be.iminds.ilabt.jfed.rspec.model.RspecFactory;
import be.iminds.ilabt.jfed.rspec.model.RspecNode;
import be.iminds.ilabt.jfed.rspec.model.StringRspec;
import be.iminds.ilabt.jfed.rspec.model.impl.BasicRspecFactory;
import be.iminds.ilabt.jfed.rspec.parser.ExtraXml;
import be.iminds.ilabt.jfed.rspec.parser.TestRspecReconstructable;
import be.iminds.ilabt.jfed.rspec.parser.TestRspecsLibrary;
import be.iminds.ilabt.jfed.util.GeniUrn;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

import static org.testng.Assert.*;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

/**
 * TestManifestRspecMerger
 */
public class TestManifestRspecMerger {
    protected final RspecFactory rspecFactory;

    protected TestManifestRspecMerger(RspecFactory rspecFactory) {
        this.rspecFactory = rspecFactory;
    }
    public TestManifestRspecMerger() {
        this(BasicRspecFactory.getInstance());
    }

    private static String emuInstaRspec = "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd \" expires=\"2014-08-22T14:03:00Z\">\n" +
            "  <node client_id=\"wall2\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"60.0\" y=\"58.0\"/>\n" +
            //"    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
            "  </node>\n" +
            "  <node client_id=\"emuInsta\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+utahddc.geniracks.net+authority+cm\" component_id=\"urn:publicid:IDN+utahddc.geniracks.net+node+pc8\" sliver_id=\"urn:publicid:IDN+utahddc.geniracks.net+sliver+25620\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"215.0\" y=\"132.0\"/>\n" +
            //"    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
            "  <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"pcvm8-2\"/><host name=\"emuInsta.merge.ch-geni-net.utahddc.geniracks.net\"/><services><login authentication=\"ssh-keys\" hostname=\"pc8.utahddc.geniracks.net\" port=\"31802\" username=\"wimvande\"/></services></node>\n" +
            "</rspec>";
    private static String wall1Rspec = "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd \" expires=\"2014-08-22T14:03:00Z\">"+
            "<node client_id=\"wall1\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+node+n143-04a\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23555\">"+
            "  <sliver_type name=\"emulab-xen\"/>"+
            "  <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"111.0\" y=\"27.0\"/>"+
            //"  <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>"+
            "<rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n143-04avm-1\"/><host name=\"wall1.merge.fed4fire-eu.wall1.ilabt.iminds.be\"/><services><login authentication=\"ssh-keys\" hostname=\"n143-04avm-1.wall1.ilabt.iminds.be\" port=\"22\" username=\"wimvande\"/></services></node>"+
            "</rspec>";
    private static String wall2Rspec = "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd \" expires=\"2014-08-22T14:03:00Z\">\n" +
            "  <node client_id=\"wall2\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n091-26\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27579\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"60.0\" y=\"58.0\"/>\n" +
          //  "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
            "  <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n091-vm26-3\"/><host name=\"wall2.merge.ch-geni-net.wall2.ilabt.iminds.be\"/><services><login authentication=\"ssh-keys\" hostname=\"n091-vm26-3.wall2.ilabt.iminds.be\" port=\"22\" username=\"wimvande\"/></services></node>\n" +
            "  <node client_id=\"emuInsta\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+utahddc.geniracks.net+authority+cm\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"215.0\" y=\"132.0\"/>\n" +
            //"    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
            "  </node>\n" +
            "</rspec>";

    public static String expectedMergedRspecString = "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd \">\n" +
            "  <node client_id=\"emuInsta\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+utahddc.geniracks.net+authority+cm\" component_id=\"urn:publicid:IDN+utahddc.geniracks.net+node+pc8\" sliver_id=\"urn:publicid:IDN+utahddc.geniracks.net+sliver+25620\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "     <services>\n" +
            "         <login authentication=\"ssh-keys\" hostname=\"pc8.utahddc.geniracks.net\" port=\"31802\" username=\"wimvande\"/>\n" +
            "     </services>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"215.0\" y=\"132.0\"/>\n" +
           // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
            "     <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"pcvm8-2\"/>\n" +
            "     <host name=\"emuInsta.merge.ch-geni-net.utahddc.geniracks.net\"/>\n" +
            "  </node>\n" +
            "  <node client_id=\"wall2\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n091-26\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27579\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"60.0\" y=\"58.0\"/>\n" +
           // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
            "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n091-vm26-3\"/>\n" +
            "    <host name=\"wall2.merge.ch-geni-net.wall2.ilabt.iminds.be\"/>\n" +
            "    <services>\n" +
            "        <login authentication=\"ssh-keys\" hostname=\"n091-vm26-3.wall2.ilabt.iminds.be\" port=\"22\" username=\"wimvande\"/>\n" +
            "    </services>\n" +
            "  </node>\n" +
            "  <node client_id=\"wall1\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+node+n143-04a\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23555\">\n"+
            "     <sliver_type name=\"emulab-xen\"/>\n"+
            "     <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"111.0\" y=\"27.0\"/>\n"+
            //"     <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n"+
            "     <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n143-04avm-1\"/>\n" +
            "     <host name=\"wall1.merge.fed4fire-eu.wall1.ilabt.iminds.be\"/>\n" +
            "     <services>\n" +
            "        <login authentication=\"ssh-keys\" hostname=\"n143-04avm-1.wall1.ilabt.iminds.be\" port=\"22\" username=\"wimvande\"/>\n" +
            "      </services>\n" +
            "   </node>\n"+
            "</rspec>";



    public static String  wall1StitchRspec =
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\" expires=\"2014-08-26T11:51:16Z\">\n" +
                    "  <node client_id=\"w2\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"51.0\" y=\"33.0\"/>\n" +
                   // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w2:if0\">\n" +
                    "      <ip address=\"10.0.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "  </node>\n" +
                    "  <node client_id=\"w1\" component_manager_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+node+n143-02b\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23697\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"39.0\" y=\"161.0\"/>\n" +
                   // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w1:if0\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+n143-02b:eth3\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23700\" mac_address=\"022d649bbb39\">\n" +
                    "      <ip address=\"10.0.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "  <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n143-02b\"/><host name=\"w1.stitch2.wall2-ilabt-iminds-be.wall1.ilabt.iminds.be\"/><services><login authentication=\"ssh-keys\" hostname=\"n143-02b.wall1.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/></services></node>\n" +
                    "  <link client_id=\"link0\" vlantag=\"347\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23699\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"w2:if0\"/>\n" +
                    "    <interface_ref client_id=\"w1:if0\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+n143-02b:eth3\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23700\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w1:if0\" source_id=\"w2:if0\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w2:if0\" source_id=\"w1:if0\"/>\n" +
                    "  </link>\n" +
                    "<stitching xmlns=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\" lastUpdateTime=\"20140826:11:57:50\">\n" +
                    "    <path id=\"link0\">\n" +
                    "      <hop id=\"1\">\n" +
                    "        <link id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+c300b:0.16\">\n" +
                    "          <trafficEngineeringMetric>10</trafficEngineeringMetric>\n" +
                    "          <capacity>10000</capacity>\n" +
                    "          <switchingCapabilityDescriptor>\n" +
                    "            <switchingcapType>l2sc</switchingcapType>\n" +
                    "            <encodingType>ethernet</encodingType>\n" +
                    "            <switchingCapabilitySpecificInfo>\n" +
                    "              <switchingCapabilitySpecificInfo_L2sc>\n" +
                    "                <interfaceMTU>1500</interfaceMTU>\n" +
                    "                <vlanRangeAvailability>197,300-349,750-1000</vlanRangeAvailability>\n" +
                    "                <suggestedVLANRange>any</suggestedVLANRange>\n" +
                    "                <vlanTranslation>false</vlanTranslation>\n" +
                    "              </switchingCapabilitySpecificInfo_L2sc>\n" +
                    "            </switchingCapabilitySpecificInfo>\n" +
                    "          </switchingCapabilityDescriptor>\n" +
                    "        </link>\n" +
                    "        <nextHop>2</nextHop>\n" +
                    "      </hop>\n" +
                    "      <hop id=\"2\">\n" +
                    "        <link id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+c300a:7.44\">\n" +
                    "          <trafficEngineeringMetric>10</trafficEngineeringMetric>\n" +
                    "          <capacity>10000</capacity>\n" +
                    "          <switchingCapabilityDescriptor>\n" +
                    "            <switchingcapType>l2sc</switchingcapType>\n" +
                    "            <encodingType>ethernet</encodingType>\n" +
                    "            <switchingCapabilitySpecificInfo>\n" +
                    "              <switchingCapabilitySpecificInfo_L2sc>\n" +
                    "                <interfaceMTU>1500</interfaceMTU>\n" +
                    "                <vlanRangeAvailability>347</vlanRangeAvailability>\n" +
                    "                <suggestedVLANRange>347</suggestedVLANRange>\n" +
                    "                <vlanTranslation>false</vlanTranslation>\n" +
                    "              </switchingCapabilitySpecificInfo_L2sc>\n" +
                    "            </switchingCapabilitySpecificInfo>\n" +
                    "          </switchingCapabilityDescriptor>\n" +
                    "        </link>\n" +
                    "        <nextHop>null</nextHop>\n" +
                    "      </hop>\n" +
                    "    </path>\n" +
                    "  </stitching>\n" +
                    "</rspec>";
    public static String  wall2StitchRspec =
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\" expires=\"2014-08-26T11:51:16Z\">\n" +
                    "  <node client_id=\"w2\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n091-21\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27791\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"51.0\" y=\"33.0\"/>\n" +
                   // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w2:if0\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n091-21:eth5\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27794\" mac_address=\"027ea3a46056\">\n" +
                    "      <ip address=\"10.0.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "  <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n091-21\"/><host name=\"w2.stitch2.wall2-ilabt-iminds-be.wall2.ilabt.iminds.be\"/><services><login authentication=\"ssh-keys\" hostname=\"n091-21.wall2.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/></services></node>\n" +
                    "  <node client_id=\"w1\" component_manager_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\" exclusive=\"true\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"39.0\" y=\"161.0\"/>\n" +
                  //  "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w1:if0\">\n" +
                    "      <ip address=\"10.0.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "  </node>\n" +
                    "  <link client_id=\"link0\" vlantag=\"347\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27793\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"w2:if0\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n091-21:eth5\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27794\"/>\n" +
                    "    <interface_ref client_id=\"w1:if0\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w1:if0\" source_id=\"w2:if0\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w2:if0\" source_id=\"w1:if0\"/>\n" +
                    "  </link>\n" +
                    "<stitching xmlns=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\" lastUpdateTime=\"20140826:11:57:50\">\n" +
                    "    <path id=\"link0\">\n" +
                    "      <hop id=\"1\">\n" +
                    "        <link id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+c300b:0.16\">\n" +
                    "          <trafficEngineeringMetric>10</trafficEngineeringMetric>\n" +
                    "          <capacity>10000</capacity>\n" +
                    "          <switchingCapabilityDescriptor>\n" +
                    "            <switchingcapType>l2sc</switchingcapType>\n" +
                    "            <encodingType>ethernet</encodingType>\n" +
                    "            <switchingCapabilitySpecificInfo>\n" +
                    "              <switchingCapabilitySpecificInfo_L2sc>\n" +
                    "                <interfaceMTU>1500</interfaceMTU>\n" +
                    "                <vlanRangeAvailability>347</vlanRangeAvailability>\n" +
                    "                <suggestedVLANRange>347</suggestedVLANRange>\n" +
                    "                <vlanTranslation>false</vlanTranslation>\n" +
                    "              </switchingCapabilitySpecificInfo_L2sc>\n" +
                    "            </switchingCapabilitySpecificInfo>\n" +
                    "          </switchingCapabilityDescriptor>\n" +
                    "        </link>\n" +
                    "        <nextHop>2</nextHop>\n" +
                    "      </hop>\n" +
                    "      <hop id=\"2\">\n" +
                    "        <link id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+c300a:7.44\">\n" +
                    "          <trafficEngineeringMetric>10</trafficEngineeringMetric>\n" +
                    "          <capacity>10000</capacity>\n" +
                    "          <switchingCapabilityDescriptor>\n" +
                    "            <switchingcapType>l2sc</switchingcapType>\n" +
                    "            <encodingType>ethernet</encodingType>\n" +
                    "            <switchingCapabilitySpecificInfo>\n" +
                    "              <switchingCapabilitySpecificInfo_L2sc>\n" +
                    "                <interfaceMTU>1500</interfaceMTU>\n" +
                    "                <vlanRangeAvailability>197,300-349,750-1000</vlanRangeAvailability>\n" +
                    "                <suggestedVLANRange>any</suggestedVLANRange>\n" +
                    "                <vlanTranslation>false</vlanTranslation>\n" +
                    "              </switchingCapabilitySpecificInfo_L2sc>\n" +
                    "            </switchingCapabilitySpecificInfo>\n" +
                    "          </switchingCapabilityDescriptor>\n" +
                    "        </link>\n" +
                    "        <nextHop>null</nextHop>\n" +
                    "      </hop>\n" +
                    "    </path>\n" +
                    "  </stitching>\n" +
                    "</rspec>";
    public static String expectedMergedStitchRspecOrder1 =
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" " +
                    "xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  " +
                    "http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\">\n" +
                    "  <node client_id=\"w2\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n091-21\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27791\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <services>\n" +
                    "      <login authentication=\"ssh-keys\" hostname=\"n091-21.wall2.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/>\n" +
                    "    </services>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"51.0\" y=\"33.0\"/>\n" +
                   // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w2:if0\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n091-21:eth5\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27794\" mac_address=\"027ea3a46056\">\n" +
                    "      <ip address=\"10.0.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n091-21\"/>\n" +
                    "    <host name=\"w2.stitch2.wall2-ilabt-iminds-be.wall2.ilabt.iminds.be\"/>\n" +
                    "  </node>\n" +
                    "  <node client_id=\"w1\" component_manager_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+node+n143-02b\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23697\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <services>\n" +
                    "      <login authentication=\"ssh-keys\" hostname=\"n143-02b.wall1.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/>\n" +
                    "    </services>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"39.0\" y=\"161.0\"/>\n" +
                   // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w1:if0\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+n143-02b:eth3\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23700\" mac_address=\"022d649bbb39\">\n" +
                    "      <ip address=\"10.0.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n143-02b\"/>\n" +
                    "    <host name=\"w1.stitch2.wall2-ilabt-iminds-be.wall1.ilabt.iminds.be\"/>\n" +
                    "  </node>\n" +
//                    "  <link client_id=\"link0\" vlantag=\"347\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27793\">\n" + //it actually needs both sliver_ids but that is impossible. so it uses the last merged one.
//                      "  <link client_id=\"link0\" vlantag=\"347\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23699\">\n" +
                      "  <link client_id=\"link0\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23699\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"w2:if0\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n091-21:eth5\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27794\"/>\n" +
                    "    <interface_ref client_id=\"w1:if0\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+n143-02b:eth3\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23700\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w1:if0\" source_id=\"w2:if0\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w2:if0\" source_id=\"w1:if0\"/>\n" +
                    "  </link>\n" +
                    //extra xml is discarded in merged manifest.
//                    "<stitching xmlns=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\" lastUpdateTime=\"20140826:11:57:50\">\n" +
//                    "    <path id=\"link0\">\n" +
//                    "      <hop id=\"1\">\n" +
//                    "        <link id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+c300b:0.16\">\n" +
//                    "          <trafficEngineeringMetric>10</trafficEngineeringMetric>\n" +
//                    "          <capacity>10000</capacity>\n" +
//                    "          <switchingCapabilityDescriptor>\n" +
//                    "            <switchingcapType>l2sc</switchingcapType>\n" +
//                    "            <encodingType>ethernet</encodingType>\n" +
//                    "            <switchingCapabilitySpecificInfo>\n" +
//                    "              <switchingCapabilitySpecificInfo_L2sc>\n" +
//                    "                <interfaceMTU>1500</interfaceMTU>\n" +
//                    "                <vlanRangeAvailability>347</vlanRangeAvailability>\n" +
//                    "                <suggestedVLANRange>347</suggestedVLANRange>\n" +
//                    "                <vlanTranslation>false</vlanTranslation>\n" +
//                    "              </switchingCapabilitySpecificInfo_L2sc>\n" +
//                    "            </switchingCapabilitySpecificInfo>\n" +
//                    "          </switchingCapabilityDescriptor>\n" +
//                    "        </link>\n" +
//                    "        <nextHop>2</nextHop>\n" +
//                    "      </hop>\n" +
//                    "      <hop id=\"2\">\n" +
//                    "        <link id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+c300a:7.44\">\n" +
//                    "          <trafficEngineeringMetric>10</trafficEngineeringMetric>\n" +
//                    "          <capacity>10000</capacity>\n" +
//                    "          <switchingCapabilityDescriptor>\n" +
//                    "            <switchingcapType>l2sc</switchingcapType>\n" +
//                    "            <encodingType>ethernet</encodingType>\n" +
//                    "            <switchingCapabilitySpecificInfo>\n" +
//                    "              <switchingCapabilitySpecificInfo_L2sc>\n" +
//                    "                <interfaceMTU>1500</interfaceMTU>\n" +
//                    "                <vlanRangeAvailability>197,300-349,750-1000</vlanRangeAvailability>\n" +
//                    "                <suggestedVLANRange>any</suggestedVLANRange>\n" +
//                    "                <vlanTranslation>false</vlanTranslation>\n" +
//                    "              </switchingCapabilitySpecificInfo_L2sc>\n" +
//                    "            </switchingCapabilitySpecificInfo>\n" +
//                    "          </switchingCapabilityDescriptor>\n" +
//                    "        </link>\n" +
//                    "        <nextHop>null</nextHop>\n" +
//                    "      </hop>\n" +
//                    "    </path>\n" +
//                    "  </stitching>\n" +
                    "</rspec>";
    public static String expectedMergedStitchRspecOrder2 =
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" type=\"manifest\" " +
                    "xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  " +
                    "http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\">\n" +
                    "  <node client_id=\"w1\" component_manager_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+node+n143-02b\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23697\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <services>\n" +
                    "      <login authentication=\"ssh-keys\" hostname=\"n143-02b.wall1.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/>\n" +
                    "    </services>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"39.0\" y=\"161.0\"/>\n" +
                    "    <interface client_id=\"w1:if0\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+n143-02b:eth3\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23700\" mac_address=\"022d649bbb39\">\n" +
                    "      <ip address=\"10.0.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n143-02b\"/>\n" +
                    "    <host name=\"w1.stitch2.wall2-ilabt-iminds-be.wall1.ilabt.iminds.be\"/>\n" +
                    "  </node>\n" +
                    "  <node client_id=\"w2\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\" exclusive=\"true\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n091-21\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27791\">\n" +
                    "    <sliver_type name=\"raw-pc\"/>\n" +
                    "    <services>\n" +
                    "      <login authentication=\"ssh-keys\" hostname=\"n091-21.wall2.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/>\n" +
                    "    </services>\n" +
                    "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"51.0\" y=\"33.0\"/>\n" +
                   // "    <nodeDescription xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\">simple-node</nodeDescription>\n" +
                    "    <interface client_id=\"w2:if0\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n091-21:eth5\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27794\" mac_address=\"027ea3a46056\">\n" +
                    "      <ip address=\"10.0.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
                    "    </interface>\n" +
                    "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n091-21\"/>\n" +
                    "    <host name=\"w2.stitch2.wall2-ilabt-iminds-be.wall2.ilabt.iminds.be\"/>\n" +
                    "  </node>\n" +
                      "  <link client_id=\"link0\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27793\" vlantag=\"347\">\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <component_manager name=\"urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm\"/>\n" +
                    "    <interface_ref client_id=\"w2:if0\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n091-21:eth5\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27794\"/>\n" +
                    "    <interface_ref client_id=\"w1:if0\" component_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+interface+n143-02b:eth3\" sliver_id=\"urn:publicid:IDN+wall1.ilabt.iminds.be+sliver+23700\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w1:if0\" source_id=\"w2:if0\"/>\n" +
                    "    <property capacity=\"10000\" dest_id=\"w2:if0\" source_id=\"w1:if0\"/>\n" +
                    "  </link>\n" +
                    "</rspec>";

    private static String wall1Urn = "urn:publicid:IDN+wall1.ilabt.iminds.be+authority+cm";
    private static String wall1SubAuthUrn = "urn:publicid:IDN+wall1.ilabt.iminds.be:test+authority+cm";
    private static String wall2Urn = "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm";
    private static String emuInstaUrn = "urn:publicid:IDN+utahddc.geniracks.net+authority+cm";

    private static String wall1Node = "urn:publicid:IDN+wall1.ilabt.iminds.be+node+a";
    private static String wall1SubAuthNode = "urn:publicid:IDN+wall1.ilabt.iminds.be:test+node+a";
    private static String wall2Node = "urn:publicid:IDN+wall2.ilabt.iminds.be+node+a";
    private static String emuInstaNode = "urn:publicid:IDN+utahddc.geniracks.net+node+a";

    @Test
    public void testAuthoritative() {
        //check urns against resources
        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Node), GeniUrn.parse(wall1Urn)));
        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthNode), GeniUrn.parse(wall1Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Node), GeniUrn.parse(wall1SubAuthUrn)));
        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthNode), GeniUrn.parse(wall1SubAuthUrn)));

        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Node), GeniUrn.parse(wall2Urn)));

        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaNode), GeniUrn.parse(emuInstaUrn)));


        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Node), GeniUrn.parse(wall1Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaNode), GeniUrn.parse(wall1Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Node), GeniUrn.parse(wall1SubAuthUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaNode), GeniUrn.parse(wall1SubAuthUrn)));

        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Node), GeniUrn.parse(wall2Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthNode), GeniUrn.parse(wall2Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaNode), GeniUrn.parse(wall2Urn)));

        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Node), GeniUrn.parse(emuInstaUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthNode), GeniUrn.parse(emuInstaUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Node), GeniUrn.parse(emuInstaUrn)));


        //check urns against themselves

        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaUrn), GeniUrn.parse(emuInstaUrn)));
        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Urn), GeniUrn.parse(wall2Urn)));
        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Urn), GeniUrn.parse(wall1Urn)));
        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthUrn), GeniUrn.parse(wall1SubAuthUrn)));

        assertTrue(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthUrn), GeniUrn.parse(wall1Urn)));

        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Urn), GeniUrn.parse(emuInstaUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Urn), GeniUrn.parse(emuInstaUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthUrn), GeniUrn.parse(emuInstaUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Urn), GeniUrn.parse(wall2Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaUrn), GeniUrn.parse(wall2Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1SubAuthUrn), GeniUrn.parse(wall2Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Urn), GeniUrn.parse(wall1Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaUrn), GeniUrn.parse(wall1Urn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall1Urn), GeniUrn.parse(wall1SubAuthUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(wall2Urn), GeniUrn.parse(wall1SubAuthUrn)));
        assertFalse(ManifestRspecMerger.isAuthoritative(GeniUrn.parse(emuInstaUrn), GeniUrn.parse(wall1SubAuthUrn)));
    }

    @Test
    public void testExtraXmlEquals() {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1Rspec));
        RspecNode rspecNodeWall1 = wall1.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNodeWall1);
        List<ExtraXml> extraXmlListWall1 = rspecNodeWall1.getExtraXml();
        assertNotNull(extraXmlListWall1);
        assertEquals(extraXmlListWall1.size(), 2);

        ExtraXml aW = extraXmlListWall1.get(0);
        ExtraXml bW = extraXmlListWall1.get(1);

        assertNotEquals(aW, bW);
        assertEquals(aW, aW);
        assertEquals(bW, bW);
        assertEquals(bW.hashCode(), bW.hashCode());
        assertEquals(aW.hashCode(), aW.hashCode());

        ManifestRspecSource expectedMerged = new ManifestRspecSource(new StringRspec(expectedMergedRspecString));
        RspecNode rspecNodeMerged = expectedMerged.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNodeMerged);
        List<ExtraXml> extraXmlListMerged = rspecNodeMerged.getExtraXml();
        assertNotNull(extraXmlListMerged);
        assertEquals(extraXmlListMerged.size(), 2);

        ExtraXml aM = extraXmlListMerged.get(0);
        ExtraXml bM = extraXmlListMerged.get(1);

        assertNotEquals(aM, bM);
        assertEquals(aM, aM);
        assertEquals(bM, bM);
        assertEquals(bM.hashCode(), bM.hashCode());
        assertEquals(aM.hashCode(), aM.hashCode());


        assertNotEquals(aM, bW);
        assertNotEquals(aW, bM);
        assertEquals(aM, aW);
        assertEquals(bM, bW);
        assertEquals(bM.hashCode(), bW.hashCode());
        assertEquals(aM.hashCode(), aW.hashCode());
    }

    private static <T> void addMissing(List<T> target, List<T> other) {
        for (T o : other) {
            if (!target.contains(o))
                target.add(o);
        }
    }
    @Test
    public void testAddMissing() {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1Rspec));
        RspecNode rspecNodeWall1 = wall1.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNodeWall1);
        List<ExtraXml> extraXmlListWall1 = rspecNodeWall1.getExtraXml();
        assertNotNull(extraXmlListWall1);
        assertEquals(extraXmlListWall1.size(), 2);

        ManifestRspecSource expectedMerged = new ManifestRspecSource(new StringRspec(expectedMergedRspecString));
        RspecNode rspecNodeMerged = expectedMerged.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNodeMerged);
        List<ExtraXml> extraXmlListMerged = rspecNodeMerged.getExtraXml();
        assertNotNull(extraXmlListMerged);
        assertEquals(extraXmlListMerged.size(), 2);

        List<ExtraXml> allExtraXml = new ArrayList<ExtraXml>();
        addMissing(allExtraXml, extraXmlListWall1);
        assertEquals(allExtraXml.size(), 2);
        addMissing(allExtraXml, extraXmlListMerged);
        assertEquals(allExtraXml.size(), 2);
    }


    @Test
    public void testCopyNode() {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1Rspec));

        RspecNode rspecNode = wall1.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNode);
        List<ExtraXml> extraXmlList = rspecNode.getExtraXml();
        assertNotNull(extraXmlList);
        assertEquals(extraXmlList.size(), 2);

        ModelRspec newModel = rspecFactory.createModelRspec("manifest");
        RspecNode newRspecNode = rspecFactory.copyNode(newModel, rspecNode, RspecNode.InterfaceCopyMethod.CREATE_NEW_INTERFACE);
        newModel.addNode(newRspecNode);

        List<ExtraXml> newExtraXmlList = newRspecNode.getExtraXml();
        assertNotNull(newExtraXmlList);
        assertEquals(newExtraXmlList.size(), 2);
    }

    @Test
    public void testOverwriteNodeProperties() {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1Rspec));

        RspecNode rspecNode = wall1.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNode);
        List<ExtraXml> extraXmlList = rspecNode.getExtraXml();
        assertNotNull(extraXmlList);
        assertEquals(extraXmlList.size(), 2);

        ModelRspec newModel = rspecFactory.createModelRspec("manifest");
        RspecNode newRspecNode = rspecFactory.copyNode(newModel, rspecNode, RspecNode.InterfaceCopyMethod.CREATE_NEW_INTERFACE);
        newModel.addNode(newRspecNode);

        List<ExtraXml> newExtraXmlList = newRspecNode.getExtraXml();
        assertNotNull(newExtraXmlList);
        assertEquals(newExtraXmlList.size(), 2);

        newRspecNode.getExtraXml().clear();

        newExtraXmlList = newRspecNode.getExtraXml();
        assertNotNull(newExtraXmlList);
        assertEquals(newExtraXmlList.size(), 0);

        newRspecNode.overwritePropertiesWith(rspecNode, false);

        newExtraXmlList = newRspecNode.getExtraXml();
        assertNotNull(newExtraXmlList);
        assertEquals(newExtraXmlList.size(), 2);
    }

    @Test
    public void testMergeKeepsExtraXml() {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1Rspec));

        RspecNode rspecNode = wall1.getModelRspec(rspecFactory.getModelRspecType()).getNodeByClientId("wall1");
        assertNotNull(rspecNode);
        List<ExtraXml> extraXmlList = rspecNode.getExtraXml();
        assertNotNull(extraXmlList);
        assertEquals(extraXmlList.size(), 2);

        ManifestRspecMerger merger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        merger.setManifest(GeniUrn.parse(wall1Urn), wall1);
        ManifestRspecSource mergedRspec = merger.getMergedManifest();

        RspecNode mergedRspecNode = mergedRspec.getModelRspec().getNodeByClientId("wall1");
        assertNotNull(mergedRspecNode);
        List<ExtraXml> mergedExtraXmlList = mergedRspecNode.getExtraXml();
        assertNotNull(mergedExtraXmlList);
        assertEquals(mergedExtraXmlList.size(), 2);
    }

    @Test
    public void testMerge() throws Exception {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1Rspec));
        ManifestRspecSource wall2 = new ManifestRspecSource(new StringRspec(wall2Rspec));
        ManifestRspecSource emuInsta = new ManifestRspecSource(new StringRspec(emuInstaRspec));

        ManifestRspecMerger merger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        merger.setManifest(GeniUrn.parse(wall2Urn), wall2);
        merger.setManifest(GeniUrn.parse(emuInstaUrn), emuInsta);
        merger.setManifest(GeniUrn.parse(wall1Urn), wall1);

        //can't use RspecCompare, because we can't be sure the nodes are merged in the same order
        ManifestRspecSource mergedRspec = merger.getMergedManifest();
        ManifestRspecSource expectedMergedRspec = new ManifestRspecSource(new StringRspec(expectedMergedRspecString));
        ManifestRspecSource rewrittenExpectedMergedRspec = new ManifestRspecSource(expectedMergedRspec.getModelRspec(rspecFactory.getModelRspecType())); //rewritten so format is more easily comparable

        //compare the actual merged manifest with what was expected
        assertTrue(
                TestRspecReconstructable.testSameXml(
                        rewrittenExpectedMergedRspec.getStringRspec().getXmlString(),
                        mergedRspec.getStringRspec().getXmlString()
                )
        );

        //check if rewrite was a good idea
        assertTrue(TestRspecReconstructable.testSameXml(
                rewrittenExpectedMergedRspec.getStringRspec().getXmlString(),
                expectedMergedRspecString
        ), "Rewrite of merge manifest loses data!");

        assertEquals(mergedRspec.getModelRspec(rspecFactory.getModelRspecType()).getType(), "manifest");
    }

    @Test
    public void testStitchMerge() throws Exception {
        ManifestRspecSource wall1 = new ManifestRspecSource(new StringRspec(wall1StitchRspec));
        ManifestRspecSource wall2 = new ManifestRspecSource(new StringRspec(wall2StitchRspec));

        ManifestRspecMerger merger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        merger.setManifest(GeniUrn.parse(wall1Urn), wall1);
        merger.setManifest(GeniUrn.parse(wall2Urn), wall2);

        //can't use RspecCompare, because we can't be sure the nodes are merged in the same order
        ManifestRspecSource mergedRspec = merger.getMergedManifest();
        ManifestRspecSource expectedMergedRspec = new ManifestRspecSource(new StringRspec(expectedMergedStitchRspecOrder2));
        ManifestRspecSource rewrittenExpectedMergedRspec = new ManifestRspecSource(expectedMergedRspec.getModelRspec
                (rspecFactory.getModelRspecType())); //rewritten so format is more easily comparable

        //compare the actual merged manifest with what was expected
        assertTrue(
                TestRspecReconstructable.testSameXml(
                        rewrittenExpectedMergedRspec.getStringRspec().getXmlString(),
                        mergedRspec.getStringRspec().getXmlString()
                )
        );

        //check if rewrite was a good idea
        assertTrue(TestRspecReconstructable.testSameXml(
                                rewrittenExpectedMergedRspec.getStringRspec().getXmlString(),
                                expectedMergedStitchRspecOrder2
                        ), "Rewrite of merge manifest loses data!");

        assertEquals(mergedRspec.getModelRspec(rspecFactory.getModelRspecType()).getType(), "manifest");
    }
    public final static String emuManifestProbExpectedMerged = "<rspec type=\"manifest\"\n" +
                "    xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
                "    xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\"\n" +
                "    xmlns:flack=\"http://www.protogeni.net/resources/rspec/ext/flack/1\"\n" +
                "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd \">\n" +
                "    <node client_id=\"VM\"\n" +
                "        component_id=\"urn:publicid:IDN+emulab.net+node+pc522\"\n" +
                "        component_manager_id=\"urn:publicid:IDN+emulab.net+authority+cm\"\n" +
                "        exclusive=\"false\"\n" +
                "        sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199754\" xmlns:flack=\"http://www.protogeni.net/resources/rspec/ext/flack/1\">\n" +
                "        <sliver_type name=\"emulab-openvz\"/>\n" +
                "        <interface client_id=\"VM:if0\"\n" +
                "            component_id=\"urn:publicid:IDN+emulab.net+interface+pc522:lo0\"\n" +
                "            mac_address=\"02f1ee04e74d\" sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199758\">\n" +
                "            <flack:interface_info addressBound=\"false\" bound=\"false\"/>\n" +
                "            <ip address=\"10.10.1.1\" type=\"ipv4\"/>\n" +
                "        </interface>\n" +
                "        <flack:node_info unbound=\"true\" x=\"251\" y=\"91\"/>\n" +
                "        <rs:vnode name=\"pcvm522-1\" xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\"/>\n" +
                "        <host name=\"VM.twalc1.ch-geni-net.emulab.net\"/>\n" +
                "        <services>\n" +
                "            <login authentication=\"ssh-keys\" hostname=\"pc522.emulab.net\"\n" +
                "                port=\"32058\" username=\"thijswa\"/>\n" +
                "        </services>\n" +
                "    </node>\n" +
                "    <node client_id=\"VM-0\"\n" +
                "        component_id=\"urn:publicid:IDN+emulab.net+node+pc522\"\n" +
                "        component_manager_id=\"urn:publicid:IDN+emulab.net+authority+cm\"\n" +
                "        exclusive=\"false\"\n" +
                "        sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199755\" xmlns:flack=\"http://www.protogeni.net/resources/rspec/ext/flack/1\">\n" +
                "        <sliver_type name=\"emulab-openvz\"/>\n" +
                "        <interface client_id=\"VM-0:if0\"\n" +
                "            component_id=\"urn:publicid:IDN+emulab.net+interface+pc522:lo0\"\n" +
                "            mac_address=\"02b53820f15c\" sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199759\">\n" +
                "            <flack:interface_info addressBound=\"false\" bound=\"false\"/>\n" +
                "            <ip address=\"10.10.1.2\" type=\"ipv4\"/>\n" +
                "        </interface>\n" +
                "        <flack:node_info unbound=\"true\" x=\"530\" y=\"282\"/>\n" +
                "        <rs:vnode name=\"pcvm522-2\" xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\"/>\n" +
                "        <host name=\"VM-0.twalc1.ch-geni-net.emulab.net\"/>\n" +
                "        <services>\n" +
                "            <login authentication=\"ssh-keys\" hostname=\"pc522.emulab.net\"\n" +
                "                port=\"32059\" username=\"thijswa\"/>\n" +
                "        </services>\n" +
                "    </node>\n" +
                "    <link client_id=\"Lan\"\n" +
                "        sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199757\" xmlns:flack=\"http://www.protogeni.net/resources/rspec/ext/flack/1\">\n" +
                "        <component_manager name=\"urn:publicid:IDN+emulab.net+authority+cm\"/>\n" +
                "        <interface_ref client_id=\"VM:if0\"\n" +
                "            component_id=\"urn:publicid:IDN+emulab.net+interface+pc522:lo0\" sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199758\"/>\n" +
                "        <interface_ref client_id=\"VM-0:if0\"\n" +
                "            component_id=\"urn:publicid:IDN+emulab.net+interface+pc522:lo0\" sliver_id=\"urn:publicid:IDN+emulab.net+sliver+199759\"/>\n" +
//                "        <property dest_id=\"VM-0:if0\" source_id=\"VM:if0\"/>\n" +
//                "        <property dest_id=\"VM:if0\" source_id=\"VM-0:if0\"/>\n" +
                "        <link_type name=\"lan\"/>\n" +
                "        <flack:link_info unboundVlantag=\"true\" x=\"382\" y=\"158\"/>\n" +
                "    </link>\n" +
                "</rspec>\n";
    @Test
    public void testSingleMerge() throws Exception {
        ManifestRspecSource emu = new ManifestRspecSource(new StringRspec(TestRspecsLibrary.emuManifestProb));

        ManifestRspecMerger merger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        merger.setManifest(GeniUrn.parse("urn:publicid:IDN+emulab.net+authority+cm"), emu);

        //can't use RspecCompare, because we can't be sure the nodes are merged in the same order
        ManifestRspecSource mergedRspec = merger.getMergedManifest();
        ManifestRspecSource expectedMergedRspec = new ManifestRspecSource(new StringRspec(emuManifestProbExpectedMerged));
        ManifestRspecSource rewrittenExpectedMergedRspec = new ManifestRspecSource(expectedMergedRspec.getModelRspec(rspecFactory.getModelRspecType())); //rewritten so format is more easily comparable

        //compare the actual merged manifest with what was expected
        assertTrue(
                TestRspecReconstructable.testSameXml(
                        rewrittenExpectedMergedRspec.getStringRspec().getXmlString(),
                        mergedRspec.getStringRspec().getXmlString()
                )
        );

        //check if rewrite was a good idea
        assertTrue(TestRspecReconstructable.testSameXml(
                                rewrittenExpectedMergedRspec.getStringRspec().getXmlString(),
                                emuManifestProbExpectedMerged
                        ), "Rewrite of merge manifest loses data!");

        assertEquals(mergedRspec.getModelRspec(rspecFactory.getModelRspecType()).getType(), "manifest");
    }

    private static final String exoSMRequest = "<?xml version='1.0'?>\n" +
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" type=\"request\" generated_by=\"jFed RSpec Editor\" generated=\"2014-11-19T13:39:32.017+01:00\" xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\" xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\" xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\" xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\" xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd \">\n" +
            "  <node client_id=\"node0\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+exogeni.net+authority+am\">\n" +
            "    <sliver_type name=\"xo.small\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"181.0\" y=\"90.5\"/>\n" +
            "    <interface client_id=\"node0:if0\">\n" +
            "      <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <node client_id=\"node1\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+exogeni.net+authority+am\">\n" +
            "    <sliver_type name=\"xo.small\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"293.0\" y=\"287.5\"/>\n" +
            "    <interface client_id=\"node1:if0\">\n" +
            "      <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <link client_id=\"link0\">\n" +
            "    <component_manager name=\"urn:publicid:IDN+exogeni.net+authority+am\"/>\n" +
            "    <interface_ref client_id=\"node0:if0\"/>\n" +
            "    <interface_ref client_id=\"node1:if0\"/>\n" +
            "    <link_type name=\"lan\"/>\n" +
            "  </link>\n" +
            "</rspec>";

    private static final String exoSMStitchRequest = "<?xml version='1.0'?>\n" +
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" type=\"request\" generated_by=\"jFed RSpec Editor\" generated=\"2014-11-19T13:39:32.017+01:00\" xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\" xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\" xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\" xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\" xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd \">\n" +
            "  <node client_id=\"node0\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+exogeni.net+authority+am\">\n" +
            "    <sliver_type name=\"xo.small\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"181.0\" y=\"90.5\"/>\n" +
            "    <interface client_id=\"node0:if0\">\n" +
            "      <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <node client_id=\"node1\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"293.0\" y=\"287.5\"/>\n" +
            "    <interface client_id=\"node1:if0\">\n" +
            "      <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <link client_id=\"link0\">\n" +
            "    <component_manager name=\"urn:publicid:IDN+exogeni.net+authority+am\"/>\n" +
            "    <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am\"/>\n" +
            "    <interface_ref client_id=\"node0:if0\"/>\n" +
            "    <interface_ref client_id=\"node1:if0\"/>\n" +
            "    <link_type name=\"lan\"/>\n" +
            "  </link>\n" +
            "</rspec>";
    private static final String exoSMManifest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
            "<rspec type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1/slice_info.xsd?format=raw http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1/sliver_info.xsd?format=raw http://www.geni.net/resources/rspec/ext/postBootScript/1 http://www.geni.net/resources/rspec/ext/postBootScript/1/request.xsd http://www.geni.net/resources/rspec/ext/color/2 http://www.geni.net/resources/rspec/ext/color/2/color.xsdhttp://www.geni.net/resources/rspec/ext/storage/1 http://www.geni.net/resources/rspec/ext/storage/1/storage.xsd\" xmlns:ns2=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\" xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:ns4=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1\" xmlns:ns3=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1\" xmlns:ns5=\"http://www.geni.net/resources/rspec/ext/postBootScript/1\" xmlns:ns6=\"http://www.geni.net/resources/rspec/ext/color/2\" xmlns:ns7=\"http://www.geni.net/resources/rspec/ext/storage/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
            "    <node client_id=\"node0\" component_id=\"urn:publicid:IDN+exogeni.net:wsuvmsite+node+orca-vm-cloud\" component_manager_id=\"urn:publicid:IDN+exogeni.net:wsuvmsite+authority+am\" component_name=\"orca-vm-cloud\" exclusive=\"false\" sliver_id=\"urn:publicid:IDN+exogeni.net+sliver+3c5ecdca-ee40-48b1-a0d4-abd850191d56:node0\">\n" +
            "        <location country=\"unknown\" longitude=\"-83.06556\" latitude=\"42.357742\"/>\n" +
            "        <sliver_type name=\"xo.small\">\n" +
            "            <disk_image name=\"http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.3.xml\" version=\"2d553fdbca830020d7cf13011399d7210dcefe96\"/>\n" +
            "        </sliver_type>\n" +
            "        <services/>\n" +
            "        <interface client_id=\"node0:if0\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <ns4:geni_sliver_info creator_urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be+user+twalcari, twalcari@wall2.ilabt.iminds.be\" creation_time=\"2014-11-19T07:39:29.000-05:00\" expiration_time=\"2014-11-19T09:39:27.000-05:00\" start_time=\"2014-11-19T07:39:29.000-05:00\" state=\"configuring\"/>\n" +
            "    </node>\n" +
            "    <node client_id=\"node1\" component_id=\"urn:publicid:IDN+exogeni.net:wsuvmsite+node+orca-vm-cloud\" component_manager_id=\"urn:publicid:IDN+exogeni.net:wsuvmsite+authority+am\" component_name=\"orca-vm-cloud\" exclusive=\"false\" sliver_id=\"urn:publicid:IDN+exogeni.net+sliver+3c5ecdca-ee40-48b1-a0d4-abd850191d56:node1\">\n" +
            "        <location country=\"unknown\" longitude=\"-83.06556\" latitude=\"42.357742\"/>\n" +
            "        <sliver_type name=\"xo.small\">\n" +
            "            <disk_image name=\"http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.3.xml\" version=\"2d553fdbca830020d7cf13011399d7210dcefe96\"/>\n" +
            "        </sliver_type>\n" +
            "        <services/>\n" +
            "        <interface client_id=\"node1:if0\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <ns4:geni_sliver_info creator_urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be+user+twalcari, twalcari@wall2.ilabt.iminds.be\" creation_time=\"2014-11-19T07:39:29.000-05:00\" expiration_time=\"2014-11-19T09:39:27.000-05:00\" start_time=\"2014-11-19T07:39:29.000-05:00\" state=\"configuring\"/>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\" sliver_id=\"urn:publicid:IDN+exogeni.net+sliver+3c5ecdca-ee40-48b1-a0d4-abd850191d56:link0\" vlantag=\"unknown\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:wsuvmsite+authority+am\"/>\n" +
            "        <interface_ref client_id=\"node1:if0\"/>\n" +
            "        <property source_id=\"node1:if0\" dest_id=\"node0:if0\" capacity=\"0\"/>\n" +
            "        <interface_ref client_id=\"node0:if0\"/>\n" +
            "        <property source_id=\"node0:if0\" dest_id=\"node1:if0\" capacity=\"0\"/>\n" +
            "        <ns4:geni_sliver_info creator_urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be+user+twalcari, twalcari@wall2.ilabt.iminds.be\" creation_time=\"2014-11-19T07:39:29.000-05:00\" expiration_time=\"2014-11-19T09:39:27.000-05:00\" start_time=\"2014-11-19T07:39:29.000-05:00\" state=\"configuring\"/>\n" +
            "    </link>\n" +
            "    <ns3:geni_slice_info urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be:fgre+slice+twalcexo2\" uuid=\"ea12cffa-4a22-42a7-b1b1-4e721ac68217\" state=\"configuring\"/>\n" +
            "</rspec>\n";
    private static final String exoSMStitchManifest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
            "<rspec type=\"manifest\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1/slice_info.xsd?format=raw http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1/sliver_info.xsd?format=raw http://www.geni.net/resources/rspec/ext/postBootScript/1 http://www.geni.net/resources/rspec/ext/postBootScript/1/request.xsd http://www.geni.net/resources/rspec/ext/color/2 http://www.geni.net/resources/rspec/ext/color/2/color.xsdhttp://www.geni.net/resources/rspec/ext/storage/1 http://www.geni.net/resources/rspec/ext/storage/1/storage.xsd\" xmlns:ns2=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\" xmlns=\"http://www.geni.net/resources/rspec/3\" xmlns:ns4=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1\" xmlns:ns3=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1\" xmlns:ns5=\"http://www.geni.net/resources/rspec/ext/postBootScript/1\" xmlns:ns6=\"http://www.geni.net/resources/rspec/ext/color/2\" xmlns:ns7=\"http://www.geni.net/resources/rspec/ext/storage/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
            "    <node client_id=\"node0\" component_id=\"urn:publicid:IDN+exogeni.net:wsuvmsite+node+orca-vm-cloud\" component_manager_id=\"urn:publicid:IDN+exogeni.net:wsuvmsite+authority+am\" component_name=\"orca-vm-cloud\" exclusive=\"false\" sliver_id=\"urn:publicid:IDN+exogeni.net+sliver+3c5ecdca-ee40-48b1-a0d4-abd850191d56:node0\">\n" +
            "        <location country=\"unknown\" longitude=\"-83.06556\" latitude=\"42.357742\"/>\n" +
            "        <sliver_type name=\"xo.small\">\n" +
            "            <disk_image name=\"http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.3.xml\" version=\"2d553fdbca830020d7cf13011399d7210dcefe96\"/>\n" +
            "        </sliver_type>\n" +
            "        <services/>\n" +
            "        <interface client_id=\"node0:if0\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <ns4:geni_sliver_info creator_urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be+user+twalcari, twalcari@wall2.ilabt.iminds.be\" creation_time=\"2014-11-19T07:39:29.000-05:00\" expiration_time=\"2014-11-19T09:39:27.000-05:00\" start_time=\"2014-11-19T07:39:29.000-05:00\" state=\"configuring\"/>\n" +
            "    </node>\n" +
            "    <node client_id=\"node1\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"emulab-xen\">\n"+
            "        </sliver_type>\n" +
            "        <services/>\n" +
            "        <interface client_id=\"node1:if0\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\" sliver_id=\"urn:publicid:IDN+exogeni.net+sliver+3c5ecdca-ee40-48b1-a0d4-abd850191d56:link0\" vlantag=\"unknown\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:wsuvmsite+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am\"/>\n" +
            "        <interface_ref client_id=\"node1:if0\"/>\n" +
            "        <property source_id=\"node1:if0\" dest_id=\"node0:if0\" capacity=\"0\"/>\n" +
            "        <interface_ref client_id=\"node0:if0\"/>\n" +
            "        <property source_id=\"node0:if0\" dest_id=\"node1:if0\" capacity=\"0\"/>\n" +
            "        <ns4:geni_sliver_info creator_urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be+user+twalcari, twalcari@wall2.ilabt.iminds.be\" creation_time=\"2014-11-19T07:39:29.000-05:00\" expiration_time=\"2014-11-19T09:39:27.000-05:00\" start_time=\"2014-11-19T07:39:29.000-05:00\" state=\"configuring\"/>\n" +
            "    </link>\n" +
            "    <ns3:geni_slice_info urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be:fgre+slice+twalcexo2\" uuid=\"ea12cffa-4a22-42a7-b1b1-4e721ac68217\" state=\"configuring\"/>\n" +
            "</rspec>\n";
    private static final String wallStitchManifest = "<?xml version='1.0'?>\n" +
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" type=\"request\" generated_by=\"jFed RSpec Editor\" generated=\"2014-11-19T13:39:32.017+01:00\" xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\" xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\" xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\" xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\" xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd \">\n" +
            "  <node client_id=\"node0\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+exogeni.net+authority+am\">\n" +
            "    <sliver_type name=\"xo.small\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"181.0\" y=\"90.5\"/>\n" +
            "    <interface client_id=\"node0:if0\">\n" +
            "      <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <node client_id=\"node1\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am\" component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n091-21\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+27791\">\n" +
            "    <sliver_type name=\"emulab-xen\"/>\n" +
            "    <services>\n" +
            "      <login authentication=\"ssh-keys\" hostname=\"n091-21.wall2.ilabt.iminds.be\" port=\"22\" username=\"wvdemeer\"/>\n" +
            "    </services>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"293.0\" y=\"287.5\"/>\n" +
            "    <interface client_id=\"node1:if0\">\n" +
            "      <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "    <rs:vnode xmlns:rs=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" name=\"n091-21\"/>\n" +
            "    <host name=\"w2.stitch2.wall2-ilabt-iminds-be.wall2.ilabt.iminds.be\"/>\n" +
            "  </node>\n" +
            "  <link client_id=\"link0\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+blabla\">\n" +
            "    <component_manager name=\"urn:publicid:IDN+exogeni.net+authority+am\"/>\n" +
            "    <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am\"/>\n" +
            "    <interface_ref client_id=\"node0:if0\"/>\n" +
            "    <interface_ref client_id=\"node1:if0\"/>\n" +
            "    <link_type name=\"lan\"/>\n" +
            "  </link>\n" +
            "</rspec>";
    private static final String exoSMStitchManifest2 = "<rspec type=\"manifest\" xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:ns2=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\"\n" +
            "    xmlns:ns3=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1\"\n" +
            "    xmlns:ns4=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1\"\n" +
            "    xmlns:ns5=\"http://www.geni.net/resources/rspec/ext/postBootScript/1\"\n" +
            "    xmlns:ns6=\"http://www.geni.net/resources/rspec/ext/color/2\"\n" +
            "    xmlns:ns7=\"http://www.geni.net/resources/rspec/ext/storage/1\"\n" +
            "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1/slice_info.xsd?format=raw http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1/sliver_info.xsd?format=raw http://www.geni.net/resources/rspec/ext/postBootScript/1 http://www.geni.net/resources/rspec/ext/postBootScript/1/request.xsd http://www.geni.net/resources/rspec/ext/color/2 http://www.geni.net/resources/rspec/ext/color/2/color.xsdhttp://www.geni.net/resources/rspec/ext/storage/1 http://www.geni.net/resources/rspec/ext/storage/1/storage.xsd\">\n" +
            "    <node client_id=\"node1\"\n" +
            "        component_id=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+node+orca-vm-cloud\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am\"\n" +
            "        component_name=\"orca-vm-cloud\" exclusive=\"false\" sliver_id=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+sliver+05f4a8ca-34ca-4e32-a440-408360e56c7d:node1\">\n" +
            "        <location country=\"unknown\" latitude=\"52.354843\" longitude=\"4.955346\"/>\n" +
            "        <sliver_type name=\"xo.small\">\n" +
            "            <disk_image\n" +
            "                name=\"http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.3.xml\" version=\"2d553fdbca830020d7cf13011399d7210dcefe96\"/>\n" +
            "        </sliver_type>\n" +
            "        <services>\n" +
            "            <login authentication=\"ssh-keys\" hostname=\"145.100.133.141\"\n" +
            "                port=\"22\" username=\"bvermeul\"/>\n" +
            "            <login authentication=\"ssh-keys\" hostname=\"145.100.133.141\"\n" +
            "                port=\"22\" username=\"root\"/>\n" +
            "        </services>\n" +
            "        <interface client_id=\"node1:if0\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <ns4:geni_sliver_info creation_time=\"2015-03-23T13:01:57.000Z\"\n" +
            "            creator_urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be+user+bvermeul, bvermeul@wall2.ilabt.iminds.be\"\n" +
            "            expiration_time=\"2015-03-23T15:01:42.000Z\"\n" +
            "            resource_id=\"uva-nl-w2:24a2264b-a57a-4632-ab4e-c27d96b7e20a\"\n" +
            "            start_time=\"2015-03-23T13:01:57.000Z\" state=\"ready\"/>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\"\n" +
            "        sliver_id=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+sliver+05f4a8ca-34ca-4e32-a440-408360e56c7d:link0\" vlantag=\"unknown\">\n" +
            "        <interface_ref client_id=\"node1:if0\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:uvanlNet+authority+am\"/>\n" +
            "    </link>\n" +
            "    <ns3:geni_slice_info state=\"ready\"\n" +
            "        urn=\"urn:publicid:IDN+wall2.ilabt.iminds.be:bvermeul+slice+tstExo4\" uuid=\"4d5260e4-3db0-4de8-bf58-d117a267bb23\"/>\n" +
            "</rspec>\n";
    private static final String wallStitchManifest2 =
            "<rspec expires=\"2015-03-23T15:01:42Z\"\n" +
            "    generated=\"2015-03-23T14:01:22.195+01:00\"\n" +
            "    generated_by=\"jFed RSpec Editor\" type=\"manifest\"\n" +
            "    xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\"\n" +
            "    xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\"\n" +
            "    xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\"\n" +
            "    xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\"\n" +
            "    xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\"\n" +
            "    xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\"\n" +
            "    xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\"\n" +
            "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\">\n" +
            "    <node client_id=\"node0\"\n" +
            "        component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n095-14a\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"\n" +
            "        exclusive=\"true\"\n" +
            "        sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+56215\" xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\">\n" +
            "        <sliver_type name=\"raw-pc\"/>\n" +
            "        <location x=\"125.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"57.5\"/>\n" +
            "        <interface client_id=\"node0:if0\"\n" +
            "            component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n095-14a:eth4\"\n" +
            "            mac_address=\"02f3ecba66d3\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+56218\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <emulab:vnode name=\"n095-14a\"/>\n" +
            "        <host name=\"node0.tstExo4.wall2-ilabt-iminds-be.wall2.ilabt.iminds.be\"/>\n" +
            "        <services>\n" +
            "            <login authentication=\"ssh-keys\"\n" +
            "                hostname=\"n095-14a.wall2.ilabt.iminds.be\" port=\"22\" username=\"bvermeul\"/>\n" +
            "        </services>\n" +
            "    </node>\n" +
            "    <node client_id=\"node1\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"default-vm\"/>\n" +
            "        <location x=\"397.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"130.5\"/>\n" +
            "        <interface client_id=\"node1:if0\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\"\n" +
            "        sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+56217\" vlantag=\"1027\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am\"/>\n" +
            "        <interface_ref client_id=\"node0:if0\"\n" +
            "            component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n095-14a:eth4\" sliver_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+sliver+56218\"/>\n" +
            "        <interface_ref client_id=\"node1:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"node1:if0\" source_id=\"node0:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"node0:if0\" source_id=\"node1:if0\"/>\n" +
            "    </link>\n" +
            "</rspec>";
    private static final String exoSMStitchRequest2 =
            "<rspec expires=\"2015-03-23T15:01:42Z\" type=\"request\"\n" +
            "    xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\"\n" +
            "    xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\"\n" +
            "    xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\"\n" +
            "    xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\"\n" +
            "    xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\"\n" +
            "    xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\"\n" +
            "    xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\"\n" +
            "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\">\n" +
            "    <node client_id=\"node0\"\n" +
            "        component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+node+n095-14a\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"\n" +
            "        exclusive=\"true\">\n" +
            "        <sliver_type name=\"raw-pc\"/>\n" +
            "        <interface client_id=\"node0:if0\"\n" +
            "            component_id=\"urn:publicid:IDN+wall2.ilabt.iminds.be+interface+n095-14a:eth4\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <node client_id=\"node1\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"default-vm\"/>\n" +
            "        <location x=\"397.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"130.5\"/>\n" +
            "        <interface client_id=\"node1:if0\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am\"/>\n" +
            "        <interface_ref client_id=\"node0:if0\"/>\n" +
            "        <interface_ref client_id=\"node1:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"node1:if0\" source_id=\"node0:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"node0:if0\" source_id=\"node1:if0\"/>\n" +
            "    </link>\n" +
            "</rspec>";
    /**
     * This test checks whether the merger can correctly merge ExoGENI-manifests where the subauthority changes between
     * the request and the manifest because of the ExoSM-broker
     *
     * @throws Exception
     */
    @Test
    public void testExoSMMerge() throws Exception{

        RequestRspecSource requestRspecSource = new RequestRspecSource(new StringRspec(exoSMRequest));

        ManifestRspecSource manifestRspecSource = new ManifestRspecSource(new StringRspec(exoSMManifest));

        ManifestRspecMerger manifestRspecMerger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        manifestRspecMerger.setRequest(requestRspecSource);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+exogeni.net+authority+am"), manifestRspecSource);


        ManifestRspecSource mergedManifest = manifestRspecMerger.getMergedManifest();


        System.out.println(mergedManifest.getStringRspec().getXmlString());

        assertEquals(mergedManifest.getModelRspec().getNodes().size(), 2);
        assertEquals(mergedManifest.getModelRspec().getLinks().size(),1);

    }

    @Test
    public void testExoSMStitchMerge() throws Exception{

        RequestRspecSource requestRspecSource = new RequestRspecSource(new StringRspec(exoSMStitchRequest));

        ManifestRspecSource manifestRspecSourceExo = new ManifestRspecSource(new StringRspec(exoSMStitchManifest));
        ManifestRspecSource manifestRspecSourceWall = new ManifestRspecSource(new StringRspec(wallStitchManifest));

        ManifestRspecMerger manifestRspecMerger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        manifestRspecMerger.setRequest(requestRspecSource);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+exogeni.net+authority+am"), manifestRspecSourceExo);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am"), manifestRspecSourceWall);


        ManifestRspecSource mergedManifest = manifestRspecMerger.getMergedManifest();


        System.out.println(mergedManifest.getStringRspec().getXmlString());

        assertEquals(mergedManifest.getModelRspec().getNodes().size(), 2);
        assertEquals(mergedManifest.getModelRspec().getLinks().size(),1);
        assertEquals(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().size(),2);

    }
    @Test
    public void testExoSMStitchMerge2() throws Exception{

        RequestRspecSource requestRspecSource = new RequestRspecSource(new StringRspec(exoSMStitchRequest2));

        ManifestRspecSource manifestRspecSourceExo = new ManifestRspecSource(new StringRspec(exoSMStitchManifest2));
        ManifestRspecSource manifestRspecSourceWall = new ManifestRspecSource(new StringRspec(wallStitchManifest2));

        ManifestRspecMerger manifestRspecMerger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        manifestRspecMerger.setRequest(requestRspecSource);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am"), manifestRspecSourceExo);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+am"), manifestRspecSourceWall);


        ManifestRspecSource mergedManifest = manifestRspecMerger.getMergedManifest();


        System.out.println(mergedManifest.getStringRspec().getXmlString());

        assertEquals(mergedManifest.getModelRspec().getNodes().size(), 2);
        assertEquals(mergedManifest.getModelRspec().getLinks().size(),1);
        assertEquals(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().size(),2);
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:uvanlvmsite+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());

        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net+authority+am")), "link cm's: " + mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:uvanlNet+authority+am")), "link cm's: " + mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());

    }

    String stitchRequest3 = "<?xml version='1.0'?>\n" +
            "<rspec xmlns=\"http://www.geni.net/resources/rspec/3\" type=\"request\" generated_by=\"jFed RSpec Editor\" generated=\"2015-04-07T11:27:40.310+02:00\" " +
            "xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\" " +
            "xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\" " +
            "xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\" " +
            "xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\" " +
            "xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\" " +
            "xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\" " +
            "xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\" " +
            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/request.xsd \">\n" +
            "  <node client_id=\"b\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\">\n" +
            "    <sliver_type name=\"default-vm\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"47.0\" y=\"37.5\"/>\n" +
            "    <interface client_id=\"b:if0\">\n" +
            "      <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <node client_id=\"c\" exclusive=\"false\" component_manager_id=\"urn:publicid:IDN+instageni.cenic.net+authority+cm\">\n" +
            "    <sliver_type name=\"default-vm\"/>\n" +
            "    <location xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" x=\"45.0\" y=\"136.5\"/>\n" +
            "    <interface client_id=\"c:if0\">\n" +
            "      <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "    </interface>\n" +
            "  </node>\n" +
            "  <link client_id=\"link0\">\n" +
            "    <component_manager name=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\"/>\n" +
            "    <component_manager name=\"urn:publicid:IDN+instageni.cenic.net+authority+cm\"/>\n" +
            "    <interface_ref client_id=\"b:if0\"/>\n" +
            "    <interface_ref client_id=\"c:if0\"/>\n" +
            "    <property source_id=\"b:if0\" dest_id=\"c:if0\" capacity=\"10000\"/>\n" +
            "    <property source_id=\"c:if0\" dest_id=\"b:if0\" capacity=\"10000\"/>\n" +
            "  </link>\n" +
            "</rspec>";
    String al2sStitchManifest3 = "<rspec generated=\"2015-04-07T11:27:40.310+02:00\"\n" +
            "    generated_by=\"jFed RSpec Editor\" type=\"manifest\"\n" +
            "    xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\"\n" +
            "    xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\"\n" +
            "    xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\"\n" +
            "    xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\"\n" +
            "    xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\"\n" +
            "    xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\"\n" +
            "    xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\"\n" +
            "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\">\n" +
            "    <node client_id=\"b\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"default-vm\"/>\n" +
            "        <location x=\"47.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"37.5\"/>\n" +
            "        <interface client_id=\"b:if0\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <node client_id=\"c\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+instageni.cenic.net+authority+cm\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"default-vm\"/>\n" +
            "        <location x=\"45.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"136.5\"/>\n" +
            "        <interface client_id=\"c:if0\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:bbnNet+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+al2s.internet2.edu+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+instageni.cenic.net+authority+cm\"/>\n" +
            "        <interface_ref client_id=\"b:if0\"/>\n" +
            "        <interface_ref client_id=\"c:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"c:if0\" source_id=\"b:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"b:if0\" source_id=\"c:if0\"/>\n" +
            "    </link>\n" +
            "</rspec>\n";
    String exoBbnStitchManifest3 = "<rspec type=\"manifest\" xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:ns2=\"http://hpn.east.isi.edu/rspec/ext/stitch/0.1/\"\n" +
            "    xmlns:ns3=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1\"\n" +
            "    xmlns:ns4=\"http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1\"\n" +
            "    xmlns:ns5=\"http://www.geni.net/resources/rspec/ext/postBootScript/1\"\n" +
            "    xmlns:ns6=\"http://www.geni.net/resources/rspec/ext/color/2\"\n" +
            "    xmlns:ns7=\"http://www.geni.net/resources/rspec/ext/storage/1\"\n" +
            "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/slice-info/1/slice_info.xsd?format=raw http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1 http://groups.geni.net/exogeni/attachment/wiki/RspecExtensions/sliver-info/1/sliver_info.xsd?format=raw http://www.geni.net/resources/rspec/ext/postBootScript/1 http://www.geni.net/resources/rspec/ext/postBootScript/1/request.xsd http://www.geni.net/resources/rspec/ext/color/2 http://www.geni.net/resources/rspec/ext/color/2/color.xsdhttp://www.geni.net/resources/rspec/ext/storage/1 http://www.geni.net/resources/rspec/ext/storage/1/storage.xsd\">\n" +
            "    <node client_id=\"b\"\n" +
            "        component_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+node+orca-vm-cloud\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\"\n" +
            "        component_name=\"orca-vm-cloud\" exclusive=\"false\" sliver_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+sliver+fd7331ff-6d11-49e1-93d8-45892ab4627e:b\">\n" +
            "        <location country=\"unknown\" latitude=\"42.38974\" longitude=\"-71.14751\"/>\n" +
            "        <sliver_type name=\"xo.small\">\n" +
            "            <disk_image\n" +
            "                name=\"http://geni-images.renci.org/images/standard/ubuntu/ub1404-v1.0.3.xml\" version=\"2d553fdbca830020d7cf13011399d7210dcefe96\"/>\n" +
            "        </sliver_type>\n" +
            "        <services>\n" +
            "            <login authentication=\"ssh-keys\" hostname=\"192.1.242.5\"\n" +
            "                port=\"22\" username=\"wimvande\"/>\n" +
            "            <login authentication=\"ssh-keys\" hostname=\"192.1.242.5\"\n" +
            "                port=\"22\" username=\"root\"/>\n" +
            "        </services>\n" +
            "        <interface client_id=\"b:if0\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <ns4:geni_sliver_info creation_time=\"2015-04-07T09:27:52.000Z\"\n" +
            "            creator_urn=\"Wim.VandeMeerssche@intec.ugent.be, urn:publicid:IDN+ch.geni.net+user+wimvande\"\n" +
            "            expiration_time=\"2015-04-07T11:28:01.000Z\"\n" +
            "            resource_id=\"bbn-w7:0df701b5-91ab-4d41-9331-0b34ed4a7ac4\"\n" +
            "            start_time=\"2015-04-07T09:27:52.000Z\" state=\"ready\"/>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\"\n" +
            "        sliver_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+sliver+fd7331ff-6d11-49e1-93d8-45892ab4627e:link0\" vlantag=\"unknown\">\n" +
            "        <interface_ref client_id=\"b:if0\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:bbnNet+authority+am\"/>\n" +
            "    </link>\n" +
            "    <ns2:stitching lastUpdateTime=\"Tue Apr 07 09:30:18 UTC 2015\">\n" +
            "        <ns2:path id=\"link0\">\n" +
            "            <ns2:hop id=\"hop1\">\n" +
            "                <ns2:link id=\"urn:publicid:IDN+exogeni.net:bbnNet+interface+bbnNet:Domain:vlan:7368c655-29ae-4dc8-ac3c-a55f1fc6c370:vlan\">\n" +
            "                    <ns2:trafficEngineeringMetric>10</ns2:trafficEngineeringMetric>\n" +
            "                    <ns2:capacity>10240000</ns2:capacity>\n" +
            "                    <ns2:switchingCapabilityDescriptor>\n" +
            "                        <ns2:switchingcapType>l2sc</ns2:switchingcapType>\n" +
            "                        <ns2:encodingType>ethernet</ns2:encodingType>\n" +
            "                        <ns2:switchingCapabilitySpecificInfo>\n" +
            "                            <ns2:switchingCapabilitySpecificInfo_L2sc>\n" +
            "                                <ns2:vlanRangeAvailability>1-4096</ns2:vlanRangeAvailability>\n" +
            "                                <ns2:suggestedVLANRange>3736</ns2:suggestedVLANRange>\n" +
            "                                <ns2:vlanTranslation>false</ns2:vlanTranslation>\n" +
            "                            </ns2:switchingCapabilitySpecificInfo_L2sc>\n" +
            "                        </ns2:switchingCapabilitySpecificInfo>\n" +
            "                    </ns2:switchingCapabilityDescriptor>\n" +
            "                </ns2:link>\n" +
            "                <ns2:nextHop>null</ns2:nextHop>\n" +
            "            </ns2:hop>\n" +
            "        </ns2:path>\n" +
            "    </ns2:stitching>\n" +
            "    <ns3:geni_slice_info state=\"ready\"\n" +
            "        urn=\"urn:publicid:IDN+ch.geni.net:fed4firetest3+slice+tstW2exo\" uuid=\"ce9d011a-9a97-4db8-8cf1-7ba565256a39\"/>\n" +
            "</rspec>\n";
    String cenicStitchManifest3 = "<rspec expires=\"2015-04-07T11:28:01Z\"\n" +
            "    generated=\"2015-04-07T11:27:40.310+02:00\"\n" +
            "    generated_by=\"jFed RSpec Editor\" type=\"manifest\"\n" +
            "    xmlns=\"http://www.geni.net/resources/rspec/3\"\n" +
            "    xmlns:client=\"http://www.protogeni.net/resources/rspec/ext/client/1\"\n" +
            "    xmlns:delay=\"http://www.protogeni.net/resources/rspec/ext/delay/1\"\n" +
            "    xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\"\n" +
            "    xmlns:jfed=\"http://jfed.iminds.be/rspec/ext/jfed/1\"\n" +
            "    xmlns:jfed-command=\"http://jfed.iminds.be/rspec/ext/jfed-command/1\"\n" +
            "    xmlns:jfed-ssh-keys=\"http://jfed.iminds.be/rspec/ext/jfed-ssh-keys/1\"\n" +
            "    xmlns:sharedvlan=\"http://www.protogeni.net/resources/rspec/ext/shared-vlan/1\"\n" +
            "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.geni.net/resources/rspec/3 http://www.geni.net/resources/rspec/3/manifest.xsd  http://hpn.east.isi.edu/rspec/ext/stitch/0.1/ http://hpn.east.isi.edu/rspec/ext/stitch/0.1/stitch-schema.xsd\">\n" +
            "    <node client_id=\"b\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\" exclusive=\"false\">\n" +
            "        <sliver_type name=\"default-vm\"/>\n" +
            "        <location x=\"47.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"37.5\"/>\n" +
            "        <interface client_id=\"b:if0\">\n" +
            "            <ip address=\"192.168.0.1\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "    </node>\n" +
            "    <node client_id=\"c\"\n" +
            "        component_id=\"urn:publicid:IDN+instageni.cenic.net+node+pc2\"\n" +
            "        component_manager_id=\"urn:publicid:IDN+instageni.cenic.net+authority+cm\"\n" +
            "        exclusive=\"false\"\n" +
            "        sliver_id=\"urn:publicid:IDN+instageni.cenic.net+sliver+3109\" xmlns:emulab=\"http://www.protogeni.net/resources/rspec/ext/emulab/1\">\n" +
            "        <sliver_type name=\"default-vm\"/>\n" +
            "        <location x=\"45.0\"\n" +
            "            xmlns=\"http://jfed.iminds.be/rspec/ext/jfed/1\" y=\"136.5\"/>\n" +
            "        <interface client_id=\"c:if0\"\n" +
            "            component_id=\"urn:publicid:IDN+instageni.cenic.net+interface+pc2:eth1\"\n" +
            "            mac_address=\"022473df5d5f\" sliver_id=\"urn:publicid:IDN+instageni.cenic.net+sliver+3112\">\n" +
            "            <ip address=\"192.168.0.2\" netmask=\"255.255.255.0\" type=\"ipv4\"/>\n" +
            "        </interface>\n" +
            "        <emulab:vnode name=\"pcvm2-1\"/>\n" +
            "        <host name=\"c.tstW2exo.ch-geni-net.instageni.cenic.net\"/>\n" +
            "        <services>\n" +
            "            <login authentication=\"ssh-keys\"\n" +
            "                hostname=\"pc2.instageni.cenic.net\" port=\"32058\" username=\"wimvande\"/>\n" +
            "            <emulab:console server=\"pc2.instageni.cenic.net\"/>\n" +
            "        </services>\n" +
            "    </node>\n" +
            "    <link client_id=\"link0\"\n" +
            "        sliver_id=\"urn:publicid:IDN+instageni.cenic.net+sliver+3111\" vlantag=\"1567\">\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+exogeni.net:bbnNet+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+al2s.internet2.edu+authority+am\"/>\n" +
            "        <component_manager name=\"urn:publicid:IDN+instageni.cenic.net+authority+cm\"/>\n" +
            "        <interface_ref client_id=\"b:if0\"/>\n" +
            "        <interface_ref client_id=\"c:if0\"\n" +
            "            component_id=\"urn:publicid:IDN+instageni.cenic.net+interface+pc2:eth1\" sliver_id=\"urn:publicid:IDN+instageni.cenic.net+sliver+3112\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"c:if0\" source_id=\"b:if0\"/>\n" +
            "        <property capacity=\"10000\" dest_id=\"b:if0\" source_id=\"c:if0\"/>\n" +
            "    </link>\n" +
            "</rspec>";

    @Test
    public void testExoSMStitchMerge3a() throws Exception{
        RequestRspecSource requestRspecSource = new RequestRspecSource(new StringRspec(stitchRequest3));

        ManifestRspecSource manifestRspecSourceExo = new ManifestRspecSource(new StringRspec(exoBbnStitchManifest3));
        ManifestRspecSource manifestRspecSourceCenic = new ManifestRspecSource(new StringRspec(cenicStitchManifest3));
        ManifestRspecSource manifestRspecSourceAl2s = new ManifestRspecSource(new StringRspec(al2sStitchManifest3));

        ManifestRspecMerger manifestRspecMerger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        manifestRspecMerger.setRequest(requestRspecSource);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am"), manifestRspecSourceExo);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+instageni.cenic.net+authority+cm"), manifestRspecSourceCenic);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+al2s.internet2.edu+authority+am"), manifestRspecSourceAl2s);

        ManifestRspecSource mergedManifest = manifestRspecMerger.getMergedManifest();


        System.out.println(mergedManifest.getStringRspec().getXmlString());

        assertEquals(mergedManifest.getModelRspec().getNodes().size(), 2);
        assertEquals(mergedManifest.getModelRspec().getLinks().size(),1);

        for (RspecNode rspecNode : mergedManifest.getModelRspec().getNodes()) {
            assertThat("node "+rspecNode.getClientId()+" must have login services", rspecNode.getLoginServices().size(), greaterThan(0));
        }

        assertEquals(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().size(), 4);
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am")), "link cm's: " + mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnNet+authority+am")), "link cm's: " + mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+instageni.cenic.net+authority+cm")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+al2s.internet2.edu+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());

//        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+al2s.internet2.edu+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
//        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnNet+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
    }

    @Test
    public void testExoSMStitchMerge3b() throws Exception{
        RequestRspecSource requestRspecSource = new RequestRspecSource(new StringRspec(stitchRequest3));

        ManifestRspecSource manifestRspecSourceExo = new ManifestRspecSource(new StringRspec(exoBbnStitchManifest3));
        ManifestRspecSource manifestRspecSourceCenic = new ManifestRspecSource(new StringRspec(cenicStitchManifest3));
        ManifestRspecSource manifestRspecSourceAl2s = new ManifestRspecSource(new StringRspec(al2sStitchManifest3));

        ManifestRspecMerger manifestRspecMerger = new ManifestRspecMerger(rspecFactory.getModelRspecType());
        manifestRspecMerger.setRequest(requestRspecSource);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+instageni.cenic.net+authority+cm"), manifestRspecSourceCenic);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+al2s.internet2.edu+authority+am"), manifestRspecSourceAl2s);
        manifestRspecMerger.setManifest(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am"), manifestRspecSourceExo);

        ManifestRspecSource mergedManifest = manifestRspecMerger.getMergedManifest();


        System.out.println(mergedManifest.getStringRspec().getXmlString());

        assertEquals(mergedManifest.getModelRspec().getNodes().size(), 2);
        assertEquals(mergedManifest.getModelRspec().getLinks().size(),1);

        for (RspecNode rspecNode : mergedManifest.getModelRspec().getNodes()) {
            assertThat("node "+rspecNode.getClientId()+" must have login services", rspecNode.getLoginServices().size(), greaterThan(0));
        }

        assertEquals(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().size(), 4);
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnvmsite+authority+am")), "link cm's: " + mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnNet+authority+am")), "link cm's: " + mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+instageni.cenic.net+authority+cm")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertTrue(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+al2s.internet2.edu+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());

//        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+al2s.internet2.edu+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
//        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net:bbnNet+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
        assertFalse(mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns().contains(GeniUrn.parse("urn:publicid:IDN+exogeni.net+authority+am")), "link cm's: "+mergedManifest.getModelRspec().getLinks().get(0).getComponentManagerUrns());
    }
}
