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());
}
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());
}
}
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());
}
}
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;
}
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;
}
Aggregations