use of com.tencent.polaris.configuration.api.core.ConfigFile in project polaris-java by polarismesh.
the class ConfigFileServiceTest method testGetNormalConfigFile.
@Test
public void testGetNormalConfigFile() {
when(configFileManager.getConfigFile(any())).thenReturn(configFile);
ConfigFile configFile2 = defaultConfigFileService.getConfigFile("somenamespace", "somegroup", "application.yaml");
verify(configFileManager).getConfigFile(any());
Assert.assertEquals(configFile2, configFile2);
}
use of com.tencent.polaris.configuration.api.core.ConfigFile in project polaris-java by polarismesh.
the class ConfigFileTest method testGetContent.
@Test
public void testGetContent() {
String content = "hello";
when(configFileRepo.getContent()).thenReturn(content);
ConfigFile configFile = new DefaultConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName, configFileRepo, configFileConfig);
Assert.assertEquals(content, configFile.getContent());
Assert.assertTrue(configFile.hasContent());
Assert.assertEquals(ConfigFileTestUtils.testNamespace, configFile.getNamespace());
Assert.assertEquals(ConfigFileTestUtils.testGroup, configFile.getFileGroup());
Assert.assertEquals(ConfigFileTestUtils.testFileName, configFile.getFileName());
}
use of com.tencent.polaris.configuration.api.core.ConfigFile in project polaris-java by polarismesh.
the class ConfigFileTest method testGetJsonObject.
@Test
public void testGetJsonObject() {
String content = "{\n" + "\t\"name\":\"zhangsan\",\n" + "\t\"age\":18,\n" + "\t\"labels\": {\n" + "\t \"key1\":\"value1\"\n" + "\t}\n" + "}";
when(configFileRepo.getContent()).thenReturn(content);
ConfigFile configFile = new DefaultConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName, configFileRepo, configFileConfig);
Assert.assertEquals(content, configFile.getContent());
ConfigFileTestUtils.User user = configFile.asJson(ConfigFileTestUtils.User.class, null);
Assert.assertNotNull(user);
Assert.assertEquals("zhangsan", user.getName());
Assert.assertEquals(18, user.getAge());
Assert.assertEquals(user.getLabels().size(), 1);
Assert.assertEquals(user.getLabels().get("key1"), "value1");
}
use of com.tencent.polaris.configuration.api.core.ConfigFile in project polaris-java by polarismesh.
the class DefaultConfigFileManager method getConfigFile.
@Override
public ConfigFile getConfigFile(ConfigFileMetadata configFileMetadata) {
ConfigFile configFile = configFileCache.get(configFileMetadata);
if (configFile == null) {
synchronized (this) {
configFile = configFileCache.get(configFileMetadata);
if (configFile == null) {
ConfigFileFactory configFileFactory = configFileFactoryManager.getFactory(configFileMetadata);
configFile = configFileFactory.createConfigFile(configFileMetadata);
configFileCache.put(configFileMetadata, configFile);
}
}
}
return configFile;
}
use of com.tencent.polaris.configuration.api.core.ConfigFile in project polaris-java by polarismesh.
the class ConfigFileTest method testGetJsonArray.
@Test
public void testGetJsonArray() {
String content = "[\n" + "\t{\n" + "\t\t\"name\":\"zhangsan\",\n" + "\t\t\"age\":18,\n" + "\t\t\"labels\": {\n" + "\t\t \"key1\":\"value1\"\n" + "\t\t}\n" + "\t},\n" + "\t{\n" + "\t\t\"name\":\"lisi\",\n" + "\t\t\"age\":20,\n" + "\t\t\"labels\": {\n" + "\t\t \"key1\":\"value2\"\n" + "\t\t}\n" + "\t}\n" + "]";
when(configFileRepo.getContent()).thenReturn(content);
ConfigFile configFile = new DefaultConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName, configFileRepo, configFileConfig);
Assert.assertEquals(content, configFile.getContent());
List<ConfigFileTestUtils.User> users = configFile.asJson(new TypeToken<List<ConfigFileTestUtils.User>>() {
}.getType(), null);
Assert.assertNotNull(users);
Assert.assertEquals(2, users.size());
for (ConfigFileTestUtils.User user : users) {
Assert.assertNotNull(user.getName());
Assert.assertTrue(user.getAge() > 0);
Assert.assertTrue(user.getLabels().size() > 0);
}
}
Aggregations