Java Code Examples for org.apache.commons.configuration2.PropertiesConfiguration#addProperty()

The following examples show how to use org.apache.commons.configuration2.PropertiesConfiguration#addProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMQConfigurationTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: RabbitMQConfigurationTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: CassandraCacheConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldReturnSuppliedConfiguration() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("cache.cassandra.ttl", "3 days");
    configuration.addProperty("cache.cassandra.timeout", "50 ms");
    configuration.addProperty("cache.sizeThresholdInBytes", "4 KiB");

    assertThat(CassandraCacheConfiguration.from(configuration))
        .isEqualTo(CassandraCacheConfiguration.builder()
            .ttl(Duration.ofDays(3))
            .timeOut(Duration.ofMillis(50))
            .sizeThresholdInBytes(4096)
            .build());
}
 
Example 4
Source File: BlobStoreConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenBlobStoreImplIsNotInSupportedList() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("implementation", "un_supported");

    assertThatThrownBy(() -> BlobStoreConfiguration.from(configuration))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("un_supported is not a valid name of BlobStores, please use one of supported values in: cassandra, objectstorage, hybrid");
}
 
Example 5
Source File: LinshareConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenUUIDIsWrongFormat() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(LinshareConfiguration.UUID_PROPERTY, SOME_RANDOM_STRING);
    configuration.addProperty(LinshareConfiguration.PASSWORD_PROPERTY, SOME_RANDOM_STRING);
    configuration.addProperty(LinshareConfiguration.URL_PROPERTY, DEFAULT_URL);

    assertThatThrownBy(() -> LinshareConfiguration.from(configuration)).isInstanceOf(IllegalArgumentException.class);
}
 
Example 6
Source File: RabbitMQConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenURIIsEmpty() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("uri", "");

    assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
        .isInstanceOf(IllegalStateException.class)
        .hasMessage("You need to specify the URI of RabbitMQ");
}
 
Example 7
Source File: ElasticSearchConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromPropertiesShouldThrowWhenTrustStorePathDoesntExist() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    configuration.addProperty("elasticsearch.hostScheme.https.sslValidationStrategy", "override");
    configuration.addProperty("elasticsearch.hostScheme.https.trustStorePath", "/home/james/ServerTrustStore.jks");
    configuration.addProperty("elasticsearch.hostScheme.https.trustStorePassword", "password");

    assertThatThrownBy(() -> ElasticSearchConfiguration.fromProperties(configuration))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("the file '/home/james/ServerTrustStore.jks' from property 'elasticsearch.hostScheme.https.trustStorePath' doesn't exist");
}
 
Example 8
Source File: ElasticSearchConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void getHostSchemeShouldBeCaseInsensitive() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    configuration.addProperty("elasticsearch.hostScheme", "HTTPs");

    ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);

    assertThat(elasticSearchConfiguration.getHostScheme())
        .isEqualTo(HostScheme.HTTPS);
}
 
Example 9
Source File: BlobStoreModulesChooserTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void providesHybridBlobStoreConfigurationShouldReturnConfiguration() {
    HybridDeclarationModule module = new HybridDeclarationModule();
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("hybrid.size.threshold", 36);
    FakePropertiesProvider propertyProvider = FakePropertiesProvider.builder()
        .register(ConfigurationComponent.NAME, configuration)
        .build();

    assertThat(module.providesHybridBlobStoreConfiguration(propertyProvider))
        .isEqualTo(new HybridBlobStore.Configuration(36));
}
 
Example 10
Source File: BlobStoreConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void provideChoosingConfigurationShouldReturnHybridConfigurationWhenConfigurationImplIsHybrid() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("implementation", BlobStoreConfiguration.BlobStoreImplName.HYBRID.getName());
    FakePropertiesProvider propertyProvider = FakePropertiesProvider.builder()
        .register(ConfigurationComponent.NAME, configuration)
        .build();

    assertThat(parse(propertyProvider))
        .isEqualTo(BlobStoreConfiguration.hybrid());
}
 
