@Test
  public void testDuplicateDiagramModel_AddsConnectionsToConnections() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModel dm = model.getDefaultDiagramModel();

    IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(element1);
    dm.getChildren().add(dmo1);

    IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(element2);
    dm.getChildren().add(dmo2);

    IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo3 = tm.createDiagramModelArchimateObjectAndAddToModel(element3);
    dm.getChildren().add(dmo3);

    IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation1.setSource(element1);
    relation1.setTarget(element2);
    IDiagramModelArchimateConnection dmc1 =
        tm.createDiagramModelArchimateConnectionAndAddToModel(relation1);
    dmc1.connect(dmo1, dmo2);

    IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
    relation2.setSource(element3);
    relation2.setTarget(relation1);
    IDiagramModelArchimateConnection dmc2 =
        tm.createDiagramModelArchimateConnectionAndAddToModel(relation2);
    dmc2.connect(dmo3, dmc1);

    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] {dm});
    handler.duplicate();

    IDiagramModel dmCopy = model.getDiagramModels().get(1);

    EList<IDiagramModelObject> children = dmCopy.getChildren();
    assertEquals(3, children.size());

    IDiagramModelArchimateObject dmo1Copy = (IDiagramModelArchimateObject) children.get(0);
    IDiagramModelArchimateObject dmo2Copy = (IDiagramModelArchimateObject) children.get(1);
    IDiagramModelArchimateObject dmo3Copy = (IDiagramModelArchimateObject) children.get(2);

    assertSame(element1, dmo1Copy.getArchimateConcept());
    assertSame(element2, dmo2Copy.getArchimateConcept());
    assertSame(element3, dmo3Copy.getArchimateConcept());

    IDiagramModelArchimateConnection dmc1Copy =
        (IDiagramModelArchimateConnection) dmo1Copy.getSourceConnections().get(0);
    assertSame(relation1, dmc1Copy.getArchimateConcept());
    assertSame(dmo2Copy, dmc1Copy.getTarget());

    // Connection to Connection
    assertSame(dmc1Copy, dmo3Copy.getSourceConnections().get(0).getTarget());
  }
  @Test
  public void testDuplicateDiagramModel() {
    ArchimateTestModel tm = new ArchimateTestModel();
    IArchimateModel model = tm.createNewModel();
    IDiagramModel dm = model.getDefaultDiagramModel();

    IArchimateElement actor = IArchimateFactory.eINSTANCE.createBusinessActor();
    IDiagramModelArchimateObject dmo1 = tm.createDiagramModelArchimateObjectAndAddToModel(actor);
    dmo1.setName("dm");
    dm.getChildren().add(dmo1);

    IArchimateElement role = IArchimateFactory.eINSTANCE.createBusinessRole();
    IDiagramModelArchimateObject dmo2 = tm.createDiagramModelArchimateObjectAndAddToModel(role);
    dm.getChildren().add(dmo2);

    IArchimateRelationship relation = IArchimateFactory.eINSTANCE.createAssignmentRelationship();
    relation.setSource(actor);
    relation.setTarget(role);
    IDiagramModelArchimateConnection dmc1 =
        tm.createDiagramModelArchimateConnectionAndAddToModel(relation);
    dmc1.connect(dmo1, dmo2);

    DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] {dm});
    handler.duplicate();
    assertEquals(2, model.getDiagramModels().size());

    IDiagramModel dmCopy = model.getDiagramModels().get(1);
    assertNotSame(dm, dmCopy);
    assertEquals(dm.getName() + " (copy)", dmCopy.getName());

    EList<IDiagramModelObject> children = dmCopy.getChildren();
    assertEquals(2, children.size());

    IDiagramModelArchimateObject dmo1Copy = (IDiagramModelArchimateObject) children.get(0);
    IDiagramModelArchimateObject dmo2Copy = (IDiagramModelArchimateObject) children.get(1);
    assertNotSame(dmo1, dmo1Copy);
    assertNotSame(dmo2, dmo2Copy);
    assertSame(actor, dmo1Copy.getArchimateConcept());
    assertSame(role, dmo2Copy.getArchimateConcept());

    EList<IDiagramModelConnection> connections = dmo1Copy.getSourceConnections();
    assertEquals(1, connections.size());

    IDiagramModelArchimateConnection dmc1Copy =
        (IDiagramModelArchimateConnection) connections.get(0);
    assertNotSame(dmc1, dmc1Copy);
    assertSame(relation, dmc1Copy.getArchimateConcept());
  }