Search in sources :

Example 1 with TestClientInputFile

use of testutils.TestClientInputFile in project sonarlint-core by SonarSource.

the class ConnectedAnalysisConfigurationTests method testToString.

@Test
void testToString(@TempDir Path temp) throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put("sonar.java.libraries", "foo bar");
    final var srcFile1 = createDirectory(temp.resolve("src1"));
    final var srcFile2 = createDirectory(temp.resolve("src2"));
    ClientInputFile inputFile = new TestClientInputFile(temp, srcFile1, false, StandardCharsets.UTF_8, null);
    ClientInputFile testInputFile = new TestClientInputFile(temp, srcFile2, true, StandardCharsets.UTF_8, null);
    var baseDir = createDirectory(temp.resolve("baseDir"));
    var config = ConnectedAnalysisConfiguration.builder().setProjectKey("foo").setBaseDir(baseDir).addInputFiles(inputFile, testInputFile).putAllExtraProperties(props).build();
    assertThat(config.toString()).isEqualTo("[\n" + "  projectKey: foo\n" + "  baseDir: " + baseDir.toString() + "\n" + "  extraProperties: {sonar.java.libraries=foo bar}\n" + "  moduleKey: null\n" + "  inputFiles: [\n" + "    " + srcFile1.toUri().toString() + " (UTF-8)\n" + "    " + srcFile2.toUri().toString() + " (UTF-8) [test]\n" + "  ]\n" + "]\n");
    assertThat(config.baseDir()).isEqualTo(baseDir);
    assertThat(config.inputFiles()).containsExactly(inputFile, testInputFile);
    assertThat(config.projectKey()).isEqualTo("foo");
    assertThat(config.extraProperties()).containsExactly(entry("sonar.java.libraries", "foo bar"));
    config = ConnectedAnalysisConfiguration.builder().setBaseDir(baseDir).addInputFiles(inputFile, testInputFile).putAllExtraProperties(props).build();
    assertThat(config.toString()).isEqualTo("[\n" + "  baseDir: " + baseDir.toString() + "\n" + "  extraProperties: {sonar.java.libraries=foo bar}\n" + "  moduleKey: null\n" + "  inputFiles: [\n" + "    " + srcFile1.toUri().toString() + " (UTF-8)\n" + "    " + srcFile2.toUri().toString() + " (UTF-8) [test]\n" + "  ]\n" + "]\n");
}
Also used : HashMap(java.util.HashMap) TestClientInputFile(testutils.TestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) TestClientInputFile(testutils.TestClientInputFile) Test(org.junit.jupiter.api.Test)

Example 2 with TestClientInputFile

use of testutils.TestClientInputFile in project sonarlint-core by SonarSource.

the class StandaloneAnalysisConfigurationTests method testToString_and_getters.

@Test
void testToString_and_getters(@TempDir Path temp) throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put("sonar.java.libraries", "foo bar");
    final var srcFile1 = createDirectory(temp.resolve("src1"));
    final var srcFile2 = createDirectory(temp.resolve("src2"));
    final var srcFile3 = createDirectory(temp.resolve("src3"));
    ClientInputFile inputFile = new TestClientInputFile(temp, srcFile1, false, StandardCharsets.UTF_8, null);
    ClientInputFile inputFileWithLanguage = new TestClientInputFile(temp, srcFile2, false, StandardCharsets.UTF_8, Language.JAVA);
    ClientInputFile testInputFile = new TestClientInputFile(temp, srcFile3, true, null, Language.PHP);
    var baseDir = createDirectory(temp.resolve("baseDir"));
    Collection<RuleKey> excludedRules = Arrays.asList(new RuleKey("squid", "S1135"), new RuleKey("squid", "S1181"));
    Collection<RuleKey> includedRules = Arrays.asList(new RuleKey("javascript", "S2424"), new RuleKey("javascript", "S1442"));
    Map<String, String> squidS5Parameters = new HashMap<>();
    squidS5Parameters.put("s5param1", "s5value1");
    squidS5Parameters.put("s5param2", "s5value2");
    Map<String, String> squidS6Parameters = new HashMap<>();
    squidS6Parameters.put("s6param1", "s6value1");
    squidS6Parameters.put("s6param2", "s6value2");
    Map<RuleKey, Map<String, String>> ruleParameters = new HashMap<>();
    ruleParameters.put(RuleKey.parse("squid:S6"), squidS6Parameters);
    var config = StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir).addInputFile(inputFile).addInputFiles(inputFileWithLanguage).addInputFiles(Arrays.asList(testInputFile)).putAllExtraProperties(props).putExtraProperty("sonar.foo", "bar").addExcludedRules(excludedRules).addExcludedRule(RuleKey.parse("squid:S1")).addExcludedRules(RuleKey.parse("squid:S2"), RuleKey.parse("squid:S3")).addIncludedRules(includedRules).addIncludedRule(RuleKey.parse("squid:I1")).addIncludedRules(RuleKey.parse("squid:I2"), RuleKey.parse("squid:I3")).addRuleParameter(RuleKey.parse("squid:S4"), "param1", "value1").addRuleParameters(RuleKey.parse("squid:S5"), squidS5Parameters).addRuleParameters(ruleParameters).build();
    assertThat(config.toString()).isEqualTo("[\n" + "  baseDir: " + baseDir.toString() + "\n" + "  extraProperties: {sonar.java.libraries=foo bar, sonar.foo=bar}\n" + "  moduleKey: null\n" + "  excludedRules: [squid:S1135, squid:S1181, squid:S1, squid:S2, squid:S3]\n" + "  includedRules: [javascript:S2424, javascript:S1442, squid:I1, squid:I2, squid:I3]\n" + "  ruleParameters: {squid:S4={param1=value1}, squid:S5={s5param1=s5value1, s5param2=s5value2}, squid:S6={s6param1=s6value1, s6param2=s6value2}}\n" + "  inputFiles: [\n" + "    " + srcFile1.toUri().toString() + " (UTF-8)\n" + "    " + srcFile2.toUri().toString() + " (UTF-8) [java]\n" + "    " + srcFile3.toUri().toString() + " (default) [test] [php]\n" + "  ]\n" + "]\n");
    assertThat(config.baseDir()).isEqualTo(baseDir);
    assertThat(config.inputFiles()).containsExactly(inputFile, inputFileWithLanguage, testInputFile);
    assertThat(config.extraProperties()).containsExactly(entry("sonar.java.libraries", "foo bar"), entry("sonar.foo", "bar"));
    assertThat(config.excludedRules()).extracting(RuleKey::toString).containsExactly("squid:S1135", "squid:S1181", "squid:S1", "squid:S2", "squid:S3");
    assertThat(config.includedRules()).extracting(RuleKey::toString).containsExactly("javascript:S2424", "javascript:S1442", "squid:I1", "squid:I2", "squid:I3");
    assertThat(config.ruleParameters()).containsKeys(RuleKey.parse("squid:S4"), RuleKey.parse("squid:S5"), RuleKey.parse("squid:S6"));
}
Also used : HashMap(java.util.HashMap) RuleKey(org.sonarsource.sonarlint.core.client.api.common.RuleKey) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) TestClientInputFile(testutils.TestClientInputFile) TestClientInputFile(testutils.TestClientInputFile) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with TestClientInputFile

