private void mockWebhookEnabled(ComponentDto... projects) { for (ComponentDto dto : projects) { when(webHooks.isEnabled(dto)).thenReturn(true); } }
private void mockWebhookDisabled(ComponentDto... projects) { for (ComponentDto dto : projects) { when(webHooks.isEnabled(dto)).thenReturn(false); } }
@Override public void onIssueChanges(QGChangeEvent qualityGateEvent, Set<ChangedIssue> changedIssues) { if (!webhooks.isEnabled(qualityGateEvent.getProject())) { return; } Optional<EvaluatedQualityGate> evaluatedQualityGate = qualityGateEvent.getQualityGateSupplier().get(); if (isQGStatusUnchanged(qualityGateEvent, evaluatedQualityGate)) { return; } try (DbSession dbSession = dbClient.openSession(false)) { callWebhook(dbSession, qualityGateEvent, evaluatedQualityGate.orElse(null)); } }
private void verifyWebhookCalled(ComponentAndBranch componentAndBranch, SnapshotDto analysis, ComponentDto project) { verify(webHooks).isEnabled(project); verify(webHooks).sendProjectAnalysisUpdate( eq(new WebHooks.Analysis(componentAndBranch.uuid(), analysis.getUuid(), null)), any()); }
@Test @UseDataProvider("allCombinationsOfStatuses") public void onIssueChanges_has_no_effect_if_no_webhook_is_configured(Metric.Level previousStatus, Metric.Level newStatus) { Configuration configuration1 = mock(Configuration.class); when(newQualityGate.getStatus()).thenReturn(newStatus); QGChangeEvent qualityGateEvent = newQGChangeEvent(configuration1, previousStatus, newQualityGate); mockWebhookDisabled(qualityGateEvent.getProject()); mockedUnderTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED); verify(webHooks).isEnabled(qualityGateEvent.getProject()); verifyZeroInteractions(webhookPayloadFactory, mockedDbClient); }
@Override public void onIssueChanges(QGChangeEvent qualityGateEvent, Set<ChangedIssue> changedIssues) { if (!webhooks.isEnabled(qualityGateEvent.getProject())) { return; } Optional<EvaluatedQualityGate> evaluatedQualityGate = qualityGateEvent.getQualityGateSupplier().get(); if (isQGStatusUnchanged(qualityGateEvent, evaluatedQualityGate)) { return; } try (DbSession dbSession = dbClient.openSession(false)) { callWebhook(dbSession, qualityGateEvent, evaluatedQualityGate.orElse(null)); } }