use of com.tencent.polaris.configuration.client.internal.DefaultConfigFile 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);
}
}
use of com.tencent.polaris.configuration.client.internal.DefaultConfigFile in project polaris-java by polarismesh.
the class ConfigFileTest method testDeleteContent.
@Test
public void testDeleteContent() throws InterruptedException {
String content = "hello";
when(configFileRepo.getContent()).thenReturn(content);
DefaultConfigFile configFile = new DefaultConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName, configFileRepo, configFileConfig);
Assert.assertEquals(content, configFile.getContent());
Assert.assertTrue(configFile.hasContent());
AtomicBoolean check = new AtomicBoolean(false);
configFile.addChangeListener(new ConfigFileChangeListener() {
@Override
public void onChange(ConfigFileChangeEvent event) {
check.set(event.getNewValue() == null && event.getOldValue().equals(content) && event.getChangeType() == ChangeType.DELETED);
}
});
configFile.onChange(ConfigFileTestUtils.assembleDefaultConfigFileMeta(), null);
TimeUnit.MILLISECONDS.sleep(100);
Assert.assertTrue(check.get());
}
use of com.tencent.polaris.configuration.client.internal.DefaultConfigFile in project polaris-java by polarismesh.
the class ConfigFileTest method testModifiedContent.
@Test
public void testModifiedContent() throws InterruptedException {
String content = "hello";
when(configFileRepo.getContent()).thenReturn(content);
DefaultConfigFile configFile = new DefaultConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName, configFileRepo, configFileConfig);
Assert.assertEquals(content, configFile.getContent());
Assert.assertTrue(configFile.hasContent());
String newContent = "hello2";
AtomicBoolean check = new AtomicBoolean(false);
configFile.addChangeListener(new ConfigFileChangeListener() {
@Override
public void onChange(ConfigFileChangeEvent event) {
check.set(event.getNewValue().equals(newContent) && event.getOldValue().equals(content) && event.getChangeType() == ChangeType.MODIFIED);
}
});
configFile.onChange(ConfigFileTestUtils.assembleDefaultConfigFileMeta(), "hello2");
TimeUnit.MILLISECONDS.sleep(100);
Assert.assertTrue(check.get());
}
use of com.tencent.polaris.configuration.client.internal.DefaultConfigFile in project polaris-java by polarismesh.
the class ConfigFileTest method testContentNotChanged.
@Test
public void testContentNotChanged() throws InterruptedException {
String content = "hello";
when(configFileRepo.getContent()).thenReturn(content);
DefaultConfigFile configFile = new DefaultConfigFile(ConfigFileTestUtils.testNamespace, ConfigFileTestUtils.testGroup, ConfigFileTestUtils.testFileName, configFileRepo, configFileConfig);
AtomicBoolean check = new AtomicBoolean(false);
configFile.addChangeListener(new ConfigFileChangeListener() {
@Override
public void onChange(ConfigFileChangeEvent event) {
check.set(event.getNewValue().equals(content) && event.getOldValue().equals(content) && event.getChangeType() == ChangeType.NOT_CHANGED);
}
});
configFile.onChange(ConfigFileTestUtils.assembleDefaultConfigFileMeta(), content);
TimeUnit.MILLISECONDS.sleep(100);
Assert.assertTrue(check.get());
}
Aggregations