@Test public void onIssueChanges_has_no_effect_if_event_has_neither_previousQGStatus_nor_qualityGate() { Configuration configuration = mock(Configuration.class); QGChangeEvent qualityGateEvent = newQGChangeEvent(configuration, null, null); mockWebhookEnabled(qualityGateEvent.getProject()); underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED); verifyZeroInteractions(webhookPayloadFactory, mockedDbClient); }
@Test public void onIssueChanges_has_no_effect_if_event_has_same_status_in_previous_and_new_QG() { Configuration configuration = mock(Configuration.class); Metric.Level previousStatus = randomLevel(); when(newQualityGate.getStatus()).thenReturn(previousStatus); QGChangeEvent qualityGateEvent = newQGChangeEvent(configuration, previousStatus, newQualityGate); mockWebhookEnabled(qualityGateEvent.getProject()); underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED); verifyZeroInteractions(webhookPayloadFactory, mockedDbClient); }
@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); }
@Test @UseDataProvider("newQGorNot") public void onIssueChanges_calls_webhook_on_main_branch(@Nullable EvaluatedQualityGate newQualityGate) { OrganizationDto organization = dbTester.organizations().insert(); ComponentAndBranch mainBranch = insertMainBranch(organization); SnapshotDto analysis = insertAnalysisTask(mainBranch); Configuration configuration = mock(Configuration.class); QGChangeEvent qualityGateEvent = newQGChangeEvent(mainBranch, analysis, configuration, newQualityGate); mockWebhookEnabled(qualityGateEvent.getProject()); underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED); verifyWebhookCalled(mainBranch, analysis, qualityGateEvent.getProject()); }
public void onIssueChangesCallsWebhookOnBranch(BranchType branchType) { OrganizationDto organization = dbTester.organizations().insert(); ComponentAndBranch mainBranch = insertMainBranch(organization); ComponentAndBranch longBranch = insertProjectBranch(mainBranch.component, branchType, "foo"); SnapshotDto analysis = insertAnalysisTask(longBranch); Configuration configuration = mock(Configuration.class); QGChangeEvent qualityGateEvent = newQGChangeEvent(longBranch, analysis, configuration, null); mockWebhookEnabled(qualityGateEvent.getProject()); underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED); verifyWebhookCalled(longBranch, analysis, qualityGateEvent.getProject()); }
@Test @UseDataProvider("newQGorNot") public void onIssueChanges_calls_webhook_for_changeEvent_with_webhook_enabled(@Nullable EvaluatedQualityGate newQualityGate) { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPublicProject(organization); ComponentAndBranch branch = insertProjectBranch(project, BranchType.SHORT, "foo"); SnapshotDto analysis = insertAnalysisTask(branch); Configuration configuration = mock(Configuration.class); mockPayloadSupplierConsumedByWebhooks(); Map<String, String> properties = new HashMap<>(); properties.put("sonar.analysis.test1", randomAlphanumeric(50)); properties.put("sonar.analysis.test2", randomAlphanumeric(5000)); insertPropertiesFor(analysis.getUuid(), properties); QGChangeEvent qualityGateEvent = newQGChangeEvent(branch, analysis, configuration, newQualityGate); mockWebhookEnabled(qualityGateEvent.getProject()); underTest.onIssueChanges(qualityGateEvent, CHANGED_ISSUES_ARE_IGNORED); ProjectAnalysis projectAnalysis = verifyWebhookCalledAndExtractPayloadFactoryArgument(branch, analysis, qualityGateEvent.getProject()); assertThat(projectAnalysis).isEqualTo( new ProjectAnalysis( new Project(project.uuid(), project.getKey(), project.name()), null, new Analysis(analysis.getUuid(), analysis.getCreatedAt()), new Branch(false, "foo", Branch.Type.SHORT), newQualityGate, null, properties)); }