// CreateShortcut, LoadResource, InitDiagramFileAction
 public void testPredefinedActions() throws Exception {
   DiaGenSource s1 = createLibraryGen(false);
   final GenEditorGenerator editorGen = s1.getGenDiagram().getEditorGen();
   GenContextMenu menu = GMFGenFactory.eINSTANCE.createGenContextMenu();
   menu.getContext().add(s1.getGenDiagram());
   final CreateShortcutAction createShortcutAction =
       GMFGenFactory.eINSTANCE.createCreateShortcutAction();
   final LoadResourceAction loadResourceAction =
       GMFGenFactory.eINSTANCE.createLoadResourceAction();
   menu.getItems().add(createShortcutAction);
   menu.getItems().add(loadResourceAction);
   editorGen.getContextMenus().clear(); // make sure there's no other (default) menus
   editorGen.getContextMenus().add(menu);
   editorGen.getDiagram().getContainsShortcutsTo().add("ecore");
   assertTrue("sanity", editorGen.getDiagram().generateCreateShortcutAction());
   //
   generateAndCompile(s1);
   //
   IProject generatedProject =
       ResourcesPlugin.getWorkspace().getRoot().getProject(editorGen.getPlugin().getID());
   IFile generatedManifest = generatedProject.getFile("plugin.xml");
   assertTrue(generatedManifest.exists());
   DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
   Document parsedManifest = db.parse(new InputSource(generatedManifest.getContents()));
   XPath xf = XPathFactory.newInstance().newXPath();
   XPathExpression xe =
       xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/command");
   NodeList result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
   assertEquals(2, result.getLength());
   xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.commands']/command");
   result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
   assertTrue(result.getLength() > 2);
   HashSet<String> allCommands = new HashSet<String>();
   for (int i = result.getLength() - 1; i >= 0; i--) {
     allCommands.add(result.item(i).getAttributes().getNamedItem("defaultHandler").getNodeValue());
   }
   assertTrue(allCommands.contains(createShortcutAction.getQualifiedClassName()));
   assertTrue(allCommands.contains(loadResourceAction.getQualifiedClassName()));
   IFile file1 =
       generatedProject.getFile(
           "/src/" + createShortcutAction.getQualifiedClassName().replace('.', '/') + ".java");
   IFile file2 =
       generatedProject.getFile(
           "/src/" + loadResourceAction.getQualifiedClassName().replace('.', '/') + ".java");
   assertTrue(file1.exists());
   assertTrue(file2.exists());
   //
   //		DiaGenSource s2 = createLibraryGen(true);
   //		fail("TODO");
 }
  public void testCustomActions() throws Exception {
    DiaGenSource s = createLibraryGen(false);
    final GenEditorGenerator editorGen = s.getGenDiagram().getEditorGen();
    GenContextMenu menu = GMFGenFactory.eINSTANCE.createGenContextMenu();
    GenCustomAction a1 = GMFGenFactory.eINSTANCE.createGenCustomAction();
    GenCustomAction a2 = GMFGenFactory.eINSTANCE.createGenCustomAction();
    GenCustomAction a3 = GMFGenFactory.eINSTANCE.createGenCustomAction();
    a1.setGenerateBoilerplate(false);
    a2.setGenerateBoilerplate(true);
    a3.setGenerateBoilerplate(true);
    a1.setQualifiedClassName("org.sample.actions.Action1");
    a2.setQualifiedClassName("org.sample.actions.Action2");
    a3.setQualifiedClassName("org.sample.actions.Action3");
    a1.setName("testaction-1");
    a2.setName("testaction-2");
    a3.setName("testaction-3");
    GenMenuManager subMenu = GMFGenFactory.eINSTANCE.createGenMenuManager();
    subMenu.setID("org.sample.submenu");
    GenGroupMarker gm = GMFGenFactory.eINSTANCE.createGenGroupMarker();
    gm.setGroupName("group.name");
    GenCommandAction cmdAction = GMFGenFactory.eINSTANCE.createGenCommandAction();
    cmdAction.setCommandIdentifier("org.sample.command");
    subMenu.getItems().add(a3);
    subMenu.getItems().add(gm);
    subMenu.getItems().add(cmdAction);
    menu.getItems().add(a1);
    menu.getItems().add(GMFGenFactory.eINSTANCE.createGenSeparator());
    menu.getItems().add(a2);
    menu.getItems().add(subMenu);
    editorGen.getContextMenus().clear(); // make sure there's no other (default) menus
    editorGen.getContextMenus().add(menu);
    //
    generateAndCompile(s);
    //
    IProject generatedProject =
        ResourcesPlugin.getWorkspace().getRoot().getProject(editorGen.getPlugin().getID());
    IFile generatedManifest = generatedProject.getFile("plugin.xml");
    assertTrue(generatedManifest.exists());
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document parsedManifest = db.parse(new InputSource(generatedManifest.getContents()));
    XPath xf = XPathFactory.newInstance().newXPath();
    XPathExpression xe =
        xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution");
    NodeList result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(
        2, result.getLength()); // one contribution to global context menu and another for submenu
    String l1 = result.item(0).getAttributes().getNamedItem("locationURI").getNodeValue();
    String l2 = result.item(1).getAttributes().getNamedItem("locationURI").getNodeValue();
    assertEquals(l1, "popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu");
    assertEquals(l2, "popup:" + subMenu.getID());
    //
    xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/menu");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(1, result.getLength());
    String menuIdAttr = result.item(0).getAttributes().getNamedItem("id").getNodeValue();
    assertEquals(subMenu.getID(), menuIdAttr);
    //
    xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/command");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(4, result.getLength());
    // FIXME assert command contribution goes into correct locationURI
    //
    xe =
        xf.compile("/plugin/extension[@point = 'org.eclipse.ui.menus']/menuContribution/separator");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(2, result.getLength());
    //
    xe =
        xf.compile(
            "/plugin/extension[@point = 'org.eclipse.ui.commands']/command[starts-with(@name,'testaction-')]");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(3, result.getLength());
    //
    xe = xf.compile("/plugin/extension[@point = 'org.eclipse.ui.handlers']/handler");
    result = (NodeList) xe.evaluate(parsedManifest, XPathConstants.NODESET);
    assertEquals(3, result.getLength());
    String h1 = result.item(0).getAttributes().getNamedItem("class").getNodeValue();
    String h2 = result.item(1).getAttributes().getNamedItem("class").getNodeValue();
    String h3 = result.item(2).getAttributes().getNamedItem("class").getNodeValue();
    assertEquals(a1.getQualifiedClassName(), h1);
    assertEquals(a2.getQualifiedClassName(), h2);
    assertEquals(a3.getQualifiedClassName(), h3);

    // check real files for handlers
    IFile file_a1 =
        generatedProject.getFile("/src/" + a1.getQualifiedClassName().replace('.', '/') + ".java");
    IFile file_a2 =
        generatedProject.getFile("/src/" + a2.getQualifiedClassName().replace('.', '/') + ".java");
    IFile file_a3 =
        generatedProject.getFile("/src/" + a3.getQualifiedClassName().replace('.', '/') + ".java");
    assertFalse(file_a1.exists());
    assertTrue(file_a2.exists());
    assertTrue(file_a3.exists());
  }