Guest User

Untitled

a guest
Jul 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. package com.nomagic.magicdraw.tests.uijemmy.diagramming;
  2.  
  3. import java.awt.Rectangle;
  4. import java.io.File;
  5.  
  6. import javax.swing.table.TableModel;
  7.  
  8. import org.netbeans.jemmy.operators.JComponentOperator;
  9. import org.netbeans.jemmy.operators.JDialogOperator;
  10. import org.netbeans.jemmy.operators.JFrameOperator;
  11. import org.netbeans.jemmy.operators.JPopupMenuOperator;
  12. import org.netbeans.jemmy.operators.JTableOperator;
  13. import org.netbeans.jemmy.util.NameComponentChooser;
  14.  
  15. import com.nomagic.magicdraw.core.Project;
  16. import com.nomagic.magicdraw.resources.DialogResource;
  17. import com.nomagic.magicdraw.resources.PropertyResource;
  18. import com.nomagic.magicdraw.tests.JemmyTestUtils;
  19. import com.nomagic.magicdraw.tests.MagicDrawJemmyTestCaseSetUp;
  20. import com.nomagic.magicdraw.tests.common.TestEnvironment;
  21. import com.nomagic.magicdraw.uml.symbols.PresentationElement;
  22. import com.nomagic.magicdraw.uml.symbols.paths.AssociationView;
  23.  
  24. /**
  25. * Checks if association end's name, navigability, visibility, multiplicity is shown
  26. *
  27. * @author Zilvaras Grybauskas
  28. */
  29. public class ConnectionEndTest extends MagicDrawJemmyTestCaseSetUp
  30. {
  31. private JComponentOperator mDiagramCanvas;
  32.  
  33. private int[] rgbInitial;
  34.  
  35. private Rectangle peb;
  36.  
  37. public ConnectionEndTest()
  38. {
  39. super();
  40. }
  41.  
  42. public void testConnectionEndInformationDisplay()
  43. {
  44. String path = new File(TestEnvironment.getResourceDir(), "menu" + File.separator + "diagramming"
  45. + File.separator).getAbsolutePath()
  46. + File.separator;
  47. Project pro = openProject(path + "ConnectionEnd.mdzip");
  48. pause();
  49.  
  50. JFrameOperator mainFrame = getMainFrame();
  51. mDiagramCanvas = new JComponentOperator(mainFrame, new NameComponentChooser("DIAGRAM_CANVAS"));
  52.  
  53. PresentationElement pe = JemmyTestUtils.getPresentationElementByName(pro.getActiveDiagram()
  54. .getPresentationElements(), "", AssociationView.class);
  55. peb = pe.getBounds();
  56. // Getting initial image
  57. rgbInitial = mDiagramCanvas.getImage().getRGB(peb.x, peb.y - 20, peb.width, 40, null, 0, peb.width);
  58.  
  59. checkUncheck(pe, "Show Name");
  60. // After showing name
  61. assertFalse("Shape did not change", isEquals());
  62.  
  63. checkUncheck(pe, "Show Name");
  64. // After hiding name
  65. assertTrue("Shape did not revert to initial", isEquals());
  66.  
  67. // ---------
  68. checkUncheck(pe, "Show Navigability");
  69. // After showing navigability
  70. assertFalse("Shape did not change", isEquals());
  71.  
  72. checkUncheck(pe, "Show Navigability");
  73. // After hiding navigability
  74. assertTrue("Shape did not revert to initial", isEquals());
  75.  
  76. // ---------
  77. checkUncheck(pe, "Show Multiplicity");
  78. // After showing multiplicity
  79. assertFalse("Shape did not change", isEquals());
  80.  
  81. checkUncheck(pe, "Show Multiplicity");
  82. // After hiding multiplicity
  83. assertTrue("Shape did not revert to initial", isEquals());
  84.  
  85. // ---------
  86. checkUncheck(pe, "Show Name");
  87. rgbInitial = mDiagramCanvas.getImage().getRGB(peb.x, peb.y - 20, peb.width, 40, null, 0, peb.width);
  88.  
  89. checkUncheck(pe, "Show Visibility");
  90. // After showing visibility
  91. assertFalse("Shape did not change", isEquals());
  92.  
  93. checkUncheck(pe, "Show Visibility");
  94. // After hiding visibility
  95. assertTrue("Shape did not revert to initial", isEquals());
  96. }
  97.  
  98. /**
  99. * Sets to true or false (if previously was true) property in symbol properties window
  100. *
  101. * @param p - shape which property should be changed
  102. * @param what - property name
  103. */
  104. private void checkUncheck(PresentationElement p, String what)
  105. {
  106. Rectangle pb = p.getBounds();
  107. mDiagramCanvas.clickForPopup(pb.x, pb.y);
  108. pause();
  109. JPopupMenuOperator popup = new JPopupMenuOperator();
  110. JemmyTestUtils.pushOnPopupMenu(popup, PropertyResource.getString("EDIT_SYMBOL"));
  111. pause();
  112. JDialogOperator dial = new JDialogOperator(DialogResource.getString("SYMBOL_PROPERTIES"));
  113. pause();
  114. JTableOperator specTable = new JTableOperator(dial);
  115. TableModel mod = specTable.getModel();
  116. for (int i = 0; i < mod.getRowCount(); i++)
  117. {
  118. if (mod.getValueAt(i, 0).toString().equals(what))
  119. {
  120. specTable.clickOnCell(i, 1);
  121. break;
  122. }
  123. }
  124. JemmyTestUtils.pushOkButton(dial);
  125. pause();
  126. }
  127.  
  128. /**
  129. * Checks if small area around association end is equal to initial
  130. *
  131. * @return true if areas are equal, otherwise false
  132. */
  133. private boolean isEquals()
  134. {
  135. int[] after = mDiagramCanvas.getImage().getRGB(peb.x, peb.y - 20, peb.width, 40, null, 0, peb.width);
  136. boolean equal = false;
  137. for (int i = 0; i < rgbInitial.length; i++)
  138. {
  139. equal = after[i] == rgbInitial[i];
  140. if (!equal)
  141. return false;
  142. }
  143. return true;
  144. }
  145. }
Add Comment
Please, Sign In to add comment