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.

DuplicationTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2016 SonarSource SA
  4. * mailto:contact 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.sonarsource.sonarqube.perf.scanner.suite;
  21. import com.sonar.orchestrator.Orchestrator;
  22. import com.sonar.orchestrator.build.MavenBuild;
  23. import com.sonar.orchestrator.locator.FileLocation;
  24. import org.sonarsource.sonarqube.perf.PerfTestCase;
  25. import java.io.IOException;
  26. import org.junit.Before;
  27. import org.junit.BeforeClass;
  28. import org.junit.ClassRule;
  29. import org.junit.Rule;
  30. import org.junit.Test;
  31. import org.junit.rules.ErrorCollector;
  32. import org.junit.rules.TemporaryFolder;
  33. import org.sonar.wsclient.services.Resource;
  34. import org.sonar.wsclient.services.ResourceQuery;
  35. import static org.fest.assertions.Assertions.assertThat;
  36. public class DuplicationTest extends PerfTestCase {
  37. @Rule
  38. public ErrorCollector collector = new ErrorCollector();
  39. @Rule
  40. public TemporaryFolder temp = new TemporaryFolder();
  41. @ClassRule
  42. public static Orchestrator orchestrator = ScannerPerfTestSuite.ORCHESTRATOR;
  43. @BeforeClass
  44. public static void setUp() throws IOException {
  45. // Execute a first analysis to prevent any side effects with cache of plugin JAR files
  46. orchestrator.executeBuild(newScanner("-Xmx512m -server", "sonar.profile", "one-xoo-issue-per-line"));
  47. }
  48. @Before
  49. public void cleanDatabase() {
  50. orchestrator.resetData();
  51. }
  52. /**
  53. * SONAR-3060
  54. */
  55. @Test
  56. public void hugeJavaFile() {
  57. MavenBuild build = MavenBuild.create(FileLocation.of("projects/huge-file/pom.xml").getFile())
  58. .setEnvironmentVariable("MAVEN_OPTS", "-Xmx1024m")
  59. .setProperty("sonar.sourceEncoding", "UTF-8")
  60. .setCleanSonarGoals();
  61. orchestrator.executeBuild(build);
  62. Resource file = getResource("com.sonarsource.it.samples:huge-file:src/main/java/huge/HugeFile.java");
  63. assertThat(file.getMeasureValue("duplicated_lines")).isGreaterThan(50000.0);
  64. }
  65. private Resource getResource(String key) {
  66. return orchestrator.getServer().getWsClient()
  67. .find(ResourceQuery.createForMetrics(key, "duplicated_lines", "duplicated_blocks", "duplicated_files", "duplicated_lines_density", "useless-duplicated-lines"));
  68. }
  69. }