Search in sources :

Example 6 with ServerApi

use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.

the class PluginsSynchronizerTests method should_not_synchronize_plugins_that_do_not_support_sonarlint.

@Test
void should_not_synchronize_plugins_that_do_not_support_sonarlint(@TempDir Path dest) {
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"de5308f43260d357acc97712ce4c5475\", \"filename\": \"sonar-java-plugin-5.13.1.18282.jar\", \"sonarLintSupported\": false}" + "]}");
    underTest = new PluginsSynchronizer(Set.of(Language.JAVA), new PluginsStorage(dest), Set.of());
    var anyPluginUpdated = underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    assertThat(dest.resolve("plugin_references.pb")).doesNotExist();
    assertThat(dest.resolve("sonar-java-plugin-5.13.1.18282.jar")).doesNotExist();
    assertThat(anyPluginUpdated).isFalse();
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) Test(org.junit.jupiter.api.Test)

Example 7 with ServerApi

use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.

the class PluginsSynchronizerTests method should_synchronize_unknown_plugins_for_custom_rules.

@Test
void should_synchronize_unknown_plugins_for_custom_rules(@TempDir Path tmp) {
    var dest = tmp.resolve("destDir");
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java-custom\", \"hash\": \"de5308f43260d357acc97712ce4c5475\", \"filename\": \"java-custom-plugin-4.3.0.1456.jar\", \"sonarLintSupported\": true}" + "]}");
    mockServer.addStringResponse("/api/plugins/download?plugin=java-custom", "content-java-custom");
    underTest = new PluginsSynchronizer(Set.of(Language.JS), new PluginsStorage(dest), emptySet());
    var anyPluginUpdated = underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    var references = ProtobufUtil.readFile(dest.resolve("plugin_references.pb"), PluginReferences.parser());
    assertThat(references.getPluginsByKeyMap().values()).extracting("key", "hash", "filename").containsOnly(tuple("java-custom", "de5308f43260d357acc97712ce4c5475", "java-custom-plugin-4.3.0.1456.jar"));
    assertThat(dest.resolve("java-custom-plugin-4.3.0.1456.jar")).hasContent("content-java-custom");
    assertThat(anyPluginUpdated).isTrue();
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) Test(org.junit.jupiter.api.Test)

Example 8 with ServerApi

use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.

the class PluginsSynchronizerTests method should_synchronize_a_plugin_when_hash_is_different.

@Test
void should_synchronize_a_plugin_when_hash_is_different(@TempDir Path tmp) throws Exception {
    var dest = tmp.resolve("destDir");
    Files.createDirectory(dest);
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"de5308f43260d357acc97712ce4c5475\", \"filename\": \"sonar-java-plugin-5.13.1.18282.jar\", \"sonarLintSupported\": true}" + "]}");
    mockServer.addStringResponse("/api/plugins/download?plugin=java", "content-java");
    underTest = new PluginsSynchronizer(Set.of(Language.JAVA), new PluginsStorage(dest), emptySet());
    underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    mockServer.addStringResponse("/api/plugins/installed", "{\"plugins\": [" + "{\"key\": \"java\", \"hash\": \"79dba9cab72d8d31767f47c03d169598\", \"filename\": \"sonar-java-plugin-5.14.0.18485.jar\", \"sonarLintSupported\": true}" + "]}");
    mockServer.addStringResponse("/api/plugins/download?plugin=java", "content-java2");
    var anyPluginUpdated = underTest.synchronize(new ServerApi(mockServer.serverApiHelper()), new ProgressMonitor(null));
    var references = ProtobufUtil.readFile(dest.resolve("plugin_references.pb"), PluginReferences.parser());
    assertThat(references.getPluginsByKeyMap().values()).extracting("key", "hash", "filename").containsOnly(tuple("java", "79dba9cab72d8d31767f47c03d169598", "sonar-java-plugin-5.14.0.18485.jar"));
    assertThat(dest.resolve("sonar-java-plugin-5.14.0.18485.jar")).hasContent("content-java2");
    assertThat(anyPluginUpdated).isTrue();
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) Test(org.junit.jupiter.api.Test)

Example 9 with ServerApi

use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.

the class SonarCloudTest method getOrganization.

@Test
public void getOrganization() {
    var helper = new ServerApi(sonarcloudEndpoint(null), new SonarLintHttpClientOkHttpImpl(SC_CLIENT)).organization();
    var org = helper.getOrganization(SONARCLOUD_ORGANIZATION, progress);
    assertThat(org).isPresent();
    assertThat(org.get().getKey()).isEqualTo(SONARCLOUD_ORGANIZATION);
    assertThat(org.get().getName()).isEqualTo("SonarLint IT Tests");
}
Also used : ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) Test(org.junit.Test)

Example 10 with ServerApi

use of org.sonarsource.sonarlint.core.serverapi.ServerApi in project sonarlint-core by SonarSource.

the class SonarCloudTest method getProject.

@Test
public void getProject() {
    var api = new ServerApi(sonarcloudEndpointITOrg(), new SonarLintHttpClientOkHttpImpl(SC_CLIENT)).component();
    assertThat(api.getProject(projectKey("foo"))).isNotPresent();
    assertThat(api.getProject(projectKey(PROJECT_KEY_RUBY))).isPresent();
}
Also used : ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) Test(org.junit.Test)

Aggregations

ServerApi (org.sonarsource.sonarlint.core.serverapi.ServerApi)23 Test (org.junit.jupiter.api.Test)13 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)13 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 Set (java.util.Set)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1