12
12
import tests .configurations .BaseProfileTest ;
13
13
14
14
import java .util .*;
15
+ import java .util .function .BooleanSupplier ;
15
16
import java .util .function .Consumer ;
16
17
17
18
import static org .testng .Assert .*;
18
19
19
20
public class SettingsFileTests extends BaseProfileTest {
20
21
private static final String TIMEOUT_POLLING_INTERVAL_PATH = "/timeouts/timeoutPollingInterval" ;
21
22
private static final String NULLVALUE_PATH = "/nullValue" ;
23
+ private static final String ABSENTVALUE_PATH = "/absentvalue" ;
22
24
private static final String TIMEOUT_POLLING_INTERVAL_KEY = "timeouts.timeoutPollingInterval" ;
23
25
private static final String LANGUAGE_ENV_KEY = "logger.language" ;
24
26
private static final String ARGUMENTS_ENV_KEY = "arguments.start" ;
27
+ private static final String BOOLEANVALUE_ENV_KEY = "booleanValue" ;
25
28
private static final String PROFILE = "jsontest" ;
26
29
private static final String FILE_NAME = String .format ("settings.%s.json" , PROFILE );
27
30
private ISettingsFile jsonSettingsFile ;
@@ -36,6 +39,24 @@ public void before() {
36
39
jsonSettingsFile = CustomAqualityServices .getServiceProvider ().getInstance (ISettingsFile .class );
37
40
}
38
41
42
+ @ Test
43
+ public void testShouldBePossibleToOverrideBooleanValueViaEnvironmentVariable () {
44
+ BooleanSupplier getCurrentValue = () -> (Boolean ) jsonSettingsFile .getValue ("/" .concat (BOOLEANVALUE_ENV_KEY ));
45
+ boolean oldValue = getCurrentValue .getAsBoolean ();
46
+ boolean targetValue = !oldValue ;
47
+ System .setProperty (BOOLEANVALUE_ENV_KEY , String .valueOf (targetValue ));
48
+ assertEquals (getCurrentValue .getAsBoolean (), targetValue , "value passed via env var is not used by SettingsFile" );
49
+ }
50
+
51
+ @ Test
52
+ public void testShouldBePossibleToSetValueWhichIsAbsentInJsonFile () {
53
+ Assert .assertFalse (jsonSettingsFile .isValuePresent (ABSENTVALUE_PATH ), "value should be absent by default" );
54
+ String targetValue = String .valueOf (true );
55
+ System .setProperty (ABSENTVALUE_PATH .substring (1 ), targetValue );
56
+ Assert .assertTrue (jsonSettingsFile .isValuePresent (ABSENTVALUE_PATH ), "value should be present after set" );
57
+ assertEquals (jsonSettingsFile .getValue (ABSENTVALUE_PATH ), targetValue , "value passed via env var is not used by SettingsFile" );
58
+ }
59
+
39
60
@ Test
40
61
public void testShouldBePossibleToGetDefaultContent () {
41
62
System .clearProperty (PROFILE_KEY );
0 commit comments