Search in sources :

Example 1 with ZookeeperConfigurationProvider

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider in project chassis by Kixeye.

the class ConfigurationBuilderTest method zookeeperHappy.

@Test
public void zookeeperHappy() throws Exception {
    String key = ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_1;
    curatorFramework.create().creatingParentsIfNeeded().forPath(key, MODULE_1_VALUE_1.getBytes());
    Assert.assertEquals(MODULE_1_VALUE_1, new String(curatorFramework.getData().forPath(key)));
    configurationBuilder.withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    Configuration configuration = configurationBuilder.build();
    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
}
Also used : Configuration(org.apache.commons.configuration.Configuration) ZookeeperConfigurationProvider(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider) Test(org.junit.Test)

Example 2 with ZookeeperConfigurationProvider

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider in project chassis by Kixeye.

the class ConfigurationBuilderTest method missingZookeeperConfig_writeDefaultsEnvironmentFileOverride.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void missingZookeeperConfig_writeDefaultsEnvironmentFileOverride() throws Exception {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated, new SimpleEntry(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName(), "false"));
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES.replace(".properties", "." + ENVIRONMENT + ".properties"), filesCreated, new SimpleEntry(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName(), "true"));
    TestUtils.deleteAll(curatorFramework);
    Assert.assertNull(curatorFramework.checkExists().forPath(ZOOKEEPER_CONFIG_ROOT));
    configurationBuilder.withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    configurationBuilder.withApplicationProperties("file://" + TEST_APP_CONFIG_PROPERTIES);
    configurationBuilder.build();
    Assert.assertNotNull(curatorFramework.checkExists().forPath(ZOOKEEPER_CONFIG_ROOT));
    Assert.assertEquals(MODULE_1_VALUE_1, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_1)));
    Assert.assertEquals(MODULE_1_VALUE_2, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_2)));
    Assert.assertEquals(MODULE_1_VALUE_3, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_3)));
    Assert.assertEquals(MODULE_2_VALUE_1, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_2_KEY_1)));
    Assert.assertEquals(4, curatorFramework.getChildren().forPath(ZOOKEEPER_CONFIG_ROOT).size());
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) ZookeeperConfigurationProvider(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider) Test(org.junit.Test)

Example 3 with ZookeeperConfigurationProvider

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider in project chassis by Kixeye.

the class ConfigurationBuilderTest method missingZookeeperConfig_writeDefaults.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void missingZookeeperConfig_writeDefaults() throws Exception {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated, new SimpleEntry(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName(), "true"));
    TestUtils.deleteAll(curatorFramework);
    Assert.assertNull(curatorFramework.checkExists().forPath(ZOOKEEPER_CONFIG_ROOT));
    configurationBuilder.withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    configurationBuilder.withApplicationProperties("file://" + TEST_APP_CONFIG_PROPERTIES);
    configurationBuilder.build();
    Assert.assertNotNull(curatorFramework.checkExists().forPath(ZOOKEEPER_CONFIG_ROOT));
    Assert.assertEquals(MODULE_1_VALUE_1, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_1)));
    Assert.assertEquals(MODULE_1_VALUE_2, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_2)));
    Assert.assertEquals(MODULE_1_VALUE_3, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_3)));
    Assert.assertEquals(MODULE_2_VALUE_1, new String(curatorFramework.getData().forPath(ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_2_KEY_1)));
    Assert.assertEquals(4, curatorFramework.getChildren().forPath(ZOOKEEPER_CONFIG_ROOT).size());
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) ZookeeperConfigurationProvider(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider) Test(org.junit.Test)

Example 4 with ZookeeperConfigurationProvider

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider in project chassis by Kixeye.

the class ConfigurationBuilderTest method missingZookeeperConfig_writeDefaultsDisabledInConfig.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test(expected = ApplicationConfigurationNotFoundException.class)
public void missingZookeeperConfig_writeDefaultsDisabledInConfig() throws Exception {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated, new SimpleEntry(BootstrapConfigKeys.PUBLISH_DEFAULTS_KEY.getPropertyName(), "false"));
    TestUtils.deleteAll(curatorFramework);
    Assert.assertNull(curatorFramework.checkExists().forPath(ZOOKEEPER_CONFIG_ROOT));
    configurationBuilder.withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    configurationBuilder.withApplicationProperties("file://" + TEST_APP_CONFIG_PROPERTIES);
    configurationBuilder.build();
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) ZookeeperConfigurationProvider(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider) Test(org.junit.Test)

Example 5 with ZookeeperConfigurationProvider

use of com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider in project chassis by Kixeye.

the class ConfigurationBuilderTest method missingZookeeperConfig.

@Test(expected = ApplicationConfigurationNotFoundException.class)
public void missingZookeeperConfig() throws Exception {
    TestUtils.deleteAll(curatorFramework);
    Assert.assertNull(curatorFramework.checkExists().forPath(ZOOKEEPER_CONFIG_ROOT));
    configurationBuilder.withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    configurationBuilder.build();
}
Also used : ZookeeperConfigurationProvider(com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider) Test(org.junit.Test)

Aggregations

ZookeeperConfigurationProvider (com.kixeye.chassis.bootstrap.configuration.zookeeper.ZookeeperConfigurationProvider)6 Test (org.junit.Test)6 SimpleEntry (java.util.AbstractMap.SimpleEntry)4 Configuration (org.apache.commons.configuration.Configuration)2