rule1.getKey().toString()); assertThat(result.getFacets().getFacetsList().stream().filter(f -> "languages".equals(f.getProperty())).findAny().get().getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .as("Facet languages") assertThat(result.getFacets().getFacetsList().stream().filter(f -> "tags".equals(f.getProperty())).findAny().get().getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .as("Facet tags") tuple(rule1.getSystemTags().iterator().next(), 1L)); assertThat(result.getFacets().getFacetsList().stream().filter(f -> "repositories".equals(f.getProperty())).findAny().get().getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .as("Facet repositories") assertThat(result.getFacets().getFacetsList().stream().filter(f -> "severities".equals(f.getProperty())).findAny().get().getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .as("Facet severities") assertThat(result.getFacets().getFacetsList().stream().filter(f -> "statuses".equals(f.getProperty())).findAny().get().getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .as("Facet statuses") assertThat(result.getFacets().getFacetsList().stream().filter(f -> "types".equals(f.getProperty())).findAny().get().getValuesList()) .extracting(Common.FacetValue::getVal, Common.FacetValue::getCount) .as("Facet types")
@Test public void should_include_selected_matching_tag_in_facet() { RuleDefinitionDto rule = db.rules().insert(setSystemTags("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tagA", "x")); indexRules(); SearchResponse result = ws.newRequest() .setParam("facets", "tags") .setParam("tags", "x") .executeProtobuf(SearchResponse.class); assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(v -> entry(v.getVal(), v.getCount())).contains(entry("x", 1L)); }
@Test public void should_included_selected_non_matching_tag_in_facet() { RuleDefinitionDto rule = db.rules().insert(setSystemTags("tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tagA")); indexRules(); SearchResponse result = ws.newRequest() .setParam("facets", "tags") .setParam("tags", "x") .executeProtobuf(SearchResponse.class); assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(v -> entry(v.getVal(), v.getCount())).contains(entry("x", 0L)); }
@Test public void should_not_return_tags_of_foreign_organization() { OrganizationDto organizationWithSpecificTags = db.organizations().insert(); OrganizationDto myOrganization = db.organizations().insert(); RuleDefinitionDto rule = db.rules().insert(setSystemTags("system1", "system2")); insertMetadata(organizationWithSpecificTags, rule, setTags("tag1", "tag2")); indexRules(); SearchResponse result = ws.newRequest() .setParam("facets", "tags") .setParam("f", "tags") .setParam("organization", myOrganization.getKey()) .executeProtobuf(SearchResponse.class); assertThat(result.getRulesList()).extracting(Rule::getKey).containsExactly(rule.getKey().toString()); assertThat(result.getFacets().getFacets(0).getValuesList()) .extracting(v -> tuple(v.getVal(), v.getCount())) .containsExactly( tuple("system1", 1L), tuple("system2", 1L)); }
@Test public void should_list_tags_ordered_by_count_then_by_name_in_tags_facet() { OrganizationDto organization = db.organizations().insert(); RuleDefinitionDto rule = db.rules().insert(setSystemTags("tag7", "tag5", "tag3", "tag1", "tag9")); insertMetadata(organization, rule, setTags("tag2", "tag4", "tag6", "tag8", "tagA")); db.rules().insert(setSystemTags("tag2")); indexRules(); SearchResponse result = ws.newRequest() .setParam("f", "repo,name") .setParam("facets", "tags") .setParam("organization", organization.getKey()) .executeProtobuf(SearchResponse.class); assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(v -> v.getVal(), v -> v.getCount()) .containsExactly(tuple("tag2", 2L), tuple("tag1", 1L), tuple("tag3", 1L), tuple("tag4", 1L), tuple("tag5", 1L), tuple("tag6", 1L), tuple("tag7", 1L), tuple("tag8", 1L), tuple("tag9", 1L), tuple("tagA", 1L)); }
@Test public void should_list_tags_in_tags_facet() { OrganizationDto organization = db.organizations().insert(); String[] tags = get101Tags(); RuleDefinitionDto rule = db.rules().insert(setSystemTags("x")); insertMetadata(organization, rule, setTags(tags)); indexRules(); SearchResponse result = ws.newRequest() .setParam("f", "repo,name") .setParam("facets", "tags") .setParam("organization", organization.getKey()) .executeProtobuf(SearchResponse.class); assertThat(result.getFacets().getFacets(0).getValuesList()).extracting(v -> v.getVal(), v -> v.getCount()) .contains(tuple("tag0", 1L), tuple("tag25", 1L), tuple("tag99", 1L)) .doesNotContain(tuple("x", 1L)); }