diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-07 22:59:22 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-09 20:46:58 +0100 |
commit | 15cd248b047daa72b37bf45b06f597ebab659187 (patch) | |
tree | f8cd76662e0fc6b0bd31525267cf2db3fd105846 /sonar-application | |
parent | 783ee9d9a79f82bac70903e9a30742a8b6808aa5 (diff) | |
download | sonarqube-15cd248b047daa72b37bf45b06f597ebab659187.tar.gz sonarqube-15cd248b047daa72b37bf45b06f597ebab659187.zip |
SONAR-8351 Clean-up AppTest
Diffstat (limited to 'sonar-application')
-rw-r--r-- | sonar-application/src/test/java/org/sonar/application/AppTest.java | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/sonar-application/src/test/java/org/sonar/application/AppTest.java b/sonar-application/src/test/java/org/sonar/application/AppTest.java index b6ba402c0a3..9a0ae277836 100644 --- a/sonar-application/src/test/java/org/sonar/application/AppTest.java +++ b/sonar-application/src/test/java/org/sonar/application/AppTest.java @@ -55,94 +55,73 @@ public class AppTest { @Test public void start_all_processes_if_cluster_mode_is_disabled() throws Exception { + Props props = initDefaultProps(); Monitor monitor = mock(Monitor.class); App app = new App(monitor); - Props props = initDefaultProps(); app.start(props); - ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); verify(monitor).start(argument.capture()); - assertThat(argument.getValue()).extracting("processId").containsExactly(ProcessId.ELASTICSEARCH, ProcessId.WEB_SERVER, ProcessId.COMPUTE_ENGINE); app.stopAsync(); + verify(monitor).stop(); } @Test public void start_only_web_server_node_in_cluster() throws Exception { - Monitor monitor = mock(Monitor.class); - App app = new App(monitor); Props props = initDefaultProps(); props.set(ProcessProperties.CLUSTER_ENABLED, "true"); props.set(ProcessProperties.CLUSTER_CE_DISABLED, "true"); props.set(ProcessProperties.CLUSTER_SEARCH_DISABLED, "true"); - app.start(props); - ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); - verify(monitor).start(argument.capture()); + List<JavaCommand> commands = start(props); - assertThat(argument.getValue()).extracting("processId").containsOnly(ProcessId.WEB_SERVER); + assertThat(commands).extracting("processId").containsOnly(ProcessId.WEB_SERVER); } @Test public void start_only_compute_engine_node_in_cluster() throws Exception { - Monitor monitor = mock(Monitor.class); - App app = new App(monitor); Props props = initDefaultProps(); props.set(ProcessProperties.CLUSTER_ENABLED, "true"); props.set(ProcessProperties.CLUSTER_WEB_DISABLED, "true"); props.set(ProcessProperties.CLUSTER_SEARCH_DISABLED, "true"); - app.start(props); - ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); - verify(monitor).start(argument.capture()); + List<JavaCommand> commands = start(props); - assertThat(argument.getValue()).extracting("processId").containsOnly(ProcessId.COMPUTE_ENGINE); + assertThat(commands).extracting("processId").containsOnly(ProcessId.COMPUTE_ENGINE); } @Test public void start_only_elasticsearch_node_in_cluster() throws Exception { - Monitor monitor = mock(Monitor.class); - App app = new App(monitor); Props props = initDefaultProps(); props.set(ProcessProperties.CLUSTER_ENABLED, "true"); props.set(ProcessProperties.CLUSTER_WEB_DISABLED, "true"); props.set(ProcessProperties.CLUSTER_CE_DISABLED, "true"); - app.start(props); - ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); - verify(monitor).start(argument.capture()); + List<JavaCommand> commands = start(props); - assertThat(argument.getValue()).extracting("processId").containsOnly(ProcessId.ELASTICSEARCH); + assertThat(commands).extracting("processId").containsOnly(ProcessId.ELASTICSEARCH); } @Test public void add_custom_jdbc_driver_to_tomcat_classpath() throws Exception { - Monitor monitor = mock(Monitor.class); - App app = new App(monitor); Props props = initDefaultProps(); props.set("sonar.jdbc.driverPath", "oracle/ojdbc6.jar"); - app.start(props); - ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); - verify(monitor).start(argument.capture()); + List<JavaCommand> commands = start(props); - assertThat(argument.getValue().get(1).getClasspath()).contains("oracle/ojdbc6.jar"); + assertThat(commands.get(1).getClasspath()).contains("oracle/ojdbc6.jar"); } @Test public void sets_TMPDIR_env_var_of_Web_process() throws Exception { - Monitor monitor = mock(Monitor.class); - App app = new App(monitor); Props props = initDefaultProps(); String expectedTmpDir = "expected tmp dir"; props.set("sonar.path.temp", expectedTmpDir); - app.start(props); - ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); - verify(monitor).start(argument.capture()); + List<JavaCommand> commands = start(props); - assertThat(argument.getValue().get(1).getEnvVariables()).contains(entry("TMPDIR", expectedTmpDir)); + assertThat(commands.get(1).getEnvVariables()).contains(entry("TMPDIR", expectedTmpDir)); } private Props initDefaultProps() throws IOException { @@ -154,6 +133,15 @@ public class AppTest { return props; } + private List<JavaCommand> start(Props props) throws Exception { + Monitor monitor = mock(Monitor.class); + App app = new App(monitor); + app.start(props); + ArgumentCaptor<List<JavaCommand>> argument = newJavaCommandArgumentCaptor(); + verify(monitor).start(argument.capture()); + return argument.getValue(); + } + private ArgumentCaptor<List<JavaCommand>> newJavaCommandArgumentCaptor() { Class<List<JavaCommand>> listClass = (Class<List<JavaCommand>>) (Class) List.class; return ArgumentCaptor.forClass(listClass); |