2626import java .nio .file .Files ;
2727import java .nio .file .Path ;
2828import java .nio .file .Paths ;
29- import java .util .HashMap ;
3029import java .util .Map ;
3130import org .junit .ClassRule ;
31+ import org .junit .Rule ;
3232import org .junit .Test ;
33+ import org .junit .rules .TemporaryFolder ;
3334
3435import static org .assertj .core .api .Assertions .assertThat ;
3536
3637public class PropertiesTest {
3738 @ ClassRule
3839 public static final OrchestratorRule ORCHESTRATOR = ScannerJavaLibraryTestSuite .ORCHESTRATOR ;
3940
41+ @ Rule
42+ public TemporaryFolder temp = new TemporaryFolder ();
43+
4044 @ Test
4145 public void testRuntimeEnvironmentPassedAsUserAgent () throws IOException {
4246 SimpleScanner scanner = new SimpleScanner ();
43- Map <String , String > params = new HashMap <>();
44- BuildResult buildResult = scanner .executeSimpleProject (project ("js-sample" ), ORCHESTRATOR .getServer ().getUrl (), params , Map .of ());
47+ BuildResult buildResult = scanner .executeSimpleProject (project ("js-sample" ), ORCHESTRATOR .getServer ().getUrl (), Map .of (), Map .of ());
4548 assertThat (buildResult .getLastStatus ()).isZero ();
4649 assertThat (buildResult .getLogs ()).contains ("2 files indexed" );
4750
@@ -53,13 +56,32 @@ public void testRuntimeEnvironmentPassedAsUserAgent() throws IOException {
5356 @ Test
5457 public void passConfigurationUsingEnvVariables () throws IOException {
5558 SimpleScanner scanner = new SimpleScanner ();
56- Map <String , String > params = new HashMap <>();
57- BuildResult buildResult = scanner .executeSimpleProject (project ("js-sample" ), ORCHESTRATOR .getServer ().getUrl (), params , Map .of ("SONAR_SCANNER_JSON_PARAMS" , "{\" sonar.exclusions\" : \" **/Hello.js\" }" ));
59+ BuildResult buildResult = scanner .executeSimpleProject (project ("js-sample" ), ORCHESTRATOR .getServer ().getUrl (), Map .of (), Map .of ("SONAR_SCANNER_JSON_PARAMS" , "{\" sonar.exclusions\" : \" **/Hello.js\" }" ));
5860 assertThat (buildResult .getLastStatus ()).isZero ();
5961
6062 assertThat (buildResult .getLogs ()).contains ("1 file indexed" );
6163 }
6264
65+ @ Test
66+ public void overrideHomeDirectoryWithEnv () throws IOException {
67+ var userHome = temp .newFolder ();
68+ SimpleScanner scanner = new SimpleScanner ();
69+ BuildResult buildResult = scanner .executeSimpleProject (project ("js-sample" ), ORCHESTRATOR .getServer ().getUrl (), Map .of (), Map .of ("SONAR_USER_HOME" , userHome .getAbsolutePath ()));
70+ assertThat (buildResult .getLastStatus ()).isZero ();
71+
72+ assertThat (userHome .toPath ().resolve ("cache" )).isDirectoryRecursivelyContaining (("glob:**/*scanner-engine*.jar" ));
73+ }
74+
75+ @ Test
76+ public void overrideHomeDirectoryWithProps () throws IOException {
77+ var userHome = temp .newFolder ();
78+ SimpleScanner scanner = new SimpleScanner ();
79+ BuildResult buildResult = scanner .executeSimpleProject (project ("js-sample" ), ORCHESTRATOR .getServer ().getUrl (), Map .of ("sonar.userHome" , userHome .getAbsolutePath ()), Map .of ());
80+ assertThat (buildResult .getLastStatus ()).isZero ();
81+
82+ assertThat (userHome .toPath ().resolve ("cache" )).isDirectoryRecursivelyContaining (("glob:**/*scanner-engine*.jar" ));
83+ }
84+
6385 private static Path project (String projectName ) {
6486 return Paths .get (".." , "projects" , projectName );
6587 }
0 commit comments