Author: yradtsevich
Date: 2009-10-15 12:54:31 -0400 (Thu, 15 Oct 2009)
New Revision: 18114
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/editor/menu/VpePopupMenuTest.java
Log:
JUnit test for the VPE pop-up menu has been fixed.
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/editor/menu/VpePopupMenuTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/editor/menu/VpePopupMenuTest.java 2009-10-15
15:36:36 UTC (rev 18113)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/editor/menu/VpePopupMenuTest.java 2009-10-15
16:54:31 UTC (rev 18114)
@@ -10,13 +10,18 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.menu;
+import java.text.MessageFormat;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.core.resources.IFile;
-import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
@@ -25,12 +30,32 @@
import org.jboss.tools.vpe.editor.VpeEditorPart;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
import org.jboss.tools.vpe.editor.util.SelectionUtil;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.ui.test.TestUtil;
import org.jboss.tools.vpe.ui.test.VpeTest;
import org.jboss.tools.vpe.ui.test.VpeUiTests;
import org.w3c.dom.Node;
+/**
+ * Performs tests for the VPE pop-up menu.
+ *
+ * @author dmaliarevich
+ * @author yradtsevich
+ */
public class VpePopupMenuTest extends VpeTest {
+ private static final String[] REQUIRED_MENU_ITEMS = {
+ MessageFormat.format(
+ VpeUIMessages.ATTRIBUTES_MENU_ITEM, "h:outputText"),
+ MessageFormat.format(
+ VpeUIMessages.PARENT_TAG_MENU_ITEM, "h3"),
+ VpeUIMessages.INSERT_AROUND,
+ VpeUIMessages.INSERT_BEFORE,
+ VpeUIMessages.INSERT_AFTER,
+ VpeUIMessages.INSERT_INTO,
+ VpeUIMessages.REPLACE_WITH,
+ VpeUIMessages.STRIP_TAG_MENU_ITEM
+ };
+ private static final Point CODE_POINT = new Point(14, 25);
private final String INITIALIZATION_FAILED = "Initialization failed!";
//$NON-NLS-1$
private final String FILE_NAME = "hello.jsp"; //$NON-NLS-1$
@@ -62,16 +87,22 @@
MozillaEditor visualEditor = vep.getVisualEditor();
StructuredTextEditor sourceEditor = vc. getSourceEditor();
- /*
- * Selecting h:outputText tag for popup menu.
- */
- int position = TestUtil.getLinePositionOffcet(sourceEditor.getTextViewer(), 14, 25);
+ // Selecting h:outputText tag for popup menu.
+ int position = TestUtil.getLinePositionOffcet(
+ sourceEditor.getTextViewer(), CODE_POINT.x, CODE_POINT.y);
Node sourceNode = SelectionUtil.getNodeBySourcePosition(sourceEditor, position);
- /*
- * Creating popup menu.
- */
+
+ // Creating popup menu.
MenuManager menuManager = new MenuManager("#popup"); //$NON-NLS-1$
final Menu contextMenu = menuManager.createContextMenu(visualEditor.getControl());
+
+ VpeMenuCreator menuCreator = new VpeMenuCreator(menuManager, sourceNode);
+ assertEquals("Menu Manger should have no items before creation.",
//$NON-NLS-1$
+ 0, menuManager.getSize());
+ menuCreator.createMenu();
+
+
+
contextMenu.addMenuListener(new MenuListener() {
Menu menu = contextMenu;
public void menuHidden(MenuEvent e) {
@@ -82,40 +113,33 @@
});
}
public void menuShown(MenuEvent e) {
- /*
- * Close popup menu after it is displayed.
- */
- menu.setVisible(false);
+ try {
+ // Check pop-up menu items menu after it is displayed.
+ Set<String> menuItemNames = new HashSet<String>();
+ for (MenuItem item : contextMenu.getItems()) {
+ menuItemNames.add(item.getText());
+ }
+
+ for (String itemName : REQUIRED_MENU_ITEMS) {
+ assertTrue("There is no '" + itemName //$NON-NLS-1$
+ + "' item in the pop-up menu." //$NON-NLS-1$
+ , menuItemNames.contains(itemName));
+ }
+ } finally {
+ // close pop-up menu
+ menu.setVisible(false);
+ }
}
});
- VpeMenuCreator menuCreator = new VpeMenuCreator(menuManager, sourceNode);
- assertNotNull(INITIALIZATION_FAILED, menuCreator);
- assertEquals("Menu Manger should have no items before initialization.",
//$NON-NLS-1$
- 0, menuManager.getSize());
- menuCreator.createMenu();
- assertEquals(
- "After menu creation the Menu Manger should have 13 items in it.",
//$NON-NLS-1$
- 13, menuManager.getSize());
/*
- * Searching InsertContributionItem among menu manger items.
- */
- IContributionItem[] menuItems = menuManager.getItems();
- InsertContributionItem insertItem = null;
- for (IContributionItem item : menuItems) {
- if (item instanceof InsertContributionItem) {
- insertItem = (InsertContributionItem) item;
- }
- }
- assertNotNull(
- "InsertContributionItem should exist in the list of menu items but it is
not.", //$NON-NLS-1$
- insertItem);
- /*
* Show context menu on the display.
* Menu will be filled in with items and drew on the screen.
* If there are any exceptions - they'll be thrown.
* After displaying the menu will be automatically hidden.
*/
contextMenu.setVisible(true);
+// TestUtil.waitForJobs();
+// TestUtil.delay(5000);
/*
* It is possible to send synthetic mouse and key events in XULRunner 1.9.
@@ -134,5 +158,4 @@
// assertNotNull(INITIALIZATION_FAILED, utils);
// utils.sendMouseEvent("mousedown", 10, 10, 0, 1, 0);
}
-
}