Search in sources :

Example 1 with ConfigModel

use of org.apache.servicecomb.config.archaius.sources.ConfigModel in project incubator-servicecomb-java-chassis by apache.

the class TestConfigUtil method testCreateDynamicConfigNoConfigCenterSPI.

@Test
public void testCreateDynamicConfigNoConfigCenterSPI() {
    new Expectations(SPIServiceUtils.class) {

        {
            SPIServiceUtils.getTargetService(ConfigCenterConfigurationSource.class);
            result = null;
        }
    };
    AbstractConfiguration dynamicConfig = ConfigUtil.createDynamicConfig();
    MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader(dynamicConfig);
    List<ConfigModel> list = loader.getConfigModels();
    Assert.assertEquals(loader, ConfigUtil.getMicroserviceConfigLoader(dynamicConfig));
    Assert.assertEquals(1, list.size());
    Assert.assertNotEquals(DynamicWatchedConfiguration.class, ((ConcurrentCompositeConfiguration) dynamicConfig).getConfiguration(0).getClass());
}
Also used : Expectations(mockit.Expectations) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration) Test(org.junit.Test)

Example 2 with ConfigModel

use of org.apache.servicecomb.config.archaius.sources.ConfigModel in project incubator-servicecomb-java-chassis by apache.

the class TestPropertiesLoader method testCanNotAssignExtendedClass.

@Test
public void testCanNotAssignExtendedClass() {
    ConfigModel configModel = MicroserviceDefinition.createConfigModel("default", "invalidExtendedClass");
    @SuppressWarnings("unchecked") Map<String, Object> desc = (Map<String, Object>) configModel.getConfig().get(CONFIG_SERVICE_DESCRIPTION_KEY);
    desc.put("propertyExtentedClass", "java.lang.String");
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Arrays.asList(configModel));
    try {
        microserviceFactory.create(microserviceDefinition);
        Assert.fail("Must throw exception");
    } catch (Error e) {
        Assert.assertEquals("Define propertyExtendedClass java.lang.String in yaml, but not implement the interface PropertyExtended.", e.getMessage());
    }
}
Also used : ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with ConfigModel

use of org.apache.servicecomb.config.archaius.sources.ConfigModel in project incubator-servicecomb-java-chassis by apache.

the class TestPropertiesLoader method testInvalidExtendedClass.

@Test
public void testInvalidExtendedClass() {
    ConfigModel configModel = MicroserviceDefinition.createConfigModel("default", "invalidExtendedClass");
    @SuppressWarnings("unchecked") Map<String, Object> desc = (Map<String, Object>) configModel.getConfig().get(CONFIG_SERVICE_DESCRIPTION_KEY);
    desc.put("propertyExtentedClass", "invalidClass");
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Arrays.asList(configModel));
    try {
        microserviceFactory.create(microserviceDefinition);
        Assert.fail("Must throw exception");
    } catch (Error e) {
        Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass());
        Assert.assertEquals("invalidClass", e.getCause().getMessage());
    }
}
Also used : ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ConfigModel

use of org.apache.servicecomb.config.archaius.sources.ConfigModel in project incubator-servicecomb-java-chassis by apache.

the class ConfigUtil method createLocalConfig.

public static ConcurrentCompositeConfiguration createLocalConfig() {
    MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
    loader.loadAndSort();
    LOGGER.info("create local config:");
    for (ConfigModel configModel : loader.getConfigModels()) {
        LOGGER.info(" {}.", configModel.getUrl());
    }
    ConcurrentCompositeConfiguration config = ConfigUtil.createLocalConfig(loader.getConfigModels());
    ConfigUtil.setMicroserviceConfigLoader(config, loader);
    return config;
}
Also used : ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) ConcurrentCompositeConfiguration(com.netflix.config.ConcurrentCompositeConfiguration)

Example 5 with ConfigModel

use of org.apache.servicecomb.config.archaius.sources.ConfigModel in project incubator-servicecomb-java-chassis by apache.

the class MicroserviceDefinition method createConfigModel.

public static ConfigModel createConfigModel(String appId, String microserviceName) {
    Map<String, Object> descMap = new HashMap<>();
    descMap.put(CONFIG_MICROSERVICE_NAME_KEY, microserviceName);
    Map<String, Object> config = new HashMap<>();
    config.put(CONFIG_APPLICATION_ID_KEY, appId);
    config.put(CONFIG_SERVICE_DESCRIPTION_KEY, descMap);
    ConfigModel configModel = new ConfigModel();
    configModel.setConfig(config);
    return configModel;
}
Also used : ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) HashMap(java.util.HashMap)

Aggregations

ConfigModel (org.apache.servicecomb.config.archaius.sources.ConfigModel)7 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)2 Map (java.util.Map)2 MicroserviceConfigLoader (org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader)2 MicroserviceDefinition (org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition)2 ArrayList (java.util.ArrayList)1 Expectations (mockit.Expectations)1 AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)1 Configuration (org.apache.commons.configuration.Configuration)1