Skip to content

Commit

Permalink
Set empty profile for it-plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vilchik-elena committed Aug 24, 2015
1 parent f526a67 commit 56192c0
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public static void prepare() {

SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(orchestrator.getFileLocationOfShared("src").getFile())
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".")
// FIXME after full migration of the grammar: was 424m before migration (and with Java 6)
.setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx2500m");

Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

wsClient = orchestrator.getServer().getWsClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -32,6 +31,8 @@

import java.util.regex.Pattern;

import static org.fest.assertions.Assertions.assertThat;

public class CoverageTest {

@ClassRule
Expand All @@ -46,11 +47,12 @@ public void clean() {
public void LCOV_path_can_be_relative() throws Exception {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".")
.setProperty("sonar.javascript.lcov.reportPath", "coverage.lcov");
Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4);
Expand All @@ -63,11 +65,12 @@ public void LCOV_path_can_be_relative() throws Exception {
public void LCOV_path_can_be_absolute() {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".")
.setProperty("sonar.javascript.lcov.reportPath", TestUtils.file("projects/lcov/coverage.lcov").getAbsolutePath());
Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4);
Expand All @@ -81,11 +84,12 @@ public void LCOV_it_coverage() {
if (Tests.is_strictly_after_plugin("2.5")) {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".")
.setProperty("sonar.javascript.lcov.itReportPath", TestUtils.file("projects/lcov/coverage.lcov").getAbsolutePath());
Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

assertThat(getProjectMeasure("it_lines_to_cover").getValue()).isEqualTo(4);
Expand All @@ -99,12 +103,13 @@ public void LCOV_it_coverage() {
public void force_zero_coverage() {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey("project")
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".")
.setProperty("sonar.javascript.forceZeroCoverage", "true");

Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4);
Expand All @@ -120,10 +125,11 @@ public void force_zero_coverage() {
public void no_coverage_information_saved() {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".");
Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

assertThat(getProjectMeasure("lines_to_cover")).isNull();
Expand All @@ -137,12 +143,13 @@ public void no_coverage_information_saved() {
public void print_log_for_not_found_resource() throws InterruptedException {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("lcov"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs(".")
.setProperty("sonar.javascript.lcov.reportPath", TestUtils.file("projects/lcov/coverage-wrong-file-name.lcov").getAbsolutePath())
.setDebugLogs(true);
Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
BuildResult result = orchestrator.executeBuild(build);

// Check that a log is printed
Expand All @@ -162,9 +169,4 @@ private Measure getFileMeasure(String metricKey) {
Resource resource = orchestrator.getServer().getWsClient().find(ResourceQuery.createForMetrics("project:file.js", metricKey));
return resource == null ? null : resource.getMeasure(metricKey);
}

private static String keyFor(String s) {
return "project:" + (orchestrator.getConfiguration().getSonarVersion().isGreaterThanOrEquals("4.2") ? "src/" : "") + s;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
Expand All @@ -31,6 +29,9 @@

import java.util.List;

import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;

public class CustomRulesTests {

@ClassRule
Expand All @@ -46,8 +47,9 @@ public void test() throws InterruptedException {
.setProjectKey("custom-rules")
.setProjectName("Custom Rules")
.setProjectVersion("1.0")
.setSourceDirs("src")
.setProfile("javascript-custom-rules-profile");
.setSourceDirs("src");
orchestrator.getServer().provisionProject("custom-rules", "Custom Rules");
orchestrator.getServer().associateProjectToQualityProfile("custom-rules", "js", "javascript-custom-rules-profile");
orchestrator.executeBuild(build);

IssueClient issueClient = orchestrator.getServer().wsClient().issueClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public static void prepare() {

SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("metrics"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs("src");
Tests.setEmptyProfile(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
orchestrator.executeBuild(build);

wsClient = orchestrator.getServer().getWsClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class Tests {

private static final String PLUGIN_KEY = "javascript";
private static final String CUSTOM_RULES_ARTIFACT_ID = "javascript-custom-rules-plugin";
public static final String PROJECT_KEY = "project";

@ClassRule
public static final Orchestrator ORCHESTRATOR;
Expand All @@ -55,6 +56,7 @@ public final class Tests {
.addPlugin(FileLocation.of(TestUtils.pluginJar(CUSTOM_RULES_ARTIFACT_ID)));
}

orchestratorBuilder.restoreProfileAtStartup(FileLocation.ofClasspath("/empty-profile.xml"));
ORCHESTRATOR = orchestratorBuilder.build();
}

Expand All @@ -73,8 +75,13 @@ public static SonarRunner createSonarRunnerBuild() {
SonarRunner build = SonarRunner.create();
build.setProperty("sonar.exclusions", "**/ecmascript6/**, **/file-for-rules/**, **/frameworks/**");
build.setSourceEncoding("UTF-8");

return build;
}


public static void setEmptyProfile(String projectKey, String projectName) {
ORCHESTRATOR.getServer().provisionProject(projectKey, projectName);
ORCHESTRATOR.getServer().associateProjectToQualityProfile(projectKey, "js", "empty-profile");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import static org.fest.assertions.Assertions.assertThat;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
Expand All @@ -33,6 +32,8 @@

import java.util.regex.Pattern;

import static org.fest.assertions.Assertions.assertThat;

public class UnitTestTest {

@ClassRule
Expand All @@ -42,6 +43,7 @@ public class UnitTestTest {
@Before
public void clean() {
orchestrator.resetData();
orchestrator.getServer().provisionProject(Tests.PROJECT_KEY, Tests.PROJECT_KEY);
}

@Test
Expand Down Expand Up @@ -119,13 +121,15 @@ private static String keyFor(String s) {
private static SonarRunner createBuildWithReport(String reportPath) {
SonarRunner build = Tests.createSonarRunnerBuild()
.setProjectDir(TestUtils.projectDir("unittest"))
.setProjectKey("project")
.setProjectName("project")
.setProjectKey(Tests.PROJECT_KEY)
.setProjectName(Tests.PROJECT_KEY)
.setProjectVersion("1.0")
.setSourceDirs("main")
.setTestDirs("test")
.setProperty("sonar.javascript.jstestdriver.reportsPath", reportPath).setDebugLogs(true);

orchestrator.getServer().associateProjectToQualityProfile(Tests.PROJECT_KEY, "js", "empty-profile");

if (!Tests.is_strictly_after_plugin("2.7")) {
build.setProperty("sonar.test.exclusions", "**/Another-PersonTest.js");
}
Expand Down
8 changes: 8 additions & 0 deletions its/plugin/tests/src/test/resources/empty-profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<profile>
<name>empty-profile</name>
<language>js</language>
<rules>
</rules>
</profile>

0 comments on commit 56192c0

Please sign in to comment.