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.

GenericTestExecutionSensorTest.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  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 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.scanner.genericcoverage;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.nio.charset.StandardCharsets;
  24. import java.util.HashMap;
  25. import java.util.Map;
  26. import org.apache.commons.io.FileUtils;
  27. import org.junit.Rule;
  28. import org.junit.Test;
  29. import org.junit.rules.TemporaryFolder;
  30. import org.sonar.api.config.internal.Encryption;
  31. import org.sonar.api.config.PropertyDefinitions;
  32. import org.sonar.api.utils.log.LogTester;
  33. import org.sonar.api.utils.log.LoggerLevel;
  34. import org.sonar.scanner.config.DefaultConfiguration;
  35. import org.sonar.scanner.deprecated.test.TestPlanBuilder;
  36. import org.sonar.scanner.scan.ProjectConfiguration;
  37. import org.sonar.api.batch.sensor.internal.SensorContextTester;
  38. import static org.assertj.core.api.Assertions.assertThat;
  39. import static org.mockito.Mockito.mock;
  40. public class GenericTestExecutionSensorTest {
  41. @Rule
  42. public TemporaryFolder temp = new TemporaryFolder();
  43. @Rule
  44. public LogTester logTester = new LogTester();
  45. @Test
  46. public void logWhenDeprecatedPropsAreUsed() throws IOException {
  47. File basedir = temp.newFolder();
  48. File report = new File(basedir, "report.xml");
  49. FileUtils.write(report, "<unitTest version=\"1\"><file path=\"A.java\"><testCase name=\"test1\" duration=\"500\"/></file></unitTest>", StandardCharsets.UTF_8);
  50. SensorContextTester context = SensorContextTester.create(basedir);
  51. Map<String, String> settings = new HashMap<>();
  52. settings.put(GenericTestExecutionSensor.OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY, "report.xml");
  53. PropertyDefinitions defs = new PropertyDefinitions(GenericTestExecutionSensor.properties());
  54. DefaultConfiguration config = new ProjectConfiguration(defs, new Encryption(null), settings);
  55. new GenericTestExecutionSensor(mock(TestPlanBuilder.class), config).execute(context);
  56. assertThat(logTester.logs(LoggerLevel.WARN)).contains(
  57. "Using 'unitTest' as root element of the report is deprecated. Please change to 'testExecutions'.",
  58. "Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.");
  59. assertThat(logTester.logs(LoggerLevel.INFO)).contains(
  60. "Imported test execution data for 0 files",
  61. "Test execution data ignored for 1 unknown files, including:\nA.java");
  62. }
  63. }