示例#1
0
  @Test
  public void testLinkWithSelectionNavigator() throws Exception {
    deleteAllProjects();
    shareProjects(repositoryFile);
    SWTBotTree tree = getOrOpenView().bot().tree();
    myRepoViewUtil.getRootItem(tree, repositoryFile).select();
    // the selection should be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
    getProjectItem(projectExplorerTree, PROJ1).select();

    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    // activate the link with selection
    toggleLinkWithSelection();

    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    // select again the project
    projectExplorerTree = TestUtil.getExplorerTree();
    getProjectItem(projectExplorerTree, PROJ1).select();

    // the selection should be project
    assertTrue(tree.selection().get(0, 0).equals(PROJ1));

    // deactivate the link with selection
    toggleLinkWithSelection();
  }
 private void createTag(String name, String message) throws Exception {
   SWTBotTree tree = getOrOpenView().bot().tree();
   myRepoViewUtil.getTagsItem(tree, repositoryFile).select();
   ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("CreateTagCommand"));
   String shellTitle = UIText.CreateTagDialog_NewTag;
   SWTBotShell createDialog = bot.shell(shellTitle).activate();
   TestUtil.joinJobs(JobFamilies.FILL_TAG_LIST);
   createDialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText(name);
   createDialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage).setText(message);
   createDialog.bot().button(IDialogConstants.OK_LABEL).click();
   TestUtil.joinJobs(JobFamilies.TAG);
 }
示例#3
0
 /**
  * Open (expand, file->editor, branch->checkout)
  *
  * @throws Exception
  */
 @Test
 public void testOpen() throws Exception {
   // expand first level
   SWTBotTree tree = getOrOpenView().bot().tree();
   SWTBotTreeItem item = myRepoViewUtil.getRootItem(tree, repositoryFile);
   item.collapse();
   refreshAndWait();
   item = myRepoViewUtil.getRootItem(tree, repositoryFile);
   assertTrue("Item should not be expanded", !item.isExpanded());
   item.doubleClick();
   assertTrue("Item should be expanded", item.isExpanded());
   // open a file in editor
   item = myRepoViewUtil.getWorkdirItem(tree, repositoryFile).expand();
   SWTBotTreeItem fileiItem =
       item.getNode(PROJ1).expand().getNode(FOLDER).expand().getNode(FILE1).select();
   fileiItem.doubleClick();
   assertTrue(bot.activeEditor().getTitle().equals(FILE1));
   bot.activeEditor().close();
   // open a branch (checkout)
   checkoutWithDoubleClick(tree, "master");
   String contentMaster = getTestFileContent();
   checkoutWithDoubleClick(tree, "stable");
   TestUtil.joinJobs(JobFamilies.CHECKOUT);
   String contentStable = getTestFileContent();
   assertNotEquals("Content of master and stable should differ", contentMaster, contentStable);
 }
  @Test
  public void testResetToTag() throws Exception {
    SWTBotTree tree = getOrOpenView().bot().tree();

    String initialContent = getTestFileContent();
    createTag("ResetToFirst", "The first tag");
    touchAndSubmit(null);
    String newContent = getTestFileContent();
    assertFalse("Wrong content", initialContent.equals(newContent));
    createTag("ResetToSecond", "The second tag");
    refreshAndWait();
    myRepoViewUtil.getTagsItem(tree, repositoryFile).expand().getNode("ResetToFirst").select();

    ContextMenuHelper.clickContextMenu(tree, myUtil.getPluginLocalizedValue("ResetCommand"));

    SWTBotShell resetDialog = bot.shell(UIText.ResetCommand_WizardTitle);
    resetDialog.bot().radio(UIText.ResetTargetSelectionDialog_ResetTypeHardButton).click();
    resetDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
    TestUtil.joinJobs(JobFamilies.RESET);

    bot.shell(UIText.ResetTargetSelectionDialog_ResetQuestion)
        .bot()
        .button(IDialogConstants.YES_LABEL)
        .click();

    Job.getJobManager().join(JobFamilies.RESET, null);

    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
    assertEquals("Wrong content", initialContent, getTestFileContent());
  }
示例#5
0
  @BeforeClass
  public static void beforeClass() throws Exception {

    MockSystemReader mockSystemReader = new MockSystemReader();
    SystemReader.setInstance(mockSystemReader);
    mockSystemReader.setProperty(
        Constants.GIT_CEILING_DIRECTORIES_KEY,
        ResourcesPlugin.getWorkspace()
            .getRoot()
            .getLocation()
            .toFile()
            .getParentFile()
            .getAbsoluteFile()
            .toString());

    TestUtil.showExplorerView();

    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
  }
