Browse Source

Fix ITs (Findbugs not compatible with Java 4.0)

tags/2.7
Julien HENRY 7 years ago
parent
commit
062cc9de4a

+ 7
- 58
it/src/test/java/com/sonar/runner/it/JavaTest.java View File

@@ -36,7 +36,6 @@ import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

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

public class JavaTest extends ScannerTestCase {

@@ -70,31 +69,16 @@ public class JavaTest extends ScannerTestCase {
assertThat(project.getName()).isEqualTo("Java Sample, with comma");
assertThat(project.getDescription()).isEqualTo("This is a Java sample");
assertThat(project.getVersion()).isEqualTo("1.2.3");
if (!orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) {
assertThat(project.getLanguage()).isEqualTo("java");
}
assertThat(project.getMeasureIntValue("files")).isEqualTo(2);
assertThat(project.getMeasureIntValue("classes")).isEqualTo(2);
assertThat(project.getMeasureIntValue("ncloc")).isGreaterThan(10);
assertThat(project.getMeasureIntValue("lcom4")).isNull(); // no bytecode
if (orchestrator.getServer().version().isGreaterThanOrEquals("3.7")) {
// the squid rules enabled in sonar-way-profile do not exist in SQ 3.0
assertThat(project.getMeasureIntValue("violations")).isGreaterThan(0);
}
assertThat(project.getMeasureIntValue("violations")).isGreaterThan(0);

Resource file = orchestrator.getServer().getWsClient()
.find(new ResourceQuery(helloFileKey()).setMetrics("files", "ncloc", "classes", "lcom4", "violations"));
if (orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) {
assertThat(file.getName()).isEqualTo("Hello.java");
} else {
assertThat(file.getName()).isEqualTo("Hello");
assertThat(file.getMeasureIntValue("lcom4")).isNull(); // no bytecode
}
.find(new ResourceQuery("java:sample:src/basic/Hello.java").setMetrics("files", "ncloc", "classes", "violations"));
assertThat(file.getName()).isEqualTo("Hello.java");
assertThat(file.getMeasureIntValue("ncloc")).isEqualTo(7);
if (orchestrator.getServer().version().isGreaterThanOrEquals("3.7")) {
// the squid rules enabled in sonar-way-profile do not exist in SQ 3.0
assertThat(file.getMeasureIntValue("violations")).isGreaterThan(0);
}
assertThat(file.getMeasureIntValue("violations")).isGreaterThan(0);
}

@Test
@@ -108,20 +92,16 @@ public class JavaTest extends ScannerTestCase {

Resource project = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:bytecode").setMetrics("lcom4", "violations"));
assertThat(project.getName()).isEqualTo("Java Bytecode Sample");
if (!orchestrator.getServer().version().isGreaterThanOrEquals("4.1")) {
// SONAR-4853 LCOM4 is no more computed on SQ 4.1
assertThat(project.getMeasureIntValue("lcom4")).isGreaterThanOrEqualTo(1);
}
// the squid rules enabled in sonar-way-profile do not exist in SQ 3.0
assertThat(project.getMeasureIntValue("violations")).isGreaterThan(0);

Resource file = orchestrator.getServer().getWsClient().find(new ResourceQuery(findbugsFileKey()).setMetrics("lcom4", "violations"));
Resource file = orchestrator.getServer().getWsClient().find(new ResourceQuery("java:bytecode:src/HasFindbugsViolation.java").setMetrics("lcom4", "violations"));
assertThat(file.getMeasureIntValue("violations")).isGreaterThan(0);

// findbugs is executed on bytecode
List<Issue> issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("findbugs:DM_EXIT")).list();
List<Issue> issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("squid:S1147")).list();
assertThat(issues).hasSize(1);
assertThat(issues.get(0).ruleKey()).isEqualTo("findbugs:DM_EXIT");
assertThat(issues.get(0).ruleKey()).isEqualTo("squid:S1147");

// Squid performs analysis of dependencies
issues = orchestrator.getServer().wsClient().issueClient().find(IssueQuery.create().componentRoots("java:bytecode").rules("squid:CallToDeprecatedMethod")).list();
@@ -201,22 +181,6 @@ public class JavaTest extends ScannerTestCase {
assertThat(result.getLogs()).contains("The folder 'bad' does not exist for 'bad-source-dirs'");
}

/**
* SONARPLUGINS-2203
*/
@Test
public void should_log_message_when_deprecated_properties_are_used() {
assumeTrue(!orchestrator.getServer().version().isGreaterThanOrEquals("4.3"));
SonarScanner build = newScanner(new File("projects/using-deprecated-props"));

BuildResult result = orchestrator.executeBuild(build);
String logs = result.getLogs();
assertThat(logs).contains("/!\\ The 'sources' property is deprecated and is replaced by 'sonar.sources'. Don't forget to update your files.");
assertThat(logs).contains("/!\\ The 'tests' property is deprecated and is replaced by 'sonar.tests'. Don't forget to update your files.");
assertThat(logs).contains("/!\\ The 'binaries' property is deprecated and is replaced by 'sonar.binaries'. Don't forget to update your files.");
assertThat(logs).contains("/!\\ The 'libraries' property is deprecated and is replaced by 'sonar.libraries'. Don't forget to update your files.");
}

