Commit 1cc78a4f authored by jashaikh's avatar jashaikh

Added Jacoco Code Coverage For Sonar.

parent 423fc2a9
package com.example;
import com.azure.core.http.rest.PagedIterable;
import com.azure.data.appconfiguration.ConfigurationClient;
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
import com.azure.data.appconfiguration.models.ConfigurationSetting;
import com.azure.data.appconfiguration.models.SettingSelector;
import com.example.service.AzureAppConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JavaAzureAppConfigApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(JavaAzureAppConfigApplication.class);
private static final String APP_CONNECTION_STRING = System.getenv("APP_CONFIGURATION_CONNECTION_STRING");
private static final String EXISTING_KEY = "config.message";
private static final String NEW_KEY = "config.dataSource";
public static void main(String[] args) {
ConfigurationClient configurationClient = new ConfigurationClientBuilder().connectionString(APP_CONNECTION_STRING).buildClient();
new AzureAppConfigService(configurationClient, new SettingSelector()).azureAppConfiguration();
AzureAppConfigService azureAppConfigService = new AzureAppConfigService(configurationClient, new SettingSelector());
String readValueByKey = azureAppConfigService.getValueByKey(EXISTING_KEY);
LOGGER.info("Message: {}", readValueByKey);
String writeValueByKey = azureAppConfigService.writeValueByKey(NEW_KEY, "Data Source URL");
LOGGER.info("Data Source URL From Application: {}", writeValueByKey);
PagedIterable<ConfigurationSetting> readAllKeyValue = azureAppConfigService.readAllKeyValue();
readAllKeyValue.forEach(property -> LOGGER.info("Key: {} \t Value: {}", property.getKey(), property.getValue()));
String deleteValueByKey = azureAppConfigService.deleteValueByKey(NEW_KEY);
LOGGER.warn("[Key: {} \t Value: {}] has been removed successfully", NEW_KEY, deleteValueByKey);
LOGGER.info("After Removing Key-Value Read All Values...");
readAllKeyValue = azureAppConfigService.readAllKeyValue();
readAllKeyValue.forEach(property -> LOGGER.info("Key: {} \t Value: {}", property.getKey(), property.getValue()));
}
}
......@@ -14,8 +14,6 @@ import org.slf4j.LoggerFactory;
public class AzureAppConfigService {
private static final Logger LOGGER = LoggerFactory.getLogger(AzureAppConfigService.class);
private static final String EXISTING_KEY = "config.message";
private static final String NEW_KEY = "config.dataSource";
private final ConfigurationClient configurationClient;
private final SettingSelector settingSelector;
......@@ -81,25 +79,4 @@ public class AzureAppConfigService {
return null;
}
}
/**
* Execute All Operation
*/
public void azureAppConfiguration() {
String readValueByKey = getValueByKey(EXISTING_KEY);
LOGGER.info("Message: {}", readValueByKey);
String writeValueByKey = writeValueByKey(NEW_KEY, "Data Source URL");
LOGGER.info("Data Source URL From Application: {}", writeValueByKey);
PagedIterable<ConfigurationSetting> readAllKeyValue = readAllKeyValue();
readAllKeyValue.forEach(property -> LOGGER.info("Key: {} \t Value: {}", property.getKey(), property.getValue()));
String deleteValueByKey = deleteValueByKey(NEW_KEY);
LOGGER.warn("[Key: {} \t Value: {}] has been removed successfully", NEW_KEY, deleteValueByKey);
LOGGER.info("After Removing Key-Value Read All Values...");
readAllKeyValue = readAllKeyValue();
readAllKeyValue.forEach(property -> LOGGER.info("Key: {} \t Value: {}", property.getKey(), property.getValue()));
}
}
......@@ -81,10 +81,4 @@ class AzureAppConfigServiceTest {
void deleteValueByKeyException() {
assertNull(azureAppConfigService.deleteValueByKey(null));
}
@Test
@Order(8)
void testAzureAppConfiguration() {
azureAppConfigService.azureAppConfiguration();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment