private static ActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) { Collection<String> qProfileKeys = getKeys(qProfiles); Set<RuleKey> loadedRulesKey = new HashSet<>(); ActiveRulesBuilder builder = new ActiveRulesBuilder(); for (String qProfileKey : qProfileKeys) { Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey); for (LoadedActiveRule r : qProfileRules) { if (!loadedRulesKey.contains(r.getRuleKey())) { loadedRulesKey.add(r.getRuleKey()); builder.addRule(transform(r, qProfileKey)); } } } return builder.build(); }
private static NewActiveRule transform(LoadedActiveRule activeRule, String qProfileKey) { NewActiveRule.Builder builder = new NewActiveRule.Builder(); builder .setRuleKey(activeRule.getRuleKey()) .setName(activeRule.getName()) .setSeverity(activeRule.getSeverity()) .setCreatedAt(activeRule.getCreatedAt()) .setUpdatedAt(activeRule.getUpdatedAt()) .setLanguage(activeRule.getLanguage()) .setInternalKey(activeRule.getInternalKey()) .setTemplateRuleKey(activeRule.getTemplateRuleKey()) .setQProfileKey(qProfileKey); // load parameters if (activeRule.getParams() != null) { for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) { builder.setParam(params.getKey(), params.getValue()); } } return builder.build(); }
@Test public void no_hotspots_on_pr_or_short_branches() throws IOException { when(branchConfig.isShortOrPullRequest()).thenReturn(true); int total = PAGE_SIZE_1 + PAGE_SIZE_2; WsTestUtil.mockStream(wsClient, urlOfPage(1, true), responseOfSize(PAGE_SIZE_1, total)); WsTestUtil.mockStream(wsClient, urlOfPage(2, true), responseOfSize(PAGE_SIZE_2, total)); Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445"); assertThat(activeRules).hasSize(total); assertThat(activeRules) .filteredOn(r -> r.getRuleKey().equals(EXAMPLE_KEY)) .extracting(LoadedActiveRule::getParams) .extracting(p -> p.get(FORMAT_KEY)) .containsExactly(FORMAT_VALUE); assertThat(activeRules) .filteredOn(r -> r.getRuleKey().equals(EXAMPLE_KEY)) .extracting(LoadedActiveRule::getSeverity) .containsExactly(SEVERITY_VALUE); WsTestUtil.verifyCall(wsClient, urlOfPage(1, true)); WsTestUtil.verifyCall(wsClient, urlOfPage(2, true)); verifyNoMoreInteractions(wsClient); }
@Test public void feed_real_response_encode_qp() throws IOException { int total = PAGE_SIZE_1 + PAGE_SIZE_2; WsTestUtil.mockStream(wsClient, urlOfPage(1, false), responseOfSize(PAGE_SIZE_1, total)); WsTestUtil.mockStream(wsClient, urlOfPage(2, false), responseOfSize(PAGE_SIZE_2, total)); Collection<LoadedActiveRule> activeRules = loader.load("c+-test_c+-values-17445"); assertThat(activeRules).hasSize(total); assertThat(activeRules) .filteredOn(r -> r.getRuleKey().equals(EXAMPLE_KEY)) .extracting(LoadedActiveRule::getParams) .extracting(p -> p.get(FORMAT_KEY)) .containsExactly(FORMAT_VALUE); assertThat(activeRules) .filteredOn(r -> r.getRuleKey().equals(EXAMPLE_KEY)) .extracting(LoadedActiveRule::getSeverity) .containsExactly(SEVERITY_VALUE); WsTestUtil.verifyCall(wsClient, urlOfPage(1, false)); WsTestUtil.verifyCall(wsClient, urlOfPage(2, false)); verifyNoMoreInteractions(wsClient); }
private static ActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) { Collection<String> qProfileKeys = getKeys(qProfiles); Set<RuleKey> loadedRulesKey = new HashSet<>(); ActiveRulesBuilder builder = new ActiveRulesBuilder(); for (String qProfileKey : qProfileKeys) { Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey); for (LoadedActiveRule r : qProfileRules) { if (!loadedRulesKey.contains(r.getRuleKey())) { loadedRulesKey.add(r.getRuleKey()); builder.addRule(transform(r, qProfileKey)); } } } return builder.build(); }
private static NewActiveRule transform(LoadedActiveRule activeRule, String qProfileKey) { NewActiveRule.Builder builder = new NewActiveRule.Builder(); builder .setRuleKey(activeRule.getRuleKey()) .setName(activeRule.getName()) .setSeverity(activeRule.getSeverity()) .setCreatedAt(activeRule.getCreatedAt()) .setUpdatedAt(activeRule.getUpdatedAt()) .setLanguage(activeRule.getLanguage()) .setInternalKey(activeRule.getInternalKey()) .setTemplateRuleKey(activeRule.getTemplateRuleKey()) .setQProfileKey(qProfileKey); // load parameters if (activeRule.getParams() != null) { for (Map.Entry<String, String> params : activeRule.getParams().entrySet()) { builder.setParam(params.getKey(), params.getValue()); } } return builder.build(); }