示例#6
0
  @Test
  public void testDeleteFileNotInProject() throws Exception {
    SWTBotTree tree = getOrOpenView().bot().tree();
    refreshAndWait();

    SWTBotTreeItem folder = findWorkdirNode(tree, PROJ2, FOLDER);
    folder.getNode(FILE1).select();

    ContextMenuHelper.clickContextMenu(
        tree, myUtil.getPluginLocalizedValue("RepoViewDeleteFile.label"));

    SWTBotShell confirm = bot.shell(UIText.DeleteResourcesOperationUI_confirmActionTitle);
    confirm.bot().button(IDialogConstants.OK_LABEL).click();
    bot.waitUntil(shellCloses(confirm));
    TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);

    folder = findWorkdirNode(tree, PROJ2, FOLDER);
    assertThat(folder.getNodes(), not(hasItem(FILE1)));
    assertThat(folder.getNodes(), hasItem(FILE2));
  }
  @Test
  public void testDeleteTag() throws Exception {
    SWTBotTree tree = getOrOpenView().bot().tree();
    int initialCount = myRepoViewUtil.getTagsItem(tree, repositoryFile).expand().rowCount();

    createTag("Delete1", "The first tag");
    refreshAndWait();
    SWTBotTreeItem tagsItem = myRepoViewUtil.getTagsItem(tree, repositoryFile).expand();
    SWTBotTreeItem[] items = tagsItem.getItems();
    assertEquals("Wrong number of tags", initialCount + 1, items.length);
    tagsItem.select("Delete1");
    ContextMenuHelper.clickContextMenu(
        tree, myUtil.getPluginLocalizedValue("DeleteTagCommand.name"));
    bot.shell(UIText.DeleteTagCommand_titleConfirm).bot().button(IDialogConstants.OK_LABEL).click();
    TestUtil.joinJobs(JobFamilies.TAG);
    refreshAndWait();
    tagsItem = myRepoViewUtil.getTagsItem(tree, repositoryFile).expand();
    items = tagsItem.getItems();
    assertEquals("Wrong number of tags", initialCount, items.length);
  }
示例#8
0
  @Test
  public void testDeleteFileInProject() throws Exception {
    SWTBotTree tree = getOrOpenView().bot().tree();
    refreshAndWait();

    IProject project1 = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1);
    // Make sure that the refresh doesn't happen on delete and cause a timeout
    project1.refreshLocal(IResource.DEPTH_INFINITE, null);

    SWTBotTreeItem folder = findWorkdirNode(tree, PROJ1, FOLDER);
    folder.getNode(FILE1).select();

    ContextMenuHelper.clickContextMenu(
        tree, myUtil.getPluginLocalizedValue("RepoViewDeleteFile.label"));

    SWTBotShell confirm = bot.shell("Delete Resources");
    confirm.bot().button(IDialogConstants.OK_LABEL).click();
    bot.waitUntil(shellCloses(confirm));
    TestUtil.joinJobs(JobFamilies.REPO_VIEW_REFRESH);

    folder = findWorkdirNode(tree, PROJ1, FOLDER);
    assertThat(folder.getNodes(), not(hasItem(FILE1)));
    assertThat(folder.getNodes(), hasItem(FILE2));
  }
  private void assertVariable(String expected, String variableName, String argument)
      throws CoreException {
    IResource findMember = project.findMember(TEST_FILE);

    SWTBotView explorerView = TestUtil.showExplorerView();
    final ISelectionProvider selectionProvider =
        explorerView.getViewReference().getView(true).getSite().getSelectionProvider();
    final StructuredSelection structuredSelection = new StructuredSelection(findMember);
    PlatformUI.getWorkbench()
        .getDisplay()
        .syncExec(
            new Runnable() {

              @Override
              public void run() {
                selectionProvider.setSelection(structuredSelection);
              }
            });

    IDynamicVariable dynamicVariable =
        VariablesPlugin.getDefault().getStringVariableManager().getDynamicVariable(variableName);
    String value = dynamicVariable.getValue(argument);
    assertEquals(expected, value);
  }
示例#10
0
 @Before
 public void setupViews() {
   TestUtil.showExplorerView();
   sharingWizard = new SharingWizard();
 }
