@Test public void testCombinationOfRules() { LoadedActiveRule r1 = mockRule("rule1"); LoadedActiveRule r2 = mockRule("rule2"); LoadedActiveRule r3 = mockRule("rule3"); List<LoadedActiveRule> qp1Rules = ImmutableList.of(r1, r2); List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3); List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3); when(loader.load(eq("qp1"))).thenReturn(qp1Rules); when(loader.load(eq("qp2"))).thenReturn(qp2Rules); when(loader.load(eq("qp3"))).thenReturn(qp3Rules); QualityProfiles profiles = mockProfiles("qp1", "qp2", "qp3"); ActiveRules activeRules = provider.provide(loader, profiles); assertThat(activeRules.findAll()).hasSize(3); assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly( RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3")); verify(loader).load(eq("qp1")); verify(loader).load(eq("qp2")); verify(loader).load(eq("qp3")); verifyNoMoreInteractions(loader); }
@Test public void testParamsAreTransformed() { LoadedActiveRule r1 = mockRule("rule1"); LoadedActiveRule r2 = mockRule("rule2"); r2.setParams(ImmutableMap.of("foo1", "bar1", "foo2", "bar2")); List<LoadedActiveRule> qpRules = ImmutableList.of(r1, r2); when(loader.load(eq("qp"))).thenReturn(qpRules); QualityProfiles profiles = mockProfiles("qp"); ActiveRules activeRules = provider.provide(loader, profiles); assertThat(activeRules.findAll()).hasSize(2); assertThat(activeRules.findAll()).extracting("ruleKey", "params").containsOnly( Tuple.tuple(RuleKey.of("rule1", "rule1"), ImmutableMap.of()), Tuple.tuple(RuleKey.of("rule2", "rule2"), ImmutableMap.of("foo1", "bar1", "foo2", "bar2"))); verify(loader).load(eq("qp")); verifyNoMoreInteractions(loader); }
@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); }