diff options
Diffstat (limited to 'sonar-runner-cli/src/test')
28 files changed, 0 insertions, 856 deletions
diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/CliTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/CliTest.java deleted file mode 100644 index f01f47c..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/CliTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import org.junit.Test; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -public class CliTest { - Exit exit = mock(Exit.class); - Logs logs = new Logs(System.out, System.err); - Cli cli = new Cli(exit, logs); - - @Test - public void should_parse_empty_arguments() { - cli.parse(new String[0]); - assertThat(cli.properties()).isNotEmpty(); - assertThat(cli.isDebugMode()).isFalse(); - assertThat(cli.isDisplayStackTrace()).isFalse(); - assertThat(cli.isDisplayVersionOnly()).isFalse(); - } - - @Test - public void should_extract_properties() { - cli.parse(new String[] {"-D", "foo=bar", "--define", "hello=world", "-Dboolean"}); - assertThat(cli.properties().get("foo")).isEqualTo("bar"); - assertThat(cli.properties().get("hello")).isEqualTo("world"); - assertThat(cli.properties().get("boolean")).isEqualTo("true"); - } - - @Test - public void dont_allow_interactive_fork() { - cli.parse(new String[] {"-i", "-DsonarRunner.mode=fork"}); - cli.verify(); - verify(exit).exit(Exit.SUCCESS); - } - - @Test - public void should_parse_optional_task() { - cli.parse(new String[] {"-D", "foo=bar"}); - assertThat(cli.properties().get("sonar.task")).isNull(); - - cli.parse(new String[] {"views", "-D", "foo=bar"}); - assertThat(cli.properties().get("sonar.task")).isEqualTo("views"); - } - - @Test - public void should_enable_debug_mode() { - cli.parse(new String[] {"-X"}); - assertThat(cli.isDebugMode()).isTrue(); - assertThat(cli.isDisplayStackTrace()).isTrue(); - assertThat(cli.properties().get("sonar.verbose")).isEqualTo("true"); - } - - @Test - public void should_enable_stacktrace_log() { - cli.parse(new String[] {"-e"}); - assertThat(cli.isDebugMode()).isFalse(); - assertThat(cli.isDisplayStackTrace()).isTrue(); - assertThat(cli.properties().get("sonar.verbose")).isNull(); - } - - @Test - public void should_disable_debug_mode_and_stacktrace_log_by_default() { - cli.parse(new String[0]); - assertThat(cli.isDebugMode()).isFalse(); - assertThat(cli.isDisplayStackTrace()).isFalse(); - assertThat(cli.properties().get("sonar.verbose")).isNull(); - } -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/ConfTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/ConfTest.java deleted file mode 100644 index c13d751..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/ConfTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import java.io.File; -import java.util.Properties; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class ConfTest { - - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - Properties args = new Properties(); - Logs logs = new Logs(System.out, System.err); - Cli cli = mock(Cli.class); - Conf conf = new Conf(cli, logs); - - @Before - public void initConf() { - when(cli.properties()).thenReturn(args); - } - - @Test - public void should_load_global_settings_by_home() throws Exception { - File home = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByHome/").toURI()); - args.setProperty("runner.home", home.getCanonicalPath()); - - assertThat(conf.properties().get("sonar.prop")).isEqualTo("value"); - } - - @Test - public void should_not_fail_if_no_home() throws Exception { - assertThat(conf.properties()).isNotEmpty(); - } - - @Test - public void should_load_conf_by_direct_path() throws Exception { - File settings = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByDirectPath/other-conf.properties").toURI()); - args.setProperty("runner.settings", settings.getCanonicalPath()); - - assertThat(conf.properties().get("sonar.prop")).isEqualTo("otherValue"); - } - - @Test - public void shouldLoadCompleteConfiguration() throws Exception { - File runnerHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/runner").toURI()); - File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/project").toURI()); - args.setProperty("runner.home", runnerHome.getCanonicalPath()); - args.setProperty("project.home", projectHome.getCanonicalPath()); - - Properties properties = conf.properties(); - - assertThat(properties.getProperty("project.prop")).isEqualTo("foo"); - assertThat(properties.getProperty("overridden.prop")).isEqualTo("project scope"); - assertThat(properties.getProperty("global.prop")).isEqualTo("jdbc:mysql:localhost/sonar"); - } - - @Test - public void shouldLoadModuleConfiguration() throws Exception { - File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project").toURI()); - args.setProperty("project.home", projectHome.getCanonicalPath()); - - Properties properties = conf.properties(); - - assertThat(properties.getProperty("module1.sonar.projectName")).isEqualTo("Module 1"); - assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2"); - } - - @Test - public void shouldSupportDeepModuleConfigurationInRoot() throws Exception { - File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project").toURI()); - args.setProperty("project.home", projectHome.getCanonicalPath()); - - Properties properties = conf.properties(); - - assertThat(properties.getProperty("1.sonar.projectName")).isEqualTo("Module 1"); - assertThat(properties.getProperty("1.11.sonar.projectName")).isEqualTo("Module 11"); - assertThat(properties.getProperty("1.11.111.sonar.projectName")).isEqualTo("Module 111"); - assertThat(properties.getProperty("1.12.sonar.projectName")).isEqualTo("Module 12"); - assertThat(properties.getProperty("2.sonar.projectName")).isEqualTo("Module 2"); - - // SONARUNNER-125 - assertThat(properties.getProperty("11.111.sonar.projectName")).isNull(); - } - - @Test - public void shouldLoadModuleConfigurationOverrideBasedir() throws Exception { - File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project").toURI()); - args.setProperty("project.home", projectHome.getCanonicalPath()); - - Properties properties = conf.properties(); - - assertThat(properties.getProperty("module1.sonar.projectName")).isEqualTo("Module 1"); - assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2"); - assertThat(properties.getProperty("module3.sonar.projectName")).isEqualTo("Module 3"); - } - - @Test - public void shouldSupportSettingBaseDirFromCli() throws Exception { - File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project").toURI()); - args.setProperty("project.home", temp.newFolder().getCanonicalPath()); - args.setProperty("sonar.projectBaseDir", projectHome.getCanonicalPath()); - - Properties properties = conf.properties(); - - assertThat(properties.getProperty("module1.sonar.projectName")).isEqualTo("Module 1"); - assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2"); - } - - @Test - public void ignoreEmptyModule() throws Exception { - File projectHome = new File(getClass().getResource("/org/sonar/runner/ConfTest/emptyModules/project").toURI()); - args.setProperty("project.home", temp.newFolder().getCanonicalPath()); - args.setProperty("sonar.projectBaseDir", projectHome.getCanonicalPath()); - - conf.properties(); - } - - @Test - public void shouldGetList() { - Properties props = new Properties(); - - props.put("prop", " foo ,, bar , \n\ntoto,tutu"); - assertThat(Conf.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu"); - } - -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/LogsTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/LogsTest.java deleted file mode 100644 index 4b1d51f..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/LogsTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.io.PrintStream; - -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.verify; - -public class LogsTest { - @Mock - private PrintStream stdOut; - - @Mock - private PrintStream stdErr; - - private Logs logs; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - logs = new Logs(stdOut, stdErr); - } - - @Test - public void testInfo() { - logs.info("info"); - verify(stdOut).println("INFO: info"); - verifyNoMoreInteractions(stdOut, stdErr); - } - - @Test - public void testError() { - Exception e = new NullPointerException("exception"); - logs.setDisplayStackTrace(false); - logs.error("error1"); - verify(stdErr).println("ERROR: error1"); - - logs.error("error2", e); - verify(stdErr).println("ERROR: error2"); - - verifyNoMoreInteractions(stdOut, stdErr); - - logs.setDisplayStackTrace(true); - logs.error("error3", e); - verify(stdErr).println("ERROR: error3"); - // other interactions to print the exception.. - } - - @Test - public void testDebug() { - logs.setDebugEnabled(true); - - logs.debug("debug"); - verify(stdOut).println("DEBUG: debug"); - - logs.setDebugEnabled(false); - logs.debug("debug"); - verifyNoMoreInteractions(stdOut, stdErr); - } -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/MainTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/MainTest.java deleted file mode 100644 index 7f1995c..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/MainTest.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Properties; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InOrder; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.sonar.runner.api.EmbeddedRunner; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class MainTest { - - @Mock - private Shutdown shutdown; - @Mock - private Cli cli; - @Mock - private Conf conf; - @Mock - private Properties properties; - @Mock - private RunnerFactory runnerFactory; - @Mock - private EmbeddedRunner runner; - @Mock - private Logs logs; - - @Before - public void setUp() throws IOException { - MockitoAnnotations.initMocks(this); - when(runnerFactory.create(any(Properties.class))).thenReturn(runner); - when(conf.properties()).thenReturn(properties); - - } - - @Test - public void should_execute_runner() { - Main main = new Main(shutdown, cli, conf, runnerFactory, logs); - main.execute(); - - verify(shutdown).exit(Exit.SUCCESS); - verify(runnerFactory).create(properties); - - verify(runner, times(1)).start(); - verify(runner, times(1)).runAnalysis(properties); - verify(runner, times(1)).stop(); - } - - @Test - public void should_stop_on_error() { - EmbeddedRunner runner = mock(EmbeddedRunner.class); - Exception e = new NullPointerException("NPE"); - e = new IllegalStateException("Error", e); - doThrow(e).when(runner).runAnalysis(any(Properties.class)); - when(runnerFactory.create(any(Properties.class))).thenReturn(runner); - - Main main = new Main(shutdown, cli, conf, runnerFactory, logs); - main.execute(); - - verify(runner).stop(); - verify(shutdown).exit(Exit.ERROR); - verify(logs).error("Caused by: NPE"); - - } - - @Test - public void show_error_stacktrace() { - Exception e = new NullPointerException("NPE"); - e = new IllegalStateException("Error", e); - when(cli.isDisplayStackTrace()).thenReturn(true); - - EmbeddedRunner runner = mock(EmbeddedRunner.class); - doThrow(e).when(runner).runAnalysis(any(Properties.class)); - when(runnerFactory.create(any(Properties.class))).thenReturn(runner); - - Main main = new Main(shutdown, cli, conf, runnerFactory, logs); - main.execute(); - - verify(runner).stop(); - verify(shutdown).exit(Exit.ERROR); - verify(logs).error("Error during Sonar runner execution", e); - } - - @Test - public void should_not_stop_on_error_in_interactive_mode() throws Exception { - EmbeddedRunner runner = mock(EmbeddedRunner.class); - doThrow(new IllegalStateException("Error")).when(runner).runAnalysis(any(Properties.class)); - when(runnerFactory.create(any(Properties.class))).thenReturn(runner); - when(cli.isInteractive()).thenReturn(true); - - Main main = new Main(shutdown, cli, conf, runnerFactory, logs); - BufferedReader inputReader = mock(BufferedReader.class); - when(inputReader.readLine()).thenReturn(""); - when(shutdown.shouldExit()).thenReturn(false).thenReturn(true); - main.setInputReader(inputReader); - main.execute(); - - verify(runner, times(2)).runAnalysis(any(Properties.class)); - verify(runner).stop(); - verify(shutdown).exit(Exit.SUCCESS); - } - - @Test - public void should_only_display_version() throws IOException { - - Properties p = new Properties(); - when(cli.isDisplayVersionOnly()).thenReturn(true); - when(conf.properties()).thenReturn(p); - - Main main = new Main(shutdown, cli, conf, runnerFactory, logs); - main.execute(); - - InOrder inOrder = Mockito.inOrder(shutdown, runnerFactory); - - inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS); - inOrder.verify(runnerFactory, times(1)).create(p); - inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS); - } - - @Test(timeout = 30000) - public void test_interactive_mode() throws IOException { - String inputStr = "qwe" + System.lineSeparator() + "qwe" + System.lineSeparator(); - InputStream input = new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8)); - System.setIn(input); - input.close(); - - when(cli.isInteractive()).thenReturn(true); - when(cli.isDebugMode()).thenReturn(true); - when(cli.isDisplayStackTrace()).thenReturn(true); - - Main main = new Main(shutdown, cli, conf, runnerFactory, logs); - main.execute(); - - verify(runner, times(1)).start(); - verify(runner, times(3)).runAnalysis(any(Properties.class)); - verify(runner, times(1)).stop(); - } -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/RunnerFactoryTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/RunnerFactoryTest.java deleted file mode 100644 index 169ea30..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/RunnerFactoryTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import org.sonar.runner.api.LogOutput.Level; -import org.sonar.runner.api.LogOutput; -import org.junit.Before; - -import java.util.Properties; - -import static org.mockito.Mockito.verifyNoMoreInteractions; - -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.mock; -import org.junit.Test; -import org.sonar.runner.api.EmbeddedRunner; -import static org.fest.assertions.Assertions.assertThat; - -public class RunnerFactoryTest { - - Properties props = new Properties(); - Logs logs; - - @Before - public void setUp() { - logs = mock(Logs.class); - } - - @Test - public void should_create_embedded_runner() { - props.setProperty("foo", "bar"); - EmbeddedRunner runner = new RunnerFactory(logs).create(props); - - assertThat(runner).isInstanceOf(EmbeddedRunner.class); - assertThat(runner.globalProperties().get("foo")).isEqualTo("bar"); - } - - @Test - public void should_fwd_logs() { - LogOutput logOutput = new RunnerFactory(logs).new DefaultLogOutput(); - - String msg = "test"; - - logOutput.log(msg, Level.DEBUG); - verify(logs).debug(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.INFO); - verify(logs).info(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.ERROR); - verify(logs).error(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.WARN); - verify(logs).info(msg); - verifyNoMoreInteractions(logs); - reset(logs); - - logOutput.log(msg, Level.TRACE); - verify(logs).debug(msg); - verifyNoMoreInteractions(logs); - reset(logs); - } - -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/ShutdownTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/ShutdownTest.java deleted file mode 100644 index 5f739fc..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/ShutdownTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import com.jayway.awaitility.Duration; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static com.jayway.awaitility.Awaitility.await; -import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Mockito.verify; - -public class ShutdownTest { - @Mock - private Exit exit; - private Shutdown shutdown; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - shutdown = new Shutdown(exit, true); - } - - @Test - public void testShutdown() { - shutdown.exit(3); - verify(exit).exit(3); - } - - @Test(timeout = 60_000) - public void testWaitReady() throws InterruptedException { - shutdown = new Shutdown(exit, true, 100_000); - shutdown.signalReady(false); - assertThat(shutdown.shouldExit()).isFalse(); - - final Thread t = new HookCaller(); - t.start(); - - await().atMost(Duration.TWO_SECONDS).pollDelay(50, TimeUnit.MILLISECONDS).until(new Callable<Boolean>() { - @Override - public Boolean call() throws Exception { - return t.isAlive(); - } - }); - - assertThat(shutdown.shouldExit()).isTrue(); - - shutdown.signalReady(true); - t.join(); - } - - @Test(timeout = 60_000) - public void testTimeout() throws InterruptedException { - shutdown = new Shutdown(exit, true, 0); - - Thread t = new HookCaller(); - t.start(); - t.join(); - } - - private class HookCaller extends Thread { - @Override - public void run() { - shutdown.hook.run(); - } - } -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/StatsTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/StatsTest.java deleted file mode 100644 index 6522fb6..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/StatsTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import org.mockito.Mockito; - -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.mock; -import org.junit.Test; -import static org.fest.assertions.Assertions.assertThat; - -public class StatsTest { - private PrintStream stdOut = mock(PrintStream.class); - private PrintStream stdErr; - private Logs logs = new Logs(stdOut, stdErr); - - @Test - public void shouldPrintStats() throws UnsupportedEncodingException { - new Stats(logs).start().stop(); - - verify(stdOut).println(Mockito.contains("Total time: ")); - verify(stdOut).println(Mockito.contains("Final Memory: ")); - } - - @Test - public void shouldFormatTime() { - assertThat(Stats.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s"); - assertThat(Stats.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s"); - assertThat(Stats.formatTime(3 * 1000 + 400)).isEqualTo("3.400s"); - assertThat(Stats.formatTime(400)).isEqualTo("0.400s"); - } -} diff --git a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/SystemInfoTest.java b/sonar-runner-cli/src/test/java/org/sonar/runner/cli/SystemInfoTest.java deleted file mode 100644 index e777003..0000000 --- a/sonar-runner-cli/src/test/java/org/sonar/runner/cli/SystemInfoTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SonarQube Runner - CLI - Distribution - * Copyright (C) 2011 SonarSource - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.runner.cli; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.verify; - -import static org.mockito.Mockito.verifyNoMoreInteractions; - -import org.sonar.runner.api.RunnerVersion; -import org.junit.Before; -import org.sonar.runner.cli.SystemInfo.System2; -import org.junit.Test; -import org.sonar.runner.cli.SystemInfo; -import static org.fest.assertions.Assertions.assertThat; - -public class SystemInfoTest { - System2 mockSystem; - Logs logs; - - @Before - public void setUp() { - mockSystem = mock(System2.class); - logs = mock(Logs.class); - SystemInfo.setSystem(mockSystem); - } - - @Test - public void test_java() { - mockJava(); - assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle (64-bit)"); - - when(mockSystem.getProperty("sun.arch.data.model")).thenReturn("32"); - assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle (32-bit)"); - - when(mockSystem.getProperty("sun.arch.data.model")).thenReturn(null); - assertThat(SystemInfo.java()).isEqualTo("Java 1.9 oracle"); - } - - @Test - public void test_os() { - mockOs(); - - assertThat(SystemInfo.os()).isEqualTo("linux 2.5 x64"); - } - - private void mockJava() { - when(mockSystem.getProperty("java.version")).thenReturn("1.9"); - when(mockSystem.getProperty("java.vendor")).thenReturn("oracle"); - when(mockSystem.getProperty("sun.arch.data.model")).thenReturn("64"); - } - - private void mockOs() { - when(mockSystem.getProperty("os.version")).thenReturn("2.5"); - when(mockSystem.getProperty("os.arch")).thenReturn("x64"); - when(mockSystem.getProperty("os.name")).thenReturn("linux"); - } - - @Test - public void should_print() { - mockOs(); - mockJava(); - when(mockSystem.getenv("SONAR_RUNNER_OPTS")).thenReturn("arg"); - - SystemInfo.print(logs); - - verify(mockSystem).getProperty("java.version"); - verify(mockSystem).getProperty("os.version"); - verify(mockSystem).getenv("SONAR_RUNNER_OPTS"); - - verify(logs).info("SonarQube Runner " + RunnerVersion.version()); - verify(logs).info("Java 1.9 oracle (64-bit)"); - verify(logs).info("linux 2.5 x64"); - verify(logs).info("SONAR_RUNNER_OPTS=arg"); - verifyNoMoreInteractions(logs); - } -} diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/emptyModules/project/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/emptyModules/project/sonar-project.properties deleted file mode 100644 index 708db4c..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/emptyModules/project/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.modules= diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/project/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/project/sonar-project.properties deleted file mode 100644 index 0d1e025..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/project/sonar-project.properties +++ /dev/null @@ -1,4 +0,0 @@ -project.prop=foo - -# overridden property -overridden.prop=project scope
\ No newline at end of file diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/runner/conf/sonar-runner.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/runner/conf/sonar-runner.properties deleted file mode 100644 index 7edfb99..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadCompleteConfiguration/runner/conf/sonar-runner.properties +++ /dev/null @@ -1,2 +0,0 @@ -overridden.prop=runner scope -global.prop=jdbc:mysql:localhost/sonar diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/module1/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/module1/sonar-project.properties deleted file mode 100644 index 6803263..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/module1/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectName=Module 1 diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/module2/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/module2/sonar-project.properties deleted file mode 100644 index c12fad8..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/module2/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectName=Module 2 diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/sonar-project.properties deleted file mode 100644 index 835124c..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfiguration/project/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.modules=module1,module2 diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module2.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module2.properties deleted file mode 100644 index 4df820c..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module2.properties +++ /dev/null @@ -1,2 +0,0 @@ -sonar.projectName=Module 2 -sonar.projectBaseDir=module_2 diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_1/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_1/sonar-project.properties deleted file mode 100644 index 6803263..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_1/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectName=Module 1 diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_2/Sample.js b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_2/Sample.js deleted file mode 100644 index e69de29..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_2/Sample.js +++ /dev/null diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_3/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_3/sonar-project.properties deleted file mode 100644 index c074231..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/module_3/sonar-project.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.projectName=Module 3 diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/sonar-project.properties deleted file mode 100644 index 999b04c..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadModuleConfigurationOverrideBasedir/project/sonar-project.properties +++ /dev/null @@ -1,4 +0,0 @@ -sonar.modules=module1,module2,module3 -module1.sonar.projectBaseDir=module_1 -module2.sonar.projectConfigFile=module2.properties -module3.sonar.projectConfigFile=module_3/sonar-project.properties diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByDirectPath/other-conf.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByDirectPath/other-conf.properties deleted file mode 100644 index 33dc79b..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByDirectPath/other-conf.properties +++ /dev/null @@ -1 +0,0 @@ -sonar.prop=otherValue diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByHome/conf/sonar-runner.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByHome/conf/sonar-runner.properties deleted file mode 100644 index 1e03622..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldLoadRunnerSettingsByHome/conf/sonar-runner.properties +++ /dev/null @@ -1,2 +0,0 @@ -sonar.prop=value -sonar.jdbc.url=jdbc:mysql:localhost/sonar diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module11/module111/placeholder.txt b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module11/module111/placeholder.txt deleted file mode 100644 index e69de29..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module11/module111/placeholder.txt +++ /dev/null diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module11/module112/placeholder.txt b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module11/module112/placeholder.txt deleted file mode 100644 index e69de29..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module11/module112/placeholder.txt +++ /dev/null diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module12/placeholder.txt b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module12/placeholder.txt deleted file mode 100644 index e69de29..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module1/module12/placeholder.txt +++ /dev/null diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module2/module21/placeholder.txt b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module2/module21/placeholder.txt deleted file mode 100644 index e69de29..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module2/module21/placeholder.txt +++ /dev/null diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module2/module22/placeholder.txt b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module2/module22/placeholder.txt deleted file mode 100644 index e69de29..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/module2/module22/placeholder.txt +++ /dev/null diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/sonar-project.properties b/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/sonar-project.properties deleted file mode 100644 index 56eb032..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/ConfTest/shouldSupportDeepModuleConfigurationInRoot/project/sonar-project.properties +++ /dev/null @@ -1,17 +0,0 @@ -sonar.modules=1,2 -1.sonar.projectName=Module 1 -1.sonar.projectBaseDir=module1 -1.sonar.modules=11,12 -1.11.sonar.projectBaseDir=module11 -1.11.sonar.projectName=Module 11 -1.11.sonar.modules=111,112 -1.11.111.sonar.projectBaseDir=module111 -1.11.111.sonar.projectName=Module 111 -1.11.112.sonar.projectBaseDir=module112 -1.11.112.sonar.projectName=Module 112 - -1.12.sonar.projectBaseDir=module12 -1.12.sonar.projectName=Module 12 - -2.sonar.projectName=Module 2 -2.sonar.projectBaseDir=module2
\ No newline at end of file diff --git a/sonar-runner-cli/src/test/resources/org/sonar/runner/RunnerTest/shouldInitDirs/fake.txt b/sonar-runner-cli/src/test/resources/org/sonar/runner/RunnerTest/shouldInitDirs/fake.txt deleted file mode 100644 index f0f877c..0000000 --- a/sonar-runner-cli/src/test/resources/org/sonar/runner/RunnerTest/shouldInitDirs/fake.txt +++ /dev/null @@ -1 +0,0 @@ -fake
\ No newline at end of file |