You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JavaCommandTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.process.monitor;
  21. import org.junit.Rule;
  22. import org.junit.Test;
  23. import org.junit.rules.TemporaryFolder;
  24. import java.io.File;
  25. import java.util.Properties;
  26. import static org.fest.assertions.Assertions.assertThat;
  27. public class JavaCommandTest {
  28. @Rule
  29. public TemporaryFolder temp = new TemporaryFolder();
  30. @Test
  31. public void test_parameters() throws Exception {
  32. JavaCommand command = new JavaCommand("es");
  33. command.setArgument("first_arg", "val1");
  34. Properties args = new Properties();
  35. args.setProperty("second_arg", "val2");
  36. command.setArguments(args);
  37. command.setClassName("org.sonar.ElasticSearch");
  38. command.setEnvVariable("JAVA_COMMAND_TEST", "1000");
  39. File tempDir = temp.newFolder();
  40. command.setTempDir(tempDir);
  41. File workDir = temp.newFolder();
  42. command.setWorkDir(workDir);
  43. command.addClasspath("lib/*.jar");
  44. command.addClasspath("conf/*.xml");
  45. command.addJavaOption("-Xmx128m");
  46. assertThat(command.toString()).isNotNull();
  47. assertThat(command.getClasspath()).containsOnly("lib/*.jar", "conf/*.xml");
  48. assertThat(command.getJavaOptions()).containsOnly("-Xmx128m");
  49. assertThat(command.getWorkDir()).isSameAs(workDir);
  50. assertThat(command.getTempDir()).isSameAs(tempDir);
  51. assertThat(command.getClassName()).isEqualTo("org.sonar.ElasticSearch");
  52. // copy current env variables
  53. assertThat(command.getEnvVariables().get("JAVA_COMMAND_TEST")).isEqualTo("1000");
  54. assertThat(command.getEnvVariables().size()).isEqualTo(System.getenv().size() + 1);
  55. }
  56. @Test
  57. public void add_java_options() throws Exception {
  58. JavaCommand command = new JavaCommand("foo");
  59. assertThat(command.getJavaOptions()).isEmpty();
  60. command.addJavaOptions("");
  61. assertThat(command.getJavaOptions()).isEmpty();
  62. command.addJavaOptions("-Xmx512m -Xms256m -Dfoo");
  63. assertThat(command.getJavaOptions()).containsOnly("-Xmx512m", "-Xms256m", "-Dfoo");
  64. }
  65. }