Example 11
Source File: ElasticSearchMailboxConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void getWriteAliasMailboxNameShouldReturnOldConfiguredValue() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    String name = "name";
    configuration.addProperty("elasticsearch.alias.write.name", name);
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    ElasticSearchMailboxConfiguration elasticSearchConfiguration = ElasticSearchMailboxConfiguration.fromProperties(configuration);

    assertThat(elasticSearchConfiguration.getWriteAliasMailboxName())
        .isEqualTo(new WriteAliasName(name));
}
 
Example 12
Source File: ElasticSearchConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromPropertiesShouldThrowWhenInvalidVerifier() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    configuration.addProperty("elasticsearch.hostScheme.https.hostNameVerifier", "invalid");

    assertThatThrownBy(() -> ElasticSearchConfiguration.fromProperties(configuration))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("invalid HostNameVerifier 'invalid'");
}
 
Example 13
Source File: PeriodicalHealthChecksConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenPeriodHasIncorrectFormat() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(HEALTH_CHECK_PERIOD, RANDOM_STRING);

    assertThatThrownBy(() -> PeriodicalHealthChecksConfiguration.from(configuration))
        .isInstanceOf(NumberFormatException.class);
}
 
Example 14
Source File: RabbitMQConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenUserIsNotGiven() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    String passwordString = "password";
    configuration.addProperty("management.password", passwordString);

    assertThatThrownBy(() -> RabbitMQConfiguration.ManagementCredentials.from(configuration))
        .isInstanceOf(IllegalStateException.class)
        .hasMessage("You need to specify the management.user property as username of rabbitmq management admin account");
}
 
Example 15
Source File: CassandraMailQueueViewConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldReturnConfiguredBucketCount() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(CassandraMailQueueViewConfiguration.BUCKET_COUNT_PROPERTY, "8");
    CassandraMailQueueViewConfiguration actual = CassandraMailQueueViewConfiguration.from(configuration);

    assertThat(actual.getBucketCount()).isEqualTo(8);
}
 
Example 16
Source File: ElasticSearchConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void getNbShardsShouldReturnDefaultValueWhenMissing() throws ConfigurationException {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    ElasticSearchConfiguration elasticSearchConfiguration = ElasticSearchConfiguration.fromProperties(configuration);

    assertThat(elasticSearchConfiguration.getNbShards())
        .isEqualTo(ElasticSearchConfiguration.DEFAULT_NB_SHARDS);
}
 
Example 17
Source File: LinshareConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenUUIDIsTooLong() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty(LinshareConfiguration.UUID_PROPERTY, "way-too-long-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    configuration.addProperty(LinshareConfiguration.PASSWORD_PROPERTY, SOME_RANDOM_STRING);
    configuration.addProperty(LinshareConfiguration.URL_PROPERTY, DEFAULT_URL);

    assertThatThrownBy(() -> LinshareConfiguration.from(configuration)).isInstanceOf(IllegalArgumentException.class);
}
 
Example 18
Source File: BlobStoreConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromShouldThrowWhenBlobStoreImplIsEmpty() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("implementation", "");

    assertThatThrownBy(() -> BlobStoreConfiguration.from(configuration))
        .isInstanceOf(IllegalStateException.class)
        .hasMessage("implementation property is missing please use one of supported values in: cassandra, objectstorage, hybrid");
}
 
Example 19
Source File: RabbitMQConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 20
Source File: ElasticSearchConfigurationTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void fromPropertiesShouldThrowWhenOnlyPassword() throws Exception {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.addProperty("elasticsearch.hosts", "127.0.0.1");

    configuration.addProperty("elasticsearch.password", "password");

    assertThatThrownBy(() -> ElasticSearchConfiguration.fromProperties(configuration))
        .isInstanceOf(NullPointerException.class)
        .hasMessage("username cannot be null when password is specified");
}