Search in sources :

Example 1 with ConfigFile

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);
}
Also used : ConfigFile(com.tencent.polaris.configuration.api.core.ConfigFile) Test(org.junit.Test)

Example 2 with ConfigFile

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());
}
Also used : DefaultConfigFile(com.tencent.polaris.configuration.client.internal.DefaultConfigFile) ConfigFile(com.tencent.polaris.configuration.api.core.ConfigFile) DefaultConfigFile(com.tencent.polaris.configuration.client.internal.DefaultConfigFile) Test(org.junit.Test)

Example 3 with ConfigFile

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");
}
Also used : DefaultConfigFile(com.tencent.polaris.configuration.client.internal.DefaultConfigFile) ConfigFile(com.tencent.polaris.configuration.api.core.ConfigFile) DefaultConfigFile(com.tencent.polaris.configuration.client.internal.DefaultConfigFile) Test(org.junit.Test)

Example 4 with ConfigFile

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;
}
Also used : ConfigFile(com.tencent.polaris.configuration.api.core.ConfigFile) ConfigFileFactory(com.tencent.polaris.configuration.client.factory.ConfigFileFactory)

Example 5 with 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);
    }
}
Also used : DefaultConfigFile(com.tencent.polaris.configuration.client.internal.DefaultConfigFile) ConfigFile(com.tencent.polaris.configuration.api.core.ConfigFile) TypeToken(com.google.gson.reflect.TypeToken) DefaultConfigFile(com.tencent.polaris.configuration.client.internal.DefaultConfigFile) Test(org.junit.Test)

Aggregations

ConfigFile (com.tencent.polaris.configuration.api.core.ConfigFile)7 Test (org.junit.Test)5 DefaultConfigFile (com.tencent.polaris.configuration.client.internal.DefaultConfigFile)3 TypeToken (com.google.gson.reflect.TypeToken)1 ConfigFileChangeEvent (com.tencent.polaris.configuration.api.core.ConfigFileChangeEvent)1 ConfigFileChangeListener (com.tencent.polaris.configuration.api.core.ConfigFileChangeListener)1 ConfigFileMetadata (com.tencent.polaris.configuration.api.core.ConfigFileMetadata)1 ConfigFileService (com.tencent.polaris.configuration.api.core.ConfigFileService)1 ConfigFileFactory (com.tencent.polaris.configuration.client.factory.ConfigFileFactory)1