22
22
import java .lang .reflect .Field ;
23
23
import java .nio .file .Files ;
24
24
import java .nio .file .Path ;
25
+ import java .util .Arrays ;
25
26
import java .util .Base64 ;
26
27
import java .util .Map ;
27
28
import java .util .Properties ;
48
49
public class BuildExtractorUtilsTest {
49
50
private static final String POPO_KEY = BuildInfoProperties .BUILD_INFO_PROP_PREFIX + "popo" ;
50
51
private static final String MOMO_KEY = BuildInfoProperties .BUILD_INFO_PROP_PREFIX + "momo" ;
52
+ private static final String KOKO_KEY = BuildInfoProperties .BUILD_INFO_PROP_PREFIX + "koko" ;
53
+ private static final String GOGO_KEY = BuildInfoProperties .BUILD_INFO_PROP_PREFIX + "gogo" ;
51
54
private static final String ENV_POPO_KEY = BuildInfoProperties .BUILD_INFO_ENVIRONMENT_PREFIX + "popo" ;
52
55
private static final String ENV_MOMO_KEY = BuildInfoProperties .BUILD_INFO_ENVIRONMENT_PREFIX + "momo" ;
53
56
@@ -67,8 +70,6 @@ public void getBuildInfoPropertiesFromSystemProps() {
67
70
assertEquals (props .size (), 2 , "there should only be 2 properties after the filtering" );
68
71
assertEquals (props .getProperty (POPO_KEY ), "buildname" , "popo property does not match" );
69
72
assertEquals (props .getProperty (MOMO_KEY ), "1" , "momo property does not match" );
70
- System .clearProperty (POPO_KEY );
71
- System .clearProperty (MOMO_KEY );
72
73
}
73
74
74
75
public void getBuildInfoPropertiesFromFile () throws IOException {
@@ -87,10 +88,31 @@ public void getBuildInfoPropertiesFromFile() throws IOException {
87
88
assertEquals (fileProps .getProperty (MOMO_KEY ), "1" , "momo property does not match" );
88
89
}
89
90
91
+ public void getBuildInfoPropertiesFromFileAndSystemProps () throws IOException {
92
+ try (FileOutputStream fileOutputStream = new FileOutputStream (tempFile .toFile ())) {
93
+ createProperties ().store (fileOutputStream , "" );
94
+ }
95
+
96
+ System .setProperty (BuildInfoConfigProperties .PROP_PROPS_FILE , tempFile .toString ());
97
+ System .setProperty (KOKO_KEY , "3" );
98
+ // Override MOMO_KEY from file
99
+ System .setProperty (MOMO_KEY , "2" );
100
+
101
+ Properties fileProps = filterDynamicProperties (
102
+ mergePropertiesWithSystemAndPropertyFile (new Properties (), getLog ()),
103
+ BUILD_INFO_PROP_PREDICATE );
104
+
105
+ assertEquals (fileProps .size (), 3 , "there should only be 2 properties after the filtering" );
106
+ assertEquals (fileProps .getProperty (POPO_KEY ), "buildname" , "popo property does not match" );
107
+ assertEquals (fileProps .getProperty (MOMO_KEY ), "2" , "momo property does not match" );
108
+ assertEquals (fileProps .getProperty (KOKO_KEY ), "3" , "koko property does not match" );
109
+ }
110
+
90
111
@ AfterMethod
91
112
private void tearDown () throws Exception {
92
113
Files .deleteIfExists (tempFile );
93
114
115
+ Arrays .asList (POPO_KEY , MOMO_KEY , KOKO_KEY , GOGO_KEY ).forEach (System ::clearProperty );
94
116
unsetEnv (BuildInfoConfigProperties .PROP_PROPS_FILE );
95
117
unsetEnv (BuildInfoConfigProperties .PROP_PROPS_FILE_KEY );
96
118
unsetEnv (BuildInfoConfigProperties .PROP_PROPS_FILE_KEY_IV );
@@ -103,10 +125,8 @@ public void getBuildInfoProperties() throws IOException {
103
125
System .setProperty (BuildInfoConfigProperties .PROP_PROPS_FILE , tempFile .toString ());
104
126
105
127
// Put system properties
106
- String kokoKey = BuildInfoProperties .BUILD_INFO_PROP_PREFIX + "koko" ;
107
- String gogoKey = BuildInfoProperties .BUILD_INFO_PROP_PREFIX + "gogo" ;
108
- System .setProperty (kokoKey , "parent" );
109
- System .setProperty (gogoKey , "2" );
128
+ System .setProperty (KOKO_KEY , "parent" );
129
+ System .setProperty (GOGO_KEY , "2" );
110
130
111
131
Properties buildInfoProperties = filterDynamicProperties (
112
132
mergePropertiesWithSystemAndPropertyFile (new Properties (), getLog ()),
@@ -115,11 +135,8 @@ public void getBuildInfoProperties() throws IOException {
115
135
assertEquals (buildInfoProperties .size (), 4 , "There should be 4 properties" );
116
136
assertEquals (buildInfoProperties .getProperty (POPO_KEY ), "buildname" , "popo property does not match" );
117
137
assertEquals (buildInfoProperties .getProperty (MOMO_KEY ), "1" , "momo number property does not match" );
118
- assertEquals (buildInfoProperties .getProperty (kokoKey ), "parent" , "koko parent name property does not match" );
119
- assertEquals (buildInfoProperties .getProperty (gogoKey ), "2" , "gogo parent number property does not match" );
120
-
121
- System .clearProperty (kokoKey );
122
- System .clearProperty (gogoKey );
138
+ assertEquals (buildInfoProperties .getProperty (KOKO_KEY ), "parent" , "koko parent name property does not match" );
139
+ assertEquals (buildInfoProperties .getProperty (GOGO_KEY ), "2" , "gogo parent number property does not match" );
123
140
}
124
141
125
142
public void getEnvPropertiesFromFile () throws IOException {
0 commit comments