private void writeRule(Rule rule, JsonWriter json) {
   json.prop("key", rule.ruleKey().toString())
       .prop("name", rule.name())
       .prop("description", rule.description());
   addNote(rule, json);
   addDate(rule.createdAt(), "createdAt", json);
   addFormattedDate(rule.createdAt(), "fCreatedAt", json);
   addDate(rule.updatedAt(), "updatedAt", json);
   addFormattedDate(rule.updatedAt(), "fUpdatedAt", json);
 }
Exemplo n.º 2
0
  @Test
  public void return_all_doc_fields_by_default() {
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("javascript", "S001")));
    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();
  }
Exemplo n.º 3
0
  @Test
  public void search_protected_chars() throws InterruptedException {
    String nameWithProtectedChars = "ja#va&sc\"r:ipt";

    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);
  }