Search in sources :

Example 1 with ProjectExplorerTreeItemAppearsCondition

use of org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition 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)

Example 2 with ProjectExplorerTreeItemAppearsCondition

use of org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition 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 3 with ProjectExplorerTreeItemAppearsCondition

use of org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition 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)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)3 Path (org.eclipse.core.runtime.Path)3 ProjectExplorerTreeItemAppearsCondition (org.eclipse.linuxtools.changelog.ui.tests.utils.ProjectExplorerTreeItemAppearsCondition)3 SWTBotEclipseEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor)3 SWTBotEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor)3 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)3 IEditorReference (org.eclipse.ui.IEditorReference)3 Test (org.junit.Test)3 IFile (org.eclipse.core.resources.IFile)2 Ignore (org.junit.Ignore)2 IResource (org.eclipse.core.resources.IResource)1 TableAppearsCondition (org.eclipse.linuxtools.changelog.ui.tests.utils.TableAppearsCondition)1 SWTBot (org.eclipse.swtbot.swt.finder.SWTBot)1 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)1 SWTBotTable (org.eclipse.swtbot.swt.finder.widgets.SWTBotTable)1