forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for manual and common rules
- Loading branch information
Simon Brandhof
committed
Jul 21, 2015
1 parent
853cb39
commit 4027764
Showing
14 changed files
with
386 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sonar.projectKey=common-rules-project | ||
sonar.projectName=Sample | ||
sonar.projectVersion=1.0-SNAPSHOT | ||
sonar.sources=src | ||
sonar.tests=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
there are duplications | ||
in this file | ||
|
||
there are duplications | ||
in this file | ||
|
||
there are duplications | ||
in this file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
lines:120 | ||
ncloc:100 | ||
complexity:7 | ||
comment_lines:3 | ||
public_api:5 | ||
public_undocumented_api:2 | ||
lines_to_cover:80 | ||
uncovered_lines:70 | ||
conditions_to_cover:10 | ||
uncovered_conditions:9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is the test |
4 changes: 4 additions & 0 deletions
4
it/it-projects/issue/common-rules/test/SampleTest.xoo.measures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
skipped_tests:5 | ||
test_errors:2 | ||
test_failures:1 | ||
tests:10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
it/it-tests/src/test/java/issue/suite/CommonRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2009-2014 SonarSource SA | ||
* All rights reserved | ||
* mailto:contact AT sonarsource DOT com | ||
*/ | ||
package issue.suite; | ||
|
||
import com.sonar.orchestrator.Orchestrator; | ||
import com.sonar.orchestrator.build.SonarRunner; | ||
import com.sonar.orchestrator.locator.FileLocation; | ||
import java.util.List; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.sonar.wsclient.issue.Issue; | ||
import org.sonar.wsclient.issue.IssueQuery; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static util.ItUtils.projectDir; | ||
|
||
public class CommonRulesTest { | ||
|
||
public static final String FILE_KEY = "common-rules-project:src/Sample.xoo"; | ||
public static final String TEST_FILE_KEY = "common-rules-project:test/SampleTest.xoo"; | ||
|
||
@ClassRule | ||
public static Orchestrator orchestrator = IssueTestSuite.ORCHESTRATOR; | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
orchestrator.resetData(); | ||
orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/issue/suite/CommonRulesTest/xoo-common-rules-profile.xml")); | ||
orchestrator.getServer().provisionProject("common-rules-project", "Sample"); | ||
orchestrator.getServer().associateProjectToQualityProfile("common-rules-project", "xoo", "xoo-common-rules"); | ||
SonarRunner analysis = SonarRunner.create(projectDir("issue/common-rules"), | ||
"sonar.cpd.xoo.minimumTokens", "2", | ||
"sonar.cpd.xoo.minimumLines", "2"); | ||
orchestrator.executeBuild(analysis); | ||
} | ||
|
||
@Test | ||
public void test_rule_on_duplicated_blocks() { | ||
List<Issue> issues = findIssues(FILE_KEY, "common-xoo:DuplicatedBlocks"); | ||
assertThat(issues).hasSize(1); | ||
} | ||
|
||
@Test | ||
public void test_rule_on_comments() { | ||
List<Issue> issues = findIssues(FILE_KEY, "common-xoo:InsufficientCommentDensity"); | ||
assertThat(issues.size()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void test_rule_on_coverage() { | ||
List<Issue> issues = findIssues(FILE_KEY, "common-xoo:InsufficientBranchCoverage"); | ||
assertThat(issues.size()).isEqualTo(1); | ||
|
||
issues = findIssues(FILE_KEY, "common-xoo:InsufficientLineCoverage"); | ||
assertThat(issues.size()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void test_rule_on_skipped_tests() { | ||
List<Issue> issues = findIssues(TEST_FILE_KEY, "common-xoo:SkippedUnitTests"); | ||
assertThat(issues.size()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
public void test_rule_on_test_errors() { | ||
List<Issue> issues = findIssues(TEST_FILE_KEY, "common-xoo:FailedUnitTests"); | ||
assertThat(issues.size()).isEqualTo(1); | ||
} | ||
|
||
private List<Issue> findIssues(String componentKey, String ruleKey) { | ||
return orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().components(componentKey).rules(ruleKey)).list(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (C) 2009-2014 SonarSource SA | ||
* All rights reserved | ||
* mailto:contact AT sonarsource DOT com | ||
*/ | ||
package issue.suite; | ||
|
||
import com.sonar.orchestrator.Orchestrator; | ||
import org.junit.ClassRule; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
import util.ItUtils; | ||
|
||
@RunWith(Suite.class) | ||
@Suite.SuiteClasses({ | ||
ManualRulesTest.class, CommonRulesTest.class | ||
}) | ||
public class IssueTestSuite { | ||
|
||
@ClassRule | ||
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv() | ||
.addPlugin(ItUtils.xooPlugin()) | ||
.build(); | ||
} |
52 changes: 52 additions & 0 deletions
52
it/it-tests/src/test/java/issue/suite/ManualRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2009-2014 SonarSource SA | ||
* All rights reserved | ||
* mailto:contact AT sonarsource DOT com | ||
*/ | ||
package issue.suite; | ||
|
||
import com.sonar.orchestrator.Orchestrator; | ||
import com.sonar.orchestrator.selenium.Selenese; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
|
||
public class ManualRulesTest { | ||
|
||
@ClassRule | ||
public static Orchestrator orchestrator = IssueTestSuite.ORCHESTRATOR; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
orchestrator.resetData(); | ||
deleteManualRules(); | ||
} | ||
|
||
@AfterClass | ||
public static void purgeManualRules() { | ||
deleteManualRules(); | ||
} | ||
|
||
@Test | ||
public void testManualRules() { | ||
Selenese selenese = Selenese | ||
.builder() | ||
.setHtmlTestsInClasspath("manual-rules", | ||
"/issue/suite/ManualRulesTest/create_edit_delete_manual_rule.html" | ||
).build(); | ||
orchestrator.executeSelenese(selenese); | ||
} | ||
|
||
protected static void deleteManualRules(){ | ||
try { | ||
Connection connection = orchestrator.getDatabase().openConnection(); | ||
connection.prepareStatement("DELETE FROM rules WHERE rules.plugin_name='manual'").execute(); | ||
} catch (SQLException e) { | ||
throw new IllegalStateException("Fail to remove manual rules", e); | ||
} | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
it/it-tests/src/test/resources/issue/suite/CommonRulesTest/xoo-common-rules-profile.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0"?><!-- Generated by Sonar --> | ||
<profile> | ||
<name>xoo-common-rules</name> | ||
<language>xoo</language> | ||
<rules> | ||
<rule> | ||
<repositoryKey>common-xoo</repositoryKey> | ||
<key>DuplicatedBlocks</key> | ||
<priority>CRITICAL</priority> | ||
</rule> | ||
<rule> | ||
<repositoryKey>common-xoo</repositoryKey> | ||
<key>InsufficientBranchCoverage</key> | ||
<priority>CRITICAL</priority> | ||
<parameters> | ||
<parameter> | ||
<key>minimumBranchCoverageRatio</key> | ||
<value>90</value> | ||
</parameter> | ||
</parameters> | ||
</rule> | ||
<rule> | ||
<repositoryKey>common-xoo</repositoryKey> | ||
<key>InsufficientCommentDensity</key> | ||
<priority>CRITICAL</priority> | ||
<parameters> | ||
<parameter> | ||
<key>minimumCommentDensity</key> | ||
<value>90.0</value> | ||
</parameter> | ||
</parameters> | ||
</rule> | ||
<rule> | ||
<repositoryKey>common-xoo</repositoryKey> | ||
<key>InsufficientLineCoverage</key> | ||
<priority>CRITICAL</priority> | ||
<parameters> | ||
<parameter> | ||
<key>minimumLineCoverageRatio</key> | ||
<value>90</value> | ||
</parameter> | ||
</parameters> | ||
</rule> | ||
<rule> | ||
<repositoryKey>common-xoo</repositoryKey> | ||
<key>FailedUnitTests</key> | ||
<priority>CRITICAL</priority> | ||
</rule> | ||
<rule> | ||
<repositoryKey>common-xoo</repositoryKey> | ||
<key>SkippedUnitTests</key> | ||
<priority>CRITICAL</priority> | ||
</rule> | ||
</rules> | ||
</profile> |
Oops, something went wrong.