|
30 | 30 | import org.sonar.api.CoreProperties;
|
31 | 31 | import org.sonar.api.batch.postjob.PostJobContext;
|
32 | 32 | import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor;
|
33 |
| -import org.sonar.api.batch.postjob.issue.PostJobIssue; |
34 |
| -import org.sonar.api.batch.rule.Severity; |
35 | 33 | import org.sonar.api.config.PropertyDefinition;
|
36 | 34 | import org.sonar.api.config.PropertyDefinitions;
|
37 | 35 | import org.sonar.api.config.internal.ConfigurationBridge;
|
38 | 36 | import org.sonar.api.config.internal.MapSettings;
|
39 | 37 | import org.sonar.api.utils.MessageException;
|
40 | 38 | import org.sonar.api.utils.System2;
|
41 | 39 |
|
42 |
| -import java.io.File; |
43 |
| -import java.util.ArrayList; |
44 | 40 | import java.util.Arrays;
|
45 | 41 | import java.util.Collections;
|
46 | 42 | import java.util.List;
|
@@ -132,162 +128,6 @@ public void testPreviewModeEmpty() {
|
132 | 128 | Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("success", "SonarQube reported no issues");
|
133 | 129 | }
|
134 | 130 |
|
135 |
| - @Test |
136 |
| - public void testPreviewMode() { |
137 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4", Utils.newMockedInputComponent("toto"), 0); |
138 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg", Utils.newMockedInputFile(new File("toto.java")), 0); |
139 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
140 |
| - |
141 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
142 |
| - when(reporter.getStatus()).thenReturn("success"); |
143 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported no issues"); |
144 |
| - |
145 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
146 |
| - |
147 |
| - commitPublishPostJob.execute(context); |
148 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
149 |
| - Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("success", "SonarQube reported no issues"); |
150 |
| - } |
151 |
| - |
152 |
| - @Test |
153 |
| - public void testIssuesMode() { |
154 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
155 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
156 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
157 |
| - |
158 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
159 |
| - when(reporter.getStatus()).thenReturn("failed"); |
160 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported 2 issues"); |
161 |
| - |
162 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
163 |
| - |
164 |
| - commitPublishPostJob.execute(context); |
165 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
166 |
| - Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 2 issues"); |
167 |
| - } |
168 |
| - |
169 |
| - @Test |
170 |
| - public void testPreviewAndIssueMode() { |
171 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
172 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
173 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
174 |
| - |
175 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
176 |
| - when(reporter.getStatus()).thenReturn("success"); |
177 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported no issues"); |
178 |
| - |
179 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
180 |
| - |
181 |
| - commitPublishPostJob.execute(context); |
182 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
183 |
| - Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("success", "SonarQube reported no issues"); |
184 |
| - } |
185 |
| - |
186 |
| - @Test |
187 |
| - public void testSuccess() { |
188 |
| - Iterable<PostJobIssue> issues = Collections.emptyList(); |
189 |
| - |
190 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
191 |
| - when(reporter.getStatus()).thenReturn("success"); |
192 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported no issues"); |
193 |
| - |
194 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
195 |
| - |
196 |
| - commitPublishPostJob.execute(context); |
197 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
198 |
| - Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("success", "SonarQube reported no issues"); |
199 |
| - } |
200 |
| - |
201 |
| - @Test |
202 |
| - public void testFailed() { |
203 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
204 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
205 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
206 |
| - |
207 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
208 |
| - when(reporter.getStatus()).thenReturn("failed"); |
209 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported no issues"); |
210 |
| - |
211 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
212 |
| - |
213 |
| - commitPublishPostJob.execute(context); |
214 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
215 |
| - Mockito.verify(commitFacade).createOrUpdateSonarQubeStatus("failed", "SonarQube reported no issues"); |
216 |
| - } |
217 |
| - |
218 |
| - @Test |
219 |
| - public void testFailedNotificationExit() { |
220 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.EXIT_CODE.getMeaning()); |
221 |
| - |
222 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
223 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
224 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
225 |
| - |
226 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
227 |
| - when(reporter.getStatus()).thenReturn("failed"); |
228 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported 2 issues"); |
229 |
| - |
230 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
231 |
| - |
232 |
| - Assertions.assertThatThrownBy(() -> commitPublishPostJob.execute(context)).isInstanceOf(MessageException.class).hasMessage("Report status=failed, desc=SonarQube reported 2 issues"); |
233 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
234 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 2 issues"); |
235 |
| - } |
236 |
| - |
237 |
| - @Test |
238 |
| - public void testSuccessNotificationExit() { |
239 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.EXIT_CODE.getMeaning()); |
240 |
| - |
241 |
| - Iterable<PostJobIssue> issues = Collections.emptyList(); |
242 |
| - |
243 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
244 |
| - when(reporter.getStatus()).thenReturn("success"); |
245 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported no issues"); |
246 |
| - |
247 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
248 |
| - |
249 |
| - commitPublishPostJob.execute(context); |
250 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
251 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("success", "SonarQube reported no issues"); |
252 |
| - } |
253 |
| - |
254 |
| - @Test |
255 |
| - public void testFailedNotificationNothing() { |
256 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.NOTHING.getMeaning()); |
257 |
| - |
258 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
259 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
260 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
261 |
| - |
262 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
263 |
| - when(reporter.getStatus()).thenReturn("failed"); |
264 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported 2 issues"); |
265 |
| - |
266 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
267 |
| - |
268 |
| - commitPublishPostJob.execute(context); |
269 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
270 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 2 issues"); |
271 |
| - } |
272 |
| - |
273 |
| - @Test |
274 |
| - public void testSuccessNotificationNothing() { |
275 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.NOTHING.getMeaning()); |
276 |
| - |
277 |
| - Iterable<PostJobIssue> issues = Collections.emptyList(); |
278 |
| - |
279 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
280 |
| - when(reporter.getStatus()).thenReturn("success"); |
281 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported no issues"); |
282 |
| - |
283 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
284 |
| - |
285 |
| - commitPublishPostJob.execute(context); |
286 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
287 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("success", "SonarQube reported no issues"); |
288 |
| - } |
289 |
| - |
290 |
| - |
291 | 131 | @Test
|
292 | 132 | public void testUnexpectedExceptionPublish() {
|
293 | 133 | // not really realistic unexpected error, but good enough for this test
|
@@ -626,75 +466,4 @@ public void testFaileReporterNotificationExit() {
|
626 | 466 | Mockito.verify(reporterBuilder).build(qualityGate, issues);
|
627 | 467 | Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("failed", "SonarQube Condition Error:0 Warning:2 Ok:3 SonarQube reported no issues");
|
628 | 468 | }
|
629 |
| - |
630 |
| - @Test |
631 |
| - public void testFailedWithExceptionWithQualityGageFailSetting() { |
632 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.NOTHING.getMeaning()); |
633 |
| - settings.setProperty(GitLabPlugin.GITLAB_FAIL_ON_QUALITY_GATE, "true"); |
634 |
| - |
635 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
636 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
637 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
638 |
| - |
639 |
| - List<Issue> issuelist = new ArrayList<Issue>(); |
640 |
| - |
641 |
| - QualityGate qualityGate = Mockito.mock(QualityGate.class); |
642 |
| - when(qualityGate.getStatus()).thenReturn(QualityGate.Status.ERROR); |
643 |
| - when(sonarFacade.loadQualityGate()).thenReturn(qualityGate); |
644 |
| - when(sonarFacade.getNewIssues()).thenReturn(issuelist); |
645 |
| - |
646 |
| - |
647 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
648 |
| - when(reporter.getStatus()).thenReturn("failed"); |
649 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported 2 issues"); |
650 |
| - when(reporterBuilder.build(qualityGate, issuelist)).thenReturn(reporter); |
651 |
| - |
652 |
| - Assertions.assertThatThrownBy(() -> commitPublishPostJob.execute(context)).isInstanceOf(MessageException.class).hasMessage("Quality Gate failed. Exiting scan with failure."); |
653 |
| - |
654 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 2 issues"); |
655 |
| - |
656 |
| - } |
657 |
| - |
658 |
| - @Test |
659 |
| - public void testFailedWithoutExceptionWithQualityGageFailSettingAsFalse() { |
660 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.NOTHING.getMeaning()); |
661 |
| - settings.setProperty(GitLabPlugin.GITLAB_FAIL_ON_QUALITY_GATE, "false"); |
662 |
| - |
663 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
664 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
665 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
666 |
| - |
667 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
668 |
| - when(reporter.getStatus()).thenReturn("failed"); |
669 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported 2 issues"); |
670 |
| - |
671 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
672 |
| - |
673 |
| - commitPublishPostJob.execute(context); |
674 |
| - |
675 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
676 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 2 issues"); |
677 |
| - |
678 |
| - } |
679 |
| - |
680 |
| - @Test |
681 |
| - public void testFailedWithoutExceptionWithNoQualityGageFailSetting() { |
682 |
| - settings.setProperty(GitLabPlugin.GITLAB_STATUS_NOTIFICATION_MODE, StatusNotificationsMode.NOTHING.getMeaning()); |
683 |
| - |
684 |
| - PostJobIssue issue1 = Utils.newMockedPostJobIssue("foo:src", Severity.BLOCKER, true, "msg4"); |
685 |
| - PostJobIssue issue2 = Utils.newMockedPostJobIssue("foo", Severity.BLOCKER, true, "msg"); |
686 |
| - Iterable<PostJobIssue> issues = Arrays.asList(issue1, issue2); |
687 |
| - |
688 |
| - Reporter reporter = Mockito.mock(Reporter.class); |
689 |
| - when(reporter.getStatus()).thenReturn("failed"); |
690 |
| - when(reporter.getStatusDescription()).thenReturn("SonarQube reported 2 issues"); |
691 |
| - |
692 |
| - when(reporterBuilder.build(eq(null), any())).thenReturn(reporter); |
693 |
| - |
694 |
| - commitPublishPostJob.execute(context); |
695 |
| - |
696 |
| - Mockito.verify(reporterBuilder).build(eq(null), any()); |
697 |
| - Mockito.verify(commitFacade, never()).createOrUpdateSonarQubeStatus("failed", "SonarQube reported 2 issues"); |
698 |
| - |
699 |
| - } |
700 | 469 | }
|
0 commit comments