use of org.eclipse.swtbot.swt.finder.waits.ICondition in project egit by eclipse.
the class BranchAndResetActionTest method testCheckoutWithNonDeleted.
@Test
public void testCheckoutWithNonDeleted() throws Exception {
// we need to check if this file system has problems to
// delete a file with an open FileInputStrem
IFile test = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1).getFolder(FOLDER).getFile("temp.txt");
test.create(new ByteArrayInputStream(new byte[0]), false, null);
File testFile = new File(test.getLocation().toString());
assertTrue(testFile.exists());
FileInputStream fis = new FileInputStream(testFile);
try {
FileUtils.delete(testFile);
return;
} catch (IOException e) {
// the test makes sense only if deletion of
// a file with open stream fails
} finally {
fis.close();
if (testFile.exists())
FileUtils.delete(testFile);
}
final Image folderImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
final Image projectImage = PlatformUI.getWorkbench().getSharedImages().getImage(SharedImages.IMG_OBJ_PROJECT);
// checkout stable
checkoutAndVerify(new String[] { LOCAL_BRANCHES, "stable" });
// add a file
IFile toBeDeleted = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1).getFolder(FOLDER).getFile("ToBeDeleted");
toBeDeleted.create(new ByteArrayInputStream(new byte[0]), false, null);
ArrayList<IFile> untracked = new ArrayList<IFile>();
untracked.add(toBeDeleted);
// commit to stable
CommitOperation op = new CommitOperation(new IFile[] { toBeDeleted }, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Add to stable");
op.execute(null);
InputStream is = toBeDeleted.getContents();
try {
checkout(new String[] { LOCAL_BRANCHES, "master" });
final SWTBotShell showUndeleted = bot.shell(UIText.NonDeletedFilesDialog_NonDeletedFilesTitle);
// repo relative path
assertEquals("ToBeDeleted", showUndeleted.bot().tree().getAllItems()[0].getItems()[0].getItems()[0].getText());
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
assertSame(folderImage, showUndeleted.bot().tree().getAllItems()[0].widget.getImage());
}
});
SWTBotToolbarDropDownButton pathButton = showUndeleted.bot().toolbarDropDownButton();
pathButton.menuItem(UIText.NonDeletedFilesTree_FileSystemPathsButton).click();
// see http://www.eclipse.org/forums/index.php/t/159133/ why we need this
pathButton.pressShortcut(KeyStroke.getInstance("ESC"));
// fs path
IPath path = new Path(lookupRepository(repositoryFile).getWorkTree().getPath()).append(PROJ1).append(FOLDER).append("ToBeDeleted");
SWTBotTreeItem[] items = showUndeleted.bot().tree().getAllItems();
for (int i = 0; i < path.segmentCount(); i++) {
boolean found = false;
String segment = path.segment(i);
for (SWTBotTreeItem item : items) if (item.getText().equals(segment)) {
found = true;
items = item.getItems();
}
assertTrue(found);
}
pathButton.menuItem(UIText.NonDeletedFilesTree_ResourcePathsButton).click();
// see http://www.eclipse.org/forums/index.php/t/159133/ why we need this
pathButton.pressShortcut(KeyStroke.getInstance("ESC"));
// resource path
assertEquals("ToBeDeleted", showUndeleted.bot().tree().getAllItems()[0].getItems()[0].getItems()[0].getText());
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
assertSame(projectImage, showUndeleted.bot().tree().getAllItems()[0].widget.getImage());
}
});
ICondition treeEmpty = new ICondition() {
@Override
public boolean test() throws Exception {
return showUndeleted.bot().tree().getAllItems().length == 0;
}
@Override
public void init(SWTBot actBot) {
// nothing
}
@Override
public String getFailureMessage() {
return "Not deleted";
}
};
showUndeleted.bot().button(UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
try {
showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
fail("Should have failed");
} catch (TimeoutException e) {
// expected
}
is.close();
showUndeleted.bot().button(UIText.NonDeletedFilesDialog_RetryDeleteButton).click();
showUndeleted.bot().waitUntil(treeEmpty, 1000, 100);
showUndeleted.close();
} finally {
is.close();
}
}
Aggregations