@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());
  }
Exemple #2
0
  @Test
  public void testGetCopy() {
    dm.setName("name");
    dm.setDocumentation("doc");

    dm.getProperties().add(IArchimateFactory.eINSTANCE.createProperty());

    IDiagramModel copy = (IDiagramModel) dm.getCopy();

    assertNotSame(dm, copy);
    assertNull(copy.getId());
    assertEquals(dm.getName(), copy.getName());
    assertEquals(dm.getDocumentation(), copy.getDocumentation());
    assertNotSame(dm.getProperties(), copy.getProperties());
    assertEquals(dm.getProperties().size(), copy.getProperties().size());
    assertNotSame(dm.getChildren(), copy.getChildren());
  }