Search in sources :

Example 1 with Builder

use of org.sonarqube.ws.Rules.SearchResponse.Builder in project sonarqube by SonarSource.

the class DefaultActiveRulesLoaderTest method responseOfSize.

/**
   * Generates an imaginary protobuf result.
   *
   * @param numberOfRules the number of rules, that the response should contain
   * @param total the number of results on all pages
   * @return the binary stream
   */
private InputStream responseOfSize(int numberOfRules, int total) {
    Builder rules = SearchResponse.newBuilder();
    Actives.Builder actives = Actives.newBuilder();
    IntStream.rangeClosed(1, numberOfRules).mapToObj(i -> RuleKey.of("squid", "S" + i)).forEach(key -> {
        Rule.Builder ruleBuilder = Rule.newBuilder();
        ruleBuilder.setKey(key.toString());
        rules.addRules(ruleBuilder);
        Active.Builder activeBuilder = Active.newBuilder();
        activeBuilder.setCreatedAt("2014-05-27T15:50:45+0100");
        if (EXAMPLE_KEY.equals(key)) {
            activeBuilder.addParams(Rules.Active.Param.newBuilder().setKey(FORMAT_KEY).setValue(FORMAT_VALUE));
            activeBuilder.setSeverity(SEVERITY_VALUE);
        }
        ActiveList activeList = Rules.ActiveList.newBuilder().addActiveList(activeBuilder).build();
        actives.putAllActives(ImmutableSortedMap.of(key.toString(), activeList));
    });
    rules.setActives(actives);
    rules.setPs(numberOfRules);
    rules.setTotal(total);
    return new ByteArrayInputStream(rules.build().toByteArray());
}
Also used : IntStream(java.util.stream.IntStream) Rule(org.sonarqube.ws.Rules.Rule) WsTestUtil(org.sonar.scanner.WsTestUtil) Builder(org.sonarqube.ws.Rules.SearchResponse.Builder) SearchResponse(org.sonarqube.ws.Rules.SearchResponse) Collection(java.util.Collection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) Active(org.sonarqube.ws.Rules.Active) ActiveList(org.sonarqube.ws.Rules.ActiveList) Actives(org.sonarqube.ws.Rules.Actives) Rules(org.sonarqube.ws.Rules) ByteArrayInputStream(java.io.ByteArrayInputStream) Severity(org.sonar.api.rule.Severity) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) RuleKey(org.sonar.api.rule.RuleKey) ScannerWsClient(org.sonar.scanner.bootstrap.ScannerWsClient) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) InputStream(java.io.InputStream) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Active(org.sonarqube.ws.Rules.Active) Actives(org.sonarqube.ws.Rules.Actives) ByteArrayInputStream(java.io.ByteArrayInputStream) ActiveList(org.sonarqube.ws.Rules.ActiveList) Builder(org.sonarqube.ws.Rules.SearchResponse.Builder) Rule(org.sonarqube.ws.Rules.Rule)

Aggregations

ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 IntStream (java.util.stream.IntStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1 RuleKey (org.sonar.api.rule.RuleKey)1 Severity (org.sonar.api.rule.Severity)1 WsTestUtil (org.sonar.scanner.WsTestUtil)1 ScannerWsClient (org.sonar.scanner.bootstrap.ScannerWsClient)1 Rules (org.sonarqube.ws.Rules)1 Active (org.sonarqube.ws.Rules.Active)1 ActiveList (org.sonarqube.ws.Rules.ActiveList)1 Actives (org.sonarqube.ws.Rules.Actives)1 Rule (org.sonarqube.ws.Rules.Rule)1