/** Ensures that ExternalJavaActionCalls with unchecked precondition are not displayed. */
 public void testPopupMenuWithExternalJavaActionCallAndFalsePrecondition() {
   // When getting the contextual menu of
   // "Employee" Class -- "wage" attribute
   // The precondition value is false and the Java Action Call action
   // should
   // not be displayed
   boolean foundContextMenu = true;
   final SWTBotTreeItem node =
       editor
           .bot()
           .tree()
           .getTreeItem(TREE_ITEM_WITH_JAVA_ACTION_CONTAINER_NAME)
           .expand()
           .getNode(TREE_ITEM_WITH_JAVA_ACTION_NAME)
           .select();
   // The test must be passed in the exception, so we deactivated the catch
   // of
   // "error log" view
   setErrorCatchActive(false);
   try {
     node.contextMenu(JAVA_ACTION_CALL_NAME);
   } catch (TimeoutException e) {
     foundContextMenu = false;
   }
   assertFalse(
       "Java Action Call  "
           + JAVA_ACTION_CALL_NAME
           + " should not be displayed on TreeITem "
           + TREE_ITEM_WITH_JAVA_ACTION_NAME,
       foundContextMenu);
   setErrorCatchActive(true);
 }
 /** Ensures that PopupMenu is not created if its precondition is not checked. */
 public void testPopupMenuWithFalsePrecondition() {
   // When getting the contextual menu of
   // "NamedEntity" Class -- "wrongFeature" attribute
   // The precondition value is false and the Pop-up Menu should
   // not be displayed
   boolean foundContextMenu = true;
   SWTBotTreeItem unaplicableNode =
       editor
           .bot()
           .tree()
           .getTreeItem(TREE_ITEM_WITH_UNAPLICABLE_POPUP_CONTAINER_NAME)
           .expand()
           .getNode(TREE_ITEM_WITH_UNAPLICABLE_POPUP_NAME);
   try {
     unaplicableNode.contextMenu(POP_UP_MENU_NAME);
   } catch (TimeoutException e) {
     foundContextMenu = false;
   }
   assertFalse(
       "Pop-up Menu "
           + POP_UP_MENU_NAME
           + " should not be displayed on TreeITem "
           + TREE_ITEM_WITH_UNAPLICABLE_POPUP_NAME,
       foundContextMenu);
 }
  /**
   * Test refreshing a trace after new content was added.
   *
   * @throws IOException on error
   */
  @Test
  public void testRefresh() throws IOException {
    ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();

    fBot.waitUntil(new NumberOfEventsCondition(activeTrace, INITIAL_NB_EVENTS));

    for (int i = 0; i < NB_REFRESH; i++) {
      appendToTrace(NEW_EVENTS_PER_REFRESH);

      // Refresh
      SWTBotTreeItem tracesFolder = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
      SWTBotTreeItem traceItem =
          SWTBotUtils.getTraceProjectItem(fBot, tracesFolder, activeTrace.getName());
      traceItem.contextMenu("Refresh").click();

      // Make sure the refresh is completed
      fBot.waitUntil(new NumberOfEventsCondition(activeTrace, getNbWrittenEvents()));
    }

    // Make sure the end of the table matches what we expect
    goToTableEnd();
    fBot.waitUntil(ConditionHelpers.selectionInEventsTable(fBot, getExpectedEndTimeStamp()));
  }
  /**
   * test opening a trace, importing
   *
   * @throws IOException won't happen
   */
  @Test
  public void test() throws IOException {
    File f = File.createTempFile("temp", ".xml").getCanonicalFile();
    try (FileWriter fw = new FileWriter(f)) {
      fw.write(TRACE_CONTENT);
    }
    File exportPackage = new File(EXPORT_LOCATION);
    if (exportPackage.exists()) {
      exportPackage.delete();
    }
    assertFalse(
        "File: " + EXPORT_LOCATION + " already present, aborting test", exportPackage.exists());
    assertTrue("Trace :" + f.getAbsolutePath() + " does not exist, aborting test", f.exists());
    SWTBotUtils.createProject(PROJECT_NAME);
    SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
    WaitUtils.waitForJobs();
    ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
    assertNotNull(trace);
    assertEquals(
        "Incorrect opened trace!",
        f.getAbsolutePath(),
        (new File(trace.getPath())).getAbsolutePath());
    SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
    assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
    projectExplorerBot.show();
    SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);

    treeItem.contextMenu(EXPORT_TRACE_PACKAGE).click();
    fBot.waitUntil(Conditions.shellIsActive(EXPORT_TRACE_PACKAGE_TITLE));
    SWTBot shellBot = fBot.activeShell().bot();
    shellBot.button(DESELECT_ALL).click();
    SWTBotTreeItem[] items = fBot.tree().getAllItems();
    for (SWTBotTreeItem item : items) {
      assertEquals(item.isChecked(), false);
    }
    shellBot.button(SELECT_ALL).click();
    for (SWTBotTreeItem item : items) {
      assertEquals(item.isChecked(), true);
    }
    shellBot.radio(SAVE_IN_TAR_FORMAT).click();
    shellBot.radio(SAVE_IN_ZIP_FORMAT).click();

    shellBot.checkBox(COMPRESS_THE_CONTENTS_OF_THE_FILE).click();
    shellBot.checkBox(COMPRESS_THE_CONTENTS_OF_THE_FILE).click();
    shellBot.comboBox().setText(EXPORT_LOCATION);
    SWTBotShell shell = fBot.activeShell();
    shellBot.button(FINISH).click();
    // finished exporting
    WaitUtils.waitForJobs();
    fBot.waitUntil(Conditions.shellCloses(shell));
    fBot = new SWTWorkbenchBot();
    exportPackage = new File(EXPORT_LOCATION);
    assertTrue("Exported package", exportPackage.exists());
    // Fixme: determine why exportPackageSize is different on different machines
    // assertEquals("Exported package size check", PACKAGE_SIZE, exportPackage.length());

    // import
    treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
    treeItem.contextMenu(IMPORT_TRACE_PACKAGE).click();
    fBot.waitUntil(Conditions.shellIsActive(IMPORT_TRACE_PACKAGE_TITLE));
    shellBot = fBot.activeShell().bot();
    shellBot.comboBox().setText(EXPORT_LOCATION);
    shellBot.comboBox().typeText("\n");

    shellBot.button(SELECT_ALL).click();
    shell = fBot.activeShell();
    shellBot.button(FINISH).click();
    fBot.button("Yes To All").click();
    fBot.waitUntil(Conditions.shellCloses(shell));
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
    trace = TmfTraceManager.getInstance().getActiveTrace();
    assertNotNull(trace);
    assertEquals("Test if import matches", f.getName(), trace.getName());
    assertFalse("Test if import files don't match", f.getAbsolutePath().equals(trace.getPath()));
    SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
    WaitUtils.waitForJobs();
  }