Java Code Examples for org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem#getNode()

The following examples show how to use org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem#getNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtBotTreeActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a tree that contains an entry with <code>itemName</code> and a direct child with a name
 * matching <code>subchildName</code>, return its tree item.
 *
 * This method is useful when there is the possibility of a tree having two similarly-named
 * top-level nodes.
 *
 * @param mainTree the tree
 * @param itemName the name of a top-level node in the tree
 * @param subchildName the name of a direct child of the top-level node (used to uniquely select
 *        the appropriate tree item for the given top-level node name)
 * @return the tree item corresponding to the top-level node with <code>itemName</code>that has a
 *         direct child with <code>subchildName</code>. If there are multiple tree items that
 *         satisfy this criteria, then the first one (in the UI) will be returned
 *
 * @throws IllegalStateException if no such node can be found
 */
public static SWTBotTreeItem getUniqueTreeItem(final SWTBot bot, final SWTBotTree mainTree,
    String itemName, String subchildName) {
  for (SWTBotTreeItem item : mainTree.getAllItems()) {
    if (itemName.equals(item.getText())) {
      try {
        item.expand();
        SwtBotTreeActions.waitUntilTreeHasText(bot, item);
        if (item.getNode(subchildName) != null) {
          return item;
        }
      } catch (WidgetNotFoundException e) {
        // Ignore
      }
    }
  }

  throw new IllegalStateException("The '" + itemName + "' node with a child of '" + subchildName
      + "' must exist in the tree.");
}
 
Example 2
Source File: ConditionHelpers.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Is the treeItem's node available
 *
 * @param name
 *            the name of the node
 * @param treeItem
 *            the treeItem
 * @return ICondition for verification
 */
public static ICondition isTreeChildNodeAvailable(final String name, final SWTBotTreeItem treeItem) {
    return new SWTBotTestCondition() {
        @Override
        public boolean test() throws Exception {
            try {
                return treeItem.getNode(name) != null;
            } catch (Exception e) {
            }
            return false;
        }

        @Override
        public String getFailureMessage() {
            return NLS.bind("No child of tree item {0} found with text ''{1}''. Child items: {2}",
                    new String[] { treeItem.toString(), name, Arrays.toString(treeItem.getItems()) });
        }
    };
}
 
Example 3
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Select a file/folder by providing a parent tree, and a list folders that lead to the
 * file/folder.
 *
 * @param item Root tree item.
 * @param folderPath List of folder names that lead to file.
 * @return Returns a SWTBotTreeItem of the last name in texts.
 */
public static SWTBotTreeItem selectProjectItem(SWTBotTreeItem item, String... folderPath) {
  for (String folder : folderPath) {
    if (item == null) {
      return null;
    }
    item.doubleClick();
    item = item.getNode(folder);
  }
  return item;
}
 
Example 4
Source File: ProjectExplorerAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static Set<AnalysisNode> getAnalysisNodes(SWTWorkbenchBot bot, String name, boolean isExperiment) {
    SWTBotTreeItem traceNode = getExpandedTraceNode(bot, name, isExperiment);
    SWTBotTreeItem viewNode = traceNode.getNode("Views");
    viewNode.expand();

    SWTBotTreeItem[] analysisNodes = viewNode.getItems();
    assertNotNull(analysisNodes);
    int length = analysisNodes.length;
    Set<AnalysisNode> actualNodes = new HashSet<>();
    for (int i = 0; i < length; i++) {
        SWTBotTreeItem analysisNode = analysisNodes[i];
        actualNodes.add(new AnalysisNode(analysisNode.getText(), analysisNode.isEnabled(), analysisNode.isVisible()));
    }
    return actualNodes;
}
 
Example 5
Source File: ProjectExplorerTraceActionsTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test that deleting a trace from an experiment: deletes the experiment if the
 * experiment is empty and deletes the trace from the Traces folder.
 */
