Package org.sonar.server.rule

Examples of org.sonar.server.rule.Rule


  public void getByKey() throws InterruptedException {
    RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("javascript", "S001"));
    dao.insert(dbSession, ruleDto);
    dbSession.commit();

    Rule rule = index.getByKey(RuleKey.of("javascript", "S001"));

    assertThat(rule.htmlDescription()).isEqualTo(ruleDto.getDescription());
    assertThat(rule.key()).isEqualTo(ruleDto.getKey());

    assertThat(rule.debtRemediationFunction().type().name())
      .isEqualTo(ruleDto.getRemediationFunction());

    assertThat(Sets.newHashSet(rule.tags())).isEqualTo(ruleDto.getTags());
    assertThat(Sets.newHashSet(rule.systemTags())).isEqualTo(ruleDto.getSystemTags());
  }
View Full Code Here


    assertThat(Sets.newHashSet(rule.systemTags())).isEqualTo(ruleDto.getSystemTags());
  }

  @Test
  public void getByKey_null_if_not_found() throws InterruptedException {
    Rule rule = index.getNullableByKey(RuleKey.of("javascript", "unknown"));

    assertThat(rule).isNull();
  }
View Full Code Here

    dbSession.commit();

    QueryContext options = new QueryContext().setFieldsToReturn(null);
    Result<Rule> results = index.search(new RuleQuery(), options);
    assertThat(results.getHits()).hasSize(1);
    Rule hit = Iterables.getFirst(results.getHits(), null);
    assertThat(hit.key()).isNotNull();
    assertThat(hit.htmlDescription()).isNotNull();
    assertThat(hit.name()).isNotNull();

    options = new QueryContext().setFieldsToReturn(Collections.<String>emptyList());
    results = index.search(new RuleQuery(), options);
    assertThat(results.getHits()).hasSize(1);
    hit = Iterables.getFirst(results.getHits(), null);
    assertThat(hit.key()).isNotNull();
    assertThat(hit.htmlDescription()).isNotNull();
    assertThat(hit.name()).isNotNull();
  }
View Full Code Here

    QueryContext options = new QueryContext();
    options.addFieldsToReturn(RuleNormalizer.RuleField.LANGUAGE.field(), RuleNormalizer.RuleField.STATUS.field());
    Result<Rule> results = index.search(new RuleQuery(), options);
    assertThat(results.getHits()).hasSize(1);

    Rule hit = Iterables.getFirst(results.getHits(), null);
    assertThat(hit.language()).isEqualTo("js");
    assertThat(hit.status()).isEqualTo(RuleStatus.READY);

    try {
      hit.htmlDescription();
      fail();
    } catch (IllegalStateException e) {
      assertThat(e).hasMessage("Field htmlDesc not specified in query options");
    }
  }
View Full Code Here

    RuleDto ruleDto = RuleTesting.newXooX1().setName(nameWithProtectedChars);
    dao.insert(dbSession, ruleDto);
    dbSession.commit();

    Rule rule = index.getByKey(RuleTesting.XOO_X1);
    assertThat(rule.name()).isEqualTo(nameWithProtectedChars);

    RuleQuery protectedCharsQuery = new RuleQuery().setQueryText(nameWithProtectedChars);
    List<Rule> results = index.search(protectedCharsQuery, new QueryContext()).getHits();
    assertThat(results).hasSize(1);
    assertThat(results.get(0).key()).isEqualTo(RuleTesting.XOO_X1);
View Full Code Here

  public void app_with_manual_rules() throws Exception {
    MockUserSession.set().addComponentPermission(UserRole.USER, SUB_PROJECT_KEY, COMPONENT_KEY);
    addComponent();

    Result<Rule> result = mock(Result.class);
    Rule rule = mock(Rule.class);
    when(rule.key()).thenReturn(RuleKey.of("manual", "API"));
    when(rule.name()).thenReturn("API");
    when(result.getHits()).thenReturn(newArrayList(rule));
    when(ruleService.search(any(RuleQuery.class), any(QueryContext.class))).thenReturn(result);

    WsTester.TestRequest request = tester.newGetRequest("api/components", "app").setParam("key", COMPONENT_KEY);
    request.execute().assertJson(getClass(), "app_with_manual_rules.json");
View Full Code Here

  }

  private void addActiveRules(ProjectReferentials ref) {
    for (org.sonar.batch.protocol.input.QProfile qProfile : ref.qProfiles()) {
      for (ActiveRule activeRule : qProfileLoader.findActiveRulesByProfile(qProfile.key())) {
        Rule rule = ruleService.getNonNullByKey(activeRule.key().ruleKey());
        org.sonar.batch.protocol.input.ActiveRule inputActiveRule = new org.sonar.batch.protocol.input.ActiveRule(
          activeRule.key().ruleKey().repository(),
          activeRule.key().ruleKey().rule(),
          rule.name(),
          activeRule.severity(),
          rule.internalKey(),
          qProfile.language());
        for (Map.Entry<String, String> entry : activeRule.params().entrySet()) {
          inputActiveRule.addParam(entry.getKey(), entry.getValue());
        }
        ref.addActiveRule(inputActiveRule);
View Full Code Here

    try {
      Result<Rule> ruleSearchResult = ruleIndex.search(ruleQuery, new QueryContext().setScroll(true)
        .setFieldsToReturn(Arrays.asList(RuleNormalizer.RuleField.KEY.field())));
      Iterator<Rule> rules = ruleSearchResult.scroll();
      while (rules.hasNext()) {
        Rule rule = rules.next();
        try {
          RuleActivation activation = new RuleActivation(rule.key());
          activation.setSeverity(severity);
          List<ActiveRuleChange> changes = activate(dbSession, activation, profileKey);
          result.addChanges(changes);
          if (!changes.isEmpty()) {
            result.incrementSucceeded();
View Full Code Here

      Result<Rule> ruleSearchResult = ruleIndex.search(ruleQuery, new QueryContext().setScroll(true)
        .setFieldsToReturn(Arrays.asList(RuleNormalizer.RuleField.KEY.field())));
      Iterator<Rule> rules = ruleSearchResult.scroll();
      while (rules.hasNext()) {
        try {
          Rule rule = rules.next();
          ActiveRuleKey key = ActiveRuleKey.of(profile, rule.key());
          List<ActiveRuleChange> changes = deactivate(dbSession, key);
          result.addChanges(changes);
          if (!changes.isEmpty()) {
            result.incrementSucceeded();
          }
View Full Code Here

      write409(response, e.ruleKey());
    }
  }

  private void writeResponse(Response response, RuleKey ruleKey) {
    Rule rule = service.getNonNullByKey(ruleKey);
    JsonWriter json = response.newJsonWriter().beginObject().name("rule");
    mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */);
    json.endObject().close();
  }
View Full Code Here

TOP

Related Classes of org.sonar.server.rule.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.