Search in sources :

Example 21 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class StorageAnalyzerTest method testNoModuleStorage.

@Test
public void testNoModuleStorage() {
    when(globalReader.get()).thenReturn(mock(GlobalStorageStatus.class));
    when(moduleReader.apply("module1")).thenReturn(null);
    exception.expect(StorageException.class);
    exception.expectMessage("No data stored for module");
    analyzer.analyze(mock(StorageContainer.class), config, mock(IssueListener.class), new ProgressWrapper(null));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) Test(org.junit.Test)

Example 22 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class ModuleHierarchyDownloaderTest method testNoPaginationWhenJustUnderPageSize.

@Test
public void testNoPaginationWhenJustUnderPageSize() throws IOException {
    TreeWsResponse.Builder responseBuilder = TreeWsResponse.newBuilder().setPaging(Paging.newBuilder().setTotal(PAGE_SIZE));
    for (int i = 0; i < PAGE_SIZE; i++) {
        responseBuilder.addComponents(Component.newBuilder().setId("id" + i).setKey("testRoot" + i));
        WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=id" + i, "/update/show_module1.pb");
    }
    WsClientTestUtils.addResponse(wsClient, "api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=testRoot&ps=500&p=1", responseBuilder.build());
    Map<String, String> fetchModuleHierarchy = downloader.fetchModuleHierarchy("testRoot", new ProgressWrapper(null));
    assertThat(fetchModuleHierarchy).hasSize(PAGE_SIZE + 1);
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse) Test(org.junit.Test)

Example 23 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class ModuleHierarchyDownloaderTest method testPagination.

@Test
public void testPagination() throws IOException {
    TreeWsResponse.Builder responseBuilder = TreeWsResponse.newBuilder().setPaging(Paging.newBuilder().setPageIndex(1).setTotal(501));
    for (int i = 0; i < PAGE_SIZE; i++) {
        responseBuilder.addComponents(Component.newBuilder().setId("id" + i).setKey("testRoot" + i));
        WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=id" + i, "/update/show_module1.pb");
    }
    WsClientTestUtils.addResponse(wsClient, "api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=testRoot&ps=500&p=1", responseBuilder.build());
    responseBuilder = TreeWsResponse.newBuilder().setPaging(Paging.newBuilder().setPageIndex(2).setTotal(501));
    for (int i = 501; i < 502; i++) {
        responseBuilder.addComponents(Component.newBuilder().setId("id" + i).setKey("testRoot" + i));
        WsClientTestUtils.addStreamResponse(wsClient, "api/components/show.protobuf?id=id" + i, "/update/show_module1.pb");
    }
    WsClientTestUtils.addResponse(wsClient, "api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=testRoot&ps=500&p=2", responseBuilder.build());
    Map<String, String> fetchModuleHierarchy = downloader.fetchModuleHierarchy("testRoot", new ProgressWrapper(null));
    assertThat(fetchModuleHierarchy).hasSize(501 + 1);
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) TreeWsResponse(org.sonarqube.ws.WsComponents.TreeWsResponse) Test(org.junit.Test)

Example 24 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class ModuleHierarchyDownloaderTest method testInvalidResponseContent.

@Test
public void testInvalidResponseContent() {
    wsClient = mock(SonarLintWsClient.class);
    WsClientTestUtils.addResponse(wsClient, "api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=testRoot&ps=500&p=1", "invalid response stream");
    downloader = new ModuleHierarchyDownloader(wsClient);
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Failed to process paginated WS");
    downloader.fetchModuleHierarchy("testRoot", new ProgressWrapper(null));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 25 with ProgressWrapper

use of org.sonarsource.sonarlint.core.util.ProgressWrapper in project sonarlint-core by SonarSource.

the class ModuleHierarchyDownloaderTest method testIOException.

@Test
public void testIOException() {
    wsClient = mock(SonarLintWsClient.class);
    WsClientTestUtils.addFailedResponse(wsClient, "api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=testRoot&ps=500&p=1", 503, "error");
    downloader = new ModuleHierarchyDownloader(wsClient);
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Error 503");
    downloader.fetchModuleHierarchy("testRoot", new ProgressWrapper(null));
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Aggregations

ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)38 Test (org.junit.Test)31 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)14 File (java.io.File)11 StorageUpdateCheckResult (org.sonarsource.sonarlint.core.client.api.connected.StorageUpdateCheckResult)9 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)8 Map (java.util.Map)6 Nullable (javax.annotation.Nullable)6 ServerInfos (org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)6 Path (java.nio.file.Path)5 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)5 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.entry (org.assertj.core.api.Assertions.entry)4 Before (org.junit.Before)4 Rule (org.junit.Rule)4 ExpectedException (org.junit.rules.ExpectedException)4