private SWTBotTreeItem getProjectTreeItem(SWTBotTree projectsTree, String projectName) {
   for (SWTBotTreeItem item : projectsTree.getAllItems()) {
     if (projectName.equals(getProjectLabel(item.getText()))) {
       return item;
     }
   }
   throw new IllegalStateException("Project " + projectName + " not available");
 }
  private void testFetchFromOrigin(boolean useRemote) throws Exception {

    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(clonedRepositoryFile);
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(clonedRepositoryFile2);

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

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

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

    selectNode(tree, useRemote, true);
    runFetch(tree);

    SWTBotShell confirm = bot.shell(dialogTitle);
    assertEquals("Wrong result tree row count", 0, confirm.bot().tree().rowCount());
    confirm.close();

    deleteAllProjects();
    shareProjects(clonedRepositoryFile2);
    String objid = repository.getRef("refs/heads/master").getTarget().getObjectId().name();
    objid = objid.substring(0, 7);
    touchAndSubmit(null);
    // push from other repository
    PushOperationUI op = new PushOperationUI(repository, "origin", false);
    op.start();

    String pushdialogTitle = NLS.bind(UIText.PushResultDialog_title, op.getDestinationString());

    bot.shell(pushdialogTitle).close();

    deleteAllProjects();

    refreshAndWait();

    selectNode(tree, useRemote, true);
    runFetch(tree);

    confirm = bot.shell(dialogTitle);
    SWTBotTreeItem[] treeItems = confirm.bot().tree().getAllItems();
    boolean found = false;
    for (SWTBotTreeItem item : treeItems) {
      found = item.getText().contains(objid);
      if (found) break;
    }
    assertTrue(found);
    confirm.close();

    selectNode(tree, useRemote, true);
    runFetch(tree);

    confirm = bot.shell(dialogTitle);
    assertEquals("Wrong result tree row count", 0, confirm.bot().tree().rowCount());
  }
 private static String adjustNodeName(SWTBotTree tree, String nodeName) {
   SWTBotTreeItem[] allItems = tree.getAllItems();
   for (SWTBotTreeItem item : allItems) {
     String node = item.getText();
     if (node.toUpperCase().startsWith(nodeName.toUpperCase())) {
       return node;
     }
   }
   return null;
 }
 @Override
 public boolean test() throws Exception {
   fParentItem.expand();
   for (SWTBotTreeItem item : fParentItem.getItems()) {
     if (item.getText().matches(fRegex)) {
       fItem = item;
       return true;
     }
   }
   return false;
 }
 private void findSelectEnterpriseRuntimeLibrary(SWTBotExt bot) throws Exception {
   SWTBotTree libraryTree = bot.tree(1);
   boolean libraryFound = false;
   for (SWTBotTreeItem libraryItem : libraryTree.getAllItems()) {
     if (libraryItem.getText().contains("JBoss Enterprise Application Platform")) {
       libraryTree.select(libraryItem);
       libraryFound = true;
       break;
     }
   }
   if (!libraryFound) throw new RuntimeException("No runtime library has been found");
 }
  @Test
  public void shouldSynchronizeInEmptyRepository() throws Exception {
    // given
    createEmptyRepository();

    // when
    launchSynchronization(EMPTY_PROJECT, "", "", true);

    // then
    SWTBotTree syncViewTree = bot.viewByTitle("Synchronize").bot().tree();
    SWTBotTreeItem projectTree = waitForNodeWithText(syncViewTree, EMPTY_PROJECT);
    assertEquals(1, syncViewTree.getAllItems().length);

    SWTBotTreeItem folderTree = waitForNodeWithText(projectTree, FOLDER);
    assertEquals(2, folderTree.getItems().length);

    SWTBotTreeItem fileTree = folderTree.getItems()[0];
    assertEquals(FILE1, fileTree.getText());
    fileTree = folderTree.getItems()[1];
    assertEquals(FILE2, fileTree.getText());
  }
  @Test
  public void connectDBTest() {

    openPerspective("Hibernate");

    bot.viewByTitle("Hibernate Configurations").setFocus();
    bot.viewByTitle("Hibernate Configurations").show();

    SWTBot viewBot = bot.viewByTitle("Hibernate Configurations").bot();
    SWTBotTreeItem item =
        TreeHelper.expandNode(
            viewBot, Properties.SEAM_PROJECT_NAME, "Database", "ModeShape.ModeShape");
    item.select();
    assertTrue("Could not find node with text:" + item.getText(), item.isVisible());
  }
  /**
   * Checks IU (Category, or Feature) in a tree
   *
   * @param iu to be checked
   * @return true if checked
   * @author Pavol Srna
   */
  private boolean checkIU(String iu) {

    boolean checked = false;
    for (SWTBotTreeItem node : bot.tree().getAllItems()) {
      // traverse through all categories
      if (node.getText().equals(iu)) {
        node.check();
        checked = true;
        break;
      } else {
        // expand category
        node.expand();
        for (SWTBotTreeItem i : node.getItems()) {
          // traverse through category features
          if (i.getText().equals(iu)) {
            i.check();
            checked = true;
            break;
          }
        }
      }
    }
    return checked;
  }
  @Test
  public void shouldListFileDeletedChange() throws Exception {
    // given
    resetRepositoryToCreateInitialTag();
    deleteFileAndCommit(PROJ1);

    // when
    launchSynchronization(HEAD, INITIAL_TAG, true);

    // then
    SWTBotTree syncViewTree = bot.viewByTitle("Synchronize").bot().tree();
    assertEquals(1, syncViewTree.getAllItems().length);

    SWTBotTreeItem projectTree = waitForNodeWithText(syncViewTree, PROJ1);
    assertEquals(1, projectTree.getItems().length);

    SWTBotTreeItem folderTree = waitForNodeWithText(projectTree, FOLDER);
    assertEquals(1, folderTree.getItems().length);

    SWTBotTreeItem fileTree = folderTree.getItems()[0];
    assertEquals("test.txt", fileTree.getText());
  }
 @Override
 public String getFailureMessage() {
   return NLS.bind("No child of {0} found with name {1}", fParentItem.getText(), fName);
 }
  @Test
  public void testServerBuild() {

    SWTBotTestUtil.createNewDiagram(bot);
    final SWTBotEditor activeEditor = bot.activeEditor();
    final String editorTitle = activeEditor.getTitle();
    // System.out.println("editorTitle1 = "+editorTitle1);
    assertFalse("Error: first diagram name is empty.", editorTitle.isEmpty());

    new BotProcessDiagramPropertiesViewFolder(bot)
        .selectExecutionTab()
        .selectInstantiationFormTab()
        .selectLegacy();
    new BotGefProcessDiagramEditor(bot).selectElement("Step1");
    new BotExecutionDiagramPropertiesView(bot).selectFormTab().selectLegacy();

    // get the GEF editor to activate tools
    final SWTBotGefEditor gmfEditor = bot.gefEditor(editorTitle);

    // Create 2 Pools
    gmfEditor.activateTool("Pool");
    gmfEditor.click(200, 500);

    new BotProcessDiagramPropertiesViewFolder(bot)
        .selectExecutionTab()
        .selectInstantiationFormTab()
        .selectLegacy();

    gmfEditor.activateTool("Pool");
    gmfEditor.click(200, 800);

    new BotProcessDiagramPropertiesViewFolder(bot)
        .selectExecutionTab()
        .selectInstantiationFormTab()
        .selectLegacy();

    // Save Diagram
    bot.menu("Diagram").menu("Save").click();

    // System.out.println(editorTitle);
    bot.waitUntil(Conditions.widgetIsEnabled(bot.menu("Server")));

    // Menu Server > Build...
    bot.menu("Server").menu("Build...").click();

    // shell 'Build'
    final SWTBotShell shell = bot.shell(Messages.buildTitle);
    bot.waitUntil(Conditions.shellIsActive(Messages.buildTitle));

    // select and check created Diagram in the Tree
    final SWTBotTree tree = bot.treeWithLabel("Select processes to export");
    final SWTBotTreeItem diagramTreeItem = tree.getTreeItem(editorTitle);

    // check the diagram to export
    diagramTreeItem.select().check();
    diagramTreeItem.expand();

    // Number of pool in the diagram
    final int poolListSize = diagramTreeItem.getItems().length;
    // System.out.println("Diagram contains "+ poolListSize + " items");
    assertEquals("Error: Diagram must contain 3 Pools.", 3, poolListSize);

    // unselect the first pool of the list

    diagramTreeItem.getNode(0).select();
    diagramTreeItem.getNode(0).uncheck();

    final Vector<String> poolTitleList = new Vector<String>(3);
    final int poolTitleListSize = poolTitleList.size();

    // check the selected pools
    for (int i = 1; i < poolTitleListSize; i++) {
      final SWTBotTreeItem poolTreeItem = diagramTreeItem.getNode(i);
      poolTitleList.set(i, poolTreeItem.getText());
      final String poolName = getItemName(poolTitleList.get(i));

      // test the good pool is checked
      assertFalse("Error: Pool " + i + " should be checked.", !poolTreeItem.isChecked());
      assertFalse("Error: Pool selected is not the good one.", !poolName.equals("Pool" + i));
    }
    // create tmp directory to write diagrams
    final File tmpBarFolder = new File(ProjectUtil.getBonitaStudioWorkFolder(), "testExportBar");
    tmpBarFolder.mkdirs();
    // set the path where files are saved
    final String tmpBarFolderPath = tmpBarFolder.getAbsolutePath();
    bot.comboBoxWithLabel(Messages.destinationPath + " *").setText(tmpBarFolderPath);
    //		String tmpBarFolderPath = bot.comboBoxWithLabel(Messages.destinationPath+" *").getText();
    //		System.out.println("tmpBarFolder = "+tmpBarFolderPath);

    // click 'Finish' button to close 'Build' shell
    bot.waitUntil(Conditions.widgetIsEnabled(bot.button(IDialogConstants.FINISH_LABEL)));
    bot.button(IDialogConstants.FINISH_LABEL).click();

    //  click 'OK' button to close 'Export' shell
    bot.waitUntil(new ShellIsActiveWithThreadSTacksOnFailure(Messages.exportSuccessTitle));
    bot.button(IDialogConstants.OK_LABEL).click();

    // wait the shell to close before checking creation of files
    bot.waitUntil(Conditions.shellCloses(shell));

    // check pools files exist
    for (int i = 1; i < poolTitleListSize; i++) {
      final String tmpPoolTitle = poolTitleList.get(i);
      final String poolFileName =
          getItemName(tmpPoolTitle) + "--" + getItemVersion(tmpPoolTitle) + ".bar";
      final File poolFile = new File(tmpBarFolderPath, poolFileName);

      assertTrue("Error: The Pool export must exist", poolFile.exists());
      assertTrue("Error: The Pool export must be a file", poolFile.isFile());
    }
  }
  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);
  }