Search in sources :

Example 36 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class DeleteCommandHandlerTests method testDelete_Elements_Deleted_Attached_Relations.

@Test
public void testDelete_Elements_Deleted_Attached_Relations() {
    // Element 1
    IArchimateElement businessActor = (IArchimateElement) ArchimateModelUtils.getObjectByID(model, "31a27739");
    assertNotNull(businessActor);
    // Element 2
    IArchimateElement businessRole = (IArchimateElement) ArchimateModelUtils.getObjectByID(model, "8ab84e91");
    assertNotNull(businessRole);
    // Connecting relationship
    IArchimateRelationship relationship = (IArchimateRelationship) ArchimateModelUtils.getObjectByID(model, "3bede7f0");
    assertNotNull(relationship);
    // Relationship is there on a diagram
    assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(relationship));
    // Zap
    DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, new Object[] { businessActor, businessRole });
    commandHandler.delete();
    // All gone
    assertNull(ArchimateModelUtils.getObjectByID(model, relationship.getId()));
    assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(relationship));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) Test(org.junit.Test)

Example 37 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class DeleteCommandHandlerTests method testDelete_More_Than_One_Model.

@Test
public void testDelete_More_Than_One_Model() throws IOException {
    // Use another instance of the same model
    ArchimateTestModel tm2 = new ArchimateTestModel(TEST_MODEL_FILE);
    IArchimateModel model2 = tm2.loadModelWithCommandStack();
    // Elements
    String[] elementIDs = new String[] { "31a27739", "8ab84e91", "46d0abd5", "8ecabfc2" };
    // Select them from both models
    List<IArchimateElement> elements1 = new ArrayList<IArchimateElement>();
    for (String id : elementIDs) {
        elements1.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
    }
    List<IArchimateElement> elements2 = new ArrayList<IArchimateElement>();
    for (String id : elementIDs) {
        elements2.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model2, id));
    }
    List<IArchimateElement> allElements = new ArrayList<IArchimateElement>(elements1);
    allElements.addAll(elements2);
    assertEquals(8, allElements.size());
    // Zap
    DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, allElements.toArray());
    commandHandler.delete();
    // Test that they are all gone in the models and in the referenced diagrams
    for (IArchimateElement element : elements1) {
        assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
    }
    for (IArchimateElement element : elements2) {
        assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNull(ArchimateModelUtils.getObjectByID(model2, element.getId()));
    }
    // And just for good measure, we'll undo it...once for each model
    CommandStack commandStack1 = (CommandStack) model.getAdapter(CommandStack.class);
    commandStack1.undo();
    CommandStack commandStack2 = (CommandStack) model2.getAdapter(CommandStack.class);
    commandStack2.undo();
    // And find them all back again!
    for (IArchimateElement element : elements1) {
        assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNotNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
    }
    for (IArchimateElement element : elements2) {
        assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
        assertNotNull(ArchimateModelUtils.getObjectByID(model2, element.getId()));
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 38 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class DuplicateCommandHandlerTests method testDuplicateDiagramModel.

@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());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel) ArchimateTestModel(com.archimatetool.testingtools.ArchimateTestModel) Test(org.junit.Test)

Example 39 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class ObjectUIFactoryProviderTests method testGetProvider_EObject_DiagramModelArchimateObject.

@Test
public void testGetProvider_EObject_DiagramModelArchimateObject() {
    IObjectUIProvider provider = new BusinessActorUIProvider();
    factory.registerProvider(provider);
    IDiagramModelArchimateObject eObject = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
    eObject.setArchimateElement(element);
    assertEquals(provider, factory.getProvider(eObject));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) BusinessActorUIProvider(com.archimatetool.editor.ui.factory.elements.BusinessActorUIProvider) Test(org.junit.Test)

Example 40 with IArchimateElement

use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.

the class CSVExporterTests method testCreateElementRow.

@Test
public void testCreateElementRow() {
    IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
    element.setId("a1234567");
    element.setName("The Main Man");
    element.setDocumentation("This is the Documentation");
    assertEquals("\"a1234567\",\"BusinessActor\",\"The Main Man\",\"This is the Documentation\"", exporter.createElementRow(element));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) Test(org.junit.Test)

Aggregations

IArchimateElement (com.archimatetool.model.IArchimateElement)92 Test (org.junit.Test)57 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)33 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)30 ArrayList (java.util.ArrayList)19 IDiagramModel (com.archimatetool.model.IDiagramModel)16 IArchimateModel (com.archimatetool.model.IArchimateModel)14 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)13 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)11 IFolder (com.archimatetool.model.IFolder)11 EObject (org.eclipse.emf.ecore.EObject)11 IIssue (com.archimatetool.hammer.validation.issues.IIssue)8 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)6 Command (org.eclipse.gef.commands.Command)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 WarningType (com.archimatetool.hammer.validation.issues.WarningType)4 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 NoteEditPart (com.archimatetool.editor.diagram.editparts.diagram.NoteEditPart)3