@Test
public void test4_11DeleteTraceFromExperiment() {
    /*
     * close the editor for the trace to avoid name conflicts with the one for the
     * experiment
     */
    fBot.closeAllEditors();

    // create experiment
    SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
    traceItem.contextMenu().menu("Open As Experiment...", "Generic Experiment").click();
    fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME));

    // find the trace under the experiment
    fBot.viewByTitle(PROJECT_EXPLORER_VIEW_NAME).setFocus();
    SWTBotTreeItem experimentsItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME), "Experiments");
    experimentsItem.expand();
    fBot.waitUntil(ConditionHelpers.isTreeChildNodeAvailable("ExampleCustomTxt.log [1]", experimentsItem));
    SWTBotTreeItem expItem = SWTBotUtils.getTraceProjectItem(fBot, experimentsItem, "ExampleCustomTxt.log [1]");
    expItem.expand();
    SWTBotTreeItem expTrace = expItem.getNode(TRACE_NAME);

    // delete it
    expTrace.contextMenu("Delete").click();
    SWTBotShell shell = fBot.shell("Confirm Delete").activate();
    shell.bot().button("Yes").click();
    fBot.waitUntil(Conditions.shellCloses(shell), DISK_ACCESS_TIMEOUT);
    fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));

    // ensure that it is properly deleted from places.
    SWTBotUtils.waitUntil(exp -> exp.getItems().length == 0, experimentsItem,
            "Failed to delete the trace from the experiment");
    fBot.waitUntil(new TraceDeletedCondition());
}
 
Example 6
Source File: SWTBotImportWizardUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * While in the import wizard, select an item in the file selection control.
 * The item can be a folder in the left tree or a file in the right table.
 * The item will be checked.
 *
 * @param bot
 *            the SWTBot
 * @param treePath
 *            the path to the item, ending with a file or folder
 */
public static void selectItem(SWTBot bot, String... treePath) {
    SWTBotTree tree = bot.tree();
    bot.waitUntil(Conditions.widgetIsEnabled(tree));
    if (treePath.length == 0) {
        return;
    }
    if (treePath.length == 1) {
        SWTBotTreeItem rootNode = SWTBotUtils.getTreeItem(bot, tree, treePath);
        rootNode.select();
        rootNode.check();
        return;
    }
    String[] parentPath = Arrays.copyOf(treePath, treePath.length - 1);
    String itemName = treePath[treePath.length - 1];
    SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(bot, tree, parentPath);
    folderNode.expand();
    if (folderNode.getNodes().contains(itemName)) {
        folderNode = folderNode.getNode(itemName);
        folderNode.select();
        folderNode.check();
    } else {
        folderNode.select();
        SWTBotTable fileTable = bot.table();
        bot.waitUntil(Conditions.widgetIsEnabled(fileTable));
        bot.waitUntil(ConditionHelpers.isTableItemAvailable(itemName, fileTable));
        SWTBotTableItem tableItem = fileTable.getTableItem(itemName);
        tableItem.check();
    }
}
 
Example 7
Source File: TraceTypePreferencePageTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static SWTBotShell openTraceTypePreferences() {
    SWTBotShell preferencesShell = SWTBotUtils.openPreferences(fBot);
    SWTBot bot = preferencesShell.bot();
    SWTBotTree tree = bot.tree(0);
    SWTBotTreeItem treeNode = tree.getTreeItem("Tracing");
    treeNode.select();
    treeNode.expand();
    bot.waitUntil(ConditionHelpers.isTreeChildNodeAvailable("Trace Types", treeNode));
    treeNode = treeNode.getNode("Trace Types");
    treeNode.select();
    return preferencesShell;
}
 
Example 8
Source File: TraceTypePreferencePageTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static List<String> getSelectTraceTypeMenuItems() {
    SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
    tracesFolder.expand();
    SWTBotTreeItem trace = tracesFolder.getNode("syslog_collapse");
    trace.select();
    List<String> menuItems = trace.contextMenu().menu("Select Trace Type...").menuItems();
    return menuItems;
}
 
Example 9
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the tree item from a parent tree item at the specified location
 *
 * @param bot
 *            the SWTBot
 * @param treeItem
 *            the treeItem to find the tree item under
 * @param nodeNames
 *            the path to the tree item, in the form of node names (from
 *            parent to child).
 * @return the tree item
 */
public static SWTBotTreeItem getTreeItem(SWTBot bot, SWTBotTreeItem treeItem, String... nodeNames) {
    if (nodeNames.length == 0) {
        return treeItem;
    }

    SWTBotTreeItem currentNode = treeItem;
    for (int i = 0; i < nodeNames.length; i++) {
        bot.waitUntil(ConditionHelpers.treeItemHasChildren(treeItem));
        currentNode.expand();

        String nodeName = nodeNames[i];
        try {
            bot.waitUntil(ConditionHelpers.isTreeChildNodeAvailable(nodeName, currentNode));
        } catch (TimeoutException e) {
            // FIXME: Sometimes in a JFace TreeViewer, it expands to
            // nothing. Need to find out why.
            currentNode.collapse();
            currentNode.expand();
            bot.waitUntil(ConditionHelpers.isTreeChildNodeAvailable(nodeName, currentNode));
        }

        SWTBotTreeItem newNode = currentNode.getNode(nodeName);
        currentNode = newNode;
    }

    return currentNode;
}
 
Example 10
Source File: FetchRemoteTracesTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static SWTBotTreeItem getTreeItem(SWTWorkbenchBot bot, SWTBotTree tree, String... nodeNames) {
    if (nodeNames.length == 0) {
        return null;
    }

    SWTBotTreeItem currentNode = tree.getTreeItem(nodeNames[0]);
    for (int i = 1; i < nodeNames.length; i++) {
        String nodeName = nodeNames[i];
        bot.waitUntil(ConditionHelpers.isTreeChildNodeAvailable(nodeName, currentNode));
        SWTBotTreeItem newNode = currentNode.getNode(nodeName);
        currentNode = newNode;
    }

    return currentNode;
}
 
Example 11
Source File: BotBdmModelEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public BotBdmModelEditor selectBusinessObject(String packageName, String businessObject) {
    SWTBotTreeItem packageItem = getBusinessObjectTree().getTreeItem(packageName);
    if (!packageItem.isExpanded()) {
        packageItem.expand();
    }
    SWTBotTreeItem node = packageItem.getNode(businessObject);
    if (!node.isSelected()) {
        node.select();
    }
    return this;
}
 
Example 12
Source File: BotBdmConstraintsEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void selectBusinessObject(String packageName, String businessObject) {
    SWTBotTreeItem packageItem = getBusinessObjectTree().getTreeItem(packageName);
    if(!packageItem.isExpanded()) {
        packageItem.expand();
    }
    SWTBotTreeItem node = packageItem.getNode(businessObject);
    if(!node.isSelected()) {
        node.select();
    }
}
 
Example 13
Source File: RenameSpecHandlerTest.java    From tlaplus with MIT License 5 votes vote down vote up
private SWTBotTreeItem checkForModelExistenceUI(final SWTBotTreeItem treeItem) {
	try {
		treeItem.expand();
		SWTBotTreeItem models = treeItem.getNode("models");
		models.expand();
		return models.getNode(TEST_MODEL).select();
	} catch(AssertionFailedException e) {
		Assert.fail(e.getMessage());
	}
	return null;
}
 
Example 14
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Expands the node matching the given node texts.
 * The method is copied from SWTBotTreeItem with an additional check if the node is already expanded.
 *
 * @param bot
 *          tree item bot, must not be {@code null}
 * @param nodes
 *          the text on the node, must not be {@code null} or empty
 * @return the last tree node that was expanded, never {@code null}
 */
public static SWTBotTreeItem expandNode(final SWTBotTreeItem bot, final String... nodes) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(nodes, ARGUMENT_NODES);
  assertArgumentIsNotEmpty(nodes, ARGUMENT_NODES);
  SWTBotTreeItem item = bot;
  for (String node : nodes) {
    item = item.getNode(node);
    if (!item.isExpanded()) {
      item.expand();
    }
  }
  return item;
}
 
Example 15
Source File: ProjectExplorerAppEngineBlockTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppEngineStandardJava8() {
  IProject project =
      projectCreator
          .withFacets(
              AppEngineStandardFacet.FACET.getVersion("JRE8"),
              JavaFacet.VERSION_1_8,
              WebFacetUtils.WEB_31)
          .getProject();
  SWTBotView explorer = SwtBotWorkbenchActions.openViewById(bot, IPageLayout.ID_PROJECT_EXPLORER);
  assertNotNull(explorer);
  SWTBotTreeItem selected = SwtBotProjectActions.selectProject(bot, explorer, project.getName());
  assertNotNull(selected);
  selected.expand();

  SwtBotTreeUtilities.waitUntilTreeHasItems(bot, selected);
  SWTBotTreeItem appEngineNode = selected.getNode(0);
  SwtBotTreeUtilities.waitUntilTreeTextMatches(
      bot, appEngineNode, startsWith("App Engine [standard: java8]"));
  appEngineNode.expand();
  // no children since we have no additional config files
  assertThat(appEngineNode.getNodes(), hasSize(0));

  // ensure App Engine content block does not appear in Deployment Descriptor
  SWTBotTreeItem deploymentDescriptorNode =
      SwtBotTreeUtilities.getMatchingNode(bot, selected, startsWith("Deployment Descriptor:"));
  deploymentDescriptorNode.expand();
  SwtBotTreeUtilities.waitUntilTreeHasItems(bot, deploymentDescriptorNode);
  SWTBotTreeItem firstNode = deploymentDescriptorNode.getNode(0);
  SwtBotTreeUtilities.waitUntilTreeTextMatches(bot, firstNode, not(startsWith("App Engine")));
}
 
Example 16
Source File: ResourcesAndCpuViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Simple test to check the CPU Usage view after getting signals.
 */
@Test
public void testCpuView() {
    IViewPart viewPart = getSWTBotView().getViewReference().getView(true);
    assertTrue(viewPart instanceof CpuUsageView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    final Chart chart = getChart();
    assertNotNull(chart);

    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 0, chart, "No data available");
    chartViewer.setNbPoints(10);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    /* Test data model */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json), "resources/cpuusage/cpu-usage-res10.json", "Chart data is not valid");

    /* Test chart style */
    verifySeriesStyle(TOTAL_SERIES_NAME, ISeries.SeriesType.LINE, BLUE, LineStyle.SOLID, false);

    /* Select a thread */
    SWTBotTreeItem rootEntry = getSWTBotView().bot().tree().getTreeItem(TRACE_NAME);
    SWTBotUtils.waitUntil(tree -> getTableCount() >= 8, rootEntry, "Did not finish loading");
    SWTBotTreeItem selectedTheadNode = rootEntry.getNode(SELECTED_THREAD);
    selectedTheadNode.check();
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 2, chart, "Only total available");

    /* Test data model */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, SELECTED_THREAD_SERIES), "resources/cpuusage/cpu-usage-res10Selected.json", "Chart data is not valid");

    /* Test chart style */
    verifySeriesStyle(SELECTED_THREAD_SERIES, ISeries.SeriesType.LINE, RED, LineStyle.SOLID, true);
    selectedTheadNode.uncheck();

    /* Selected an another thread and test in HD */
    String otherSelectedThread = "lttng-consumerd";
    SWTBotTreeItem otherSelectedThreadNode = rootEntry.getNode(otherSelectedThread);
    otherSelectedThreadNode.check();
    chartViewer.setNbPoints(100);
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 2, chart, "Only total available");
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    /* Test data model */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, OTHERTHREAD_SERIES), "resources/cpuusage/cpu-usage-res100Selected.json", "Chart data is not valid");

    /* Test chart style */
    verifySeriesStyle(OTHERTHREAD_SERIES, ISeries.SeriesType.LINE, GREEN, LineStyle.SOLID, true);

    /*
     * Test new TimeRange
     */
    chartViewer.setNbPoints(10);
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 2, chart, "Only total available");
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
    assertNotNull(activeTrace);
    fResourcesViewBot.getToolbarButtons().stream().filter(button -> button.getToolTipText().contains(RESET)).findAny().get().click();
    fBot.waitUntil(ConditionHelpers.windowRange(new TmfTimeRange(TRACE_START, TRACE_END)));
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 2, chart, "Only total available");
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    /* Test data model */
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, OTHERTHREAD_SERIES), "resources/cpuusage/cpu-usage-all-res10.json", "Chart data is not valid");

    /* Test chart style */
    verifySeriesStyle(OTHERTHREAD_SERIES, ISeries.SeriesType.LINE, GREEN, LineStyle.SOLID, true);
}
 
Example 17
Source File: KernelMemoryUsageViewTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Simple test to check the Kernel Memory Usage view data model
 */
@Test
public void testKernelMemoryView() {
    IViewPart viewPart = getSWTBotView().getViewReference().getView(true);
    assertTrue(viewPart instanceof KernelMemoryUsageView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    final Chart chart = getChart();
    assertNotNull(chart);
    chartViewer.setNbPoints(NUMBER_OF_POINT);

    SWTBotTree treeBot = getSWTBotView().bot().tree();
    SWTBotTreeItem totalNode = treeBot.getTreeItem(fTraceName);
    SWTBotUtils.waitUntil(root -> root.getItems().length >= 5, totalNode, "Did not finish loading");

    /*
     * Select the total entry, which should be the first entry with an empty pid
     * column.
     */
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 1, chart, "No data available");

    /* Test type, style and color of series */
    verifySeriesStyle(TOTAL_PID, ISeries.SeriesType.LINE, BLUE, LineStyle.SOLID, false);

    /* Test data model*/
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json), "resources/kernelmemory/kernel-memory-res50.json", "Chart data is not valid");

    /*
     * Select a thread
     */
    SWTBotTreeItem sessiondEntry = totalNode.getNode("lttng-sessiond");
    sessiondEntry.check();
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 2, chart, "Only total available");

    /* Test type, style and color of series */
    verifySeriesStyle(SESSIOND_PID, ISeries.SeriesType.LINE, RED, LineStyle.SOLID, false);

    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, SESSIOND_PID), "resources/kernelmemory/kernel-memory-res50Selected.json", "Chart data is not valid");

    /*
     * Select an another thread and change zoom
     */
    SWTBotTreeItem consumerdEntry = totalNode.getNode("lttng-consumerd");
    consumerdEntry.check();
    chartViewer.setNbPoints(MORE_POINTS);
    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length >= 3, chart, "Only total and sessiond available");

    /* Test type, style and color of series */
    verifySeriesStyle(CONSUMERD_PID, ISeries.SeriesType.LINE, GREEN, LineStyle.SOLID, false);

    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, CONSUMERD_PID), "resources/kernelmemory/kernel-memory-res100Selected.json", "Chart data is not valid");
}
 
Example 18
Source File: ProjectExplorerBot.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected SWTBotTreeItem getTreeItem(SWTBotTreeItem parent, String item) {
    parent.expand();
    bot.waitUntil(nodeAvailable(parent, item));
    return parent.getNode(item);
}
 
Example 19
Source File: BarExporterTest.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testServerBuild() {

    SWTBotTestUtil.createNewDiagram(bot);
    final SWTBotEditor activeEditor = bot.activeEditor();
    final String editorTitle = activeEditor.getTitle();
    assertFalse("Error: first diagram name is empty.", editorTitle.isEmpty());

    final BotExecutionDiagramPropertiesView executionTab = new BotProcessDiagramPropertiesViewFolder(bot)
            .selectExecutionTab();
    executionTab.selectInstantiationFormTab().selectNone();
    new BotGefProcessDiagramEditor(bot).selectElement("Step1");
    executionTab.selectFormTab().selectNone();

    // get the GEF editor to activate tools
    final SWTBotGefEditor gmfEditor = bot.gefEditor(editorTitle);

    // Create 2 Pools
    gmfEditor.activateTool("Pool");
    gmfEditor.click(200, 500);

    new BotProcessDiagramPropertiesViewFolder(bot).selectExecutionTab().selectInstantiationFormTab().selectNone();

    gmfEditor.activateTool("Pool");
    gmfEditor.click(200, 800);

    new BotProcessDiagramPropertiesViewFolder(bot).selectExecutionTab().selectInstantiationFormTab().selectNone();

    // Save Diagram
    bot.menu("File").menu("Save").click();
    bot.waitUntil(BonitaBPMConditions.noPopupActive());

    // Menu Server > Build...
    bot.menu("Server").menu("Build...").click();

    // shell 'Build'
    final SWTBotShell shell = bot.shell(Messages.buildTitle);
    bot.waitUntil(Conditions.shellIsActive(Messages.buildTitle));

    // select and check created Diagram in the Tree
    final SWTBotTree tree = bot.treeWithLabel("Select processes to export");
    final SWTBotTreeItem diagramTreeItem = tree.getTreeItem(editorTitle);

    // check the diagram to export
    diagramTreeItem.select().check();
    diagramTreeItem.expand();

    // Number of pool in the diagram
    final int poolListSize = diagramTreeItem.getItems().length;
    assertEquals("Error: Diagram must contain 3 Pools.", 3, poolListSize);

    // unselect the first pool of the list

    diagramTreeItem.getNode(0).select();
    diagramTreeItem.getNode(0).uncheck();

    final List<String> poolTitleList = new ArrayList<>(3);
    final int poolTitleListSize = poolTitleList.size();

    // check the selected pools
    for (int i = 1; i < poolTitleListSize; i++) {
        final SWTBotTreeItem poolTreeItem = diagramTreeItem.getNode(i);
        poolTitleList.set(i, poolTreeItem.getText());
        final String poolName = getItemName(poolTitleList.get(i));

        // test the good pool is checked
        assertFalse("Error: Pool " + i + " should be checked.", !poolTreeItem.isChecked());
        assertFalse("Error: Pool selected is not the good one.", !poolName.equals("Pool" + i));
    }
    // create tmp directory to write diagrams
    final File tmpBarFolder = new File(ProjectUtil.getBonitaStudioWorkFolder(), "testExportBar");
    tmpBarFolder.deleteOnExit();
    tmpBarFolder.mkdirs();
    //set the path where files are saved
    final String tmpBarFolderPath = tmpBarFolder.getAbsolutePath();
    bot.comboBoxWithLabel(Messages.destinationPath + " *").setText(tmpBarFolderPath);

    // click 'Finish' button to close 'Build' shell
    bot.waitUntil(Conditions.widgetIsEnabled(bot.button(IDialogConstants.FINISH_LABEL)));
    bot.button(IDialogConstants.FINISH_LABEL).click();

    //  click 'OK' button to close 'Export' shell
    bot.waitUntil(new ShellIsActiveWithThreadSTacksOnFailure(Messages.exportSuccessTitle), 10000);
    bot.button(IDialogConstants.OK_LABEL).click();

    // wait the shell to close before checking creation of files
    bot.waitUntil(Conditions.shellCloses(shell));

    // check pools files exist
    for (int i = 1; i < poolTitleListSize; i++) {
        final String tmpPoolTitle = poolTitleList.get(i);
        final String poolFileName = getItemName(tmpPoolTitle) + "--" + getItemVersion(tmpPoolTitle) + ".bar";
        final File poolFile = new File(tmpBarFolderPath, poolFileName);
        poolFile.deleteOnExit();
        assertTrue("Error: The Pool export must exist", poolFile.exists());
        assertTrue("Error: The Pool export must be a file", poolFile.isFile());
    }
}
 
Example 20
Source File: ProjectExplorerTraceActionsTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test the backward compatibility
 */
@Test
public void testExperimentLinkBackwardCompatibility() {
    /*
     * close the editor for the trace to avoid name conflicts with the one for the
     * experiment
     */
    fBot.closeAllEditors();

    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    final IProject project = root.getProject(TRACE_PROJECT_NAME);
    assertTrue(project.exists());
    TmfProjectElement projectElement = TmfProjectRegistry.getProject(project);

    // Get the experiment folder
    TmfExperimentFolder experimentsFolder = projectElement.getExperimentsFolder();
    assertNotNull("Experiment folder should exist", experimentsFolder);
    IFolder experimentsFolderResource = experimentsFolder.getResource();
    String experimentName = "exp";
    IFolder expFolder = experimentsFolderResource.getFolder(experimentName);
    assertFalse(expFolder.exists());

    // Create the experiment
    try {
        expFolder.create(true, true, null);
        IFile file = expFolder.getFile(TRACE_NAME);
        file.createLink(Path.fromOSString(fTestFile.getAbsolutePath()), IResource.REPLACE, new NullProgressMonitor());
    } catch (CoreException e) {
        fail("Failed to create the experiment");
    }

    fBot.viewByTitle(PROJECT_EXPLORER_VIEW_NAME).setFocus();
    SWTBotTreeItem experimentsItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME), "Experiments");

    SWTBotTreeItem expItem = SWTBotUtils.getTraceProjectItem(fBot, experimentsItem, "exp");

    // find the trace under the experiment
    expItem.expand();
    expItem.getNode(TRACE_NAME);

    // Open the experiment
    expItem.contextMenu().menu("Open").click();
    fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, experimentName));
}