/**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports (on node) from
   * the model content view , the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromModelContentView() {

    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    final Property firstProperty = class3.getOwnedAttribute("Prop3to2", class2);
    final Property secondProperty = class3.getOwnedAttribute("OtherProp3to2", class2);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();
  }
  public void testOpenOnlyStartupsOfSelectedSiriuss() throws Exception {
    // Open startup representation
    SessionHelper.openStartupRepresentations(session, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Check opening the session opens the right representation and not the
    // other (-> representation of selected viewpoints should be opened)
    assertEquals(
        "Only the startup table editor should be opened (check editors opened).",
        1,
        getOpenedEditors().size());
    IEditingSession uiSession = SessionUIManager.INSTANCE.getUISession(session);
    assertEquals(
        "Only the startup table editor should be opened (check editors associated with editing session).",
        1,
        uiSession.getEditors().size());
    assertTrue(
        "The table should be opened",
        uiSession.getEditors().iterator().next().getRepresentation() instanceof DTable);

    // Change viewpoint activation VP-2734 > VP-2891
    uiSession.closeEditors(false, uiSession.getEditors());
    TestsUtil.emptyEventsFromUIThread();
    deactivateViewpoint("VP-2734");
    activateViewpoint("VP-2891");

    // Test O editor open.
    TestsUtil.synchronizationWithUIThread();
    assertEquals(
        "Only the startup table editor should be opened (check editors opened).",
        0,
        getOpenedEditors().size());
    assertEquals(
        "Only the startup table editor should be opened (check editors associated with editing session).",
        0,
        uiSession.getEditors().size());

    // Open startup representations
    SessionHelper.openStartupRepresentations(session, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Check opening the session opens the right representation and not the
    // other (-> representation of selected viewpoints should be opened)
    assertEquals(
        "Only the startup diagram editor should be opened (check editors opened).",
        1,
        getOpenedEditors().size());
    assertEquals(
        "Only the startup diagram editor should be opened (check editors associated with editing session).",
        1,
        uiSession.getEditors().size());
    assertTrue(
        "The diagram should be opened",
        uiSession.getEditors().iterator().next().getRepresentation() instanceof DDiagram);
  }
 public void testOpenTableRepresentation() throws Exception {
   if (TestsUtil.shouldSkipUnreliableTests()) {
     /*
     org.eclipse.swtbot.swt.finder.widgets.TimeoutException: Timeout after: 10000 ms.: tree item with text  is not selected
     at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:407)
     at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:381)
     at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(SWTBotFactory.java:369)
     at org.eclipse.sirius.tests.swtbot.support.api.business.UIProject.getUIItemFromResource(UIProject.java:157)
     at org.eclipse.sirius.tests.swtbot.support.api.business.UIProject.selectResource(UIProject.java:122)
     at org.eclipse.sirius.tests.swtbot.support.api.business.UIPerspective.openSessionCreationWizardFromSemanticResource(UIPerspective.java:188)
     at org.eclipse.sirius.tests.swtbot.OpenMultipleRepresentationsTest.onSetUpAfterOpeningDesignerPerspective(OpenMultipleRepresentationsTest.java:61)
     */
     return;
   }
   SWTBotTreeItem modelElementItem =
       localSession.getLocalSessionBrowser().perSemantic().expandNode("root").click();
   final UITableRepresentation tableRepresentation =
       localSession
           .newTableRepresentation("Classes in root package")
           .on(modelElementItem)
           .withDefaultName()
           .ok();
   final SWTBotEditor editor = tableRepresentation.open().getEditor();
   assertEditorIsNotError("editor was an error one", editor);
 }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    TestsUtil.emptyEventsFromUIThread();

    genericSetUp(SEMANTIC_MODEL_PATH, MODELER_PATH, REPRESENTATION_MODEL_PATH);

    diagram = (DDiagram) getRepresentations(REPRESENTATION_DESC_NAME).toArray()[0];
    assertNotNull(diagram);
    editor =
        (DiagramEditor)
            DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();
    assertNotNull(editor);
  }
  @Override
  protected void tearDown() throws Exception {

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    diagram = null;
    editorPart = null;

    super.tearDown();
  }
  private void doTestCloseOpenUnsynchronized() {
    Model model;
    Activity activity;
    ActivityEdge edge;
    DEdge edgeElement;
    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    diagram = (DDiagram) getRepresentations(REPRESENTATION_DESC_NAME).toArray()[0];
    assertNotNull(diagram);
    editorPart = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    model = (Model) semanticModel;
    activity = (Activity) model.getPackagedElements().get(0);
    edge = activity.getEdges().get(0);
    assertNotNull(edge);
    edgeElement = getFirstEdgeElement(diagram, edge);
    assertNotNull(edgeElement);
  }
  /** test to move up the second interaction use */
  public void
      testSecondInteractionUseVerticalMoveDownToCenterOfReflexiveSyncCallOnNotSemanticallyCoveredParticipant() {
    if (TestsUtil.shouldSkipLongTests()) {
      /*
      junit.framework.AssertionFailedError: The execution named  is not displayed at the expected vertical position expected:<420.0> but was:<485.0>
      at junit.framework.Assert.fail(Assert.java:57)
      at junit.framework.Assert.failNotEquals(Assert.java:329)
      at junit.framework.Assert.assertEquals(Assert.java:142)
      at junit.framework.TestCase.assertEquals(TestCase.java:298)
      at org.eclipse.sirius.tests.swtbot.sequence.AbstractSequenceDiagramTestCase.assertSequenceNodeHasValidBounds(AbstractSequenceDiagramTestCase.java:1371)
      at org.eclipse.sirius.tests.swtbot.sequence.AbstractSequenceDiagramTestCase.assertExecutionHasValidScreenBounds(AbstractSequenceDiagramTestCase.java:1305)
      at org.eclipse.sirius.tests.swtbot.sequence.InteractionUseMoveDownTests.commonPreparationForMoveDownTests(InteractionUseMoveDownTests.java:227)
      at org.eclipse.sirius.tests.swtbot.sequence.InteractionUseMoveDownTests.testSecondInteractionUseVerticalMoveDownToCenterOfReflexiveSyncCallOnNotSemanticallyCoveredParticipant(InteractionUseMoveDownTests.java:360)
      */
      return;
    }

    int dY = commonPreparationForMoveDownTests();

    // Move second interaction to have its top in the middle of E6
    CheckEditPartMoved checkMoved = new CheckEditPartMoved(secondInteractionUseBot);
    editor.drag(secondInteractionUseBounds.getTop(), e6Bounds.getCenter());
    bot.waitUntil(checkMoved);

    int dy2 = e6Bounds.getCenter().y - secondInteractionUseBounds.getTop().y;
    int deltaResize = secondInteractionUseBounds.height;

    e6Bot =
        instanceRoleEditPartEBot
            .parent()
            .descendants(IsInstanceOf.instanceOf(ExecutionEditPart.class))
            .get(0);
    callMessageOnE6Bot = e6Bot.targetConnections().get(0);
    returnMessageOfE6Bot = e6Bot.sourceConnections().get(0);

    assertInteractionUseHasValidScreenBounds(
        (InteractionUseEditPart) firstInteractionUseBot.part(), firstInteractionUseBounds);
    assertInteractionUseHasValidScreenBounds(
        (InteractionUseEditPart) secondInteractionUseBot.part(),
        secondInteractionUseBounds.getTranslated(0, dy2));

    assertExecutionHasValidScreenBounds((ExecutionEditPart) e1Bot.part(), e1Bounds);
    assertExecutionHasValidScreenBounds(
        (ExecutionEditPart) e2Bot.part(), e2Bounds.getResized(0, dY + deltaResize));
    assertExecutionHasValidScreenBounds(
        (ExecutionEditPart) e3Bot.part(), e3Bounds.getResized(0, dY + deltaResize));
    assertExecutionHasValidScreenBounds(
        (ExecutionEditPart) e4Bot.part(), e4Bounds.getResized(0, dY + deltaResize));
    assertExecutionHasValidScreenBounds(
        (ExecutionEditPart) e5Bot.part(), e5Bounds.getTranslated(0, dY + deltaResize));
    assertExecutionHasValidScreenBounds(
        (ExecutionEditPart) e6Bot.part(), e6Bounds.getResized(0, deltaResize));

    assertMessageVerticalPosition(
        (SequenceMessageEditPart) callMessageOnE1Bot.part(), callMessageOnE1Bounds.y);
    assertMessageVerticalPosition(
        (SequenceMessageEditPart) callMessageOnE2Bot.part(), callMessageOnE2Bounds.y);
    assertMessageVerticalPosition(
        (SequenceMessageEditPart) callMessageOnE4Bot.part(), callMessageOnE4Bounds.y);
    assertMessageHasValidScreenBounds(
        (SequenceMessageEditPart) callMessageOnE6Bot.part(), callMessageOnE6Bounds, true, false);

    assertMessageVerticalPosition(
        (SequenceMessageEditPart) returnMessageOfE1Bot.part(), returnMessageOfE1Bounds.y);
    assertMessageVerticalPosition(
        (SequenceMessageEditPart) returnMessageOfE2Bot.part(),
        returnMessageOfE2Bounds.getTranslated(0, dY + deltaResize).y);
    assertMessageVerticalPosition(
        (SequenceMessageEditPart) returnMessageOfE4Bot.part(),
        returnMessageOfE4Bounds.getTranslated(0, dY + deltaResize).y);
    assertMessageHasValidScreenBounds(
        (SequenceMessageEditPart) returnMessageOfE6Bot.part(),
        returnMessageOfE6Bounds.getTranslated(0, deltaResize),
        true,
        false);

    validateOrdering(24);
  }
  /**
   * Check that :
   *
   * <UL>
   *   <LI>the size of new collapsed bordered nodes is 1x1 (and not the same as not collapsed),
   *   <LI>the space between two new collapsed bordered nodes is the same as between two new normal
   *       bordered nodes.
   *   <LI>the size of an existing bordered nodes is 1x1 after collapse filter application, and its
   *       location is contains in the original bounds.
   * </UL>
   *
   * Steps of this test:
   *
   * <UL>
   *   <LI>Open a first diagram
   *       <UL>
   *         <LI>modify the semantic (causing creation of new ports),
   *         <LI>take the bounds of new ports (without collapse filter),
   *         <LI>take the space between them,
   *         <LI>apply the collapse filter,
   *         <LI>check that the size of the port is 1x1 and its new location is contained in the old
   *             bounds,
   *         <LI>close the diagram,
   *         <LI>undo the semantic modifications,
   *       </UL>
   *   <LI>Open a new diagram,
   *       <UL>
   *         <LI>enable the collapse filter,
   *         <LI>make the same semantic modifications (causing creation of new ports),
   *         <LI>compare the size ans the space with previous diagram.
   *       </UL>
   * </UL>
   *
   * See VP-3833
   */
  public void testPortLocationsAndMoreWithForCollapseFilter() {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);

    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Open the editor (and refresh it)
    IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Add 3 Property to class3 (that will cause the creation of 3
    // new ports during refresh)
    String prefix = "aPort";
    addProperties(class3, class2, "aPort", 3);
    // Refresh the diagram
    refresh(diagram);

    Property thirdProperty = class3.getOwnedAttribute(prefix + 1, class2);
    DDiagramElement thirdPropertyDiagramElement = getFirstDiagramElement(diagram, thirdProperty);
    Node thirdPropertyNode = getGmfNode(thirdPropertyDiagramElement);
    final Bounds expectedThirdBounds = (Bounds) thirdPropertyNode.getLayoutConstraint();

    Property fourthProperty = class3.getOwnedAttribute(prefix + 2, class2);
    DDiagramElement fourthPropertyDiagramElement = getFirstDiagramElement(diagram, fourthProperty);
    Node fourthPropertyNode = getGmfNode(fourthPropertyDiagramElement);
    final Bounds expectedFourthBounds = (Bounds) fourthPropertyNode.getLayoutConstraint();

    Property fifthProperty = class3.getOwnedAttribute(prefix + 3, class2);
    DDiagramElement fifthPropertyDiagramElement = getFirstDiagramElement(diagram, fifthProperty);
    Node fifthPropertyNode = getGmfNode(fifthPropertyDiagramElement);
    final Bounds expectedFifthBounds = (Bounds) fifthPropertyNode.getLayoutConstraint();
    // Activate the filter
    activateFilter(diagram, "FilterPropertyStartingWithA");
    // Refresh the diagram
    refresh(diagram);
    // Check the size and the new location of one of the collapsed bordered
    // node
    final Bounds collapseThirdBounds = (Bounds) thirdPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of the collapse bordered node is not OK.", 1, collapseThirdBounds.getWidth());
    assertEquals(
        "The height of the collapse bordered node is not OK.", 1, collapseThirdBounds.getHeight());
    assertTrue(
        "The new collapsed location should be contains in the not collapsed bounds.",
        new Rectangle(
                expectedThirdBounds.getX(),
                expectedThirdBounds.getY(),
                expectedThirdBounds.getWidth(),
                expectedThirdBounds.getHeight())
            .contains(new Point(collapseThirdBounds.getX(), collapseThirdBounds.getY())));

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    // Remove the 3 added properties
    removeProperties(class3, 3);

    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Open the editor (and refresh it)
    editorPart = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();
    // Activate the filter
    activateFilter(diagram, "FilterPropertyStartingWithA");

    // Add 3 Property to class3 (that will cause the creation of 3
    // new ports during refresh)
    addProperties(class3, class2, "aPort", 3);
    // Refresh the diagram
    refresh(diagram);

    thirdProperty = class3.getOwnedAttribute(prefix + 1, class2);
    thirdPropertyDiagramElement = getFirstDiagramElement(diagram, thirdProperty);
    thirdPropertyNode = getGmfNode(thirdPropertyDiagramElement);
    Bounds thirdCollapseBounds = (Bounds) thirdPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of a new collapsed bordered node is not correct.",
        1,
        thirdCollapseBounds.getWidth());
    assertEquals(
        "The height of a new collapsed bordered node is not correct.",
        1,
        thirdCollapseBounds.getHeight());

    fourthProperty = class3.getOwnedAttribute(prefix + 2, class2);
    fourthPropertyDiagramElement = getFirstDiagramElement(diagram, fourthProperty);
    fourthPropertyNode = getGmfNode(fourthPropertyDiagramElement);
    Bounds fourthCollapseBounds = (Bounds) fourthPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of a new collapsed bordered node is not correct.",
        1,
        fourthCollapseBounds.getWidth());
    assertEquals(
        "The height of a new collapsed bordered node is not correct.",
        1,
        fourthCollapseBounds.getHeight());

    fifthProperty = class3.getOwnedAttribute(prefix + 3, class2);
    fifthPropertyDiagramElement = getFirstDiagramElement(diagram, fifthProperty);
    fifthPropertyNode = getGmfNode(fifthPropertyDiagramElement);
    Bounds fifthCollapseBounds = (Bounds) fifthPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of a new collapsed bordered node is not correct.",
        1,
        fifthCollapseBounds.getWidth());
    assertEquals(
        "The height of a new collapsed bordered node is not correct.",
        1,
        fifthCollapseBounds.getHeight());

    assertEquals(
        "The space bewteen the collapsed bordered nodes should be the same as between the not collapsed bordered nodes.",
        expectedFourthBounds.getY() - expectedThirdBounds.getY(),
        fourthCollapseBounds.getY() - thirdCollapseBounds.getY());
    assertEquals(
        "The space bewteen the collapsed bordered nodes should be the same as between the not collapsed bordered nodes.",
        expectedFifthBounds.getY() - expectedFourthBounds.getY(),
        fifthCollapseBounds.getY() - fourthCollapseBounds.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();
  }
  /**
   * Open the diagram, modify the semantic (causing creation of new ports), check the position of
   * new ports (not the same). See VP-3095
   */
  protected void testPortLocationAfterRefresh(boolean activateCollapseFilter) {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    final Property firstProperty = class3.getOwnedAttribute("Prop3to2", class2);
    final Property secondProperty = class3.getOwnedAttribute("OtherProp3to2", class2);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    if (activateCollapseFilter) {
      activateFilter(diagram, "FilterPropertyStartingWithA");
    }

    // Add 3 Property to class3 (that will cause the creation of 3
    // new ports during refresh).
    addProperties(class3, class2, "Prop3to2_", 3);
    // Refresh the diagram
    refresh(diagram);

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    final Property thirdProperty = class3.getOwnedAttribute("Prop3to2_1", class2);
    final Property fourthProperty = class3.getOwnedAttribute("Prop3to2_2", class2);
    final Property fifthProperty = class3.getOwnedAttribute("Prop3to2_3", class2);
    final DDiagramElement thirdPropertyDiagramElement =
        getFirstDiagramElement(diagram, thirdProperty);
    assertNotNull(
        "The third property has no corresponding diagramElement", thirdPropertyDiagramElement);
    final Node thirdPropertyNode = getGmfNode(thirdPropertyDiagramElement);
    assertNotNull("The third property has no corresponding GMF node", thirdPropertyNode);
    assertTrue(
        "Bag layout constraint type", thirdPropertyNode.getLayoutConstraint() instanceof Location);
    final Location thirdLocation = (Location) thirdPropertyNode.getLayoutConstraint();
    final DDiagramElement fourthPropertyDiagramElement =
        getFirstDiagramElement(diagram, fourthProperty);
    assertNotNull(
        "The fourth property has no corresponding diagramElement", fourthPropertyDiagramElement);
    final Node fourthPropertyNode = getGmfNode(fourthPropertyDiagramElement);
    assertNotNull("The fourth property has no corresponding GMF node", fourthPropertyNode);
    assertTrue(
        "Bag layout constraint type", fourthPropertyNode.getLayoutConstraint() instanceof Location);
    final Location fourthLocation = (Location) fourthPropertyNode.getLayoutConstraint();
    final DDiagramElement fifthPropertyDiagramElement =
        getFirstDiagramElement(diagram, fifthProperty);
    assertNotNull(
        "The fifth property has no corresponding diagramElement", fifthPropertyDiagramElement);
    final Node fifthPropertyNode = getGmfNode(fifthPropertyDiagramElement);
    assertNotNull("The fifth property has no corresponding GMF node", fifthPropertyNode);
    assertTrue(
        "Bag layout constraint type", fifthPropertyNode.getLayoutConstraint() instanceof Location);
    final Location fifthLocation = (Location) fifthPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        thirdLocation.getX() == 0
            && thirdLocation.getY() == 0
            && fourthLocation.getX() == 0
            && fourthLocation.getY() == 0
            && fifthLocation.getX() == 0
            && fifthLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        thirdLocation.getX() != fourthLocation.getX()
            || thirdLocation.getY() != fourthLocation.getY());
    assertTrue(
        "All the layout constraints of the ports should be different",
        thirdLocation.getX() != fifthLocation.getX()
            || thirdLocation.getY() != fifthLocation.getY());
    assertTrue(
        "All the layout constraints of the ports should be different",
        fifthLocation.getX() != fourthLocation.getX()
            || fifthLocation.getY() != fourthLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();
  }
  /**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports from an
   * existing diagram, the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromNavigation() {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Set the focus to the desired package
    assertTrue(
        "We should have a DiagramDocumentEditor", editorPart instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editorPart;

    // Get the package named "SubPackage"
    PackageableElement element = model.getPackagedElement("SubPackage");
    assertTrue("Corrupted input data", element instanceof Package);
    final Package packageSubPackage = (Package) element;

    IMenuManager popupMenu = new MenuManager();
    popupMenu.add(
        new MenuManager(
            IWorkbenchActionConstants.MB_ADDITIONS,
            IWorkbenchActionConstants.MB_ADDITIONS)); // $NON-NLS-1$ //$NON-NLS-2$
    popupMenu.add(new MenuManager("popup.new", "popup.new")); // $NON-NLS-1$

    // Set the focus to package SubPackage
    IGraphicalEditPart elementEditPart =
        getEditPart(getFirstDiagramElement(diagram, packageSubPackage));
    diagramEditor.getDiagramGraphicalViewer().setFocus(elementEditPart);

    DNode focusedElement =
        (DNode)
            ((GraphicalEditPart) diagramEditor.getDiagramGraphicalViewer().getFocusEditPart())
                .resolveSemanticElement();
    assertTrue(
        "This is not the good focused element", focusedElement.getTarget() instanceof Package);
    assertEquals(
        "This is not the good focused element",
        "SubPackage",
        ((Package) focusedElement.getTarget()).getName());

    ContributionItemService.getInstance().contributeToPopupMenu(popupMenu, diagramEditor);

    // Check the popup menu.
    IMenuManager newRepresentationMenu = (IMenuManager) popupMenu.find("popup.new");
    IContributionItem[] items = newRepresentationMenu.getItems();

    boolean inNewRepresentationToGroup = false;

    ActionContributionItem actionContribution = null;

    for (int i = 0; i < items.length; i++) {
      if (items[i] instanceof Separator) {
        Separator sep = (Separator) items[i];
        if ("createRepresentationGroup".equals(sep.getId())) {
          inNewRepresentationToGroup = true;
        } else {
          inNewRepresentationToGroup = false;
        }
      }
      if (inNewRepresentationToGroup && items[i] instanceof ActionContributionItem) {
        assertNull("There should be only one ActionContributionItem", actionContribution);
        actionContribution = (ActionContributionItem) items[i];
      }
    }

    assertNotNull("There should be one ActionContributionItem", actionContribution);
    final IAction action = actionContribution.getAction();

    assertEquals("Action has not the correct text", "New diagram", action.getText());

    // Disabling ui callback of diagram command factory
    final Object adapter = diagramEditor.getAdapter(IDiagramCommandFactoryProvider.class);
    final IDiagramCommandFactoryProvider diagramCmdFactoryProvider =
        (IDiagramCommandFactoryProvider) adapter;
    final IDiagramCommandFactory diagramCommandFactory =
        diagramCmdFactoryProvider.getCommandFactory(session.getTransactionalEditingDomain());
    diagramCommandFactory.setUserInterfaceCallBack(new NoUICallback());

    action.run();

    IEditorPart editor2 =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue("We should have a DiagramDocumentEditor", editor2 instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor2 = (DiagramDocumentEditor) editor2;
    GraphicalEditPart diagramPart = (GraphicalEditPart) diagramEditor2.getDiagramEditPart();
    final DSemanticDiagram diagram2 = (DSemanticDiagram) diagramPart.resolveSemanticElement();

    assertEquals(
        "The opened diagram is not valid", diagram2.getTarget(), focusedElement.getTarget());

    // Get the class named "SubClass1"
    element = packageSubPackage.getPackagedElement("SubClass1");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class subClass1 = (Class) element;

    final Property firstProperty = subClass1.getOwnedAttribute("Prop1", subClass1);
    final Property secondProperty = subClass1.getOwnedAttribute("Prop2", subClass1);

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram2, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram2, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    DialectUIManager.INSTANCE.closeEditor(editor2, false);
    TestsUtil.synchronizationWithUIThread();
  }
 private void doTest() throws Exception {
   activateFilter(diagram, HIDE_EREFERENCES);
   TestsUtil.synchronizationWithUIThread();
   deactivateFilter(diagram, HIDE_EREFERENCES);
   TestsUtil.synchronizationWithUIThread();
 }