@Override public boolean equals(@Nullable Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RuleImpl rule = (RuleImpl) o; return key.equals(rule.key); }
@Override public boolean equals(@Nonnull Object o) { if (this == o) { return true; } LineAndLineHashKey that = (LineAndLineHashKey) o; // start with most discriminant field return Objects.equals(line, that.line) && lineHash.equals(that.lineHash) && ruleKey.equals(that.ruleKey); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } LineHashKey that = (LineHashKey) o; // start with most discriminant field return lineHash.equals(that.lineHash) && ruleKey.equals(that.ruleKey); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ActiveRuleKey activeRuleKey = (ActiveRuleKey) o; if (!ruleProfileUuid.equals(activeRuleKey.ruleProfileUuid)) { return false; } return ruleKey.equals(activeRuleKey.ruleKey); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } LineHashAndMessageKey that = (LineHashAndMessageKey) o; // start with most discriminant field return lineHash.equals(that.lineHash) && message.equals(that.message) && ruleKey.equals(that.ruleKey); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } LineAndMessageKey that = (LineAndMessageKey) o; // start with most discriminant field return Objects.equals(line, that.line) && message.equals(that.message) && ruleKey.equals(that.ruleKey); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } LineAndLineHashAndMessage that = (LineAndLineHashAndMessage) o; // start with most discriminant field return Objects.equals(line, that.line) && lineHash.equals(that.lineHash) && message.equals(that.message) && ruleKey.equals(that.ruleKey); }
@Override public boolean apply(@Nonnull RuleDebt input) { return input.ruleKey().equals(RuleKey.of(repoKey, ruleKey)); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Rule rule = (Rule) o; return ruleKey.equals(rule.ruleKey); }
private static Optional<ActiveRuleDto> findRule(List<ActiveRuleDto> activeRules, RuleDefinitionDto rule) { return activeRules.stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst(); }
private void map(Collection<RAW> raws, Collection<BASE> bases, Tracking<RAW, BASE> result) { for (RAW raw : raws) { for (BASE base : bases) { if (result.containsUnmatchedBase(base) && base.getRuleKey().equals(raw.getRuleKey())) { result.match(raw, base); break; } } } }
private void assertThatRuleIsNotPresent(QProfileDto profile, RuleDefinitionDto rule) { Optional<OrgActiveRuleDto> activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst(); assertThat(activeRule).isEmpty(); }
private void assertThatRuleIsNotPresent(QProfileDto profile, RuleDefinitionDto rule) { Optional<OrgActiveRuleDto> activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst(); assertThat(activeRule).isEmpty(); }
private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst() .orElseThrow(IllegalStateException::new); assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); assertThat(params).hasSize(expectedParams.size()); }
private static Stream<String> filterInvalidDeprecatedRuleKeys(ImmutableMap<RuleKey, SingleDeprecatedRuleKey> dbDeprecatedRuleKeysByOldRuleKey, RulesDefinition.Rule rule) { return rule.deprecatedRuleKeys().stream() .map(rk -> { SingleDeprecatedRuleKey singleDeprecatedRuleKey = dbDeprecatedRuleKeysByOldRuleKey.get(rk); if (singleDeprecatedRuleKey == null) { // new deprecated rule key : OK return null; } RuleKey parentRuleKey = RuleKey.of(rule.repository().key(), rule.key()); if (parentRuleKey.equals(singleDeprecatedRuleKey.getNewRuleKeyAsRuleKey())) { // same parent : OK return null; } if (rule.deprecatedRuleKeys().contains(parentRuleKey)) { // the new rule is deprecating the old parentRuleKey : OK return null; } return format("The deprecated rule key [%s] was previously deprecated by [%s]. [%s] should be a deprecated key of [%s],", rk.toString(), singleDeprecatedRuleKey.getNewRuleKeyAsRuleKey().toString(), singleDeprecatedRuleKey.getNewRuleKeyAsRuleKey().toString(), RuleKey.of(rule.repository().key(), rule.key()).toString()); }); }
private void assertThatRuleIsUpdated(QProfileDto profile, RuleDefinitionDto rule, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst() .orElseThrow(IllegalStateException::new); assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); assertThat(params).hasSize(expectedParams.size()); }
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst() .orElseThrow(IllegalStateException::new); assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); assertThat(params).hasSize(expectedParams.size()); if (changes != null) { ActiveRuleChange change = changes.stream() .filter(c -> c.getActiveRule().getId().equals(activeRule.getId())) .findFirst().orElseThrow(IllegalStateException::new); assertThat(change.getInheritance()).isEqualTo(expectedInheritance); assertThat(change.getSeverity()).isEqualTo(expectedSeverity); assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED); } }
private void assertThatRuleIsActivated(QProfileDto profile, RuleDefinitionDto rule, @Nullable List<ActiveRuleChange> changes, String expectedSeverity, @Nullable ActiveRuleInheritance expectedInheritance, Map<String, String> expectedParams) { OrgActiveRuleDto activeRule = db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), profile) .stream() .filter(ar -> ar.getRuleKey().equals(rule.getKey())) .findFirst() .orElseThrow(IllegalStateException::new); assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); assertThat(activeRule.getCreatedAt()).isNotNull(); assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleId(db.getSession(), activeRule.getId()); assertThat(params).hasSize(expectedParams.size()); if (changes != null) { ActiveRuleChange change = changes.stream() .filter(c -> c.getActiveRule().getId().equals(activeRule.getId())) .findFirst().orElseThrow(IllegalStateException::new); assertThat(change.getInheritance()).isEqualTo(expectedInheritance); assertThat(change.getSeverity()).isEqualTo(expectedSeverity); assertThat(change.getType()).isEqualTo(ActiveRuleChange.Type.ACTIVATED); } }
@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); }