Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nomagic.magicdraw.tests.uijemmy.diagramming;
- import java.awt.Rectangle;
- import java.io.File;
- import javax.swing.table.TableModel;
- import org.netbeans.jemmy.operators.JComponentOperator;
- import org.netbeans.jemmy.operators.JDialogOperator;
- import org.netbeans.jemmy.operators.JFrameOperator;
- import org.netbeans.jemmy.operators.JPopupMenuOperator;
- import org.netbeans.jemmy.operators.JTableOperator;
- import org.netbeans.jemmy.util.NameComponentChooser;
- import com.nomagic.magicdraw.core.Project;
- import com.nomagic.magicdraw.resources.DialogResource;
- import com.nomagic.magicdraw.resources.PropertyResource;
- import com.nomagic.magicdraw.tests.JemmyTestUtils;
- import com.nomagic.magicdraw.tests.MagicDrawJemmyTestCaseSetUp;
- import com.nomagic.magicdraw.tests.common.TestEnvironment;
- import com.nomagic.magicdraw.uml.symbols.PresentationElement;
- import com.nomagic.magicdraw.uml.symbols.paths.AssociationView;
- /**
- * Checks if association end's name, navigability, visibility, multiplicity is shown
- *
- * @author Zilvaras Grybauskas
- */
- public class ConnectionEndTest extends MagicDrawJemmyTestCaseSetUp
- {
- private JComponentOperator mDiagramCanvas;
- private int[] rgbInitial;
- private Rectangle peb;
- public ConnectionEndTest()
- {
- super();
- }
- public void testConnectionEndInformationDisplay()
- {
- String path = new File(TestEnvironment.getResourceDir(), "menu" + File.separator + "diagramming"
- + File.separator).getAbsolutePath()
- + File.separator;
- Project pro = openProject(path + "ConnectionEnd.mdzip");
- pause();
- JFrameOperator mainFrame = getMainFrame();
- mDiagramCanvas = new JComponentOperator(mainFrame, new NameComponentChooser("DIAGRAM_CANVAS"));
- PresentationElement pe = JemmyTestUtils.getPresentationElementByName(pro.getActiveDiagram()
- .getPresentationElements(), "", AssociationView.class);
- peb = pe.getBounds();
- // Getting initial image
- rgbInitial = mDiagramCanvas.getImage().getRGB(peb.x, peb.y - 20, peb.width, 40, null, 0, peb.width);
- checkUncheck(pe, "Show Name");
- // After showing name
- assertFalse("Shape did not change", isEquals());
- checkUncheck(pe, "Show Name");
- // After hiding name
- assertTrue("Shape did not revert to initial", isEquals());
- // ---------
- checkUncheck(pe, "Show Navigability");
- // After showing navigability
- assertFalse("Shape did not change", isEquals());
- checkUncheck(pe, "Show Navigability");
- // After hiding navigability
- assertTrue("Shape did not revert to initial", isEquals());
- // ---------
- checkUncheck(pe, "Show Multiplicity");
- // After showing multiplicity
- assertFalse("Shape did not change", isEquals());
- checkUncheck(pe, "Show Multiplicity");
- // After hiding multiplicity
- assertTrue("Shape did not revert to initial", isEquals());
- // ---------
- checkUncheck(pe, "Show Name");
- rgbInitial = mDiagramCanvas.getImage().getRGB(peb.x, peb.y - 20, peb.width, 40, null, 0, peb.width);
- checkUncheck(pe, "Show Visibility");
- // After showing visibility
- assertFalse("Shape did not change", isEquals());
- checkUncheck(pe, "Show Visibility");
- // After hiding visibility
- assertTrue("Shape did not revert to initial", isEquals());
- }
- /**
- * Sets to true or false (if previously was true) property in symbol properties window
- *
- * @param p - shape which property should be changed
- * @param what - property name
- */
- private void checkUncheck(PresentationElement p, String what)
- {
- Rectangle pb = p.getBounds();
- mDiagramCanvas.clickForPopup(pb.x, pb.y);
- pause();
- JPopupMenuOperator popup = new JPopupMenuOperator();
- JemmyTestUtils.pushOnPopupMenu(popup, PropertyResource.getString("EDIT_SYMBOL"));
- pause();
- JDialogOperator dial = new JDialogOperator(DialogResource.getString("SYMBOL_PROPERTIES"));
- pause();
- JTableOperator specTable = new JTableOperator(dial);
- TableModel mod = specTable.getModel();
- for (int i = 0; i < mod.getRowCount(); i++)
- {
- if (mod.getValueAt(i, 0).toString().equals(what))
- {
- specTable.clickOnCell(i, 1);
- break;
- }
- }
- JemmyTestUtils.pushOkButton(dial);
- pause();
- }
- /**
- * Checks if small area around association end is equal to initial
- *
- * @return true if areas are equal, otherwise false
- */
- private boolean isEquals()
- {
- int[] after = mDiagramCanvas.getImage().getRGB(peb.x, peb.y - 20, peb.width, 40, null, 0, peb.width);
- boolean equal = false;
- for (int i = 0; i < rgbInitial.length; i++)
- {
- equal = after[i] == rgbInitial[i];
- if (!equal)
- return false;
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment