Search in sources :

Example 6 with SWTBotTreeItem

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem in project linuxtools by eclipse.

the class TestCreateSystemtapScript method testTapsetContents.

@Test
public void testTapsetContents() {
    // Create a blank script and add a function to it while it's open.
    String scriptName = "probeScript.stp";
    createScript(bot, scriptName);
    SWTBotView funcView = bot.viewByTitle("Function");
    funcView.setFocus();
    SWTBotTree funcTree = funcView.bot().tree();
    SWTBotTreeItem item = funcTree.getTreeItem(funcNodeName);
    item.doubleClick();
    SWTBotEclipseEditor editor = bot.activeEditor().toTextEditor();
    assertTrue(editor.getText().contains(item.getText()));
    // Open a non-stap file and add a probe. This should bring up a dialog
    // asking if the function should be added to the only open .stp file.
    clickMainMenu("File", "New", "Other...");
    SWTBotShell shell = bot.shell("New");
    shell.setFocus();
    shell.bot().text().setText("Untitled Text File");
    bot.waitUntil(new NodeAvailableAndSelect(bot.tree(), "General", "Untitled Text File"));
    bot.button("Finish").click();
    bot.waitUntil(Conditions.shellCloses(shell));
    SWTBotView probeView = bot.viewByTitle("Probe Alias");
    probeView.setFocus();
    SWTBotTree probeTree = probeView.bot().tree();
    SWTBotTreeItem probeCategory = probeTree.getTreeItem(probeCategoryFull);
    probeCategory.expand();
    bot.waitUntil(new TreeItemPopulated(probeCategory));
    String dialogTitle = "Select Script";
    item = probeCategory.getNode(probeGroup);
    item.expand();
    bot.waitUntil(new TreeItemPopulated(item));
    item = item.getNode(0);
    item.doubleClick();
    {
        Matcher<Shell> withText = withText(dialogTitle);
        bot.waitUntil(Conditions.waitForShell(withText));
    }
    shell = bot.shell(dialogTitle);
    shell.setFocus();
    bot.button("Yes").click();
    bot.waitUntil(Conditions.shellCloses(shell));
    // The editor containing the script should now be in focus.
    bot.waitUntil(new EditorIsActive(scriptName));
    assertTrue(wasProbeInserted(editor, item, false));
    // Open the probe's definition file (an .stp script).
    probeView.show();
    item.contextMenu("View Definition").click();
    bot.waitUntil(new EditorIsActive(probeDef.getName()));
    // Adding a probe while an .stp editor is in focus should always add it
    // to that editor, even if multiple .stp editors are open.
    item = probeCategory.getNode(probeGroup);
    item.doubleClick();
    assertTrue(wasProbeInserted(bot.activeEditor().toTextEditor(), item, true));
    assertFalse(wasProbeInserted(editor, item, true));
    // Switch to the non-stp editor, and add a probe. A dialog should appear
    // to let the user choose which of the open files to add to.
    editor = bot.editorByTitle("Untitled 1").toTextEditor();
    editor.show();
    item = probeCategory.getNode(probeSingleWithoutDef);
    item.doubleClick();
    shell = bot.shell(dialogTitle);
    shell.setFocus();
    SWTBotTable table = bot.table();
    assertTrue(table.containsItem(scriptName));
    assertTrue(table.containsItem(probeDef.getName()));
    table.select(scriptName);
    bot.button("OK").click();
    bot.waitUntil(Conditions.shellCloses(shell));
    bot.waitUntil(new EditorIsActive(scriptName));
    assertTrue(wasProbeInserted(bot.activeEditor().toTextEditor(), item, false));
}
Also used : SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) Matcher(org.hamcrest.Matcher) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Test(org.junit.Test)

Example 7 with SWTBotTreeItem

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem in project linuxtools by eclipse.

the class TestCreateSystemtapScript method wasProbeInserted.