示例#11
0
  /**
   * Link with editor, both ways
   *
   * @throws Exception
   */
  @Test
  @Ignore("'Link with Selection' does not activate editor on selection change (bug 409722).")
  public void testLinkWithSelectionEditor() throws Exception {
    deleteAllProjects();
    shareProjects(repositoryFile);
    SWTBotTree tree = getOrOpenView().bot().tree();
    myRepoViewUtil.getRootItem(tree, repositoryFile).select();
    // the selection should be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    SWTBotView view = TestUtil.showExplorerView();
    SWTBotTree projectExplorerTree = view.bot().tree();

    SWTBotTreeItem item =
        getProjectItem(projectExplorerTree, PROJ1).expand().getNode(FOLDER).expand().getNode(FILE1);
    view.show();
    item.doubleClick();

    item =
        getProjectItem(projectExplorerTree, PROJ1).expand().getNode(FOLDER).expand().getNode(FILE2);
    view.show();
    item.doubleClick();
    // now we should have two editors

    // the selection should be still be root
    assertTrue(tree.selection().get(0, 0).startsWith(REPO1));

    // activate the link with selection
    toggleLinkWithSelection();

    bot.editorByTitle(FILE2).show();
    // the selection should have changed to the latest editor
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE2, 10000);

    bot.editorByTitle(FILE1).show();
    // selection should have changed
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE1, 10000);

    // deactivate the link with editor
    toggleLinkWithSelection();

    bot.editorByTitle(FILE2).show();
    // the selection should be still be test.txt
    TestUtil.waitUntilTreeHasSelectedNodeWithText(bot, tree, FILE1, 10000);

    bot.editorByTitle(FILE1).show();

    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE2)
        .select();

    // the editor should still be test.txt
    assertEquals(FILE1, bot.activeEditor().getTitle());

    // activate again
    toggleLinkWithSelection();

    // make sure focus is here
    // tried to remove this waitInUI but failed.
    // tried setting focus, waiting for focus, joining RepositoriesView
    // refresh job
    waitInUI();
    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE2)
        .select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE2), 10000);

    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE1)
        .select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE1), 10000);

    // deactivate the link with editor
    toggleLinkWithSelection();

    myRepoViewUtil
        .getWorkdirItem(tree, repositoryFile)
        .expand()
        .getNode(PROJ1)
        .expand()
        .getNode(FOLDER)
        .expand()
        .getNode(FILE2)
        .select();
    TestUtil.waitUntilEditorIsActive(bot, bot.editorByTitle(FILE1), 10000);
  }
示例#12
0
 private SWTBotTree selectProject() {
   SWTBotTree tree = TestUtil.getExplorerTree();
   TestUtil.getNode(tree.getAllItems(), PROJ1).select();
   return tree;
 }
  private void testPushToOrigin(boolean useRemote) throws Exception {
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(clonedRepositoryFile);
    shareProjects(clonedRepositoryFile);

    Repository repository = lookupRepository(clonedRepositoryFile);
    // add the configuration for push
    repository
        .getConfig()
        .setString("remote", "origin", "push", "refs/heads/*:refs/remotes/origin/*");
    repository.getConfig().save();

    // make sure to have a "new" branch name so that the
    // dialog will return with a corresponding message
    String currentBranch = repository.getBranch();
    new Git(repository)
        .branchRename()
        .setOldName(currentBranch)
        .setNewName("" + System.currentTimeMillis())
        .call();

    SWTBotTree tree = getOrOpenView().bot().tree();
    tree.select(0);

    TestUtil.waitForJobs(50, 5000);
    selectNode(tree, useRemote, false);

    runPush(tree);

    String destinationString = clonedRepositoryFile.getParentFile().getName() + " - " + "origin";
    String dialogTitle = NLS.bind(UIText.PushResultDialog_title, destinationString);

    // first time: expect new branch
    SWTBotShell confirmed = bot.shell(dialogTitle);
    SWTBotTreeItem[] treeItems = confirmed.bot().tree().getAllItems();
    boolean newBranch = false;
    for (SWTBotTreeItem item : treeItems) {
      newBranch = item.getText().contains(UIText.PushResultTable_statusOkNewBranch);
      if (newBranch) break;
    }
    confirmed.close();
    assertTrue("New branch expected", newBranch);
    // second time: expect up to date
    selectNode(tree, useRemote, false);

    runPush(tree);

    confirmed = bot.shell(dialogTitle);
    treeItems = confirmed.bot().tree().getAllItems();
    boolean uptodate = false;
    for (SWTBotTreeItem item : treeItems) {
      uptodate = item.getText().contains(UIText.PushResultTable_statusUpToDate);
      if (uptodate) break;
    }
    confirmed.close();
    assertTrue("Up to date expected", uptodate);
    // touch and run again: expect new branch
    String objectIdBefore =
        repository.getRef(repository.getFullBranch()).getLeaf().getObjectId().name();
    objectIdBefore = objectIdBefore.substring(0, 7);
    touchAndSubmit(null);

    SWTBotTree updatedTree = getOrOpenView().bot().tree();
    updatedTree.select(0);
    selectNode(updatedTree, useRemote, false);

    runPush(updatedTree);

    confirmed = bot.shell(dialogTitle);
    treeItems = confirmed.bot().tree().getAllItems();
    newBranch = false;
    for (SWTBotTreeItem item : treeItems) {
      newBranch = item.getText().contains(objectIdBefore);
      if (newBranch) break;
    }
    confirmed.close();
    assertTrue("New branch expected", newBranch);
  }