@BeforeMethod
  public void setup() throws IOException {
    MockitoAnnotations.initMocks(this);

    deleteIfExists(BASE_TMP_DIRECTORY);

    createDirectory(BASE_TMP_DIRECTORY);
    createDirectory(REPORT_TMP_DIRECTORY);
    createDirectory(LOG_TMP_DIRECTORY);
    createDirectory(TEST_TMP_DIRECTORY);

    spyInterrupter = getSpyInterrupter();
    when(spyInterrupter.useSudo())
        .thenReturn(false); // prevents asking sudo password when running the tests locally

    // create local puppet log file
    Path puppetLogFile = LOG_TMP_DIRECTORY.resolve(spyInterrupter.getPuppetLogFile().getFileName());
    FileUtils.write(puppetLogFile.toFile(), logWithoutErrorMessages);
    when(spyInterrupter.getPuppetLogFile()).thenReturn(puppetLogFile);

    // create IM CLI client log
    Path imLogFile =
        TEST_TMP_DIRECTORY.resolve(
            PuppetErrorReport.CLI_CLIENT_NON_INTERACTIVE_MODE_LOG.getFileName());
    FileUtils.write(imLogFile.toFile(), "");

    PuppetErrorReport.CLI_CLIENT_NON_INTERACTIVE_MODE_LOG = imLogFile;
    PuppetErrorReport.BASE_TMP_DIRECTORY = REPORT_TMP_DIRECTORY;
    PuppetErrorReport.useSudo =
        false; // prevents asking sudo password when running the tests locally

    // prepare Codenvy Config
    doReturn(getInstallType()).when(mockConfigManager).detectInstallationType();
    doReturn(
            new Config(
                ImmutableMap.of(
                    Config.HOST_URL, "localhost",
                    Config.ADMIN_LDAP_USER_NAME, "admin",
                    Config.SYSTEM_LDAP_PASSWORD, "password")))
        .when(mockConfigManager)
        .loadInstalledCodenvyConfig();
  }
  protected void checkPuppetErrors(String puppetLog, PuppetError expectedError) {
    List<String> lines = Arrays.asList(puppetLog.split("\n"));

    PuppetError error = null;
    for (String line : lines) {
      error = spyInterrupter.checkPuppetError(getTestNode(), line);
      if (error != null) {
        break;
      }
    }

    assertEquals(error, expectedError);
  }
  protected void assertNodeErrorReport(
      String errorMessage, String expectedContentOfLogFile, NodeConfig testNode)
      throws IOException, InterruptedException {
    Pattern errorReportInfoPattern = Pattern.compile("target/reports/error_report_.*.tar.gz");
    Matcher pathToReportMatcher = errorReportInfoPattern.matcher(errorMessage);
    assertTrue(pathToReportMatcher.find());

    Path report = Paths.get(pathToReportMatcher.group());
    assertNotNull(report);
    assertTrue(exists(report));

    CommandLibrary.createUnpackCommand(report, TEST_TMP_DIRECTORY).execute();
    Path puppetLogFile =
        TEST_TMP_DIRECTORY
            .resolve(testNode.getType().toString().toLowerCase())
            .resolve(spyInterrupter.getPuppetLogFile().getFileName());
    assertTrue(exists(puppetLogFile));

    String logFileContent = FileUtils.readFileToString(puppetLogFile.toFile());
    assertEquals(logFileContent, expectedContentOfLogFile);
  }
  protected void assertLocalErrorReport(String errorMessage, String expectedContentOfLogFile)
      throws IOException, InterruptedException {
    Pattern errorReportInfoPattern = Pattern.compile("target/reports/error_report_.*.tar.gz");
    Matcher pathToReportMatcher = errorReportInfoPattern.matcher(errorMessage);
    assertTrue(pathToReportMatcher.find());

    Path report = Paths.get(pathToReportMatcher.group());
    assertNotNull(report);
    assertTrue(exists(report));

    CommandLibrary.createUnpackCommand(report, TEST_TMP_DIRECTORY).execute();
    Path puppetLogFile =
        TEST_TMP_DIRECTORY.resolve(spyInterrupter.getPuppetLogFile().getFileName());
    assertTrue(exists(puppetLogFile));
    String puppetLogFileContent = FileUtils.readFileToString(puppetLogFile.toFile());
    assertEquals(puppetLogFileContent, expectedContentOfLogFile);

    Path imLogfile =
        TEST_TMP_DIRECTORY.resolve(
            PuppetErrorReport.CLI_CLIENT_NON_INTERACTIVE_MODE_LOG.getFileName());
    assertTrue(exists(imLogfile));
  }