Search in sources :

Example 11 with CliConfig

use of com.torodb.stampede.CliConfig in project torodb by torodb.

the class ConfigTest method testParseWithYAML.

@Test
public void testParseWithYAML() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasConfFile() {
            return true;
        }

        @Override
        public InputStream getConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-yaml.yml");
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/logging not defined", config.getLogging() != null);
    Assert.assertTrue("/logging/packages not defined", config.getLogging().getPackages() != null);
    Assert.assertTrue("/logging/packages/com.torodb not defined", config.getLogging().getPackages().get("com.torodb") != null);
    Assert.assertEquals("/logging/level has different value than that specified", LogLevel.NONE, config.getLogging().getLevel());
    Assert.assertEquals("/logging/packages has not 1 entry", 1, config.getLogging().getPackages().size());
    Assert.assertEquals("/logging/packages/com.torodb has different value than that specified", LogLevel.DEBUG, config.getLogging().getPackages().get("com.torodb"));
    Assert.assertTrue("/replication not defined", config.getReplication() != null);
    Assert.assertEquals("/replication/replSetName has different value than that specified", "rs1", config.getReplication().getReplSetName());
    Assert.assertEquals("/replication/role has different value than that specified", Role.HIDDEN_SLAVE, config.getReplication().getRole());
    Assert.assertEquals("/replication/syncSource has different value than that specified", "localhost:27017", config.getReplication().getSyncSource());
    Assert.assertTrue("/backend not defined", config.getBackend() != null);
    Assert.assertEquals("/backend/postgres not defined", Postgres.class, config.getBackend().getBackendImplementation().getClass());
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres", config.getBackend().is(Postgres.class));
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres Like", config.getBackend().isLike(Postgres.class));
    Assert.assertEquals("/backend/postgres/host has different value than that specified", "localhost", config.getBackend().as(Postgres.class).getHost());
    Assert.assertEquals("/backend/postgres/port has different value than that specified", Integer.valueOf(5432), config.getBackend().as(Postgres.class).getPort());
    Assert.assertEquals("/backend/postgres/user has different value than that specified", "root", config.getBackend().as(Postgres.class).getUser());
    Assert.assertEquals("/backend/postgres/password specified but should have not been read from parameters", null, config.getBackend().as(Postgres.class).getPassword());
}
Also used : CliConfig(com.torodb.stampede.CliConfig) Config(com.torodb.stampede.config.model.Config) CliConfig(com.torodb.stampede.CliConfig) Postgres(com.torodb.stampede.config.model.backend.postgres.Postgres) Test(org.junit.Test)

Example 12 with CliConfig

use of com.torodb.stampede.CliConfig in project torodb by torodb.

the class ConfigTest method testParseWithLogPackagesParam.

