コード例 #1
0
ファイル: UTLogging.java プロジェクト: hiCarlosSilva/eap
  @Test
  // Check the next log file name when <date> is not specified:
  public void testLogFileWithoutDate() throws BasicIOException {
    // 1) First getNextLogFile() simple returns the file name:
    String logFileName = "log_t01.xls";
    LogFile logFile = new LogFile(_testLocation, logFileName, 0);
    assertEquals(UT.getNextLogFile(logFile), logFileName);

    // 2) getNextLogFile() returns sequencial file names:
    for (int i = 1; i < 99; i++) {
      UT.getNextLogFile(logFile);
    }
    assertEquals(UT.getNextLogFile(logFile), "log_t01_100.xls");
    assertEquals(UT.getNextLogFile(logFile), "log_t01_101.xls");

    // 3) If there is an existing log_t01_xx.xls file, getNextLogFile() returns it:
    logFileName = "log_t01_67.xls";
    _testLocation.createFile(logFileName);
    logFile = new LogFile(_testLocation, logFileName, 0);
    assertEquals(UT.getNextLogFile(logFile), logFileName);

    // 4) Check for a different extension:
    logFileName = "another_file_01.xls";
    String txtFileName = "another_file.txt";
    _testLocation.createFile(logFileName);
    logFile = new LogFile(_testLocation, txtFileName, 0);
    assertEquals(UT.getNextLogFile(logFile), txtFileName);
    assertEquals(UT.getNextLogFile(logFile), "another_file_02.txt");
  }
コード例 #2
0
ファイル: UTLogging.java プロジェクト: hiCarlosSilva/eap
  @Test
  // Check the next log file name when <date> is specified:
  public void testLogFileWithDate() throws BasicIOException {
    // 1) When the directory is empty, the log file name has today's date:
    String logFileName = "log_t02_<date>.xls";
    String realFileName = "log_t02_" + today.format(dateFormat) + ".xls";
    LogFile logFile = new LogFile(_testLocation, logFileName, 1);
    assertEquals(UT.getNextLogFile(logFile), realFileName);

    // 2) getNextLogFile() returns sequencial file names:
    for (int i = 1; i < 99; i++) {
      UT.getNextLogFile(logFile);
    }
    realFileName = "log_t02_" + today.format(dateFormat) + "_100.xls";
    assertEquals(UT.getNextLogFile(logFile), realFileName);
    realFileName = "log_t02_" + today.format(dateFormat) + "_101.xls";
    assertEquals(UT.getNextLogFile(logFile), realFileName);

    // 3) If a file exists within the range of days, the existing file is used:
    today.setLenient(true);
    Date past = today.setDay(today.getDay() - 15);
    String pastFileName = "log_t02_" + past.format(dateFormat) + ".xls";
    File file = _testLocation.createFile(pastFileName);
    logFile = new LogFile(_testLocation, logFileName, 15);
    assertEquals(UT.getNextLogFile(logFile), pastFileName);

    // 4) If a file exists but is already outside the range of days, a new file is created:
    file.delete();
    past = today.setDay(today.getDay() - 16);
    logFile = new LogFile(_testLocation, logFileName, 15);
    realFileName = "log_t02_" + today.format(dateFormat) + ".xls";
    assertEquals(UT.getNextLogFile(logFile), realFileName);

    // 5) If there is an existing log_t01_xx.xls file, getNextLogFile() returns it:
    realFileName = "log_t02_" + today.format(dateFormat) + "_49.xls";
    _testLocation.createFile(realFileName);
    logFile = new LogFile(_testLocation, logFileName, 15);
    assertEquals(UT.getNextLogFile(logFile), realFileName);
  }