use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class DeleteCommandHandlerTests method testDelete_Elements.
@Test
public void testDelete_Elements() {
String[] elementIDs = new String[] { "31a27739", "8ab84e91", "46d0abd5", "8ecabfc2" };
List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
for (String id : elementIDs) {
elements.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
}
// Ensure these elements are referenced in diagrams
for (IArchimateElement element : elements) {
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
}
// Delete them
DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, elements.toArray());
commandHandler.delete();
// Test that they are all gone in the model and in the referenced diagrams
for (IArchimateElement element : elements) {
assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
}
// And just for good measure, we'll undo it
CommandStack commandStack = (CommandStack) model.getAdapter(CommandStack.class);
commandStack.undo();
// And find them all back again!
for (IArchimateElement element : elements) {
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNotNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
}
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class DeleteCommandHandlerTests method testDelete_Folder_Deleted_SubElements.
@Test
public void testDelete_Folder_Deleted_SubElements() {
// Sub-folder with elements
Object[] folder = new Object[] { ArchimateModelUtils.getObjectByID(model, "0bd99416") };
assertTrue(folder[0] instanceof IFolder);
// sub-Elements that should be zapped
String[] elementIDs = new String[] { // element
"e836c6be", // element
"b5742e18", // element
"d1247cf1" };
List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
for (String id : elementIDs) {
elements.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
}
// Delete top folder
DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, folder);
commandHandler.delete();
// Is top folder deleted?
assertNull(ArchimateModelUtils.getObjectByID(model, "0bd99416"));
// Is sub folder deleted?
assertNull(ArchimateModelUtils.getObjectByID(model, "02460ff1"));
// Are elements deleted?
for (IArchimateElement element : elements) {
assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
}
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class DuplicateCommandHandlerTests method testDuplicateArchimateElements.
@Test
public void testDuplicateArchimateElements() {
ArchimateTestModel tm = new ArchimateTestModel();
IArchimateModel model = tm.createNewModel();
IFolder folder = model.getFolder(FolderType.BUSINESS);
IArchimateElement element1 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
element1.setName("Actor 1");
element1.setDocumentation("Doc 1");
assertEquals(1, folder.getElements().size());
assertSame(element1, folder.getElements().get(0));
IArchimateElement element2 = (IArchimateElement) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getBusinessActor());
element2.setName("Actor 2");
element2.setDocumentation("Doc 2");
assertEquals(2, folder.getElements().size());
assertSame(element2, folder.getElements().get(1));
IArchimateRelationship relation = (IArchimateRelationship) tm.createModelElementAndAddToModel(IArchimatePackage.eINSTANCE.getAssociationRelationship());
relation.connect(element1, element2);
assertTrue(element1.getSourceRelationships().contains(relation));
assertTrue(element2.getTargetRelationships().contains(relation));
DuplicateCommandHandler handler = new DuplicateCommandHandler(new Object[] { element1, element2 });
handler.duplicate();
assertEquals(4, folder.getElements().size());
assertSame(element1, folder.getElements().get(0));
assertSame(element2, folder.getElements().get(1));
IArchimateElement copy1 = (IArchimateElement) folder.getElements().get(2);
assertNotSame(element1, copy1);
assertNotEquals(element1.getId(), copy1.getId());
assertEquals(element1.getName() + " (copy)", copy1.getName());
assertEquals(element1.getDocumentation(), copy1.getDocumentation());
IArchimateElement copy2 = (IArchimateElement) folder.getElements().get(3);
assertNotSame(element2, copy2);
assertNotEquals(element2.getId(), copy2.getId());
assertEquals(element2.getName() + " (copy)", copy2.getName());
assertEquals(element2.getDocumentation(), copy2.getDocumentation());
assertTrue(copy1.getSourceRelationships().isEmpty());
assertTrue(copy1.getTargetRelationships().isEmpty());
assertTrue(copy2.getSourceRelationships().isEmpty());
assertTrue(copy2.getTargetRelationships().isEmpty());
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class DuplicateCommandHandlerTests method testDuplicateDiagramModel_AddsConnectionsToConnections.
@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());
}
use of com.archimatetool.model.IArchimateElement in project archi by archimatetool.
the class DiagramModelUtilsTests method findReferencedDiagramsForArchimateConcept.
private void findReferencedDiagramsForArchimateConcept(String[][] data) {
IArchimateElement element = (IArchimateElement) tm.getObjectByID(data[0][0]);
assertNotNull(element);
List<IDiagramModel> list = DiagramModelUtils.findReferencedDiagramsForArchimateConcept(element);
assertEquals(data[1].length, list.size());
for (int i = 0; i < data[1].length; i++) {
String id = data[1][i];
assertEquals(id, list.get(i).getId());
}
}
Aggregations