Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Sonar Standalone Runner
  3. * Copyright (C) 2011 SonarSource
  4. * dev@sonar.codehaus.org
  5. *
  6. * This program 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. * This program 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
  17. * License along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.runner;
  21. import org.apache.commons.configuration.BaseConfiguration;
  22. import org.apache.commons.configuration.Configuration;
  23. import org.junit.Test;
  24. import java.io.File;
  25. import static org.hamcrest.Matchers.is;
  26. import static org.hamcrest.Matchers.startsWith;
  27. import static org.junit.Assert.assertThat;
  28. import static org.junit.Assert.fail;
  29. public class LauncherTest {
  30. @Test
  31. public void shouldFilterFiles() throws Exception {
  32. File baseDir = new File(getClass().getResource("/org/sonar/runner/LauncherTest/shouldFilterFiles/").toURI());
  33. assertThat(Launcher.getLibraries(baseDir, "in*.txt").length, is(1));
  34. assertThat(Launcher.getLibraries(baseDir, "*.txt").length, is(2));
  35. assertThat(Launcher.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/in*.txt").length, is(1));
  36. assertThat(Launcher.getLibraries(baseDir.getParentFile(), "shouldFilterFiles/*.txt").length, is(2));
  37. }
  38. @Test
  39. public void shouldWorkWithAbsolutePath() throws Exception {
  40. File baseDir = new File("not-exists");
  41. String absolutePattern = new File(getClass().getResource("/org/sonar/runner/LauncherTest/shouldFilterFiles/").toURI()).getAbsolutePath() + "/in*.txt";
  42. assertThat(Launcher.getLibraries(baseDir.getParentFile(), absolutePattern).length, is(1));
  43. }
  44. @Test
  45. public void shouldThrowExceptionWhenNoFilesMatchingPattern() throws Exception {
  46. File baseDir = new File(getClass().getResource("/org/sonar/runner/LauncherTest/shouldFilterFiles/").toURI());
  47. try {
  48. Launcher.getLibraries(baseDir, "*.jar");
  49. fail("Exception expected");
  50. } catch (RunnerException e) {
  51. assertThat(e.getMessage(), startsWith("No files matching pattern \"*.jar\" in directory "));
  52. }
  53. }
  54. @Test
  55. public void testGetSqlLevel() throws Exception {
  56. Configuration conf = new BaseConfiguration();
  57. assertThat(Launcher.getSqlLevel(conf), is("WARN"));
  58. conf.setProperty("sonar.showSql", "true");
  59. assertThat(Launcher.getSqlLevel(conf), is("DEBUG"));
  60. conf.setProperty("sonar.showSql", "false");
  61. assertThat(Launcher.getSqlLevel(conf), is("WARN"));
  62. }
  63. @Test
  64. public void testGetSqlResultsLevel() throws Exception {
  65. Configuration conf = new BaseConfiguration();
  66. assertThat(Launcher.getSqlResultsLevel(conf), is("WARN"));
  67. conf.setProperty("sonar.showSqlResults", "true");
  68. assertThat(Launcher.getSqlResultsLevel(conf), is("DEBUG"));
  69. conf.setProperty("sonar.showSqlResults", "false");
  70. assertThat(Launcher.getSqlResultsLevel(conf), is("WARN"));
  71. }
  72. }