Search in sources :

Example 1 with Rules

use of org.sonarsource.sonarlint.core.proto.Sonarlint.Rules in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method unknown_type.

@Test
public void unknown_type() throws IOException {
    org.sonarqube.ws.Rules.SearchResponse response = org.sonarqube.ws.Rules.SearchResponse.newBuilder().addRules(org.sonarqube.ws.Rules.Rule.newBuilder().setKey("S:101").build()).build();
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addResponse(wsClient, RULES_SEARCH_URL + "&p=1&ps=500", response);
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
    Rules saved = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.RULES_PB), Rules.parser());
    assertThat(saved.getRulesByKeyMap()).hasSize(1);
    assertThat(saved.getRulesByKeyMap().get("S:101").getType()).isEqualTo("");
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) Rules(org.sonarsource.sonarlint.core.proto.Sonarlint.Rules) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) File(java.io.File) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 2 with Rules

use of org.sonarsource.sonarlint.core.proto.Sonarlint.Rules in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method rules_update_protobuf.

@Test
public void rules_update_protobuf() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse(RULES_SEARCH_URL + "&p=1&ps=500", "/update/rulesp1.pb");
    WsClientTestUtils.addStreamResponse(wsClient, RULES_SEARCH_URL + "&p=2&ps=500", "/update/rulesp2.pb");
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
    Rules rules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.RULES_PB), Rules.parser());
    assertThat(rules.getRulesByKeyMap()).hasSize(939);
    ActiveRules jsActiveRules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.ACTIVE_RULES_FOLDER).resolve("js-sonar-way-62960.pb"), ActiveRules.parser());
    assertThat(jsActiveRules.getActiveRulesByKeyMap()).hasSize(85);
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) File(java.io.File) Rules(org.sonarsource.sonarlint.core.proto.Sonarlint.Rules) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 3 with Rules

use of org.sonarsource.sonarlint.core.proto.Sonarlint.Rules in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method rules_update_protobuf_with_org.

@Test
public void rules_update_protobuf_with_org() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse(RULES_SEARCH_URL + "&organization=myOrg&p=1&ps=500", "/update/rulesp1.pb");
    WsClientTestUtils.addStreamResponse(wsClient, RULES_SEARCH_URL + "&organization=myOrg&p=2&ps=500", "/update/rulesp2.pb");
    when(wsClient.getOrganizationKey()).thenReturn("myOrg");
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
    Rules rules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.RULES_PB), Rules.parser());
    assertThat(rules.getRulesByKeyMap()).hasSize(939);
    ActiveRules jsActiveRules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.ACTIVE_RULES_FOLDER).resolve("js-sonar-way-62960.pb"), ActiveRules.parser());
    assertThat(jsActiveRules.getActiveRulesByKeyMap()).hasSize(85);
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) File(java.io.File) Rules(org.sonarsource.sonarlint.core.proto.Sonarlint.Rules) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Aggregations

File (java.io.File)3 Test (org.junit.Test)3 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)3 ActiveRules (org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules)3 Rules (org.sonarsource.sonarlint.core.proto.Sonarlint.Rules)3 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)3