コード例 #1
0
  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));
  }
コード例 #2
0
  // 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();
  }
コード例 #3
0
  public void setUp() throws Exception {
    super.setUp();

    _queueId = UUIDGenerator.generateRandomUUID();
    _exchangeId = UUIDGenerator.generateRandomUUID();

    _storeName = getName();
    _storePath = TMP_FOLDER + File.separator + _storeName;
    FileUtils.delete(new File(_storePath), true);
    setTestSystemProperty("QPID_WORK", TMP_FOLDER);
    _configuration = mock(Configuration.class);
    _recoveryHandler = mock(ConfigurationRecoveryHandler.class);
    _queueRecoveryHandler = mock(QueueRecoveryHandler.class);
    _exchangeRecoveryHandler = mock(ExchangeRecoveryHandler.class);
    _bindingRecoveryHandler = mock(BindingRecoveryHandler.class);
    _storedMessageRecoveryHandler = mock(StoredMessageRecoveryHandler.class);
    _logRecoveryHandler = mock(TransactionLogRecoveryHandler.class);
    _messageStoreRecoveryHandler = mock(MessageStoreRecoveryHandler.class);
    _queueEntryRecoveryHandler =
        mock(TransactionLogRecoveryHandler.QueueEntryRecoveryHandler.class);
    _dtxRecordRecoveryHandler = mock(TransactionLogRecoveryHandler.DtxRecordRecoveryHandler.class);

    when(_messageStoreRecoveryHandler.begin()).thenReturn(_storedMessageRecoveryHandler);
    when(_recoveryHandler.begin(isA(MessageStore.class))).thenReturn(_exchangeRecoveryHandler);
    when(_exchangeRecoveryHandler.completeExchangeRecovery()).thenReturn(_queueRecoveryHandler);
    when(_queueRecoveryHandler.completeQueueRecovery()).thenReturn(_bindingRecoveryHandler);
    when(_logRecoveryHandler.begin(any(MessageStore.class))).thenReturn(_queueEntryRecoveryHandler);
    when(_queueEntryRecoveryHandler.completeQueueEntryRecovery())
        .thenReturn(_dtxRecordRecoveryHandler);
    when(_exchange.getNameShortString()).thenReturn(AMQShortString.valueOf(EXCHANGE_NAME));
    when(_exchange.getId()).thenReturn(_exchangeId);
    when(_configuration.getString(eq(MessageStoreConstants.ENVIRONMENT_PATH_PROPERTY), anyString()))
        .thenReturn(_storePath);

    _bindingArgs = new FieldTable();
    AMQShortString argKey = AMQPFilterTypes.JMS_SELECTOR.getValue();
    String argValue = "some selector expression";
    _bindingArgs.put(argKey, argValue);

    reopenStore();
  }
コード例 #4
0
  /**
   * Reads the properties file, and creates a dynamic security provider to register the SASL
   * implementations with.
   */
  public static ProviderRegistrationResult registerSaslProviders() {
    _logger.debug("public static void registerSaslProviders(): called");
    ProviderRegistrationResult result = ProviderRegistrationResult.FAILED;
    // Open the SASL properties file, using the default name is one is not specified.
    String filename = System.getProperty(FILE_PROPERTY);
    InputStream is =
        FileUtils.openFileOrDefaultResource(
            filename, DEFAULT_RESOURCE_NAME, DynamicSaslRegistrar.class.getClassLoader());

    try {
      Properties props = new Properties();
      props.load(is);

      _logger.debug("props = " + props);

      Map<String, Class<? extends SaslClientFactory>> factories = parseProperties(props);

      if (factories.size() > 0) {
        // Ensure we are used before the defaults
        JCAProvider qpidProvider = new JCAProvider(factories);
        if (Security.insertProviderAt(qpidProvider, 1) == -1) {
          Provider registeredProvider = findProvider(JCAProvider.QPID_CLIENT_SASL_PROVIDER_NAME);
          if (registeredProvider == null) {
            result = ProviderRegistrationResult.FAILED;
            _logger.error("Unable to load custom SASL providers.");
          } else if (registeredProvider.equals(qpidProvider)) {
            result = ProviderRegistrationResult.EQUAL_ALREADY_REGISTERED;
            _logger.debug("Custom SASL provider is already registered with equal properties.");
          } else {
            result = ProviderRegistrationResult.DIFFERENT_ALREADY_REGISTERED;
            _logger.warn("Custom SASL provider was already registered with different properties.");
            if (_logger.isDebugEnabled()) {
              _logger.debug(
                  "Custom SASL provider "
                      + registeredProvider
                      + " properties: "
                      + new HashMap<Object, Object>(registeredProvider));
            }
          }
        } else {
          result = ProviderRegistrationResult.SUCCEEDED;
          _logger.info("Additional SASL providers successfully registered.");
        }
      } else {
        result = ProviderRegistrationResult.NO_SASL_FACTORIES;
        _logger.warn("No additional SASL factories found to register.");
      }
    } catch (IOException e) {
      result = ProviderRegistrationResult.FAILED;
      _logger.error("Error reading properties: " + e, e);
    } finally {
      if (is != null) {
        try {
          is.close();

        } catch (IOException e) {
          _logger.error("Unable to close properties stream: " + e, e);
        }
      }
    }
    return result;
  }
コード例 #5
0
 public void tearDown() throws Exception {
   FileUtils.delete(new File(_storePath), true);
   super.tearDown();
 }