Search in sources :

Example 11 with IArchimateModel

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

the class DiagramModelExtraTests method testDiagramModelArchimateObject_eInverseAdd_ArchimateElement_getReferencingDiagramObjects.

/**
 * See {@link DiagramModelArchimateObject#eInverseAdd(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
 * See {@link DiagramModelArchimateObject#eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
 */
@Test
public void testDiagramModelArchimateObject_eInverseAdd_ArchimateElement_getReferencingDiagramObjects() {
    IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    IDiagramModelArchimateObject dmo3a = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    dmo1.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    dmo2.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    dmo3.setArchimateElement(IArchimateFactory.eINSTANCE.createBusinessActor());
    // dmo3a shares an archimate element with dmo3
    dmo3a.setArchimateElement(dmo3.getArchimateElement());
    // Set up model and diagram model
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setDefaults();
    IDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    // Add some parents
    IDiagramModelGroup parent1 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
    dm.getChildren().add(parent1);
    IDiagramModelArchimateObject parent2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
    parent1.getChildren().add(parent2);
    // Starts at sizes
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Add to dm
    dm.getChildren().add(dmo1);
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    // Add to parent 1
    parent1.getChildren().add(dmo2);
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    // Add to parent 2
    parent2.getChildren().add(dmo3);
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Add dmo3a - dmo3.getArchimateElement() should be same
    dm.getChildren().add(dmo3a);
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Remove diagram model, should be the same
    ((IFolder) dm.eContainer()).getElements().remove(dm);
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Add diagram model back again, should be the same
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    assertEquals(1, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(2, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Simple remove from direct parent
    dm.getChildren().remove(dmo1);
    parent1.getChildren().remove(dmo2);
    parent2.getChildren().remove(dmo3);
    assertEquals(0, dmo1.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(0, dmo2.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(1, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
    // Remove Again
    dm.getChildren().remove(dmo3a);
    assertEquals(0, dmo3.getArchimateElement().getReferencingDiagramObjects().size());
    assertEquals(0, dmo3a.getArchimateElement().getReferencingDiagramObjects().size());
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 12 with IArchimateModel

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

the class DiagramModelObjectTests method testGetArchimateModel.

@Test
public void testGetArchimateModel() {
    assertNull(object.getArchimateModel());
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    dm.getChildren().add(object);
    assertSame(model, object.getArchimateModel());
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 13 with IArchimateModel

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

the class DiagramModelObjectTests method testGetID.

@Test
public void testGetID() {
    assertNull(component.getId());
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.getDefaultFolderForObject(dm).getElements().add(dm);
    dm.getChildren().add(object);
    assertNotNull(component.getId());
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 14 with IArchimateModel

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

the class MetadataTests method testEntryCreated.

@Test
public void testEntryCreated() throws Exception {
    String key = "some_key", value = "some_value";
    // Add a metadata entry as a property key/value pair
    IProperty property = IArchimateFactory.eINSTANCE.createProperty();
    property.setKey(key);
    property.setValue(value);
    metadata.getEntries().add(property);
    // Check entry is correct
    EList<IProperty> entries = metadata.getEntries();
    assertEquals(1, entries.size());
    IProperty testProperty = entries.get(0);
    assertEquals(property, testProperty);
    assertEquals(testProperty.getKey(), key);
    assertEquals(testProperty.getValue(), value);
    // Save to file
    File file = TestSupport.saveModel(model);
    assertTrue(file.exists());
    // Load it in again
    IArchimateModel testModel = TestSupport.loadModel(file);
    // Check it persisted
    EList<IProperty> testEntries = testModel.getMetadata().getEntries();
    assertEquals(1, testEntries.size());
    testProperty = testEntries.get(0);
    assertEquals(testProperty.getKey(), key);
    assertEquals(testProperty.getValue(), value);
}
Also used : IProperty(com.archimatetool.model.IProperty) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) Test(org.junit.Test)

Example 15 with IArchimateModel

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

the class CreateEmptyModelProvider method run.

public void run(CommandLine commandLine) throws Exception {
    if (commandLine.hasOption(OPTION_CREATE_EMPTY_MODEL)) {
        IArchimateModel model = null;
        // Template option?
        String template = commandLine.getOptionValue(OPTION_CREATE_EMPTY_MODEL);
        if (template != null) {
            model = createEmptyModelFromTemplate(template);
        } else {
            model = createEmptyModel();
        }
        CommandLineState.setModel(model);
    }
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel)

Aggregations

IArchimateModel (com.archimatetool.model.IArchimateModel)124 Test (org.junit.Test)51 File (java.io.File)35 IOException (java.io.IOException)22 IArchimateElement (com.archimatetool.model.IArchimateElement)14 EObject (org.eclipse.emf.ecore.EObject)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 ArchimateTestModel (com.archimatetool.testingtools.ArchimateTestModel)13 IDiagramModel (com.archimatetool.model.IDiagramModel)12 CommandStack (org.eclipse.gef.commands.CommandStack)11 IFolder (com.archimatetool.model.IFolder)10 ArrayList (java.util.ArrayList)10 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)9 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)9 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)7 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)6 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)5 IIdentifier (com.archimatetool.model.IIdentifier)5 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)5