Example usage for org.apache.commons.configuration PropertiesConfiguration addProperty

List of usage examples for org.apache.commons.configuration PropertiesConfiguration addProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration addProperty.

Prototype

public void addProperty(String key, Object value) 

Source Link

Document

Adds a new property to this configuration.

Usage

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenManagementURIIsNull() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672");
    configuration.addProperty("management.uri", null);

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class)
            .hasMessage("You need to specify the management URI of RabbitMQ");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenManagementURIIsEmpty() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672");
    configuration.addProperty("management.uri", "");

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class)
            .hasMessage("You need to specify the management URI of RabbitMQ");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenManagementURIIsInvalid() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672");
    configuration.addProperty("management.uri", ":invalid");

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class).hasMessage("You need to specify a valid URI");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldReturnTheConfigurationWhenRequiredParametersAreGiven() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    String amqpUri = "amqp://james:james@rabbitmq_host:5672";
    configuration.addProperty("uri", amqpUri);
    String managementUri = "http://james:james@rabbitmq_host:15672/api/";
    configuration.addProperty("management.uri", managementUri);
    configuration.addProperty("management.user", DEFAULT_USER);
    configuration.addProperty("management.password", DEFAULT_PASSWORD_STRING);

    assertThat(RabbitMQConfiguration.from(configuration)).isEqualTo(RabbitMQConfiguration.builder()
            .amqpUri(URI.create(amqpUri)).managementUri(URI.create(managementUri))
            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL).build());
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldThrowWhenManagementCredentialsAreNotGiven() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    String amqpUri = "amqp://james:james@rabbitmq_host:5672";
    configuration.addProperty("uri", amqpUri);
    String managementUri = "http://james:james@rabbitmq_host:15672/api/";
    configuration.addProperty("management.uri", managementUri);

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class).hasMessage(
                    "You need to specify the management.user property as username of rabbitmq management admin account");
}

From source file:org.apache.james.backend.rabbitmq.RabbitMQConfigurationTest.java

@Test
void fromShouldReturnCustomValueWhenManagementCredentialsAreGiven() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    String amqpUri = "amqp://james:james@rabbitmq_host:5672";
    configuration.addProperty("uri", amqpUri);
    String managementUri = "http://james:james@rabbitmq_host:15672/api/";
    configuration.addProperty("management.uri", managementUri);
    String user = "james";
    configuration.addProperty("management.user", user);
    String passwordString = "james_password";
    configuration.addProperty("management.password", passwordString);

    RabbitMQConfiguration.ManagementCredentials credentials = new RabbitMQConfiguration.ManagementCredentials(
            user, passwordString.toCharArray());

    assertThat(RabbitMQConfiguration.from(configuration).getManagementCredentials()).isEqualTo(credentials);
}

From source file:org.apache.james.backends.cassandra.init.QueryLoggerConfigurationTest.java

@Test
public void fromShouldNotThrowWithMinimalConfigAboutAConstantThresholdSlowQueryLogger() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("cassandra.query.logger.constant.threshold", 100);

    assertThatCode(() -> QueryLoggerConfiguration.from(configuration)).doesNotThrowAnyException();
}

From source file:org.apache.james.backends.cassandra.init.QueryLoggerConfigurationTest.java

@Test
public void fromShouldNotThrowWithPersonalizedConfigAboutPercentileSlowQuerryLogger() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();

    configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile", 90);
    configuration.addProperty("cassandra.query.logger.max.logged.parameters", 9);
    configuration.addProperty("cassandra.query.logger.max.query.string.length", 9000);
    configuration.addProperty("cassandra.query.logger.max.parameter.value.length", 90);

    assertThatCode(() -> QueryLoggerConfiguration.from(configuration)).doesNotThrowAnyException();
}

From source file:org.apache.james.backends.cassandra.init.QueryLoggerConfigurationTest.java

@Test
public void fromShouldThrowIfConfigAboutLoggerIsInvalid() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("cassandra.query.slow.query.latency.threshold.percentile", 90);
    configuration.addProperty("cassandra.query.logger.constant.threshold", 100);

    assertThatThrownBy(() -> QueryLoggerConfiguration.from(configuration))
            .isInstanceOf(IllegalStateException.class);
}

From source file:org.apache.james.backends.es.ElasticSearchConfigurationTest.java

@Test
public void getNbReplicaShouldReturnConfiguredValue() throws ConfigurationException {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    int value = 36;
    configuration.addProperty("elasticsearch.nb.replica", value);
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration
            .fromProperties(configuration);

    assertThat(elasticSearchConfiguration.getNbReplica()).isEqualTo(value);
}