Search in sources :

Example 6 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class UnitTestsTest method tests_with_report_name_suffix.

@Test
public void tests_with_report_name_suffix() {
    MavenBuild build = MavenBuild.create().setPom(TestUtils.projectPom("tests-surefire-suffix")).setGoals("clean test-compile surefire:test -Dsurefire.reportNameSuffix=Run1", "test-compile surefire:test -Dsurefire.reportNameSuffix=Run2", "sonar:sonar");
    orchestrator.executeBuild(build);
    Map<String, Measure> measures = getMeasures("com.sonarsource.it.samples:tests-surefire-suffix", "tests", "test_errors", "test_failures", "skipped_tests", "test_execution_time", "test_success_density");
    assertThat(parseInt(measures.get("tests").getValue())).isEqualTo(2);
    assertThat(parseInt(measures.get("test_errors").getValue())).isEqualTo(0);
    assertThat(parseInt(measures.get("test_failures").getValue())).isEqualTo(0);
    assertThat(parseInt(measures.get("skipped_tests").getValue())).isEqualTo(2);
    assertThat(parseInt(measures.get("test_execution_time").getValue())).isGreaterThan(0);
    assertThat(parseDouble(measures.get("test_success_density").getValue())).isEqualTo(100.0);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Measure(org.sonarqube.ws.WsMeasures.Measure) Test(org.junit.Test)

Example 7 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaExtensionsTest method test.

@Test
public void test() {
    MavenBuild build = MavenBuild.create(TestUtils.projectPom("java-extension")).setCleanSonarGoals().setProperty("sonar.profile", "java-extension");
    orchestrator.executeBuild(build);
    IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
    List<Issue> issues = issueClient.find(IssueQuery.create().rules("java-extension:example").componentRoots("com.sonarsource.it.projects:java-extension")).list();
    // We found issues so the extension rule was properly set.
    assertThat(issues).hasSize(4);
    issues = issueClient.find(IssueQuery.create().rules("java-extension:subscriptionexamplecheck").componentRoots("com.sonarsource.it.projects:java-extension")).list();
    assertThat(issues).hasSize(3);
    issues = issueClient.find(IssueQuery.create().rules("java-extension:subscriptionexampletestcheck").componentRoots("com.sonarsource.it.projects:java-extension")).list();
    assertThat(issues).hasSize(1);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) Issue(org.sonar.wsclient.issue.Issue) IssueClient(org.sonar.wsclient.issue.IssueClient) Test(org.junit.Test)

Example 8 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JaCoCoControllerTest method test_coverage_per_test_reuse_forks.

@Test
public void test_coverage_per_test_reuse_forks() throws Exception {
    MavenBuild build = MavenBuild.create(TestUtils.projectPom("coverage_error")).setProperty("skipTests", "false").setProperty("javaPluginVersion", javaVersion).setGoals("org.jacoco:jacoco-maven-plugin:prepare-agent clean verify", "sonar:sonar").addArgument("-P coverage-per-test-forked");
    BuildResult buildResult = orchestrator.executeBuildQuietly(build);
    assertThat(buildResult.isSuccess()).isTrue();
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) BuildResult(com.sonar.orchestrator.build.BuildResult) Test(org.junit.Test)

Example 9 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JaCoCoControllerTest method test_error_thrown.

@Test
public void test_error_thrown() {
    // We build the project with JunitListeners to get coverage but with no jacoco agent to let JaCoCoController throw NoClassDefFoundError
    MavenBuild build = MavenBuild.create(TestUtils.projectPom("coverage_error")).setProperty("skipTests", "false").setProperty("javaPluginVersion", javaVersion).setGoals("clean", "package");
    BuildResult buildResult = orchestrator.executeBuildQuietly(build);
    assertThat(buildResult.isSuccess()).isFalse();
    assertThat(buildResult.getLogs()).contains("JacocoControllerError");
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) BuildResult(com.sonar.orchestrator.build.BuildResult) Test(org.junit.Test)

Example 10 with MavenBuild

use of com.sonar.orchestrator.build.MavenBuild in project sonar-java by SonarSource.

the class JavaComplexityTest method analyzeProject.

@BeforeClass
public static void analyzeProject() {
    orchestrator.resetData();
    MavenBuild build = MavenBuild.create(TestUtils.projectPom("java-complexity")).setCleanSonarGoals().setProperty("sonar.dynamicAnalysis", "false").setProperty("sonar.java.binaries", "target").setProperty("sonar.profile", "java-complexity");
    orchestrator.executeBuild(build);
}
Also used : MavenBuild(com.sonar.orchestrator.build.MavenBuild) BeforeClass(org.junit.BeforeClass)

Aggregations

MavenBuild (com.sonar.orchestrator.build.MavenBuild)30 Test (org.junit.Test)23 BuildResult (com.sonar.orchestrator.build.BuildResult)7 BeforeClass (org.junit.BeforeClass)4 Issue (org.sonar.wsclient.issue.Issue)3 IssueClient (org.sonar.wsclient.issue.IssueClient)3 File (java.io.File)2 Measure (org.sonarqube.ws.WsMeasures.Measure)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 FileLocation (com.sonar.orchestrator.locator.FileLocation)1 MavenLocation (com.sonar.orchestrator.locator.MavenLocation)1 MavenLocator (com.sonar.orchestrator.locator.MavenLocator)1 Double.parseDouble (java.lang.Double.parseDouble)1 WsComponents (org.sonarqube.ws.WsComponents)1