@VisibleForTesting
    @Nonnull
    Map<String, Object> prepareContextForPaginatedResponse(@Nonnull List<RuleDao> rules) {
        final Map<String, RuleDao> ruleTitleMap = rules
                .stream()
                .collect(Collectors.toMap(RuleDao::title, dao -> dao));

        final Map<String, List<PipelineCompactSource>> result = new HashMap<>();
        rules.forEach(r -> result.put(r.id(), new ArrayList<>()));

        pipelineServiceHelper.groupByRuleName(
                        pipelineService::loadAll, ruleTitleMap.keySet())
                .forEach((ruleTitle, pipelineDaos) -> {
                    result.put(
                            ruleTitleMap.get(ruleTitle).id(),
                            pipelineDaos.stream()
                                    .map(dao -> PipelineCompactSource.builder()
                                            .id(dao.id())
                                            .title(dao.title())
                                            .build())
                                    .toList()
                    );
                });

        return Map.of("used_in_pipelines", result);
    }
@Test
    public void prepareContextForPaginatedResponse_returnsRuleUsageMapIfRulesUsedByPipelines() {
        final List<RuleDao> rules = List.of(
                ruleDao("rule-1", "Rule 1"),
                ruleDao("rule-2", "Rule 2"),
                ruleDao("rule-3", "Rule 3"),
                ruleDao("rule-4", "Rule 4")
        );

        when(pipelineServiceHelper.groupByRuleName(any(), eq(ImmutableSet.of("Rule 1", "Rule 2", "Rule 3", "Rule 4"))))
                .thenReturn(Map.of(
                        "Rule 1", List.of(pipelineDao("pipeline-1", "Pipeline 1")),
                        "Rule 2", List.of(pipelineDao("pipeline-2", "Pipeline 2")),
                        "Rule 3", List.of(
                                pipelineDao("pipeline-1", "Pipeline 1"),
                                pipelineDao("pipeline-2", "Pipeline 2"),
                                pipelineDao("pipeline-3", "Pipeline 3")
                        ),
                        "Rule 4", List.of()
                ));

        assertThat(underTest.prepareContextForPaginatedResponse(rules))
                .isEqualTo(Map.of("used_in_pipelines", Map.of(
                        "rule-1", List.of(PipelineCompactSource.create("pipeline-1", "Pipeline 1")),
                        "rule-2", List.of(PipelineCompactSource.create("pipeline-2", "Pipeline 2")),
                        "rule-3", List.of(
                                PipelineCompactSource.create("pipeline-1", "Pipeline 1"),
                                PipelineCompactSource.create("pipeline-2", "Pipeline 2"),
                                PipelineCompactSource.create("pipeline-3", "Pipeline 3")
                        ),
                        "rule-4", List.of()
                )));
    }