Search in sources :

Example 16 with SWTBotEditor

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

the class AddChangelogEntrySWTBotTest method canAddChangeLogEntryUsingShortCutIfSourceIsActive.

/**
 * ChangeLog editor should pop-up if inside an active editor
 * and a ChangeLog file exists in the project. Tests the CTRL+ALT+c
 * shortcut.
 *
 * @throws Exception
 */
@Ignore
@Test
public void canAddChangeLogEntryUsingShortCutIfSourceIsActive() throws Exception {
    // Add a Java source file
    System.out.println(name.getMethodName());
    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
    projectExplorerViewTree.expandNode(PROJECT_NAME).expandNode("src").expandNode("JavaTest.java").doubleClick();
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName("JavaTest.java"));
    // Wait for Java editor to open
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotEditor swtBoteditor = bot.editorByTitle("JavaTest.java");
    SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
    eclipseEditor.selectLine(getLineOfOffsetMarker(sourceCode));
    // Press: CTRL + ALT + c
    eclipseEditor.pressShortcut(Keystrokes.CTRL, Keystrokes.ALT, KeyStroke.getInstance("c"));
    // 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with SWTBotEditor

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

the class CreateChangeLogFromHistorySWTBotTest method canPrepareChangeLogFromSVNHistory.

/**
 * Create changelog from SVN history (commit messages).
 *
 * @throws Exception
 */
@Test
@Ignore
public void canPrepareChangeLogFromSVNHistory() throws Exception {
    // select ChangeLog file
    String teamProviderString = "[changelog/trunk/" + PROJECT_NAME + "]";
    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");
    changeLogItem.select();
    // open history for ChangeLog file
    clickOnShowHistory(projectExplorerViewTree);
    SWTBot historyViewBot = bot.viewByTitle("History").bot();
    // wait for SVN revision table to appear
    oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = 3 * 5000;
    historyViewBot.waitUntil(new TableAppearsCondition());
    SWTBotPreferences.TIMEOUT = oldTimeout;
    SWTBotTable historyTable = historyViewBot.table();
    // select the first row
    historyTable.select(0);
    // right-click => Generate Changelog...
    clickOnGenerateChangeLog(historyTable);
    SWTBotShell shell = bot.shell("Generate ChangeLog").activate();
    SWTBot generateChangelogBot = shell.bot();
    generateChangelogBot.radio("Clipboard").click();
    generateChangelogBot.button("OK").click();
    // create and open a new file for pasting
    String pasteFile = "newFile";
    IFile newFile = project.getFile(new Path(pasteFile));
    newFile.create(new ByteArrayInputStream("".getBytes()), /* empty content */
    false, null);
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    assertNotNull(project.findMember(new Path(pasteFile)));
    ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString).expandNode(pasteFile).select().doubleClick();
    Matcher<IEditorReference> editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName(pasteFile));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    oldTimeout = SWTBotPreferences.TIMEOUT;
    SWTBotPreferences.TIMEOUT = oldTimeout;
    SWTBotEditor swtBoteditor = bot.activeEditor();
    assertEquals(pasteFile, swtBoteditor.getTitle());
    SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
    // go to beginning of editor
    eclipseEditor.selectRange(0, 0, 0);
    // paste
    eclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("V"));
    swtBoteditor.save();
    // make sure some changelog like text was pasted
    String text = eclipseEditor.getText();
    assertFalse(text.isEmpty());
}
Also used : Path(org.eclipse.core.runtime.Path) ProjectExplorerTreeItemAppearsCondition(org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition) IFile(org.eclipse.core.resources.IFile) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) TableAppearsCondition(org.eclipse.linuxtools.changelog.ui.tests.utils.TableAppearsCondition) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) 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) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with SWTBotEditor

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

the class PrepareChangelogSWTBotTest method canPrepareChangeLogAndSaveChangesInChangeLogFileToClipboard.

/**
 * Should be able to save changes to ChangeLog file in clipboard.
 * Tests CTRL + ALT + V functionality.
 *
 * @throws Exception
 */