@Test
public void testParseWithLogPackagesParam() throws Exception {
    final String logPackage = "com.torodb";
    final LogLevel level = LogLevel.NONE;
    CliConfig cliConfig = new CliConfig() {

        @Override
        public List<String> getParams() {
            String[] params = new String[] { "/logging/packages/" + logPackage + "=" + level.name() };
            return Arrays.asList(params);
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/logging/packages not defined", config.getLogging().getPackages() != null);
    Assert.assertTrue("/logging/packages/" + logPackage + " not defined", config.getLogging().getPackages().get(logPackage) != null);
    Assert.assertEquals("/logging/packages has not 1 entry", 1, config.getLogging().getPackages().size());
    Assert.assertEquals("/logging/packages/" + logPackage + " has different value than that specified", level, config.getLogging().getPackages().get(logPackage));
}
Also used : CliConfig(com.torodb.stampede.CliConfig) Config(com.torodb.stampede.config.model.Config) CliConfig(com.torodb.stampede.CliConfig) LogLevel(com.torodb.packaging.config.model.generic.LogLevel) Test(org.junit.Test)

Example 13 with CliConfig

use of com.torodb.stampede.CliConfig in project torodb by torodb.

the class ConfigTest method testParseWithNullParam.

@Test
public void testParseWithNullParam() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public List<String> getParams() {
            String[] params = new String[] { "/logging/file=null" };
            return Arrays.asList(params);
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertEquals("Parameter has different value than that specified", null, config.getLogging().getFile());
}
Also used : CliConfig(com.torodb.stampede.CliConfig) Config(com.torodb.stampede.config.model.Config) CliConfig(com.torodb.stampede.CliConfig) Test(org.junit.Test)

Example 14 with CliConfig

use of com.torodb.stampede.CliConfig in project torodb by torodb.

the class ConfigTest method testParseWithXML.

@Test
public void testParseWithXML() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasXmlConfFile() {
            return true;
        }

        @Override
        public InputStream getXmlConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-xml.xml");
        }
    };
    Config config = CliConfigUtils.readConfig(cliConfig);
    Assert.assertTrue("/logging not defined", config.getLogging() != null);
    Assert.assertTrue("/logging/packages not defined", config.getLogging().getPackages() != null);
    Assert.assertTrue("/logging/packages/com.torodb not defined", config.getLogging().getPackages().get("com.torodb") != null);
    Assert.assertEquals("/logging/level has different value than that specified", LogLevel.NONE, config.getLogging().getLevel());
    Assert.assertEquals("/logging/packages has not 1 entry", 1, config.getLogging().getPackages().size());
    Assert.assertEquals("/logging/packages/com.torodb has different value than that specified", LogLevel.DEBUG, config.getLogging().getPackages().get("com.torodb"));
    Assert.assertTrue("/replication not defined", config.getReplication() != null);
    Assert.assertEquals("/replication/replSetName has different value than that specified", "rs1", config.getReplication().getReplSetName());
    Assert.assertEquals("/replication/role has different value than that specified", Role.HIDDEN_SLAVE, config.getReplication().getRole());
    Assert.assertEquals("/replication/syncSource has different value than that specified", "localhost:27017", config.getReplication().getSyncSource());
    Assert.assertTrue("/backend not defined", config.getBackend() != null);
    Assert.assertEquals("/backend/postgres not defined", Postgres.class, config.getBackend().getBackendImplementation().getClass());
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres", config.getBackend().is(Postgres.class));
    Assert.assertTrue("/backend/postgres not identified as AbstractPostgres Like", config.getBackend().isLike(Postgres.class));
    Assert.assertEquals("/backend/postgres/host has different value than that specified", "localhost", config.getBackend().as(Postgres.class).getHost());
    Assert.assertEquals("/backend/postgres/port has different value than that specified", Integer.valueOf(5432), config.getBackend().as(Postgres.class).getPort());
    Assert.assertEquals("/backend/postgres/user has different value than that specified", "root", config.getBackend().as(Postgres.class).getUser());
    Assert.assertEquals("/backend/postgres/password has different value than that specified", null, config.getBackend().as(Postgres.class).getPassword());
}
Also used : CliConfig(com.torodb.stampede.CliConfig) Config(com.torodb.stampede.config.model.Config) CliConfig(com.torodb.stampede.CliConfig) Postgres(com.torodb.stampede.config.model.backend.postgres.Postgres) Test(org.junit.Test)

Example 15 with CliConfig

use of com.torodb.stampede.CliConfig in project torodb by torodb.

the class ConfigTest method testParseWithYAMLUsingEmptyProtocol.

@Test(expected = IllegalArgumentException.class)
public void testParseWithYAMLUsingEmptyProtocol() throws Exception {
    CliConfig cliConfig = new CliConfig() {

        @Override
        public boolean hasConfFile() {
            return true;
        }

        @Override
        public InputStream getConfInputStream() {
            return ConfigTest.class.getResourceAsStream("/test-parse-with-yaml-using-empty-replication.yml");
        }
    };
    CliConfigUtils.readConfig(cliConfig);
}
Also used : CliConfig(com.torodb.stampede.CliConfig) Test(org.junit.Test)

Aggregations

CliConfig (com.torodb.stampede.CliConfig)15 Test (org.junit.Test)15 Config (com.torodb.stampede.config.model.Config)8 Postgres (com.torodb.stampede.config.model.backend.postgres.Postgres)5 LogLevel (com.torodb.packaging.config.model.generic.LogLevel)1 IndexFilter (com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter)1 File (java.io.File)1