/**
* SONARPLUGINS-2256
*/
@@ -303,19 +267,4 @@ public class JavaTest extends ScannerTestCase {
assertThat(logs).contains("java.lang.OutOfMemoryError");
}

private String findbugsFileKey() {
if (orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) {
return "java:bytecode:src/HasFindbugsViolation.java";
} else {
return "java:bytecode:[default].HasFindbugsViolation";
}
}

private String helloFileKey() {
if (orchestrator.getServer().version().isGreaterThanOrEquals("4.2")) {
return "java:sample:src/basic/Hello.java";
} else {
return "java:sample:basic.Hello";
}
}
}

+ 11
- 11
it/src/test/java/com/sonar/runner/it/MultimoduleTest.java View File

@@ -20,7 +20,7 @@
package com.sonar.runner.it;

import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import org.junit.After;
import org.junit.Test;
@@ -41,7 +41,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_simplest_with_props_on_root() {
SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));
SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-root"));

orchestrator.executeBuild(build);

@@ -72,7 +72,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_multi_language_with_same_projectdir() {
SonarRunner build = newScanner(new File("projects/multi-module/multi-language"));
SonarScanner build = newScanner(new File("projects/multi-module/multi-language"));

orchestrator.executeBuild(build);

@@ -95,7 +95,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_simplest_with_props_on_each_module() {
SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));

orchestrator.executeBuild(build);

@@ -118,7 +118,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_warning_when_source_folder_on_root_module() {
SonarRunner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));
SonarScanner build = newScanner(new File("projects/multi-module/simplest/simplest-with-props-on-each-module"));

assertThat(orchestrator.executeBuild(build).getLogs()).contains("/!\\ A multi-module project can't have source folders");
}
@@ -128,7 +128,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_deep_path_for_modules() {
SonarRunner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));
SonarScanner build = newScanner(new File("projects/multi-module/customization/deep-path-for-modules"));

orchestrator.executeBuild(build);

@@ -151,7 +151,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_module_path_with_space() {
SonarRunner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));
SonarScanner build = newScanner(new File("projects/multi-module/customization/module-path-with-space"));

orchestrator.executeBuild(build);

@@ -174,7 +174,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_overwriting_parent_properties() {
SonarRunner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));
SonarScanner build = newScanner(new File("projects/multi-module/customization/overwriting-parent-properties"));

orchestrator.executeBuild(build);

@@ -200,7 +200,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void test_using_config_file_property() {
SonarRunner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));
SonarScanner build = newScanner(new File("projects/multi-module/advanced/using-config-file-prop"));

orchestrator.executeBuild(build);

@@ -223,7 +223,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void should_fail_if_unexisting_base_dir() {
SonarRunner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));
SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-base-dir"));

BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure
@@ -238,7 +238,7 @@ public class MultimoduleTest extends ScannerTestCase {
*/
@Test
public void should_fail_if_unexisting_config_file() {
SonarRunner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));
SonarScanner build = newScanner(new File("projects/multi-module/failures/unexisting-config-file"));

BuildResult result = orchestrator.executeBuildQuietly(build);
// expect build failure

+ 0
- 2
it/src/test/java/com/sonar/runner/it/SonarScannerTestSuite.java View File

@@ -33,8 +33,6 @@ public class SonarScannerTestSuite {
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.setOrchestratorProperty("javaVersion", "LATEST_RELEASE")
.addPlugin("java")
.setOrchestratorProperty("findbugsVersion", "LATEST_RELEASE")
.addPlugin("findbugs")
.setOrchestratorProperty("javascriptVersion", "LATEST_RELEASE")
.addPlugin("javascript")
.build();

+ 2
- 2
it/src/test/resources/requires-bytecode-profile.xml View File

@@ -9,8 +9,8 @@
<priority>MINOR</priority>
</rule>
<rule>
<repositoryKey>findbugs</repositoryKey>
<key>DM_EXIT</key>
<repositoryKey>squid</repositoryKey>
<key>S1147</key>
<priority>MAJOR</priority>
</rule>
</rules>

+ 6
- 0
pom.xml View File

@@ -66,6 +66,12 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>

+ 3
- 0
src/test/java/org/sonarsource/scanner/cli/ConfTest.java View File

@@ -25,12 +25,14 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import org.apache.commons.lang.SystemUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@@ -233,6 +235,7 @@ public class ConfTest {

@Test
public void shouldNotResolveSymlinks() throws IOException, URISyntaxException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path root = temp.getRoot().toPath();
Path realProjectHome = Paths.get(getClass().getResource("ConfTest/shouldLoadModuleConfiguration/project").toURI());
Path linkProjectHome = root.resolve("link");

Loading…
Cancel
Save