Skip to content

Commit

Permalink
incorporated review comments and updated test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaya Gupta committed May 3, 2023
1 parent 774e223 commit a9a93c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/main/java/ai/apptuit/metrics/jinsight/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ private static Map<String, Object> loadSystemProperties() {
}

private static String getProperty(String propertyName) {
String updatedPropertyName = propertyName;
if(!propertyName.contains(".")) {
propertyName = "jinsight." + propertyName;
updatedPropertyName = "jinsight." + propertyName;
}
String propertyValue = System.getenv(propertyName);
String propertyValue = System.getenv(updatedPropertyName);
if(propertyValue == null || propertyValue.equals("")){
propertyValue = System.getProperty(propertyName);
propertyValue = System.getProperty(updatedPropertyName);
}
return propertyValue != null && !propertyValue.equals("") ? propertyValue : null;
}
Expand Down
17 changes: 5 additions & 12 deletions src/test/java/ai/apptuit/metrics/jinsight/ConfigServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public void testAgentVersion() throws Exception {
assertEquals(System.getProperty("project.version"), cs.getAgentVersion());
}

@SuppressWarnings("all")
@Test
public void testLoadSystemProperties() throws Exception {
// setup here since ConfigService.getInstance() has been initialized in several tests
Expand All @@ -335,7 +336,6 @@ public void testLoadSystemProperties() throws Exception {
initialize();

ConfigService cs = ConfigService.getInstance();

assertEquals("APPTUIT", cs.getReporterType().name());
assertEquals("TEST_TOKEN", cs.getApiToken());
assertEquals("http://api.test.bicycle.io", cs.getApiUrl().toString());
Expand All @@ -350,17 +350,10 @@ public void testLoadSystemProperties() throws Exception {
doPrivilegedAction();
}

private void doPrivilegedAction() {
AccessController.doPrivileged((PrivilegedAction<String>) () -> {
try {
Field singletonField = ConfigService.class.getDeclaredField("singleton");
singletonField.setAccessible(true);
singletonField.set(null, null);
return "";
} catch (ReflectiveOperationException | SecurityException e) {
throw new RuntimeException(e);
}
});
private void doPrivilegedAction() throws Exception {
Field singletonField = ConfigService.class.getDeclaredField("singleton");
singletonField.setAccessible(true);
singletonField.set(null, null);

}

Expand Down

0 comments on commit a9a93c8

Please sign in to comment.