// This indirectly tests QPID-6283
  public void testFileSystemCheckWarnsWhenFileSystemDoesNotExist() throws Exception {
    Map<String, Object> attributes =
        Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
    final MessageStore store = mock(MessageStore.class);
    when(store.newMessageStoreReader()).thenReturn(mock(MessageStore.MessageStoreReader.class));
    File nonExistingFile = TestFileUtils.createTempFile(this);
    FileUtils.delete(nonExistingFile, false);
    when(store.getStoreLocationAsFile()).thenReturn(nonExistingFile);
    setTestSystemProperty("virtualhost.housekeepingCheckPeriod", "100");

    final AbstractVirtualHost host =
        new AbstractVirtualHost(attributes, _node) {
          @Override
          protected MessageStore createMessageStore() {
            return store;
          }
        };

    String loggerName = AbstractVirtualHost.class.getName();
    assertActionProducesLogMessage(
        new Runnable() {
          @Override
          public void run() {
            host.open();
          }
        },
        loggerName,
        Level.WARN,
        "Cannot check file system for disk space");
    host.close();
  }
public class ResultsCsvWriterTest extends QpidTestCase {
  private CSVFormatter _csvFormater = mock(CSVFormatter.class);

  private File _outputDir = TestFileUtils.createTestDirectory();

  private ResultsCsvWriter _resultsFileWriter = new ResultsCsvWriter(_outputDir);

  @Override
  public void setUp() {
    _resultsFileWriter.setCsvFormater(_csvFormater);
  }

  public void testWriteResultsToFile() {
    List<ITestResult> testResult1 = mock(List.class);
    ResultsForAllTests results1 = mock(ResultsForAllTests.class);
    when(results1.getTestResults()).thenReturn(testResult1);

    List<ITestResult> testResult2 = mock(List.class);
    ResultsForAllTests results2 = mock(ResultsForAllTests.class);
    when(results2.getTestResults()).thenReturn(testResult2);

    String expectedCsvContents1 = "expected-csv-contents1";
    String expectedCsvContents2 = "expected-csv-contents2";
    String expectedSummaryFileContents = "expected-summary-file";
    when(_csvFormater.format(testResult1)).thenReturn(expectedCsvContents1);
    when(_csvFormater.format(testResult2)).thenReturn(expectedCsvContents2);

    _resultsFileWriter.begin();
    _resultsFileWriter.writeResults(results1, "config1.json");

    File resultsFile1 = new File(_outputDir, "config1.csv");
    assertEquals(expectedCsvContents1, FileUtils.readFileAsString(resultsFile1));

    _resultsFileWriter.writeResults(results2, "config2.json");

    File resultsFile2 = new File(_outputDir, "config2.csv");
    assertEquals(expectedCsvContents2, FileUtils.readFileAsString(resultsFile2));

    when(_csvFormater.format(any(List.class))).thenReturn(expectedSummaryFileContents);

    _resultsFileWriter.end();

    File summaryFile = new File(_outputDir, ResultsCsvWriter.TEST_SUMMARY_FILE_NAME);
    assertEquals(expectedSummaryFileContents, FileUtils.readFileAsString(summaryFile));
  }
}