// 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"); }