private static boolean wasProbeInserted(SWTBotEclipseEditor editor, SWTBotTreeItem probeNode, boolean isGroup) {
    String scriptText = editor.getText();
    int entryIndex = scriptText.indexOf("probe " + probeNode.getText() + (isGroup ? ".*\n" : "\n"));
    if (entryIndex == -1) {
        return false;
    }
    String probeText = scriptText.substring(entryIndex);
    if (!isGroup) {
        SWTBotTreeItem[] variables = probeNode.getItems();
        if (variables.length > 0) {
            // If the probe has variables, each one should be mentioned in comments.
            for (SWTBotTreeItem variable : probeNode.getItems()) {
                if (!probeText.contains(variable.getText())) {
                    return false;
                }
            }
        } else if (probeText.contains("variables")) {
            // If the probe has no variables, no mention of variables should be added in comments.
            return false;
        }
    }
    return true;
}
Also used : SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Point(org.eclipse.swt.graphics.Point)

Example 8 with SWTBotTreeItem

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem in project linuxtools by eclipse.

the class AddChangelogEntrySWTBotTest method canAddChangeLogEntryUsingEditMenuIfSourceIsActive.

/**
 * ChangeLog editor should pop-up if inside an active editor
 * and a ChangeLog file exists in the project. Tests the "Edit" => "ChangeLog Entry"
 * menu item.
 *
 * @throws Exception
 */
@Test
public void canAddChangeLogEntryUsingEditMenuIfSourceIsActive() throws Exception {
    // Add a Java source file
    String sourceCode = "package src;\n" + "public class JavaTest {\n" + "public static void main(String args[]) {\n" + "//" + OFFSET_MARKER + "\n" + "System.out.println(\"Hello World!\");\n" + "}\n" + "}\n";
    assertNull(project.getTestProject().findMember(new Path("/src/JavaTest.java")));
    InputStream newFileInputStream = new ByteArrayInputStream(sourceCode.getBytes());
    project.addFileToProject("/src", "JavaTest.java", newFileInputStream);
    // Add a changelog file
    newFileInputStream = new ByteArrayInputStream("".getBytes());
    project.addFileToProject("/", "ChangeLog", newFileInputStream);
    assertNotNull(project.getTestProject().findMember(new Path("/src/JavaTest.java")));
    assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    // Open JavaTest.java in an editor
    SWTBotTreeItem projectItem = projectExplorerViewTree.expandNode(PROJECT_NAME);
    projectItem.expandNode("src").expandNode("JavaTest.java").doubleClick();
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("JavaTest.java"));
    // Wait for editor to open
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotEditor swtBoteditor = bot.editorByTitle("JavaTest.java");
    SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
    eclipseEditor.selectLine(getLineOfOffsetMarker(sourceCode));
    // Click menu item.
    bot.menu("Edit").menu("Insert ChangeLog entry").click();
    // Wait for ChangeLog editor to open
    editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("ChangeLog"));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    swtBoteditor = bot.activeEditor();
    // save to avoid "save changes"-pop-up
    swtBoteditor.save();
    assertEquals("ChangeLog", swtBoteditor.getTitle());
    eclipseEditor = swtBoteditor.toTextEditor();
    // make sure expected entry has been added.
    assertTrue(eclipseEditor.getText().contains("* src/JavaTest.java"));
}
Also used : Path(org.eclipse.core.runtime.Path) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) IEditorReference(org.eclipse.ui.IEditorReference) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Test(org.junit.Test)

Example 9 with SWTBotTreeItem

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem in project linuxtools by eclipse.

the class DisabledPrepareChangelogSWTBotTest method cannotPrepareChangeLogOnNonCVSOrSVNProject.

/**
 * If the project is not shared by any CVS or SVN team provider, "Prepare ChangeLog"
 * should be disabled.
 *
 * @throws Exception
 */