@Test
@Ignore
public void canPrepareChangeLogAndSaveChangesInChangeLogFileToClipboard() throws Exception {
    // Find manifest file
    IResource manifest = project.findMember(new Path("/META-INF/MANIFEST.MF"));
    assertNotNull(manifest);
    // delete it
    manifest.delete(true, null);
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    // select ChangeLog file
    String teamProviderString = "[changelog/trunk/" + PROJECT_NAME + "]";
    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");
    changeLogItem.select();
    // CTRL + ALT + P
    bot.activeShell().pressShortcut(Keystrokes.CTRL, Keystrokes.ALT, KeyStroke.getInstance("P"));
    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();
    // save to avoid "save changes"-pop-up
    swtBoteditor.save();
    assertEquals("ChangeLog", swtBoteditor.getTitle());
    SWTBotEclipseEditor eclipseEditor = swtBoteditor.toTextEditor();
    // make sure expected entry has been added.
    assertTrue(matchHead(eclipseEditor.getText(), "\t* META-INF/MANIFEST.MF:", 3));
    // select first line
    eclipseEditor.selectLine(0);
    final String expectedFirstLineContent = eclipseEditor.getSelection();
    // save changes to clipboard: CTRL + ALT + V
    eclipseEditor.pressShortcut(Keystrokes.CTRL, Keystrokes.ALT, KeyStroke.getInstance("V"));
    // create and open a new file for pasting
    String pasteFile = "newFile";
    IFile newFile = project.getFile(new Path(pasteFile));
    newFile.create(new ByteArrayInputStream("".getBytes()), /* empty content */
    false, null);
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    assertNotNull(project.findMember(new Path(pasteFile)));
    ProjectExplorer.expandProject(projectExplorerViewTree, PROJECT_NAME, teamProviderString).expandNode(pasteFile).select().doubleClick();
    // bot.activeShell().pressShortcut(Keystrokes.F3); // open file
    editorMatcher = allOf(IsInstanceOf.instanceOf(IEditorReference.class), withPartName(pasteFile));
    bot.waitUntil(Conditions.waitForEditor(editorMatcher));
    SWTBotPreferences.TIMEOUT = oldTimeout;
    swtBoteditor = bot.activeEditor();
    assertEquals(pasteFile, swtBoteditor.getTitle());
    eclipseEditor = swtBoteditor.toTextEditor();
    // go to beginning of editor
    eclipseEditor.selectRange(0, 0, 0);
    // paste
    eclipseEditor.pressShortcut(Keystrokes.CTRL, KeyStroke.getInstance("V"));
    swtBoteditor.save();
    // make sure proper content was pasted
    assertTrue(matchHead(eclipseEditor.getText(), "\t* META-INF/MANIFEST.MF:", 3));
    // select first line
    eclipseEditor.selectLine(0);
    final String actualFirstLineContent = eclipseEditor.getSelection();
    assertEquals(expectedFirstLineContent, actualFirstLineContent);
}
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) IFile(org.eclipse.core.resources.IFile) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IResource(org.eclipse.core.resources.IResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with SWTBotEditor

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor in project eclipse-integration-commons by spring-projects.

the class UITestCase method workspaceCleanUp.

/**
 * General cleanup: close all editors. Delete all projects. Copied from:
 * StsUiTestCase
 *
 * @author Steffen Pingel
 */
public static void workspaceCleanUp() throws CoreException {
    List<? extends SWTBotEditor> editors = bot.editors();
    for (SWTBotEditor editor : editors) {
        editor.close();
    }
    deleteAllProjects();
}
Also used : SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor)

Example 20 with SWTBotEditor

use of org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor in project dsl-devkit by dsldevkit.

the class AbstractOccurrencesTest method testOccurrences.

/**
 * Tests occurrences.
 *
 * @throws BadLocationException
 *           if thrown means bad test
 */
public void testOccurrences() throws BadLocationException {
    // Occurrence job starts after we open an editor, need to wait
    getBot().waitUntil(occurenceJobCondition, TIMEOUT_FOR_MARKING);
    SWTBotEditor editorBot = getBot().activeEditor();
    SWTBotEclipseEditor eBot = editorBot.toTextEditor();
    OccurrencesToCheck occurrencesMap = (OccurrencesToCheck) getTestInformation().getTestObject(OccurrencesToCheck.class);
    IEditorPart editorPart = editorBot.getReference().getEditor(true);
    ITextEditor editor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
    IDocumentProvider provider = editor.getDocumentProvider();
    IDocument document = provider.getDocument(editorPart.getEditorInput());
    int cursorLine = document.getLineOfOffset(occurrencesMap.cursorOffset);
    int cursorColumn = occurrencesMap.cursorOffset - document.getLineOffset(cursorLine);
    // Reset the listener and trigger the second occurrence job
    jobChangeListener.reset();
    eBot.navigateTo(cursorLine, cursorColumn);
    eBot.pressShortcut(Keystrokes.LEFT);
    getBot().waitUntil(occurenceJobCondition, TIMEOUT_FOR_MARKING);
    for (int offset : occurrencesMap.semanticMarkers) {
        Color color = getColorAtOffset(eBot, document, offset);
        // $NON-NLS-1$
        assertNotSame("Semantical reference selection colored", color, NO_COLOR);
    }
    for (int offset : occurrencesMap.noSemanticMarkers) {
        Color color = getColorAtOffset(eBot, document, offset);
        // $NON-NLS-1$
        assertSame("No semantical reference selection should not be colored", color, NO_COLOR);
    }
}
Also used : SWTBotEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) Color(org.eclipse.swt.graphics.Color) IEditorPart(org.eclipse.ui.IEditorPart) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

SWTBotEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor)24 Test (org.junit.Test)11 Path (org.eclipse.core.runtime.Path)7 SWTBotEclipseEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor)7 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)7 IEditorReference (org.eclipse.ui.IEditorReference)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)5 Ignore (org.junit.Ignore)5 IsEditorOpened (net.heartsome.test.swtbot.waits.IsEditorOpened)4 IFile (org.eclipse.core.resources.IFile)3 ProjectExplorerTreeItemAppearsCondition (org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition)3 SWTWorkbenchBot (org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)3 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)3 SWTBotTable (org.eclipse.swtbot.swt.finder.widgets.SWTBotTable)3 IEditorPart (org.eclipse.ui.IEditorPart)3 InputStream (java.io.InputStream)2 IResource (org.eclipse.core.resources.IResource)2 AbstractChartBuilder (org.eclipse.linuxtools.systemtap.graphing.ui.charts.AbstractChartBuilder)2 SWTBot (org.eclipse.swtbot.swt.finder.SWTBot)2