use of testutils.TestClientInputFile in project sonarlint-core by SonarSource.

the class AnalysisConfigurationTests method testToString_and_getters.

@Test
void testToString_and_getters(@TempDir Path temp) throws Exception {
    Map<String, String> props = new HashMap<>();
    props.put("sonar.java.libraries", "foo bar");
    final var srcFile1 = createDirectory(temp.resolve("src1"));
    final var srcFile2 = createDirectory(temp.resolve("src2"));
    final var srcFile3 = createDirectory(temp.resolve("src3"));
    ClientInputFile inputFile = new TestClientInputFile(temp, srcFile1, false, StandardCharsets.UTF_8, null);
    ClientInputFile inputFileWithLanguage = new TestClientInputFile(temp, srcFile2, false, StandardCharsets.UTF_8, Language.JAVA);
    ClientInputFile testInputFile = new TestClientInputFile(temp, srcFile3, true, null, Language.PHP);
    var baseDir = createDirectory(temp.resolve("baseDir"));
    var activeRuleWithParams = new ActiveRule("php:S123", null);
    activeRuleWithParams.setParams(Map.of("param1", "value1"));
    var config = AnalysisConfiguration.builder().setBaseDir(baseDir).addInputFile(inputFile).addInputFiles(inputFileWithLanguage).addInputFiles(List.of(testInputFile)).putAllExtraProperties(props).putExtraProperty("sonar.foo", "bar").addActiveRules(List.of(new ActiveRule("java:S123", null), new ActiveRule("java:S456", null))).addActiveRule(activeRuleWithParams).addActiveRules(new ActiveRule("python:S123", null), new ActiveRule("python:S456", null)).build();
    assertThat(config).hasToString("[\n" + "  baseDir: " + baseDir + "\n" + "  extraProperties: {sonar.java.libraries=foo bar, sonar.foo=bar}\n" + "  activeRules: [java:S123, java:S456, php:S123{param1=value1}, python:S123, python:S456]\n" + "  inputFiles: [\n" + "    " + srcFile1.toUri() + " (UTF-8)\n" + "    " + srcFile2.toUri() + " (UTF-8) [java]\n" + "    " + srcFile3.toUri() + " (default) [test] [php]\n" + "  ]\n" + "]\n");
    assertThat(config.baseDir()).isEqualTo(baseDir);
    assertThat(config.inputFiles()).containsExactly(inputFile, inputFileWithLanguage, testInputFile);
    assertThat(config.extraProperties()).containsExactly(entry("sonar.java.libraries", "foo bar"), entry("sonar.foo", "bar"));
    assertThat(config.activeRules()).extracting(ActiveRule::getRuleKey).containsExactly("java:S123", "java:S456", "php:S123", "python:S123", "python:S456");
}
Also used : HashMap(java.util.HashMap) TestClientInputFile(testutils.TestClientInputFile) TestClientInputFile(testutils.TestClientInputFile) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 TestClientInputFile (testutils.TestClientInputFile)3 ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)2 Map (java.util.Map)1 RuleKey (org.sonarsource.sonarlint.core.client.api.common.RuleKey)1