@Test
@Ignore
public void cannotPrepareChangeLogOnNonCVSOrSVNProject() throws Exception {
    assertNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    final String changeLogContent = "2010-12-08  Will Probe  <will@example.com>\n\n" + "\t* path/to/some/non-existing/file.c: New file.\n";
    project.addFileToProject("/", "ChangeLog", new ByteArrayInputStream(changeLogContent.getBytes()));
    assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    // select ChangeLog file
    String teamProviderString = "n/a";
    SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, projectName, teamProviderString);
    SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
    changeLogItem.select();
    long oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 100;
    try {
        // Should be disabled (throws exception)
        bot.menu("Prepare ChangeLog").click();
        fail("'Prepare ChangeLog' should be disabled");
    } catch (TimeoutException e) {
        assertTrue(e.getMessage().contains("The widget with mnemonic 'Prepare ChangeLog' was not enabled."));
    }
    SWTBotPreferences.TIMEOUT = oldTimeout;
}
Also used : Path(org.eclipse.core.runtime.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) TimeoutException(org.eclipse.swtbot.swt.finder.widgets.TimeoutException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with SWTBotTreeItem

use of org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem in project linuxtools by eclipse.

the class FormatChangeLogSWTBotTest method canFormatChangeLogFile.

/**
 * Simple test for ChangeLog formatting.
 *
 * @throws Exception
 */
@Test
public void canFormatChangeLogFile() throws Exception {
    // add a ChangeLog file
    assertNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    final String changelogContent = "2010-12-14  Severin Gehwolf  <sgehwolf@redhat.com>\n\n" + "\tAdded org.eclipse.linuxtools.changelog.tests.ui plug-in.\n" + "\t* .classpath: New file.\n" + "\t* .project: New file.\n" + "\t* .settings/org.eclipse.jdt.core.prefs: New file.\n" + "\t* build.properties: New file.\n" + "\t* src/log4j.xml: New file.\n" + "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ContextMenuHelper.java: New file.\n" + "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ProjectExplorer.java: New file.\n" + "\t* src/org/eclipse/linuxtools/changelog/tests/ui/utils/ProjectExplorerTreeItemAppearsCondition.java: New file.\n";
    project.addFileToProject("/", "ChangeLog", new ByteArrayInputStream(changelogContent.getBytes()));
    assertNotNull(project.getTestProject().findMember(new Path("/ChangeLog")));
    // select ChangeLog file
    String teamProviderString = "n/a";
    SWTBotTreeItem projectItem = ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString);
    long oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 5000;
    bot.waitUntil(new ProjectExplorerTreeItemAppearsCondition(projectExplorerViewTree, PROJECT_NAME, teamProviderString, "ChangeLog"));
    SWTBotPreferences.TIMEOUT = oldTimeout;
    SWTBotTreeItem changeLogItem = ProjectExplorer.getProjectItem(projectItem, "ChangeLog");
    // should open ChangeLog file
    changeLogItem.doubleClick();
    oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 3 * 5000;
    // Wait for ChangeLog editor to open
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("ChangeLog"));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotEditor swtBoteditor = bot.activeEditor();
    assertEquals("ChangeLog", swtBoteditor.getTitle());
    SWTBotEclipseEditor swtBotEclipseEditor = swtBoteditor.toTextEditor();
    // Add two extra lines after the first date line
    swtBotEclipseEditor.insertText(1, 0, "\n\n");
    // Should have 3 empty lines between date-line and first file entry
    swtBotEclipseEditor.selectRange(1, 0, 3);
    // format: ESC CTRL+F
    swtBotEclipseEditor.pressShortcut(Keystrokes.ESC);
    swtBotEclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("F"));
    swtBoteditor.save();
}
Also used : Path(org.eclipse.core.runtime.Path) SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) ProjectExplorerTreeItemAppearsCondition(org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition) IEditorReference(org.eclipse.ui.IEditorReference) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) Test(org.junit.Test)

Aggregations

SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)63 Test (org.junit.Test)38 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)20 DockerClient (com.spotify.docker.client.DockerClient)19 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)9 Path (org.eclipse.core.runtime.Path)7 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)7 IDockerConnectionStorageManager (org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager)6 SWTBotEclipseEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 SWTBotEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor)5 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)5 IEditorReference (org.eclipse.ui.IEditorReference)5 Ignore (org.junit.Ignore)5 IResource (org.eclipse.core.resources.IResource)4 File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 ProjectExplorerTreeItemAppearsCondition (org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition)3 TCPConnectionSettings (org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings)3 UnixSocketConnectionSettings (org.eclipse.linuxtools.internal.docker.core.UnixSocketConnectionSettings)2