Package org.sonar.server.search

Examples of org.sonar.server.search.Result


      .setSystemTags(ImmutableSet.<String>of());
    dbSession.commit();

    // should not have any facet!
    RuleQuery query = new RuleQuery();
    Result result = index.search(query, new QueryContext());
    assertThat(result.getFacets()).isEmpty();

    // should not have any facet on non matching query!
    result = index.search(new RuleQuery().setQueryText("aeiou"), new QueryContext().addFacets(Arrays.asList("repositories")));
    assertThat(result.getFacets()).isEmpty();

    // Repositories Facet is preset
    result = index.search(query, new QueryContext().addFacets(Arrays.asList("repositories", "tags")));
    assertThat(result.getFacets()).isNotNull();
    assertThat(result.getFacets()).hasSize(3);

    // Verify the value of a given facet
    Collection<FacetValue> repoFacets = result.getFacetValues("repositories");
    assertThat(repoFacets).hasSize(2);
    assertThat(Iterables.get(repoFacets, 0).getKey()).isEqualTo("php");
    assertThat(Iterables.get(repoFacets, 0).getValue()).isEqualTo(2);
    assertThat(Iterables.get(repoFacets, 1).getKey()).isEqualTo("javascript");
    assertThat(Iterables.get(repoFacets, 1).getValue()).isEqualTo(1);

    // Check that tag facet has both Tags and SystemTags values
    Collection<FacetValue> tagFacet = result.getFacetValues("tags");
    assertThat(tagFacet).hasSize(3);
    assertThat(Iterables.get(tagFacet, 0).getKey()).isEqualTo("tag1");
    assertThat(Iterables.get(tagFacet, 0).getValue()).isEqualTo(2);
  }
View Full Code Here


  public void search_all_rules() throws InterruptedException {
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("javascript", "S001")));
    dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "S002")));
    dbSession.commit();

    Result results = index.search(new RuleQuery(), new QueryContext());

    assertThat(results.getTotal()).isEqualTo(2);
    assertThat(results.getHits()).hasSize(2);
  }
View Full Code Here

    for (int i = 0; i < max; i++) {
      dao.insert(dbSession, RuleTesting.newDto(RuleKey.of("java", "scroll_" + i)));
    }
    dbSession.commit();

    Result results = index.search(new RuleQuery(), new QueryContext().setScroll(true));

    assertThat(results.getTotal()).isEqualTo(max);
    assertThat(results.getHits()).hasSize(0);

    Iterator<Rule> it = results.scroll();
    int count = 0;
    while (it.hasNext()) {
      count++;
      it.next();
    }
View Full Code Here

    dbSession.commit();

    // from 0 to 1 included
    QueryContext options = new QueryContext();
    options.setOffset(0).setLimit(2);
    Result results = index.search(new RuleQuery(), options);
    assertThat(results.getTotal()).isEqualTo(3);
    assertThat(results.getHits()).hasSize(2);

    // from 0 to 9 included
    options.setOffset(0).setLimit(10);
    results = index.search(new RuleQuery(), options);
    assertThat(results.getTotal()).isEqualTo(3);
    assertThat(results.getHits()).hasSize(3);

    // from 2 to 11 included
    options.setOffset(2).setLimit(10);
    results = index.search(new RuleQuery(), options);
    assertThat(results.getTotal()).isEqualTo(3);
    assertThat(results.getHits()).hasSize(1);

    // from 2 to 11 included
    options.setOffset(2).setLimit(0);
    results = index.search(new RuleQuery(), options);
    assertThat(results.getTotal()).isEqualTo(3);
    assertThat(results.getHits()).hasSize(0);
  }
View Full Code Here

  }

  @Test
  public void search_all_rules() throws Exception {
    List<Rule> rules = newArrayList(mock(Rule.class));
    Result serviceResult = mock(Result.class);
    when(serviceResult.scroll()).thenReturn(rules.iterator());

    when(ruleService.search(any(RuleQuery.class), any(QueryContext.class))).thenReturn(serviceResult);

    HashMap<String, Object> params = newHashMap();
    params.put("pageSize", "-1");
View Full Code Here

    request.setParam("severities", "BLOCKER");

    SearchOptions options = SearchOptions.create(request);
    StringWriter json = new StringWriter();
    JsonWriter jsonWriter = JsonWriter.of(json).beginObject();
    Result result = mock(Result.class);
    when(result.getTotal()).thenReturn(42L);
    options.writeStatistics(jsonWriter, result);
    jsonWriter.endObject().close();

    JSONAssert.assertEquals("{\"total\": 42, \"p\": 3, \"ps\": 10}", json.toString(), true);
  }
View Full Code Here

TOP

Related Classes of org.sonar.server.search.Result

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.